dhcp-agent-commits Mailing List for dhcp-agent (Page 30)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv11824 Modified Files: Makefile.am Makefile.in dhcp-agent.h dhcp-arp-discovery.c dhcp-icmp-discovery.c dhcp-icmp.c dhcp-net.c dhcp-packet-build.c Log Message: icmp and arp discovery routines now work Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile.am 19 May 2002 16:24:37 -0000 1.15 --- Makefile.am 19 May 2002 17:53:28 -0000 1.16 *************** *** 14,18 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-test.c dhcp-util.c \ dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c \ --- 14,18 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c \ dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c \ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile.in 19 May 2002 16:24:37 -0000 1.15 --- Makefile.in 19 May 2002 17:53:28 -0000 1.16 *************** *** 83,87 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-test.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcp-arp-discovery.c dhcp-route.c --- 83,87 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcp-arp-discovery.c dhcp-route.c *************** *** 110,114 **** dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = ! dhcpclient_OBJECTS = dhcp-test.o dhcp-util.o dhcp-align.o dhcp-net.o \ dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o dhcp-arp.o \ dhcp-icmp.o dhcp-log.o dhcp-daemon.o dhcp-client-cache.o \ --- 110,114 ---- dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = ! dhcpclient_OBJECTS = dhcp-client.o dhcp-util.o dhcp-align.o dhcp-net.o \ dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o dhcp-arp.o \ dhcp-icmp.o dhcp-log.o dhcp-daemon.o dhcp-client-cache.o \ *************** *** 141,152 **** .deps/dhcp-arp.P .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ ! .deps/dhcp-client-states.P .deps/dhcp-com.P .deps/dhcp-convert.P \ ! .deps/dhcp-daemon.P .deps/dhcp-eth.P .deps/dhcp-files.P \ ! .deps/dhcp-icmp-discovery.P .deps/dhcp-icmp.P .deps/dhcp-interface.P \ ! .deps/dhcp-ip.P .deps/dhcp-list.P .deps/dhcp-log.P .deps/dhcp-net.P \ ! .deps/dhcp-options-strings.P .deps/dhcp-packet-build.P \ ! .deps/dhcp-print.P .deps/dhcp-route.P .deps/dhcp-rtt.P \ ! .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P \ ! .deps/dhcp-test.P .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) --- 141,152 ---- .deps/dhcp-arp.P .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ ! .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ ! .deps/dhcp-convert.P .deps/dhcp-daemon.P .deps/dhcp-eth.P \ ! .deps/dhcp-files.P .deps/dhcp-icmp-discovery.P .deps/dhcp-icmp.P \ ! .deps/dhcp-interface.P .deps/dhcp-ip.P .deps/dhcp-list.P \ ! .deps/dhcp-log.P .deps/dhcp-net.P .deps/dhcp-options-strings.P \ ! .deps/dhcp-packet-build.P .deps/dhcp-print.P .deps/dhcp-route.P \ ! .deps/dhcp-rtt.P .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P \ ! .deps/dhcp-sysconf.P .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** dhcp-agent.h 19 May 2002 16:24:37 -0000 1.34 --- dhcp-agent.h 19 May 2002 17:53:28 -0000 1.35 *************** *** 796,799 **** --- 796,800 ---- extern uint32_t icmp_mask_get_mask(icmp_obj *icmp_p); extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); + extern int icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet, int len); /* Alignment functions. */ Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-arp-discovery.c 19 May 2002 16:24:37 -0000 1.2 --- dhcp-arp-discovery.c 19 May 2002 17:53:28 -0000 1.3 *************** *** 44,55 **** received_addr = arp_get_sender_protocol_address(net->arp_p); - /* check for arp type, header length, type, address lengths, - * and op type. */ - - info_message("%d %d %d %d %d %d", net->type, arp_get_hardware_type(net->arp_p), - arp_get_protocol_type(net->arp_p), arp_get_hardware_len(net->arp_p), - arp_get_protocol_len(net->arp_p), arp_get_op(net->arp_p)); - - if((net->type == RAWNET_ARP) && (arp_get_hardware_type(net->arp_p) == ARP_HRD_ETH) && --- 44,47 ---- *************** *** 87,91 **** sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, &sender_addr, ETH_ADDR_LEN); /* just free up pair. FIXME: this isn't good because we're --- 79,83 ---- sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); /* just free up pair. FIXME: this isn't good because we're Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-icmp-discovery.c 19 May 2002 16:24:37 -0000 1.3 --- dhcp-icmp-discovery.c 19 May 2002 17:53:28 -0000 1.4 *************** *** 80,90 **** } ! /* Check for icmp mask response. */ static int icmp_check_echo_reply(void *arg) { rawnet_t *net = arg; ! ! if((net->type = RAWNET_ICMP) && (icmp_get_type(net->icmp_p) == ICMP_ECHOREPLY)) return 1; --- 80,90 ---- } ! /* Check for icmp echo reply. */ static int icmp_check_echo_reply(void *arg) { rawnet_t *net = arg; ! ! if((net->type == RAWNET_ICMP) && (icmp_get_type(net->icmp_p) == ICMP_ECHOREPLY)) return 1; *************** *** 94,98 **** /* Send out an echo request per retries to get latency of host. */ ! int icmp_do_echo(rawnet_t *net, ip_addr_t dest_addr, eth_addr_t dest_mac, int retries) { uint32_t id, seq; --- 94,98 ---- /* Send out an echo request per retries to get latency of host. */ ! int icmp_do_echo(rawnet_t *net, ip_addr_t dest_addr, eth_addr_t dest_mac) { uint32_t id, seq; *************** *** 101,135 **** id = get_random(); ! seq = 0; ! ! while(retries--) { ! ! /* we need to rebuild each time for different sequence ! numbers. */ ! ! seq++; ! build_icmp_echo_request(net, net->ip_addr, dest_addr, net->hw_addr, dest_mac, id, seq); ! ! gettimeofday(&before, NULL); ! if(rawnet_packet_transact(net, net, NULL, icmp_check_echo_reply)) { ! /* on a timeout we set the latency to -1 */ ! continue; ! } ! gettimeofday(&after, NULL); ! difference = timeval_diff(before, after); ! ! /* milliseconds are accurate enough for us. ! * FIXME: the integer may overflow if our ! * rtt mechanism is setup to wait for too long before a ! * timeout. */ ! latency = (difference.tv_sec * 1000); ! latency += (difference.tv_usec/1000); ! return latency; } ! return -1; } --- 101,125 ---- id = get_random(); ! seq = get_random(); ! build_icmp_echo_request(net, net->ip_addr, dest_addr, net->hw_addr, dest_mac, id, seq); ! gettimeofday(&before, NULL); ! if(rawnet_packet_transact(net, net, NULL, icmp_check_echo_reply)) { ! /* on a timeout we set the latency to -1 */ ! return -1; } + gettimeofday(&after, NULL); + difference = timeval_diff(before, after); ! /* milliseconds are accurate enough for us. ! * FIXME: the integer may overflow if our ! * rtt mechanism is setup to wait for too long before a ! * timeout. */ ! ! latency = (difference.tv_sec * 1000); ! latency += (difference.tv_usec/1000); + return latency; } *************** *** 144,148 **** /* FIXME: we need to underengineer this code. */ ! list_t *icmp_rtt_discovery(rawnet_t *net, int retries, int sends, list_t *addresses) { list_t *rtts = NULL; --- 134,138 ---- /* FIXME: we need to underengineer this code. */ ! list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses, int sends) { list_t *rtts = NULL; *************** *** 152,160 **** eth_addr_t dest_mac; - if(retries <= 0 || sends <= 0) { /* let's not get hosed shall we? */ - error_message("icmp rtt discovery: received invalid retry or send count."); - return NULL; - } - /* Our algorithm works as such: send out an ICMP echo request * and wait for a reply. We count the total number of --- 142,145 ---- *************** *** 173,179 **** * arp_discover_hardware_address for that. */ ! if(arp_discover_hardware_address(net, retries, *host_addr, &dest_mac)) { ! /* No arp reply. Skip. */ ! warn_message("icmp rtt discovery: could not ARP for address for %s -- skipping", network_address_to_string_static(*host_addr)); continue; } --- 158,163 ---- * arp_discover_hardware_address for that. */ ! if(route_find(net, *host_addr, &dest_mac)) { ! error_message("icmp rtt discovery: could not find route for address for %s -- skipping", network_address_to_string_static(*host_addr)); continue; } *************** *** 190,194 **** /* fill up our latency array. */ for(send_count = 0; send_count < sends; send_count++) ! latency[send_count] = icmp_do_echo(net, *(host_addr), dest_mac, retries); /* This part is a little tricky. We want to make sure --- 174,178 ---- /* fill up our latency array. */ for(send_count = 0; send_count < sends; send_count++) ! latency[send_count] = icmp_do_echo(net, *(host_addr), dest_mac); /* This part is a little tricky. We want to make sure Index: dhcp-icmp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-icmp.c 17 Feb 2002 04:37:35 -0000 1.5 --- dhcp-icmp.c 19 May 2002 17:53:28 -0000 1.6 *************** *** 154,161 **** } ! void icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet) { align_icmp(packet, &icmp->icmp_header); packet += ICMP_HDR_LEN; switch(icmp->icmp_header.icmp_type) { --- 154,165 ---- } ! int icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet, int len) { + if(len < ICMP_LEN_MIN) + return -1; + align_icmp(packet, &icmp->icmp_header); packet += ICMP_HDR_LEN; + len -= ICMP_HDR_LEN; switch(icmp->icmp_header.icmp_type) { *************** *** 165,169 **** align_icmp_echo(packet, &icmp->icmp_msg.echo); ! break; case ICMP_MASK: --- 169,173 ---- align_icmp_echo(packet, &icmp->icmp_msg.echo); ! return 0; case ICMP_MASK: *************** *** 171,175 **** align_icmp_mask(packet, &icmp->icmp_msg.mask); ! break; default: --- 175,179 ---- align_icmp_mask(packet, &icmp->icmp_msg.mask); ! return 0; default: *************** *** 178,182 **** } ! return; } --- 182,186 ---- } ! return -1; } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-net.c 19 May 2002 16:24:37 -0000 1.19 --- dhcp-net.c 19 May 2002 17:53:28 -0000 1.20 *************** *** 367,371 **** int rawnet_up(rawnet_t *net) { - net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscious); if(net->pcap == NULL) { --- 367,370 ---- *************** *** 464,468 **** case IP_PROTO_ICMP: ! break; default: --- 463,471 ---- case IP_PROTO_ICMP: ! if(icmp_read_packet_image(net->icmp_p, packet, pkthdr.caplen) < 0) ! return RAWNET_MALFORMED_PACKET; ! ! net->type = RAWNET_ICMP; ! return RAWNET_OK; default: Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-packet-build.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-packet-build.c 25 Feb 2002 01:39:30 -0000 1.2 --- dhcp-packet-build.c 19 May 2002 17:53:28 -0000 1.3 *************** *** 254,258 **** { ip_set_hl(net->ip_p, IP_HDR_LEN); ! ip_set_tos(net->ip_p, IP_TOS_RELIABILITY); ip_set_len(net->ip_p, ip_len); ip_set_id(net->ip_p, IP_DF); --- 254,258 ---- { ip_set_hl(net->ip_p, IP_HDR_LEN); ! ip_set_tos(net->ip_p, IP_TOS_DEFAULT); ip_set_len(net->ip_p, ip_len); ip_set_id(net->ip_p, IP_DF); |
From: Thamer Al-H. <act...@us...> - 2002-05-19 16:24:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv24153 Modified Files: Makefile.am Makefile.in configure dhcp-agent.h dhcp-align.c dhcp-arp-discovery.c dhcp-arp.c dhcp-files.c dhcp-icmp-discovery.c dhcp-net.c Log Message: fixed up arp-discovery to work Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Makefile.am 18 May 2002 18:10:09 -0000 1.14 --- Makefile.am 19 May 2002 16:24:37 -0000 1.15 *************** *** 14,18 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c \ dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c \ --- 14,18 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-test.c dhcp-util.c \ dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c \ *************** *** 21,25 **** dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 21,25 ---- dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c dhcp-route.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Makefile.in 18 May 2002 18:10:09 -0000 1.14 --- Makefile.in 19 May 2002 16:24:37 -0000 1.15 *************** *** 83,87 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcp-arp-discovery.c --- 83,87 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-test.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcp-arp-discovery.c dhcp-route.c *************** *** 110,114 **** dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = ! dhcpclient_OBJECTS = dhcp-client.o dhcp-util.o dhcp-align.o dhcp-net.o \ dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o dhcp-arp.o \ dhcp-icmp.o dhcp-log.o dhcp-daemon.o dhcp-client-cache.o \ --- 110,114 ---- dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = ! dhcpclient_OBJECTS = dhcp-test.o dhcp-util.o dhcp-align.o dhcp-net.o \ dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o dhcp-arp.o \ dhcp-icmp.o dhcp-log.o dhcp-daemon.o dhcp-client-cache.o \ *************** *** 116,120 **** dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcp-icmp-discovery.o dhcp-arp-discovery.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = --- 116,121 ---- dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcp-icmp-discovery.o dhcp-arp-discovery.o \ ! dhcp-route.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = *************** *** 140,151 **** .deps/dhcp-arp.P .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ ! .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ ! .deps/dhcp-convert.P .deps/dhcp-daemon.P .deps/dhcp-eth.P \ ! .deps/dhcp-files.P .deps/dhcp-icmp-discovery.P .deps/dhcp-icmp.P \ ! .deps/dhcp-interface.P .deps/dhcp-ip.P .deps/dhcp-list.P \ ! .deps/dhcp-log.P .deps/dhcp-net.P .deps/dhcp-options-strings.P \ ! .deps/dhcp-packet-build.P .deps/dhcp-print.P .deps/dhcp-rtt.P \ .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P \ ! .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) --- 141,152 ---- .deps/dhcp-arp.P .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ ! .deps/dhcp-client-states.P .deps/dhcp-com.P .deps/dhcp-convert.P \ ! .deps/dhcp-daemon.P .deps/dhcp-eth.P .deps/dhcp-files.P \ ! .deps/dhcp-icmp-discovery.P .deps/dhcp-icmp.P .deps/dhcp-interface.P \ ! .deps/dhcp-ip.P .deps/dhcp-list.P .deps/dhcp-log.P .deps/dhcp-net.P \ ! .deps/dhcp-options-strings.P .deps/dhcp-packet-build.P \ ! .deps/dhcp-print.P .deps/dhcp-route.P .deps/dhcp-rtt.P \ .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P \ ! .deps/dhcp-test.P .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) Index: configure =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** configure 14 Feb 2002 10:43:34 -0000 1.10 --- configure 19 May 2002 16:24:37 -0000 1.11 *************** *** 1,5 **** #! /bin/sh # Guess values for system-dependent variables and create Makefiles. ! # Generated by Autoconf 2.50 for dhcp-agent 0.351a. # # Report bugs to <tm...@wh...>. --- 1,5 ---- #! /bin/sh # Guess values for system-dependent variables and create Makefiles. ! # Generated by Autoconf 2.50 for dhcp-agent 0.36. # # Report bugs to <tm...@wh...>. *************** *** 145,150 **** PACKAGE_NAME='dhcp-agent' PACKAGE_TARNAME='dhcp-agent' ! PACKAGE_VERSION='0.351a' ! PACKAGE_STRING='dhcp-agent 0.351a' PACKAGE_BUGREPORT='tm...@wh...' --- 145,150 ---- PACKAGE_NAME='dhcp-agent' PACKAGE_TARNAME='dhcp-agent' ! PACKAGE_VERSION='0.36' ! PACKAGE_STRING='dhcp-agent 0.36' PACKAGE_BUGREPORT='tm...@wh...' *************** *** 554,558 **** # This message is too long to be a string in the A/UX 3.1 sh. cat <<EOF ! \`configure' configures dhcp-agent 0.351a to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... --- 554,558 ---- # This message is too long to be a string in the A/UX 3.1 sh. cat <<EOF ! \`configure' configures dhcp-agent 0.36 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... *************** *** 616,620 **** if test -n "$ac_init_help"; then case $ac_init_help in ! short | recursive ) echo "Configuration of dhcp-agent 0.351a:";; esac cat <<\EOF --- 616,620 ---- if test -n "$ac_init_help"; then case $ac_init_help in ! short | recursive ) echo "Configuration of dhcp-agent 0.36:";; esac cat <<\EOF *************** *** 682,686 **** if $ac_init_version; then cat <<\EOF ! dhcp-agent configure 0.351a generated by GNU Autoconf 2.50 --- 682,686 ---- if $ac_init_version; then cat <<\EOF ! dhcp-agent configure 0.36 generated by GNU Autoconf 2.50 *************** *** 697,701 **** running configure, to aid debugging if configure makes a mistake. ! It was created by dhcp-agent $as_me 0.351a, which was generated by GNU Autoconf 2.50. Invocation command line was --- 697,701 ---- running configure, to aid debugging if configure makes a mistake. ! It was created by dhcp-agent $as_me 0.36, which was generated by GNU Autoconf 2.50. Invocation command line was *************** *** 1103,1107 **** PACKAGE=dhcp-agent ! VERSION=0.351a if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then --- 1103,1107 ---- PACKAGE=dhcp-agent ! VERSION=0.36 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then *************** *** 3016,3020 **** cat >>$CONFIG_STATUS <<EOF ac_cs_version="\\ ! dhcp-agent config.status 0.351a configured by $0, generated by GNU Autoconf 2.50, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" --- 3016,3020 ---- cat >>$CONFIG_STATUS <<EOF ac_cs_version="\\ ! dhcp-agent config.status 0.36 configured by $0, generated by GNU Autoconf 2.50, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" *************** *** 3104,3108 **** ## ----------------------- ## ! This file was extended by $as_me (dhcp-agent 0.351a) 2.50, executed with > $ac_cs_invocation on `(hostname || uname -n) 2>/dev/null | sed 1q` --- 3104,3108 ---- ## ----------------------- ## ! This file was extended by $as_me (dhcp-agent 0.36) 2.50, executed with > $ac_cs_invocation on `(hostname || uname -n) 2>/dev/null | sed 1q` Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** dhcp-agent.h 19 May 2002 00:34:22 -0000 1.33 --- dhcp-agent.h 19 May 2002 16:24:37 -0000 1.34 *************** *** 552,555 **** --- 552,559 ---- extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr); + /* routing table routines. */ + + extern int route_find(rawnet_t *net, ip_addr_t addr, eth_addr_t *dest_mac); + /* Daemon routines. */ *************** *** 757,760 **** --- 761,766 ---- extern unsigned char *arp_get_sender_protocol_address(arp_obj *arp); + extern int arp_read_packet_image(arp_obj *arp, const unsigned char *packet, int len); + /* UDP obj routines. */ *************** *** 800,803 **** --- 806,811 ---- extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); + extern void align_arp_header(const unsigned char *data, struct arp_hdr *header); + extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); /* Linked List routines. */ Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-align.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-align.c 12 Feb 2002 15:23:59 -0000 1.4 --- dhcp-align.c 19 May 2002 16:24:37 -0000 1.5 *************** *** 195,196 **** --- 195,229 ---- return; } + + void align_arp_header(const unsigned char *data, struct arp_hdr *header) + { + memcpy(&header->ar_hrd, data, sizeof(header->ar_hrd)); + data += sizeof(header->ar_hrd); + + memcpy(&header->ar_pro, data, sizeof(header->ar_pro)); + data += sizeof(header->ar_pro); + + memcpy(&header->ar_hln, data, sizeof(header->ar_hln)); + data += sizeof(header->ar_hln); + + memcpy(&header->ar_pln, data, sizeof(header->ar_pln)); + data += sizeof(header->ar_pln); + + memcpy(&header->ar_op, data, sizeof(header->ar_op)); + + return; + } + + void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data) + { + memcpy(&arp_data->ar_sha, data, sizeof(arp_data->ar_sha)); + data += sizeof(arp_data->ar_sha); + + memcpy(&arp_data->ar_spa, data, sizeof(arp_data->ar_spa)); + data += sizeof(arp_data->ar_spa); + + memcpy(&arp_data->ar_tha, data, sizeof(arp_data->ar_tha)); + data += sizeof(arp_data->ar_tha); + + memcpy(&arp_data->ar_tpa, data, sizeof(arp_data->ar_tpa)); + } Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-arp-discovery.c 25 Feb 2002 01:39:29 -0000 1.1 --- dhcp-arp-discovery.c 19 May 2002 16:24:37 -0000 1.2 *************** *** 47,50 **** --- 47,55 ---- * and op type. */ + info_message("%d %d %d %d %d %d", net->type, arp_get_hardware_type(net->arp_p), + arp_get_protocol_type(net->arp_p), arp_get_hardware_len(net->arp_p), + arp_get_protocol_len(net->arp_p), arp_get_op(net->arp_p)); + + if((net->type == RAWNET_ARP) && (arp_get_hardware_type(net->arp_p) == ARP_HRD_ETH) && *************** *** 64,68 **** } ! extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr) { list_t *arg_list = NULL; --- 69,73 ---- } ! int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr) { list_t *arg_list = NULL; *************** *** 72,77 **** arg_list = add_to_list(arg_list, net); ! build_arp_request(net, 0, address, net->hw_addr); /* 0 for source ip, address to discover for dest, ! * our hardware address so we get a reply back. */ while(retries--) { --- 77,82 ---- arg_list = add_to_list(arg_list, net); ! build_arp_request(net, net->ip_addr, address, net->hw_addr); /* 0 for source ip, address to discover for dest, ! * our hardware address so we get a reply back. */ while(retries--) { Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-arp.c 25 Feb 2002 01:39:29 -0000 1.7 --- dhcp-arp.c 19 May 2002 16:24:37 -0000 1.8 *************** *** 100,104 **** uint16_t arp_get_op(arp_obj *arp) { ! return(arp->header.ar_op); } --- 100,104 ---- uint16_t arp_get_op(arp_obj *arp) { ! return(ntohs(arp->header.ar_op)); } *************** *** 164,165 **** --- 164,179 ---- return; } + + int arp_read_packet_image(arp_obj *arp, const unsigned char *packet, int len) + { + if(len < (ARP_HDR_LEN + ARP_ETHIP_LEN)) + return -1; + + align_arp_header(packet, &arp->header); + packet += ARP_HDR_LEN; + + align_arp_data(packet, &arp->arp_data); + + return 0; + } + Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-files.c 9 Feb 2002 16:22:35 -0000 1.5 --- dhcp-files.c 19 May 2002 16:24:37 -0000 1.6 *************** *** 21,24 **** --- 21,25 ---- * * Handles our variable files. + * */ Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-icmp-discovery.c 25 Feb 2002 01:39:29 -0000 1.2 --- dhcp-icmp-discovery.c 19 May 2002 16:24:37 -0000 1.3 *************** *** 176,180 **** /* No arp reply. Skip. */ warn_message("icmp rtt discovery: could not ARP for address for %s -- skipping", network_address_to_string_static(*host_addr)); ! break; } --- 176,180 ---- /* No arp reply. Skip. */ warn_message("icmp rtt discovery: could not ARP for address for %s -- skipping", network_address_to_string_static(*host_addr)); ! continue; } *************** *** 245,248 **** --- 245,249 ---- } + xfree(latency); /* free our latency array. */ rtts = add_to_list(rtts, average_latency); } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-net.c 19 May 2002 00:34:22 -0000 1.18 --- dhcp-net.c 19 May 2002 16:24:37 -0000 1.19 *************** *** 428,432 **** case ETH_TYPE_ARP: ! break; case ETH_TYPE_IP: --- 428,436 ---- case ETH_TYPE_ARP: ! if(arp_read_packet_image(net->arp_p, packet, pkthdr.caplen) < 0) ! return RAWNET_MALFORMED_PACKET; ! ! net->type = RAWNET_ARP; ! return RAWNET_OK; case ETH_TYPE_IP: |
From: Thamer Al-H. <act...@us...> - 2002-05-19 00:35:42
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv24169 Modified Files: dhcp-client.c Log Message: client now correctly downs interface on exit Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-client.c 18 May 2002 17:50:49 -0000 1.17 --- dhcp-client.c 19 May 2002 00:35:39 -0000 1.18 *************** *** 168,171 **** --- 168,172 ---- error_message("could not send signal to dhcpclient process."); error_message("maybe it's not running?"); + return; } *************** *** 368,372 **** /* Go in background now before main loop. */ ! if(want_background) { /* are we interactive? if so stay in foreground. */ destroy_dhcp_client_control(dc); --- 369,374 ---- /* Go in background now before main loop. */ ! if(want_background) { /* are we interactive? if so stay in foreground. ! * ... otherwise ... */ destroy_dhcp_client_control(dc); |
From: Thamer Al-H. <act...@us...> - 2002-05-19 00:35:38
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv24142 Modified Files: COST configure.in Log Message: just a COST file update (heh), and the configure.in with a new version number Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** COST 18 May 2002 18:10:09 -0000 1.7 --- COST 19 May 2002 00:35:35 -0000 1.8 *************** *** 3,8 **** May - June 2001 ! 3 pots of coffee; 42 camel filter cigarretes; one sorry poser; ! cleaned up apartment 0 times; April - May 2001 --- 3,9 ---- May - June 2001 ! 18 pots of coffee; 122 camel filter cigarretes; one sorry poser; ! cleaned up apartment 0 times; bought one futon; 12 measely rye ! beers; April - May 2001 Index: configure.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** configure.in 14 Feb 2002 10:43:34 -0000 1.10 --- configure.in 19 May 2002 00:35:35 -0000 1.11 *************** *** 5,10 **** dnl init ! AC_INIT(dhcp-agent, 0.351a, tm...@wh...) ! AM_INIT_AUTOMAKE(dhcp-agent, 0.351a) AM_CONFIG_HEADER(config.h) --- 5,10 ---- dnl init ! AC_INIT(dhcp-agent, 0.36, tm...@wh...) ! AM_INIT_AUTOMAKE(dhcp-agent, 0.36) AM_CONFIG_HEADER(config.h) |
From: Thamer Al-H. <act...@us...> - 2002-05-19 00:34:25
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv23971 Modified Files: dhcp-net.c dhcp-client-control.c dhcp-client-states.c dhcp-agent.h Log Message: fixed up interface handling so we now only down interface upon release -- and we don't reinitialize IP if the interface is up and running. Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-net.c 18 May 2002 18:10:09 -0000 1.17 --- dhcp-net.c 19 May 2002 00:34:22 -0000 1.18 *************** *** 109,121 **** { /* are we using a fake address? */ ! if(net->fake_hw_addr == NULL) { ! return(eth_get(net->eth, addr)); ! } else { memcpy(addr, net->fake_hw_addr->data, ETH_ADDR_LEN); return 0; } } ! /* get real interface address skipping fake if its available. */ int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr) { --- 109,121 ---- { /* are we using a fake address? */ ! if(net->fake_hw_addr != NULL) { memcpy(addr, net->fake_hw_addr->data, ETH_ADDR_LEN); return 0; + } else { + return(eth_get(net->eth, addr)); } } ! /* get real interface address skipping fake even if its available. */ int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr) { *************** *** 245,252 **** } ! /* We need to bring the interface up, ! * even if its not initialized properly. */ ! ! rawnet_interface_up(net, 0, 0xffffff, -1); /* get pcap handler */ --- 245,251 ---- } ! /* Is the interface up? */ ! if(!interface_is_up(net->intf_handle)) ! rawnet_interface_up(net, 0, 0xffffff, -1); /* then bring it up with dum values. */ /* get pcap handler */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client-control.c 18 May 2002 18:10:09 -0000 1.15 --- dhcp-client-control.c 19 May 2002 00:34:22 -0000 1.16 *************** *** 225,226 **** --- 225,242 ---- xfree(dc); } + + /* Utility routines to bring down interface. + * we need this because we have to be explicit + * about it. We can't do this at the time we + * destroy the control object -- for example + * we destroy the control object through forks + * to clean out our environment but we don't want + * to down the interface (necessarily) then. + * this routine just makes it explicit so we call + * it when we mean it. */ + + void dhcp_client_interface_down(dhcp_client_control_t *dc) + { + rawnet_interface_down(dc->rawnet); + return; + } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-client-states.c 18 May 2002 18:10:09 -0000 1.19 --- dhcp-client-states.c 19 May 2002 00:34:22 -0000 1.20 *************** *** 349,352 **** --- 349,355 ---- client_broadcast_unarp(dc); + + /* since we're releasing the lease we should down the interface */ + dhcp_client_interface_down(dc); return 0; /* called from do_shutdown() so no real state returned */ Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** dhcp-agent.h 18 May 2002 18:10:09 -0000 1.32 --- dhcp-agent.h 19 May 2002 00:34:22 -0000 1.33 *************** *** 849,852 **** --- 849,853 ---- char *fake_hw_addr); extern dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface); + extern void dhcp_client_interface_down(dhcp_client_control_t *dc); /* dhcp client conf */ |
From: Thamer Al-H. <act...@us...> - 2002-05-18 18:18:01
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv18012 Modified Files: README THANKS TODO Log Message: text changes to reflect upcoming release. Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** README 16 Feb 2002 17:54:33 -0000 1.5 --- README 18 May 2002 18:17:59 -0000 1.6 *************** *** 35,39 **** http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (1.1 or above). http://libdnet.sourceforge.net/ --- 35,39 ---- http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (1.4 or above). http://libdnet.sourceforge.net/ Index: THANKS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/THANKS,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** THANKS 25 Feb 2002 01:39:29 -0000 1.4 --- THANKS 18 May 2002 18:17:59 -0000 1.5 *************** *** 15,16 **** --- 15,18 ---- -- Bill Traynor for Solaris x86. + + -- Stephanie Fox for the Mascot "Fangs" Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TODO 18 May 2002 18:10:09 -0000 1.12 --- TODO 18 May 2002 18:17:59 -0000 1.13 *************** *** 1,2 **** --- 1,4 ---- + [ Quite a bit! ] + Things that need to be done for RFC compliance: *************** *** 13,16 **** --- 15,19 ---- other todo: + -- make dhcp-agent use more goodies from libdnet -- add test for kill(0, pid) to see if it correctly identifies the running process. |
From: Thamer Al-H. <act...@us...> - 2002-05-18 18:10:12
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv12618 Modified Files: COST Makefile.am Makefile.in TODO dhcp-agent.h dhcp-client-control.c dhcp-client-states.c dhcp-convert.c dhcp-interface.c dhcp-net.c dhcp-sysconf.c dhcp-util.c Log Message: various updates; bug fixes; Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** COST 25 Feb 2002 01:39:29 -0000 1.6 --- COST 18 May 2002 18:10:09 -0000 1.7 *************** *** 1,11 **** In writing dhcp-agent I suffered the following: - - Feb - March 2001 (Current values as of the Feb 24) ! 83 pots of coffee; 211 camel filter cigarettes; 35 diet cokes ! (cutting down); 845 mp3s (thanks stephanie); 18 historical trips ! to the wash room; 16 showers; lost one pretty geekette; got one ! job offer; got one pretty geekette; startin' to feel some justice ! in this world; Jan - Feb 2001 --- 1,21 ---- In writing dhcp-agent I suffered the following: ! May - June 2001 ! ! 3 pots of coffee; 42 camel filter cigarretes; one sorry poser; ! cleaned up apartment 0 times; ! ! April - May 2001 ! ! lost one geek girl; haven't kept track -- will soon ! ! March - April 2001 ! ! -- didn't write much code so no costs involved; earned new place ! ! Feb - March 2001 ! ! -- gained one geek girl: as you can imagine little was done; ! earned job Jan - Feb 2001 Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.am 25 Feb 2002 01:39:29 -0000 1.13 --- Makefile.am 18 May 2002 18:10:09 -0000 1.14 *************** *** 10,14 **** dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \ ! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 10,14 ---- dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \ ! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.in 25 Feb 2002 01:39:29 -0000 1.13 --- Makefile.in 18 May 2002 18:10:09 -0000 1.14 *************** *** 78,82 **** bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c dhcp-rtt.c --- 78,82 ---- bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c *************** *** 106,110 **** dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \ dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \ ! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcp-rtt.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = --- 106,111 ---- dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \ dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \ ! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcp-rtt.o \ ! dhcp-interface.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** TODO 25 Feb 2002 01:39:29 -0000 1.11 --- TODO 18 May 2002 18:10:09 -0000 1.12 *************** *** 65,66 **** --- 65,70 ---- by using devices like /dev/urandom explicitly if available. -- fix overflow issue in dhcp-icmp-discovery (icmp_do_echo) + -- check if pcap prefixes its error messages if so remove pcap prefixes. + -- we need a proper error passing scheme for error strings so + that we wind up with a single string in the end. + Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** dhcp-agent.h 25 Feb 2002 01:39:29 -0000 1.31 --- dhcp-agent.h 18 May 2002 18:10:09 -0000 1.32 *************** *** 257,260 **** --- 257,272 ---- } udp_obj; + /* interface control object: + * we store dnet's interface handle, + * and interface_entry structure. + * We need the entry structure + */ + + typedef struct { + intf_t *interface_handle; + struct intf_entry interface_entry; + } interface_control_t; + + /* * DHCP raw network object. *************** *** 268,272 **** /* we should not interface directly with any of these members ! * above the rawnet layer. */ pcap_t *pcap; /* packet capturing device (pcap). */ --- 280,284 ---- /* we should not interface directly with any of these members ! * above the rawnet layer: FIXME -- unfortunately we do. */ pcap_t *pcap; /* packet capturing device (pcap). */ *************** *** 283,289 **** eth_addr_t hw_addr; /* our hardware address. */ ip_addr_t ip_addr; /* our ip address. */ int promiscious; /* run in promiscious mode flag. */ ! /* * Data objects --- 295,304 ---- eth_addr_t hw_addr; /* our hardware address. */ + eth_addr_t *fake_hw_addr; /* our fake hardware address. */ ip_addr_t ip_addr; /* our ip address. */ int promiscious; /* run in promiscious mode flag. */ ! interface_control_t ! *intf_handle; /* interface control handle. */ ! /* * Data objects *************** *** 335,349 **** } client_conf_t; - /* interface control object: - * we store dnet's interface handle, - * and interface_entry structure. - * We need the entry structure - */ - - typedef struct { - intf_t *interface_handle; - struct intf_entry interface_entry; - } interface_control_t; - /* Client data object. */ --- 350,353 ---- *************** *** 360,367 **** uint32_t renewal_time; /* when to renew lease (secs). */ - interface_control_t *interface_control; /* interface handler. */ char *interface; /* interface name. */ unsigned char *class_id, *client_id; /* client_id, class_id */ - unsigned char *client_hw_addr; /* our hardware address. */ int state; /* our current state. */ int discover_offer_retries; /* how many times we should discover/offer before giving up. */ --- 364,369 ---- *************** *** 496,503 **** extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); ! extern int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr); extern char *rawnet_strerror(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); --- 498,508 ---- extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); ! extern int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr); ! extern int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr); ! extern int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr); extern char *rawnet_strerror(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); + extern void reinitialize_rawnet(rawnet_t *net, int promiscious); extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); *************** *** 538,543 **** int (*check)(void *arg)); ! /* droppage in rawnet is probably wrong -- but we'll clean up later (FIXME) */ ! extern char *network_address_to_string_static(uint32_t addr); /* ICMP discovery routines. */ --- 543,548 ---- int (*check)(void *arg)); ! extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); ! extern int rawnet_interface_down(rawnet_t *net); /* ICMP discovery routines. */ *************** *** 898,901 **** --- 903,909 ---- extern int rtt_can_retry(rtt_t *rtt); extern void rtt_destroy(rtt_t *rtt); + + /* global conversion routines. */ + extern char *network_address_to_string_static(uint32_t addr); /* Global vars. */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-control.c 16 Feb 2002 17:54:33 -0000 1.14 --- dhcp-client-control.c 18 May 2002 18:10:09 -0000 1.15 *************** *** 59,63 **** { unsigned char *s; ! unsigned char mac_add[6]; s = xmalloc(1 + ETH_ADDR_LEN); --- 59,63 ---- { unsigned char *s; ! unsigned char mac_add[ETH_ADDR_LEN]; s = xmalloc(1 + ETH_ADDR_LEN); *************** *** 122,126 **** dc->state = 0; dc->interface = strdup(interface); - dc->interface_control = create_interface_control(interface); dc->conf = create_client_conf(dc); dc->cache = create_client_cache(dc); --- 122,125 ---- *************** *** 131,145 **** } - /* We need to bring the interface up, - * even if its not initialized properly. */ - - if(interface_up(dc->interface_control, 0, 0xffffffff, -1)) { - - error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno)); - destroy_dhcp_client_control(dc); - return NULL; - - } - /* Get port numbers from services db. */ --- 130,133 ---- *************** *** 189,193 **** #endif /* HAVE_UNAME */ ! if(rawnet_get_interface_hw_addr(dc->rawnet, &interface_addr)) { error_message("could not acquire interface address"); destroy_dhcp_client_control(dc); --- 177,181 ---- #endif /* HAVE_UNAME */ ! if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) { error_message("could not acquire interface address"); destroy_dhcp_client_control(dc); *************** *** 201,210 **** /* use fake address in 0x:0x:0x:0x:0x we need to notify rawnet about this. ! * achtung: arp packets still have proper address so we don't fudge arp caches up. */ void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr) { char *new_client_id = create_fake_client_id(fake_hw_addr); ! ! xfree(dc->client_id); dc->client_id = new_client_id; --- 189,199 ---- /* use fake address in 0x:0x:0x:0x:0x we need to notify rawnet about this. ! * achtung: all packets _except_ dhcp packets will still use the real hardware address. */ void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr) { char *new_client_id = create_fake_client_id(fake_hw_addr); ! ! if(dc->client_id != NULL) ! xfree(dc->client_id); dc->client_id = new_client_id; *************** *** 228,234 **** xfree(dc->interface); - if(dc->interface_control) - destroy_interface_control(dc->interface_control); - if(dc->class_id) xfree(dc->class_id); --- 217,220 ---- *************** *** 236,242 **** if(dc->client_id) xfree(dc->client_id); - - if(dc->client_hw_addr) - xfree(dc->client_hw_addr); xfree(dc); --- 222,225 ---- Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-client-states.c 16 Feb 2002 17:54:33 -0000 1.18 --- dhcp-client-states.c 18 May 2002 18:10:09 -0000 1.19 *************** *** 28,39 **** #include <dhcp-agent.h> ! static uint32_t client_ip_addr; ! static eth_addr_t client_hw_addr; static sig_atomic_t have_alarm = 0; static RETSIGTYPE handle_alarm(int i) { ! have_alarm= 1; return (RETSIGTYPE) 0; } --- 28,48 ---- #include <dhcp-agent.h> ! /* alarm handling routine and variable. */ ! ! /* wrap for volatine integers, or proper sig_atomic_t types. */ ! ! #ifdef HAVE_SIG_ATOMIC_T static sig_atomic_t have_alarm = 0; + #else /* HAVE_SIG_ATOMIC_T */ + + static int have_alarm = 0; + + #endif + static RETSIGTYPE handle_alarm(int i) { ! have_alarm = 1; return (RETSIGTYPE) 0; } *************** *** 83,88 **** * matching xid. */ ! if(dc->rawnet->type != RAWNET_DHCP || ! (!rawnet_is_valid(dc->rawnet)) || (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) return 0; --- 92,97 ---- * matching xid. */ ! if((!rawnet_is_valid(dc->rawnet)) || ! dc->rawnet->type != RAWNET_DHCP || (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) return 0; *************** *** 119,139 **** } - /* Called after initialization. - * This lets us do things like arp and unarp - * without having to sift through the cache. - */ - - static int client_update_addresses(dhcp_client_control_t *dc) - { - - if(rawnet_get_interface_hw_addr(dc->rawnet, &client_hw_addr) || - interface_get_ip_addr(dc->interface_control, &client_ip_addr)) { - error_message("could get get hardware and ip addresses after initialization."); - return -1; - } - - return 0; - } - /* * Use this to send out a broadcast reply claiming that we own the --- 128,131 ---- *************** *** 145,148 **** --- 137,145 ---- static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { + ip_addr_t client_ip_addr; + eth_addr_t client_hw_addr; + + rawnet_get_ip_addr(dc->rawnet, &client_ip_addr); + rawnet_get_real_hw_addr(dc->rawnet, &client_hw_addr); build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); *************** *** 155,158 **** --- 152,161 ---- static void client_broadcast_unarp(dhcp_client_control_t *dc) { + ip_addr_t client_ip_addr; + eth_addr_t client_hw_addr; + + rawnet_get_ip_addr(dc->rawnet, &client_ip_addr); + rawnet_get_real_hw_addr(dc->rawnet, &client_hw_addr); + build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); *************** *** 276,282 **** do_sysconf(options, dc); cache_entry_purge_list(options); - - if(client_update_addresses(dc)) - return -1; client_broadcast_arp_reply(dc); --- 279,282 ---- Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-convert.c 9 Feb 2002 16:22:35 -0000 1.7 --- dhcp-convert.c 18 May 2002 18:10:09 -0000 1.8 *************** *** 772,774 **** --- 772,787 ---- } + /* variation on network_addr_to_string in dhcp-convert.c we use + * this when we don't want to run around freeing results up, and + * know that it will be statically stored. Useful for insertion + * in message log routines. */ + + char *network_address_to_string_static(uint32_t addr) + { + struct in_addr in; + in.s_addr = addr; + + return(inet_ntoa(in)); + } + /* Gee, lots of workhorses in this source file. */ Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-interface.c 25 Feb 2002 01:39:29 -0000 1.13 --- dhcp-interface.c 18 May 2002 18:10:09 -0000 1.14 *************** *** 33,37 **** if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; } --- 33,38 ---- if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name, ! strerror(errno)); return -1; } *************** *** 43,47 **** { if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; } --- 44,49 ---- { if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name, ! strerror(errno)); return -1; } *************** *** 59,63 **** ic->interface_handle = intf_open(); if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */ ! fatal_error("could not acquire interface handler"); strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1); --- 61,65 ---- ic->interface_handle = intf_open(); if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */ ! fatal_error("interface_control: could not acquire interface handler"); strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1); Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-net.c 25 Feb 2002 01:39:30 -0000 1.16 --- dhcp-net.c 18 May 2002 18:10:09 -0000 1.17 *************** *** 63,79 **** #include <dhcp-agent.h> - /* variation on network_addr_to_string in dhcp-convert.c we use - * this when we don't want to run around freeing results up, and - * know that it will be statically stored. Useful for insertion - * in message log routines. */ - - char *network_address_to_string_static(uint32_t addr) - { - struct in_addr in; - in.s_addr = addr; - - return(inet_ntoa(in)); - } - /* Get port number for named service. */ --- 63,66 ---- *************** *** 85,89 **** if((sv = getservbyname(serv, proto)) == NULL) { ! error_message("could not get service listing: %d", strerror(errno)); return -1; } --- 72,76 ---- if((sv = getservbyname(serv, proto)) == NULL) { ! error_message("rawnet: could not get service listing: %d", strerror(errno)); return -1; } *************** *** 108,116 **** if(host == NULL) { ! error_message("unable to resolv host: %s", hstrerror(h_errno)); return -1; } ! memcpy((int *) * &host->h_addr, &addr, sizeof(addr)); } --- 95,103 ---- if(host == NULL) { ! error_message("rawnet: unable to resolv host: %s", hstrerror(h_errno)); return -1; } ! memcpy(&addr, (int *) * &host->h_addr, sizeof(addr)); } *************** *** 118,124 **** } ! int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr) { return(eth_get(net->eth, addr)); } --- 105,132 ---- } ! /* get interface address. */ ! int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr) { + /* are we using a fake address? */ + if(net->fake_hw_addr == NULL) { + return(eth_get(net->eth, addr)); + } else { + memcpy(addr, net->fake_hw_addr->data, ETH_ADDR_LEN); + return 0; + } + } + + /* get real interface address skipping fake if its available. */ + int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr) + { + /* are we using a fake address? */ return(eth_get(net->eth, addr)); + + } + + /* get IP address. */ + int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr) + { + return(interface_get_ip_addr(net->intf_handle, addr)); } *************** *** 144,148 **** if(interface_name == NULL) { ! error_message("pcap_lookupdev: %s", errbuf); return NULL; } --- 152,156 ---- if(interface_name == NULL) { ! error_message("rawnet: pcap_lookupdev: %s", errbuf); return NULL; } *************** *** 152,156 **** pcap = pcap_open_live(interface_name, SNAPLEN, promiscious, 0, errbuf); if(pcap == NULL) { ! error_message("pcap_openlive: %s", errbuf); return NULL; } --- 160,164 ---- pcap = pcap_open_live(interface_name, SNAPLEN, promiscious, 0, errbuf); if(pcap == NULL) { ! error_message("rawnet: pcap_openlive: %s", errbuf); return NULL; } *************** *** 158,162 **** if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) { pcap_close(pcap); ! error_message("pcap_compile: %s",pcap_geterr(pcap)); return NULL; } --- 166,170 ---- if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) { pcap_close(pcap); ! error_message("rawnet: pcap_compile: %s",pcap_geterr(pcap)); return NULL; } *************** *** 164,168 **** if(pcap_setfilter(pcap, &filter) == -1) { pcap_close(pcap); ! error_message("pcap_setfilter: %s", pcap_geterr(pcap)); return NULL; } --- 172,176 ---- if(pcap_setfilter(pcap, &filter) == -1) { pcap_close(pcap); ! error_message("rawnet: pcap_setfilter: %s", pcap_geterr(pcap)); return NULL; } *************** *** 175,178 **** --- 183,215 ---- } + /* wrapper around interface handler routines. */ + + /* bring up interface, and assign ourselves the address passed. */ + int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu) + { + + if(interface_up(net->intf_handle, addr, netmask, mtu)) { + error_message("rawnet: could not bring up interface: %s: %s", net->device, strerror(errno)); + rawnet_destroy(net); + return 1; + } + + memcpy(&net->ip_addr, &addr, IP_ADDR_LEN); /* set our IP address. */ + return 0; + } + + /* bring down interface. */ + int rawnet_interface_down(rawnet_t *net) + { + if(interface_down(net->intf_handle)) { + error_message("rawnet: could not bring down interface: %s: %s", net->device, strerror(errno)); + rawnet_destroy(net); + return 1; + } + + memset(&net->ip_addr, 0, IP_ADDR_LEN); /* clear our IP address -- this isn't very useful though. */ + return 0; + } + /* Create the workhorse network module. */ *************** *** 196,204 **** net->eth = eth_open(device); if(net->eth == NULL) { ! error_message("device not supported or unavailable: %s", device); rawnet_destroy(net); return NULL; } /* get pcap handler */ --- 233,253 ---- net->eth = eth_open(device); if(net->eth == NULL) { ! error_message("rawnet: device not supported or unavailable: %s", device); rawnet_destroy(net); return NULL; } + /* get the interface handle for bringing it up or down and querying it. */ + net->intf_handle = create_interface_control(net->device); + if(net->intf_handle == NULL) { + rawnet_destroy(net); + return NULL; + } + + /* We need to bring the interface up, + * even if its not initialized properly. */ + + rawnet_interface_up(net, 0, 0xffffff, -1); + /* get pcap handler */ *************** *** 211,219 **** net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! error_message("cannot get descriptor for %s, this system may not be supported.", device); rawnet_destroy(net); return NULL; } /* Build packet handler objects. * --- 260,275 ---- net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! error_message("rawnet: cannot get descriptor for %s, this system may not be supported.", device); rawnet_destroy(net); return NULL; } + /* When we first initialize we use a real hardware + * address. This can be changed later to a fake hardware + * address if the system supports it. */ + + rawnet_get_hw_addr(net, &net->hw_addr); + rawnet_get_ip_addr(net, &net->ip_addr); + /* Build packet handler objects. * *************** *** 229,256 **** net->dhcp_p = dhcp_create(); - /* For now we use the real hardware address in hw_addr. - * rawnet_use_fake_hw_addr can always be called to change - * this. */ - - rawnet_get_interface_hw_addr(net, &net->hw_addr); - return net; } /* Use a fake hardware address (diagnostic purposes). We need to ! * reinitialize our rawnet to use promiscious packet ! * capturing. */ void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { ! unsigned char *mac_addr; ! ! ! mac_addr = xmalloc(ETH_ADDR_LEN); if(hex_string_to_value(mac_string, mac_addr)) fatal_error("malformed mac_string for fake client hw addr. please check mac address."); memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); ! xfree(mac_addr); return; --- 285,307 ---- net->dhcp_p = dhcp_create(); return net; } /* Use a fake hardware address (diagnostic purposes). We need to ! * reinitialize our rawnet to use promiscious packet capturing ! * since we do want to accept packets for this hardware ! * address. */ void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { ! unsigned char mac_addr[ETH_ADDR_LEN]; + net->fake_hw_addr = xmalloc(sizeof(eth_addr_t)); if(hex_string_to_value(mac_string, mac_addr)) fatal_error("malformed mac_string for fake client hw addr. please check mac address."); memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); ! ! /* now reinitialize in promiscious mode */ ! reinitialize_rawnet(net, 1); return; *************** *** 261,264 **** --- 312,319 ---- if(net->eth != NULL) eth_close(net->eth); + + if(net->intf_handle) { + destroy_interface_control(net->intf_handle); + } if(net->pcap != NULL) *************** *** 273,277 **** if(net->pcap_filter) xfree(net->pcap_filter); ! if(net->ether_p) eth_destroy(net->ether_p); --- 328,332 ---- if(net->pcap_filter) xfree(net->pcap_filter); ! if(net->ether_p) eth_destroy(net->ether_p); *************** *** 287,295 **** dhcp_destroy(net->dhcp_p); ! xfree(net); return; } /* Bring pcap/dnet up and down. * Useful for wait states when --- 342,354 ---- dhcp_destroy(net->dhcp_p); ! xfree(net); return; } + /* The rawnet up and down routines don't mess with the interface + * intentionally. They're meant only to close our packet capturing + * and sending devices so as to free up system resources. */ + /* Bring pcap/dnet up and down. * Useful for wait states when *************** *** 323,326 **** --- 382,394 ---- } + void reinitialize_rawnet(rawnet_t *net, int promiscious) + { + net->promiscious = promiscious; + rawnet_down(net); + rawnet_up(net); + + return; + } + /* * rawnet get packet: *************** *** 523,527 **** if(rawnet_send_packet(net) < 0) { ! error_message("could not send packet: %s", strerror(errno)); rtt_destroy(rtt); return -1; --- 591,595 ---- if(rawnet_send_packet(net) < 0) { ! error_message("rawnet: could not send packet: %s", strerror(errno)); rtt_destroy(rtt); return -1; *************** *** 535,539 **** case RAWNET_PCAP_ERROR: ! error_message("couldn't wait for packets: %s : %s", net->device, strerror(errno)); rtt_destroy(rtt); --- 603,607 ---- case RAWNET_PCAP_ERROR: ! error_message("rawnet: couldn't wait for packets: %s : %s", net->device, strerror(errno)); rtt_destroy(rtt); *************** *** 572,576 **** default: ! error_message("invalid return from rawnet_send_packet() -- this is a bug report it please"); break; } --- 640,644 ---- default: ! error_message("rawnet: invalid return from rawnet_send_packet() -- this is a bug report it please"); break; } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-sysconf.c 15 Feb 2002 09:19:52 -0000 1.8 --- dhcp-sysconf.c 18 May 2002 18:10:09 -0000 1.9 *************** *** 227,231 **** fatal_error("do not have enough settings for interface configuration!"); ! if(interface_up(dc->interface_control, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); --- 227,231 ---- fatal_error("do not have enough settings for interface configuration!"); ! if(rawnet_interface_up(dc->rawnet, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); *************** *** 268,275 **** info_message("configuring for option %s", dhcp_options_strings[i]); ! ! data = option_convert_handlers[i].serialize_to_internal(ce->value); ! sysconf_handlers[i].sysconf_handler(data, dc); option_convert_handlers[i].free_internal(data); } --- 268,278 ---- info_message("configuring for option %s", dhcp_options_strings[i]); ! data = option_convert_handlers[i].serialize_to_internal(ce->value); ! ! if(sysconf_handlers[i].sysconf_handler(data, dc)) ! error_message("error configuring for option %s: %s", dhcp_options_strings[i], ! strerror(errno)); ! option_convert_handlers[i].free_internal(data); } Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-util.c 25 Feb 2002 01:39:30 -0000 1.9 --- dhcp-util.c 18 May 2002 18:10:09 -0000 1.10 *************** *** 291,296 **** } ! /* interface to splice_string. */ ! char *splice_many_strings(int num, char *string, ...) { --- 291,295 ---- } ! /* splice many strings lets us pass a variable amount of strings to be spliced. */ char *splice_many_strings(int num, char *string, ...) { |
From: Thamer Al-H. <act...@us...> - 2002-05-18 17:50:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv31911 Modified Files: dhcp-client.c Log Message: fixed bug when trying to kill running client Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client.c 16 Feb 2002 17:54:33 -0000 1.16 --- dhcp-client.c 18 May 2002 17:50:49 -0000 1.17 *************** *** 36,42 **** if(dc) { /* only do clean up if we can. */ client_release(dc); ! if(interface_down(dc->interface_control)) ! error_message("warning: could not bring interface down."); ! delete_pid_file(dc->interface); } --- 36,40 ---- if(dc) { /* only do clean up if we can. */ client_release(dc); ! destroy_dhcp_client_control(dc); delete_pid_file(dc->interface); } *************** *** 93,96 **** --- 91,97 ---- do_shutdown(dc); + /* if we're only running to be setup, + * return here. */ + if(have_setup && only_setup) { return state; *************** *** 146,149 **** --- 147,151 ---- error_message("could not send signal to dhcpclient process."); error_message("maybe it's not running?"); + return; } *************** *** 180,184 **** if(!get_pid_file(interface, &pid)) { /* A race condition exists between the discover and request state. ! * So we can't hup the client and tell it the cache has been deleted. */ error_message("dhcpclient already running."); error_message("i won't delete cache until it's shutdown."); --- 182,186 ---- if(!get_pid_file(interface, &pid)) { /* A race condition exists between the discover and request state. ! * And we can't hup the client and tell it the cache has been deleted. */ error_message("dhcpclient already running."); error_message("i won't delete cache until it's shutdown."); *************** *** 186,193 **** } ! /* As long as no client is being run we can go ahead and delete the cache. ! * We need a client cache structure though, pass it a dummy structure ! * with the interface. That's all it needs. ! * (this is the hack). */ --- 188,195 ---- } ! /* As long as no client is running we can go ahead and delete ! * the cache. We need a client cache structure though, pass ! * it a dummy structure with the interface. That's all it ! * needs. (this is the hack). */ *************** *** 290,295 **** } } ! info_message("(C) 2001 Thamer Al-Harbash <tm...@wh...>"); info_message("starting for interface %s", interface); --- 292,299 ---- } } ! info_message("(C) 2001 Thamer Al-Harbash <tm...@wh...>"); + info_message("See LICENSE file for details."); + info_message(" "); info_message("starting for interface %s", interface); *************** *** 336,339 **** --- 340,348 ---- * */ + + /* "and she came from a great Desktop; and she razed the + * posers leaving a blanket of ash; and we were Praised in + * our Judgements;" -- from the Book of Ada (blessed be her + * semicolons) */ setup_interrupt_handlers(); /* setup signal handling */ |
From: Thamer Al-H. <act...@us...> - 2002-02-25 01:43:03
|
Update of /cvsroot/dhcp-agent/dhcp-agent/doc In directory usw-pr-cvs1:/tmp/cvs-serv27070/doc Added Files: rfc0950.txt Log Message: added rfc for subnet discovery; --- NEW FILE: rfc0950.txt --- Network Working Group J. Mogul (Stanford) Request for Comments: 950 J. Postel (ISI) August 1985 Internet Standard Subnetting Procedure Status Of This Memo This RFC specifies a protocol for the ARPA-Internet community. If subnetting is implemented it is strongly recommended that these procedures be followed. Distribution of this memo is unlimited. Overview This memo discusses the utility of "subnets" of Internet networks, which are logically visible sub-sections of a single Internet [...987 lines suppressed...] Mogul & Postel [Page 18] |
From: Thamer Al-H. <act...@us...> - 2002-02-25 01:39:33
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv26529 Modified Files: COST Makefile.am Makefile.in THANKS TODO dhcp-agent.h dhcp-arp.c dhcp-icmp-discovery.c dhcp-interface.c dhcp-net.c dhcp-packet-build.c dhcp-util.c Added Files: dhcp-arp-discovery.c Log Message: now working with libdnet-current; added more icmp discovery routines and arping routines; small fixes and some code clean up (need more); --- NEW FILE: dhcp-arp-discovery.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v 1.1 2002/02/25 01:39:29 actmodern Exp $ * * Copyright 2001 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #include <dhcp-agent.h> /* Accept a list of arguments. Will contain rawnet first, and * then the ip address we're interested in. */ static int check_for_arp_reply(void *data) { rawnet_t *net; unsigned char *addr, *received_addr; list_t *argument_list = data; net = argument_list->data; if(argument_list->next) addr = argument_list->next->data; else { warn_message("check arp reply: no address passed to function -- skipping"); return 0; } received_addr = arp_get_sender_protocol_address(net->arp_p); /* check for arp type, header length, type, address lengths, * and op type. */ if((net->type == RAWNET_ARP) && (arp_get_hardware_type(net->arp_p) == ARP_HRD_ETH) && (arp_get_protocol_type(net->arp_p) == ARP_PRO_IP) && (arp_get_hardware_len(net->arp_p) == ETH_ADDR_LEN) && (arp_get_protocol_len(net->arp_p) == IP_ADDR_LEN) && (arp_get_op(net->arp_p) == ARP_OP_REPLY)) { /* now check if its the address we're looking for */ if(!memcmp(addr, received_addr, IP_ADDR_LEN)) return 1; /* yes! address match */ else return 0; /* nope we got another response. */ } return 0; /* not the right kind of packet. */ } extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr) { list_t *arg_list = NULL; unsigned char *sender_addr; arg_list = add_to_list(arg_list, &address); arg_list = add_to_list(arg_list, net); build_arp_request(net, 0, address, net->hw_addr); /* 0 for source ip, address to discover for dest, * our hardware address so we get a reply back. */ while(retries--) { if(rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply)) continue; /* Yummy! We got a valid reply! */ sender_addr = arp_get_sender_hardware_address(net->arp_p); memcpy(mac_addr->data, &sender_addr, ETH_ADDR_LEN); /* just free up pair. FIXME: this isn't good because we're * breaking the list blackbox. we need a better way to do this. * the datums don't need to be freed since we keep them on the stack. */ xfree(arg_list->next); xfree(arg_list); return 0; } /* FIXME: ditto (see above) */ xfree(arg_list->next); xfree(arg_list); /* no response, return error. */ return 1; } Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** COST 15 Feb 2002 09:19:52 -0000 1.5 --- COST 25 Feb 2002 01:39:29 -0000 1.6 *************** *** 1,10 **** In writing dhcp-agent I suffered the following: ! Feb - March 2001 (Current values as of the Feb 14) ! 24 pots of coffee; 132 camel filter cigarettes; 12 diet cokes (cutting down); 845 mp3s (thanks stephanie); 18 historical trips to the wash room; 16 showers; lost one pretty geekette; got one ! job offer; moving up in the world... Jan - Feb 2001 --- 1,11 ---- In writing dhcp-agent I suffered the following: ! Feb - March 2001 (Current values as of the Feb 24) ! 83 pots of coffee; 211 camel filter cigarettes; 35 diet cokes (cutting down); 845 mp3s (thanks stephanie); 18 historical trips to the wash room; 16 showers; lost one pretty geekette; got one ! job offer; got one pretty geekette; startin' to feel some justice ! in this world; Jan - Feb 2001 Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile.am 17 Feb 2002 04:37:35 -0000 1.12 --- Makefile.am 25 Feb 2002 01:39:29 -0000 1.13 *************** *** 20,26 **** dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 20,27 ---- dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile.in 17 Feb 2002 04:37:35 -0000 1.12 --- Makefile.in 25 Feb 2002 01:39:29 -0000 1.13 *************** *** 83,90 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 83,90 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcp-arp-discovery.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h *************** *** 115,119 **** dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcp-icmp-discovery.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = --- 115,119 ---- dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcp-icmp-discovery.o dhcp-arp-discovery.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = *************** *** 136,141 **** TAR = tar GZIP_ENV = --best ! DEP_FILES = .deps/dhcp-align.P .deps/dhcp-arp.P \ ! .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ --- 136,141 ---- TAR = tar GZIP_ENV = --best ! DEP_FILES = .deps/dhcp-align.P .deps/dhcp-arp-discovery.P \ ! .deps/dhcp-arp.P .deps/dhcp-cache-entry.P .deps/dhcp-client-cache.P \ .deps/dhcp-client-conf.P .deps/dhcp-client-control.P \ .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ Index: THANKS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/THANKS,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** THANKS 15 Feb 2002 02:00:24 -0000 1.3 --- THANKS 25 Feb 2002 01:39:29 -0000 1.4 *************** *** 9,13 **** http://www.fiction.net/blong/programs/snprintf.c ! -- Dug Song, and the others behind libdnet. -- The Tcpdump Group for their work on libpcap --- 9,14 ---- http://www.fiction.net/blong/programs/snprintf.c ! -- Dug Song, and the others behind libdnet for their code and the ! support given to make sure dhcp-agent worked well with libdnet. -- The Tcpdump Group for their work on libpcap Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TODO 16 Feb 2002 17:54:33 -0000 1.10 --- TODO 25 Feb 2002 01:39:29 -0000 1.11 *************** *** 51,53 **** address. check, fix, clean. -- clean up dhcp-packet-build.c ! -- need a proper rtt featured re/send/accept routine for raw packets. \ No newline at end of file --- 51,66 ---- address. check, fix, clean. -- clean up dhcp-packet-build.c ! -- need a proper rtt featured re/send/accept routine for raw packets. ! -- in arp discovery we're using a list to pass two arguments. we ! should use something else, or have list routines specific to ! this. ! -- the rawnet routines should be a shared library due to too many ! dependencies. the sniffer for example, only needs the packet ! parsing routines. ! -- net->hw_addr is broken. i don't like it being at that level. ! we should always specify our hardware address at a higher ! level on a per-use basis and thus give us control over ! how much Marla is faking it. ! -- would be nice to have more unpredictable random numbers ! by using devices like /dev/urandom explicitly if available. ! -- fix overflow issue in dhcp-icmp-discovery (icmp_do_echo) Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** dhcp-agent.h 17 Feb 2002 04:37:35 -0000 1.30 --- dhcp-agent.h 25 Feb 2002 01:39:29 -0000 1.31 *************** *** 162,165 **** --- 162,169 ---- #define MAX_VERBOSITY_LEVEL DEBUG_VERBOSITY_LEVEL + /* default configuration */ + + #define DISCOVER_OFFER_RETRIES 3 + /* * * * * * * * * * * * Data structures. * *************** *** 217,230 **** typedef struct { ! dhcphdr fixedheader; ! uint32_t magic_cookie; ! list_t *options; ! list_t *options_seek; } dhcp_obj; - /* default configuration */ - - #define DISCOVER_OFFER_RETRIES 3 - /* * Other packet objects. --- 221,230 ---- typedef struct { ! dhcphdr fixedheader; /* DHCP fixed header. */ ! uint32_t magic_cookie; /* Magic cookie. */ ! list_t *options; /* Option list. */ ! list_t *options_seek; /* Seek pointer to option list. */ } dhcp_obj; /* * Other packet objects. *************** *** 266,283 **** typedef struct { - - /* Internal members. - * Not to be messed about with directly. */ ! pcap_t *pcap; /* packet capturing device. */ ! int pcap_fd; /* file des we can select on */ ! eth_t *eth; /* ethernet device. */ ! char *device; /* device name. */ ! char *packet_data; /* internal packet data. */ ! int packet_len; /* total length of packet. */ ! struct timeval tstamp; /* timestamp. */ ! uint16_t src_port, ! dst_port; /* udp ports for writing packets. */ ! eth_addr_t hw_addr; /* used for faking client mac address. */ int promiscious; /* run in promiscious mode flag. */ --- 266,287 ---- typedef struct { ! /* we should not interface directly with any of these members ! * above the rawnet layer. */ ! ! pcap_t *pcap; /* packet capturing device (pcap). */ ! int pcap_fd; /* file descriptor we can select on for pcap. */ ! eth_t *eth; /* ethernet device handler (libdnet). */ ! ! uint16_t src_port, dst_port; /* udp ports for writing packets. */ ! char *device; /* device name. */ ! ! char *packet_data; /* packet data. */ ! int packet_len; /* total length of packet. */ ! ! struct timeval tstamp; /* timestamp. */ ! ! eth_addr_t hw_addr; /* our hardware address. */ ! ip_addr_t ip_addr; /* our ip address. */ int promiscious; /* run in promiscious mode flag. */ *************** *** 326,330 **** unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ ! int discover_offer_retries; /* amount of times we're willing to keep rediscovering before giving up. */ } client_conf_t; --- 330,336 ---- unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ ! int discover_offer_retries; /* amount of times we're willing to keep ! * rediscovering before giving up. */ ! } client_conf_t; *************** *** 346,351 **** rawnet_t *rawnet; /* raw network handle */ ! client_cache_t *cache; /* cache */ ! client_conf_t *conf; /* configuration. */ uint32_t xid; /* unique xid */ --- 352,357 ---- rawnet_t *rawnet; /* raw network handle */ ! client_cache_t *cache; /* cache */ ! client_conf_t *conf; /* configuration. */ uint32_t xid; /* unique xid */ *************** *** 354,363 **** uint32_t renewal_time; /* when to renew lease (secs). */ ! interface_control_t *interface_control; ! char *interface; ! unsigned char *class_id, *client_id; ! unsigned char *client_hw_addr; ! int state; ! int discover_offer_retries; } dhcp_client_control_t; --- 360,369 ---- uint32_t renewal_time; /* when to renew lease (secs). */ ! interface_control_t *interface_control; /* interface handler. */ ! char *interface; /* interface name. */ ! unsigned char *class_id, *client_id; /* client_id, class_id */ ! unsigned char *client_hw_addr; /* our hardware address. */ ! int state; /* our current state. */ ! int discover_offer_retries; /* how many times we should discover/offer before giving up. */ } dhcp_client_control_t; *************** *** 498,509 **** extern void build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); extern void build_arp_reply(rawnet_t *net, ! uint32_t source_addr, ! uint32_t dest_addr, ! eth_addr_t source_hw_addr, ! eth_addr_t dest_hw_addr); extern void build_unarp(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); --- 504,522 ---- extern void build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); ! extern void build_arp_reply(rawnet_t *net, ! uint32_t source_addr, ! uint32_t dest_addr, ! eth_addr_t source_hw_addr, ! eth_addr_t dest_hw_addr); ! ! extern void build_arp_request(rawnet_t *net, ! uint32_t source_addr, ! uint32_t dest_addr, ! eth_addr_t source_hw_addr); ! extern void build_unarp(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); *************** *** 514,517 **** --- 527,533 ---- extern void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); extern void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); + extern void build_icmp_echo_request(rawnet_t *net, ip_addr_t source_addr, ip_addr_t dest_addr, + eth_addr_t source_mac, eth_addr_t dest_mac, uint32_t id, + uint32_t seq); extern int rawnet_up(rawnet_t *net); *************** *** 522,525 **** --- 538,550 ---- int (*check)(void *arg)); + /* droppage in rawnet is probably wrong -- but we'll clean up later (FIXME) */ + extern char *network_address_to_string_static(uint32_t addr); + + /* ICMP discovery routines. */ + extern int icmp_subnet_mask_discovery(rawnet_t *net, int retries, uint32_t *subnet_mask); + + /* ARP discovery routines. */ + extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr); + /* Daemon routines. */ *************** *** 558,561 **** --- 583,587 ---- extern int is_string(const char *string, int len); extern int get_random(void); + extern struct timeval timeval_diff(struct timeval begin, struct timeval end); /* Replacement vsnprintf, snprintf if needed. */ *************** *** 717,720 **** --- 743,754 ---- extern void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr); extern void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr); + + extern uint16_t arp_get_op(arp_obj *arp); + extern uint16_t arp_get_hardware_type(arp_obj *arp); + extern uint16_t arp_get_protocol_type(arp_obj *arp); + extern uint8_t arp_get_hardware_len(arp_obj *arp); + extern uint8_t arp_get_protocol_len(arp_obj *arp); + extern unsigned char *arp_get_sender_hardware_address(arp_obj *arp); + extern unsigned char *arp_get_sender_protocol_address(arp_obj *arp); /* UDP obj routines. */ Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-arp.c 3 Feb 2002 16:56:00 -0000 1.6 --- dhcp-arp.c 25 Feb 2002 01:39:29 -0000 1.7 *************** *** 96,99 **** --- 96,136 ---- } + /* get routines. */ + + uint16_t arp_get_op(arp_obj *arp) + { + return(arp->header.ar_op); + } + + uint16_t arp_get_hardware_type(arp_obj *arp) + { + return(ntohs(arp->header.ar_hrd)); + } + + uint16_t arp_get_protocol_type(arp_obj *arp) + { + return(ntohs(arp->header.ar_pro)); + } + + uint8_t arp_get_hardware_len(arp_obj *arp) + { + return(arp->header.ar_hln); + } + + uint8_t arp_get_protocol_len(arp_obj *arp) + { + return(arp->header.ar_pln); + } + + unsigned char *arp_get_sender_hardware_address(arp_obj *arp) + { + return(arp->arp_data.ar_sha); + } + + unsigned char *arp_get_sender_protocol_address(arp_obj *arp) + { + return(arp->arp_data.ar_spa); + } + /* dump image to packet. */ void arp_write_packet_image(arp_obj *arp, unsigned char *packet) Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-icmp-discovery.c 17 Feb 2002 04:37:35 -0000 1.1 --- dhcp-icmp-discovery.c 25 Feb 2002 01:39:29 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * Copyright 2001 Thamer Alharbash <tm...@wh...> * *************** *** 22,27 **** * ICMP discovery routines: * ! * We currently have code for subnet mask discovery, and ! * discovery of host with least latency. * */ --- 23,27 ---- * ICMP discovery routines: * ! * subnet discovery, and rtt discovery by icmp echo requests. * */ *************** *** 47,51 **** */ ! int icmp_subnet_mask_discovery(rawnet_t *net, uint32_t *subnet_mask) { uint32_t reply_mask; --- 47,51 ---- */ ! int icmp_subnet_mask_discovery(rawnet_t *net, int retries, uint32_t *subnet_mask) { uint32_t reply_mask; *************** *** 58,66 **** build_icmp_mask_request(net, 0, 0); ! if(rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply)) { ! error_message("icmp mask discovery: timeout on discovery"); return -1; } /* A reply should contain the subnet mask. If we're actually * doing subnet mask discovery we assume any subnet mask --- 58,73 ---- build_icmp_mask_request(net, 0, 0); ! if(retries <= 0) /* let's not get hosed shall we? */ { ! error_message("icmp mask discovery: bad number of retries"); return -1; } + while(retries--) { + if(rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply)) { + error_message("icmp mask discovery: timeout on discovery"); + return -1; + } + } + /* A reply should contain the subnet mask. If we're actually * doing subnet mask discovery we assume any subnet mask *************** *** 71,73 **** --- 78,251 ---- return 0; + } + + /* Check for icmp mask response. */ + + static int icmp_check_echo_reply(void *arg) + { + rawnet_t *net = arg; + + if((net->type = RAWNET_ICMP) && + (icmp_get_type(net->icmp_p) == ICMP_ECHOREPLY)) + return 1; + else + return 0; + } + + /* Send out an echo request per retries to get latency of host. */ + int icmp_do_echo(rawnet_t *net, ip_addr_t dest_addr, eth_addr_t dest_mac, int retries) + { + uint32_t id, seq; + struct timeval before, after, difference; + int latency; + + id = get_random(); + seq = 0; + + while(retries--) { + + /* we need to rebuild each time for different sequence + numbers. */ + + seq++; + build_icmp_echo_request(net, net->ip_addr, dest_addr, net->hw_addr, dest_mac, id, seq); + + gettimeofday(&before, NULL); + if(rawnet_packet_transact(net, net, NULL, icmp_check_echo_reply)) { + /* on a timeout we set the latency to -1 */ + continue; + } + gettimeofday(&after, NULL); + difference = timeval_diff(before, after); + + /* milliseconds are accurate enough for us. + * FIXME: the integer may overflow if our + * rtt mechanism is setup to wait for too long before a + * timeout. */ + + latency = (difference.tv_sec * 1000); + latency += (difference.tv_usec/1000); + + return latency; + } + + return -1; + + } + + /* + * ICMP Round Trip Time (RTT) Discovery: + * Here we're interested in how long it takes to + * get a response from a list of addresses. + * We return a list of unsigned integers giving + * us the average rtt time for each address. + * + */ + + /* FIXME: we need to underengineer this code. */ + list_t *icmp_rtt_discovery(rawnet_t *net, int retries, int sends, list_t *addresses) + { + list_t *rtts = NULL; + int *latency, *average_latency; + int send_count, unreachable_count, highest_latency; + ip_addr_t *host_addr; + eth_addr_t dest_mac; + + if(retries <= 0 || sends <= 0) { /* let's not get hosed shall we? */ + error_message("icmp rtt discovery: received invalid retry or send count."); + return NULL; + } + + /* Our algorithm works as such: send out an ICMP echo request + * and wait for a reply. We count the total number of + * milliseconds we waited as the latency time. We keep doing + * this per the packet_count. If we don't get a reply we keep + * doing per number of retries. If we run out of retries we + * return -1 as the latency signifying an unreliable + * address. */ + + /* loop per address. */ + for(;addresses;addresses = addresses->next) { + + host_addr = addresses->data; + + /* We need to arp for MAC address first. Call + * arp_discover_hardware_address for that. */ + + if(arp_discover_hardware_address(net, retries, *host_addr, &dest_mac)) { + /* No arp reply. Skip. */ + warn_message("icmp rtt discovery: could not ARP for address for %s -- skipping", network_address_to_string_static(*host_addr)); + break; + } + + /* We have the MAC address here. Run + * icmp_get_echo_latency to get latency. This also tells + * us if the host is up. */ + + + /* allocate latency array. */ + latency = xmalloc(sizeof(int) * sends); + send_count = 0; + + /* fill up our latency array. */ + for(send_count = 0; send_count < sends; send_count++) + latency[send_count] = icmp_do_echo(net, *(host_addr), dest_mac, retries); + + /* This part is a little tricky. We want to make sure + * the host is actually up first. So if we got al -1's + * we know it wasn't. Then if it is up we set the -1 + * latencies (indicating we never got an answer) to the + * largest latency multiplied by two. This severely hurts + * a host's average, but it's the right thing to do as + * long as we're doing it fairly to everyone. + * FIXME: we do need a better way to deal with this. */ + + /* check our latency if it's all -1 */ + unreachable_count = 0; + for(send_count = 0; send_count < sends; send_count++) { + if(latency[send_count] == -1) + unreachable_count++; + } + + average_latency = xmalloc(sizeof(int)); + + if(unreachable_count == send_count) { /* the host is + * unreachable. */ + + /* host is unreachable give it an average of -1. */ + *average_latency = -1; + + } else { + + if(unreachable_count) { /* the host didn't + respond to some of our + packets in time. */ + /* get highest. */ + highest_latency = 0; + for(send_count = 0; send_count < sends; send_count++) { + if(latency[send_count] > highest_latency) + highest_latency = latency[send_count]; + } + + /* replace unreachables with highest multiplied by two */ + for(send_count = 0; send_count < sends; send_count++) { + if(latency[send_count] == -1) + latency[send_count] = highest_latency * 2; + } + } + + /* now we can get the average. */ + + *average_latency = 0; + for(send_count = 0; send_count < sends; send_count++) { + *average_latency += latency[send_count]; + } + + *average_latency /= sends; + } + + rtts = add_to_list(rtts, average_latency); + } + + return rtts; } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-interface.c 16 Feb 2002 17:54:33 -0000 1.12 --- dhcp-interface.c 25 Feb 2002 01:39:29 -0000 1.13 *************** *** 93,99 **** if(addr != INADDR_ANY) { ! ic->interface_entry.intf_addr->addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry.intf_addr->addr_bits); ! memcpy(&ic->interface_entry.intf_addr->addr_ip, &addr, IP_ADDR_LEN); } --- 93,100 ---- if(addr != INADDR_ANY) { ! ic->interface_entry.intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, ! &ic->interface_entry.intf_addr.addr_bits); ! memcpy(&ic->interface_entry.intf_addr.addr_ip, &addr, IP_ADDR_LEN); } *************** *** 133,139 **** if(interface_get_info(ic)) return -1; ! ! memcpy(addr, &ic->interface_entry.intf_addr->addr_ip, IP_ADDR_LEN); ! return 0; } --- 134,140 ---- if(interface_get_info(ic)) return -1; ! ! memcpy(addr, &ic->interface_entry.intf_addr.addr_ip, IP_ADDR_LEN); ! return 0; } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-net.c 16 Feb 2002 17:54:33 -0000 1.15 --- dhcp-net.c 25 Feb 2002 01:39:30 -0000 1.16 *************** *** 63,66 **** --- 63,79 ---- #include <dhcp-agent.h> + /* variation on network_addr_to_string in dhcp-convert.c we use + * this when we don't want to run around freeing results up, and + * know that it will be statically stored. Useful for insertion + * in message log routines. */ + + char *network_address_to_string_static(uint32_t addr) + { + struct in_addr in; + in.s_addr = addr; + + return(inet_ntoa(in)); + } + /* Get port number for named service. */ Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-packet-build.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-packet-build.c 15 Feb 2002 02:00:24 -0000 1.1 --- dhcp-packet-build.c 25 Feb 2002 01:39:30 -0000 1.2 *************** *** 133,144 **** * * * * * * * * * * * */ ! /* build ethernet header with broadcast destination address. */ ! static void build_eth_broadcast(rawnet_t *net, ! eth_addr_t client_hw_addr, ! uint16_t type) ! { ! eth_set_dst_address(net->ether_p, eth_broadcast); ! eth_set_src_address(net->ether_p, client_hw_addr); eth_set_type(net->ether_p, type); --- 133,143 ---- * * * * * * * * * * * */ ! static void build_eth(rawnet_t *net, ! eth_addr_t source_hw_addr, ! eth_addr_t dest_hw_addr, ! uint16_t type) { ! eth_set_dst_address(net->ether_p, dest_hw_addr); ! eth_set_src_address(net->ether_p, source_hw_addr); eth_set_type(net->ether_p, type); *************** *** 146,149 **** --- 145,156 ---- } + /* build ethernet header with broadcast destination address. */ + static void build_eth_broadcast(rawnet_t *net, eth_addr_t source_hw_addr, uint16_t type) + + { + build_eth(net, source_hw_addr, eth_broadcast, type); + return; + } + /* * * * * * * * * * * * * ARP/UNARP Routines. * *************** *** 196,203 **** /* Build ARP reply. */ void build_arp_reply(rawnet_t *net, ! uint32_t source_addr, ! uint32_t dest_addr, ! eth_addr_t source_hw_addr, ! eth_addr_t dest_hw_addr) { build_arp_proc(net, ARP_OP_REPLY, source_hw_addr, source_addr, dest_hw_addr, dest_addr); --- 203,210 ---- /* Build ARP reply. */ void build_arp_reply(rawnet_t *net, ! uint32_t source_addr, ! uint32_t dest_addr, ! eth_addr_t source_hw_addr, ! eth_addr_t dest_hw_addr) { build_arp_proc(net, ARP_OP_REPLY, source_hw_addr, source_addr, dest_hw_addr, dest_addr); *************** *** 205,208 **** --- 212,226 ---- } + /* Build ARP request. */ + void build_arp_request(rawnet_t *net, + uint32_t source_addr, + uint32_t dest_addr, + eth_addr_t source_hw_addr) + + { + build_arp_proc(net, ARP_OP_REQUEST, source_hw_addr, source_addr, eth_broadcast, dest_addr); + return; + } + /* Build ARP reply with broadcast destination hardware address. */ void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) *************** *** 210,214 **** build_arp_reply(net, source_addr, ip_addr_broadcast, ! source_hw_addr, eth_broadcast); return; } --- 228,232 ---- build_arp_reply(net, source_addr, ip_addr_broadcast, ! source_hw_addr, eth_broadcast); return; } *************** *** 232,236 **** * * * * * * * * * * * * * * * */ ! static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len, uint8_t protocol) { ip_set_hl(net->ip_p, IP_HDR_LEN); --- 250,255 ---- * * * * * * * * * * * * * * * */ ! static void build_ip(rawnet_t *net, uint16_t ip_len, uint8_t protocol, ! ip_addr_t source_addr, ip_addr_t dest_addr) { ip_set_hl(net->ip_p, IP_HDR_LEN); *************** *** 244,249 **** /* Do checksum later. */ ! ip_set_source_addr(net->ip_p, 0); ! ip_set_dest_addr(net->ip_p, ip_addr_broadcast); return; --- 263,276 ---- /* Do checksum later. */ ! ip_set_source_addr(net->ip_p, source_addr); ! ip_set_dest_addr(net->ip_p, dest_addr); ! ! return; ! } ! ! static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len, uint8_t protocol, ip_addr_t source_addr) ! { ! ! build_ip(net, ip_len, protocol, source_addr, ip_addr_broadcast); return; *************** *** 345,349 **** build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_UDP); build_udp(net, udp_len); build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); --- 372,376 ---- build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_UDP, 0); build_udp(net, udp_len); build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); *************** *** 402,406 **** build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); --- 429,433 ---- build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_ICMP, 0); build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); *************** *** 417,422 **** build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); net->type = RAWNET_ICMP; --- 444,476 ---- build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_ICMP, 0); build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); + + net->type = RAWNET_ICMP; + net->packet_len = ETH_HDR_LEN + ip_len; + + write_packet(net); + } + + static void build_icmp_echo_request_proc(rawnet_t *net, uint32_t id, uint32_t seq) + { + icmp_echo_set_id(net->icmp_p, seq); + icmp_echo_set_seq(net->icmp_p, seq); + + return; + } + + /* build icmp echo request. */ + void build_icmp_echo_request(rawnet_t *net, ip_addr_t source_addr, ip_addr_t dest_addr, + eth_addr_t source_mac, eth_addr_t dest_mac, uint32_t id, + uint32_t seq) + { + int ip_len = IP_HDR_LEN + + ICMP_HDR_LEN + 4; /* 4 bytes for vanilla icmp echo + request packet. */ + build_eth(net, source_mac, dest_mac, ETH_TYPE_IP); + build_ip(net, ip_len, IP_PROTO_ICMP, source_addr, dest_addr); + build_icmp_header_proc(net, ICMP_ECHO, 0); + build_icmp_echo_request_proc(net, id, seq); net->type = RAWNET_ICMP; Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-util.c 9 Feb 2002 15:50:30 -0000 1.8 --- dhcp-util.c 25 Feb 2002 01:39:30 -0000 1.9 *************** *** 439,440 **** --- 439,455 ---- return(random()); } + + struct timeval timeval_diff(struct timeval begin, struct timeval end) + { + struct timeval difference; + + if(begin.tv_usec > end.tv_usec) { + end.tv_sec--; + end.tv_usec += 1000000; + } + + difference.tv_sec = end.tv_sec - begin.tv_sec; + difference.tv_usec = end.tv_usec - begin.tv_usec; + + return difference; + } |
From: Thamer Al-H. <act...@us...> - 2002-02-17 04:37:38
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv17426 Modified Files: Makefile.am Makefile.in dhcp-agent.h dhcp-icmp.c Added Files: dhcp-icmp-discovery.c Log Message: added icmp subnet discovery; not tested yet; --- NEW FILE: dhcp-icmp-discovery.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v 1.1 2002/02/17 04:37:35 actmodern Exp $ * Copyright 2001 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * ICMP discovery routines: * * We currently have code for subnet mask discovery, and * discovery of host with least latency. * */ #include <dhcp-agent.h> /* Check for icmp mask response. */ static int icmp_check_mask_reply(void *arg) { rawnet_t *net = arg; if((net->type = RAWNET_ICMP) && (icmp_get_type(net->icmp_p) == ICMP_MASKREPLY)) return 1; else return 0; } /* Discover subnet mask: * If discovered fill in subnet_mask and return 0. * Otherwise return 1 */ int icmp_subnet_mask_discovery(rawnet_t *net, uint32_t *subnet_mask) { uint32_t reply_mask; /* Build ICMP mask request packet. We don't actually care * about sequence or IDs since we'll accept the first * response on our subnet regardless. Still let's be nice to * the mask repliers and set them up anyway. */ build_icmp_mask_request(net, 0, 0); if(rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply)) { error_message("icmp mask discovery: timeout on discovery"); return -1; } /* A reply should contain the subnet mask. If we're actually * doing subnet mask discovery we assume any subnet mask * returned is valid. */ reply_mask = icmp_mask_get_mask(net->icmp_p); memcpy(subnet_mask, &reply_mask, IP_ADDR_LEN); return 0; } Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Makefile.am 16 Feb 2002 17:54:33 -0000 1.11 --- Makefile.am 17 Feb 2002 04:37:35 -0000 1.12 *************** *** 20,24 **** dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence --- 20,24 ---- dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Makefile.in 16 Feb 2002 17:54:33 -0000 1.11 --- Makefile.in 17 Feb 2002 04:37:35 -0000 1.12 *************** *** 83,87 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c --- 83,87 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c *************** *** 115,119 **** dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = --- 115,119 ---- dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcp-icmp-discovery.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = *************** *** 141,150 **** .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ .deps/dhcp-convert.P .deps/dhcp-daemon.P .deps/dhcp-eth.P \ ! .deps/dhcp-files.P .deps/dhcp-icmp.P .deps/dhcp-interface.P \ ! .deps/dhcp-ip.P .deps/dhcp-list.P .deps/dhcp-log.P .deps/dhcp-net.P \ ! .deps/dhcp-options-strings.P .deps/dhcp-packet-build.P \ ! .deps/dhcp-print.P .deps/dhcp-rtt.P .deps/dhcp-sniff.P \ ! .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P .deps/dhcp-udp.P \ ! .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) --- 141,150 ---- .deps/dhcp-client-states.P .deps/dhcp-client.P .deps/dhcp-com.P \ .deps/dhcp-convert.P .deps/dhcp-daemon.P .deps/dhcp-eth.P \ ! .deps/dhcp-files.P .deps/dhcp-icmp-discovery.P .deps/dhcp-icmp.P \ ! .deps/dhcp-interface.P .deps/dhcp-ip.P .deps/dhcp-list.P \ ! .deps/dhcp-log.P .deps/dhcp-net.P .deps/dhcp-options-strings.P \ ! .deps/dhcp-packet-build.P .deps/dhcp-print.P .deps/dhcp-rtt.P \ ! .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P \ ! .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** dhcp-agent.h 16 Feb 2002 17:54:33 -0000 1.29 --- dhcp-agent.h 17 Feb 2002 04:37:35 -0000 1.30 *************** *** 749,753 **** extern uint8_t icmp_get_type(icmp_obj *icmp); ! extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); --- 749,753 ---- extern uint8_t icmp_get_type(icmp_obj *icmp); ! extern uint32_t icmp_mask_get_mask(icmp_obj *icmp_p); extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); Index: dhcp-icmp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-icmp.c 14 Feb 2002 10:06:53 -0000 1.4 --- dhcp-icmp.c 17 Feb 2002 04:37:35 -0000 1.5 *************** *** 45,48 **** --- 45,53 ---- } + uint32_t icmp_mask_get_mask(icmp_obj *icmp) + { + return(icmp->icmp_msg.mask.icmp_mask); + } + /* set routines. */ void icmp_set_type(icmp_obj *icmp, uint8_t type) *************** *** 73,77 **** void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask) { ! icmp->icmp_msg.mask.icmp_mask = htonl(mask); } --- 78,82 ---- void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask) { ! icmp->icmp_msg.mask.icmp_mask = mask; } |
From: Thamer Al-H. <act...@us...> - 2002-02-16 17:54:37
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv10882 Modified Files: Makefile.am Makefile.in README TODO dhcp-agent.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-interface.c dhcp-net.c dhcp-sniff.c Log Message: moved client_transact to a rawnet generic function; this is to make it useable for icmp discovery; still broken because of libdnet-1.1 but we're compatible with it too :-); Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile.am 15 Feb 2002 09:19:52 -0000 1.10 --- Makefile.am 16 Feb 2002 17:54:33 -0000 1.11 *************** *** 10,14 **** dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \ ! dhcp-sniffer-ohandlers.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 10,14 ---- dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \ dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \ ! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile.in 15 Feb 2002 09:19:52 -0000 1.10 --- Makefile.in 16 Feb 2002 17:54:33 -0000 1.11 *************** *** 78,82 **** bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c --- 78,82 ---- bin_PROGRAMS = dhcpsniff dhcpclient ! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c dhcp-rtt.c *************** *** 106,110 **** dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \ dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \ ! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = --- 106,110 ---- dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \ dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \ ! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcp-rtt.o dhcpsniff_DEPENDENCIES = dhcpsniff_LDFLAGS = Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** README 1 Feb 2002 00:42:03 -0000 1.4 --- README 16 Feb 2002 17:54:33 -0000 1.5 *************** *** 35,46 **** http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (0.8 or above). http://libdnet.sourceforge.net/ Please note that if you wish to get dhcp-agent ported to another ! operating system, you should first check if libdnet and libpcap have ! been ported to that system. dhcp-agent relies on these two libraries ! for a portable raw network layer. See the CAVEATS file for more known issues. --- 35,47 ---- http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (1.1 or above). http://libdnet.sourceforge.net/ Please note that if you wish to get dhcp-agent ported to another ! operating system, you should first check if libdnet and libpcap ! can be ported to that system. dhcp-agent relies on these two ! libraries for a portable raw network layer as well as a portable ! method of setting up networking. See the CAVEATS file for more known issues. *************** *** 94,97 **** --- 95,109 ---- For announcements. + + For filing a support request or bug report please consider + visiting dhcp-agent's page at sourceforge and using the + applicable forum: + + http://www.sourceforge.net/projects/dhcp-agent/ + + Although I do try to reply to mails sent to me personaly, please + know that you are more likely to receive a response from others + on the list, or receive better support from the support forums. I + am slower than a greater collective of users. About the license Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TODO 15 Feb 2002 09:19:52 -0000 1.9 --- TODO 16 Feb 2002 17:54:33 -0000 1.10 *************** *** 51,52 **** --- 51,53 ---- address. check, fix, clean. -- clean up dhcp-packet-build.c + -- need a proper rtt featured re/send/accept routine for raw packets. \ No newline at end of file Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** dhcp-agent.h 15 Feb 2002 09:19:52 -0000 1.28 --- dhcp-agent.h 16 Feb 2002 17:54:33 -0000 1.29 *************** *** 20,24 **** * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! * check specific source files for their licenses. */ --- 20,24 ---- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! * */ *************** *** 337,341 **** typedef struct { intf_t *interface_handle; ! struct intf_entry *interface_entry; } interface_control_t; --- 337,341 ---- typedef struct { intf_t *interface_handle; ! struct intf_entry interface_entry; } interface_control_t; *************** *** 487,491 **** extern int resolv(char *address, uint32_t *addr); ! extern rawnet_t *net_create(char *device, char *filter, int sport, int dport, int promiscious); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); --- 487,491 ---- extern int resolv(char *address, uint32_t *addr); ! extern rawnet_t *rawnet_create(char *device, char *filter, int sport, int dport, int promiscious); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); *************** *** 517,520 **** --- 517,524 ---- extern int rawnet_up(rawnet_t *net); extern void rawnet_down(rawnet_t *net); + + extern int rawnet_packet_transact(rawnet_t *net, void *arg, + void (*update)(void *arg), + int (*check)(void *arg)); /* Daemon routines. */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-control.c 15 Feb 2002 09:19:52 -0000 1.13 --- dhcp-client-control.c 16 Feb 2002 17:54:33 -0000 1.14 *************** *** 113,117 **** char filter_buff[GENERIC_BUFFSIZE]; eth_addr_t interface_addr; - int retval; #ifdef HAVE_UNAME --- 113,116 ---- *************** *** 135,157 **** * even if its not initialized properly. */ ! retval = interface_is_up(dc->interface_control); ! ! switch(retval) { ! ! case -1: ! destroy_dhcp_client_control(dc); ! return NULL; ! ! case 0: ! if(interface_up(dc->interface_control, INADDR_ANY, 0xffffffff, -1)) { ! error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno)); ! destroy_dhcp_client_control(dc); ! return NULL; ! } - case 1: /* is up: fallthrough. */ - default: - break; } --- 134,143 ---- * even if its not initialized properly. */ ! if(interface_up(dc->interface_control, 0, 0xffffffff, -1)) { ! error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno)); ! destroy_dhcp_client_control(dc); ! return NULL; } *************** *** 179,183 **** dport, sport); ! if((dc->rawnet = net_create(interface, filter_buff, sport, dport, promiscious)) == NULL) { destroy_dhcp_client_control(dc); return NULL; --- 165,169 ---- dport, sport); ! if((dc->rawnet = rawnet_create(interface, filter_buff, sport, dport, promiscious)) == NULL) { destroy_dhcp_client_control(dc); return NULL; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-client-states.c 15 Feb 2002 09:19:52 -0000 1.17 --- dhcp-client-states.c 16 Feb 2002 17:54:33 -0000 1.18 *************** *** 76,86 **** } ! /* these checking routines are independant of the checks done ! * in client_transact. they're a more specific type of check.*/ ! /* filter to check for valid discover responses. */ ! static int client_discover_check(dhcp_client_control_t *dc) { ! if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) || dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)) return 1; --- 76,103 ---- } ! /* Basic DHCP test on incoming rawnet packet. */ ! static int client_check_dhcp(dhcp_client_control_t *dc) ! { ! /* check for generic dhcp response. ! * we check for type, validity and ! * matching xid. */ ! if(dc->rawnet->type != RAWNET_DHCP || ! (!rawnet_is_valid(dc->rawnet)) || ! (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) ! return 0; ! ! /* great: valid dhcp response. */ ! return 1; ! ! } ! ! /* check for valid discover responses. */ ! static int client_discover_check(void *arg) { ! dhcp_client_control_t *dc = arg; ! ! if(client_check_dhcp(dc) || ! dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) || dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)) return 1; *************** *** 89,96 **** } ! /* filter to check for valid request responses. */ ! static int client_request_check(dhcp_client_control_t *dc) { ! if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM) || dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM)) return 1; --- 106,116 ---- } ! /* check for valid request responses. */ ! static int client_request_check(void *arg) { ! dhcp_client_control_t *dc = arg; ! ! if(client_check_dhcp(dc) || ! dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM) || dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM)) return 1; *************** *** 141,229 **** } ! /* Send and wait for reply. */ ! static int client_transact(dhcp_client_control_t *dc, unsigned update_secs, ! int (*check)(dhcp_client_control_t *dc)) { ! rtt_t *rtt; ! int retval; ! unsigned char send_packet = 1; ! ! rtt = rtt_create(); ! ! while(1) { ! ! if(send_packet) { ! ! send_packet = 0; ! ! if(rawnet_send_packet(dc->rawnet) < 0) { ! error_message("could not send packet: %s", strerror(errno)); ! rtt_destroy(rtt); ! return -1; ! } ! ! } ! ! retval = rawnet_wait(dc->rawnet, rtt_get_timeout(rtt)); ! ! switch(retval) { ! ! case RAWNET_PCAP_ERROR: ! error_message("couldn't wait for packets: %s : %s", dc->interface, ! strerror(errno)); ! rtt_destroy(rtt); ! return -1; ! ! case RAWNET_TIMEOUT: ! ! rtt_timeout(rtt); ! if(!rtt_can_retry(rtt)) { ! rtt_destroy(rtt); ! return -1; ! } ! ! /* During DISCOVER we keep updating our seconds field. */ ! ! if(update_secs) { ! dhcp_client_update_secs(dc); ! rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs); ! } ! ! send_packet = 1; ! break; ! ! case RAWNET_OK: ! ! /* Fixme: update timeout if packet isn't right. */ ! ! rawnet_get_packet(dc->rawnet); ! ! /* run tests. */ ! ! /* is it dhcp?. */ ! if(dc->rawnet->type != RAWNET_DHCP) ! break; ! ! /* is it valid? */ ! if(!rawnet_is_valid(dc->rawnet)) ! break; ! ! /* does it have the right xid? */ ! if(dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid) ! break; ! ! /* run check routine. */ ! if(!check(dc)) ! break; ! ! /* great: valid packet. destroy rtt object and return. */ ! rtt_destroy(rtt); ! return 0; ! default: ! break; ! ! } ! } } --- 161,172 ---- } ! /* update secs field. */ ! static void client_update_packet(void *arg) { ! dhcp_client_control_t *dc = arg; ! dhcp_client_update_secs(dc); ! rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs); ! return; } *************** *** 248,252 **** build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); ! if(client_transact(dc, 1, client_discover_check)) { error_message("timeout on DHCP DISCOVER."); return -1; --- 191,196 ---- build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); ! if(rawnet_packet_transact(dc->rawnet, dc, client_update_packet, ! client_discover_check)) { error_message("timeout on DHCP DISCOVER."); return -1; *************** *** 299,303 **** build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); ! if(client_transact(dc, 1, client_request_check)) { error_message("timeout on DHCP REQUEST."); return -1; --- 243,247 ---- build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); ! if(rawnet_packet_transact(dc->rawnet, dc, NULL, client_request_check)) { error_message("timeout on DHCP REQUEST."); return -1; Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client.c 15 Feb 2002 09:19:52 -0000 1.15 --- dhcp-client.c 16 Feb 2002 17:54:33 -0000 1.16 *************** *** 230,234 **** int promiscious = 0; ! while((c = getopt(argc, argv, "gcdavim:kwh:l:")) != -1) { switch(c) { --- 230,234 ---- int promiscious = 0; ! while((c = getopt(argc, argv, "gcdavi:m:kwh:l:")) != -1) { switch(c) { *************** *** 247,250 **** --- 247,251 ---- case 'i': + printf("%s\n",optarg); interface = strdup(optarg); break; Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-interface.c 15 Feb 2002 09:19:52 -0000 1.11 --- dhcp-interface.c 16 Feb 2002 17:54:33 -0000 1.12 *************** *** 32,37 **** { ! if(intf_get(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry->intf_name, strerror(errno)); return -1; } --- 32,37 ---- { ! if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; } *************** *** 42,47 **** static int interface_set_info(interface_control_t *ic) { ! if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry->intf_name, strerror(errno)); return -1; } --- 42,47 ---- static int interface_set_info(interface_control_t *ic) { ! if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; } *************** *** 51,60 **** /* Initialize interface handle. */ - interface_control_t *create_interface_control(char *name) { interface_control_t *ic; ! ic = xmalloc(sizeof(interface_control_t)); ic->interface_handle = intf_open(); --- 51,59 ---- /* Initialize interface handle. */ interface_control_t *create_interface_control(char *name) { interface_control_t *ic; ! ic = xcalloc(sizeof(interface_control_t)); ic->interface_handle = intf_open(); *************** *** 62,71 **** fatal_error("could not acquire interface handler"); ! ic->interface_entry = xmalloc(1024); ! memset(ic->interface_entry, 0, sizeof(struct intf_entry)); ! ic->interface_entry->intf_len = 1024; ! ! strlcpy(ic->interface_entry->intf_name, name, sizeof(ic->interface_entry->intf_name) -1); ! ic->interface_entry->intf_name[sizeof(ic->interface_entry->intf_name) -1] = 0; return ic; --- 61,66 ---- fatal_error("could not acquire interface handler"); ! strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1); ! ic->interface_entry.intf_name[sizeof(ic->interface_entry.intf_name) -1] = 0; return ic; *************** *** 79,83 **** /* Check to see if an interface is up. */ - int interface_is_up(interface_control_t *ic) { --- 74,77 ---- *************** *** 86,90 **** return -1; ! return(ic->interface_entry->intf_flags&INTF_FLAG_UP); } --- 80,84 ---- return -1; ! return(ic->interface_entry.intf_flags&INTF_FLAG_UP); } *************** *** 99,105 **** if(addr != INADDR_ANY) { ! ic->interface_entry->intf_addr->addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr->addr_bits); ! memcpy(&ic->interface_entry->intf_addr->addr_ip, &addr, IP_ADDR_LEN); } --- 93,99 ---- if(addr != INADDR_ANY) { ! ic->interface_entry.intf_addr->addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry.intf_addr->addr_bits); ! memcpy(&ic->interface_entry.intf_addr->addr_ip, &addr, IP_ADDR_LEN); } *************** *** 107,115 **** if(mtu != -1) ! ic->interface_entry->intf_mtu = mtu; else ! ic->interface_entry->intf_mtu = DEFAULT_MTU; ! ic->interface_entry->intf_flags |= INTF_FLAG_UP; if(interface_set_info(ic)) --- 101,109 ---- if(mtu != -1) ! ic->interface_entry.intf_mtu = mtu; else ! ic->interface_entry.intf_mtu = DEFAULT_MTU; ! ic->interface_entry.intf_flags |= INTF_FLAG_UP; if(interface_set_info(ic)) *************** *** 126,130 **** return -1; ! ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; if(interface_set_info(ic)) --- 120,124 ---- return -1; ! ic->interface_entry.intf_flags &= ~INTF_FLAG_UP; if(interface_set_info(ic)) *************** *** 140,144 **** return -1; ! memcpy(addr, &ic->interface_entry->intf_addr->addr_ip, IP_ADDR_LEN); return 0; --- 134,138 ---- return -1; ! memcpy(addr, &ic->interface_entry.intf_addr->addr_ip, IP_ADDR_LEN); return 0; Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-net.c 15 Feb 2002 02:00:24 -0000 1.14 --- dhcp-net.c 16 Feb 2002 17:54:33 -0000 1.15 *************** *** 164,170 **** /* Create the workhorse network module. */ ! rawnet_t *net_create(char *device, char *filter, ! int dhcp_src_port, int dhcp_dst_port, ! int promiscious) { rawnet_t *net; --- 164,170 ---- /* Create the workhorse network module. */ ! rawnet_t *rawnet_create(char *device, char *filter, ! int dhcp_src_port, int dhcp_dst_port, ! int promiscious) { rawnet_t *net; *************** *** 481,483 **** --- 481,565 ---- return 0; + } + + /* Generic send and wait for reply: + * + * Calls update() after timeout. + * Calls check() on every packet coming in. + * + */ + + int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), + int (*check)(void *arg)) + { + rtt_t *rtt; + int retval; + unsigned char send_packet = 1; + + /* create rtt mechanism. */ + rtt = rtt_create(); + + /* We loop here and re-send packets if we timeout, or fail a + * check on an incoming packets. */ + + while(1) { + + if(send_packet) { + + send_packet = 0; + + if(rawnet_send_packet(net) < 0) { + error_message("could not send packet: %s", strerror(errno)); + rtt_destroy(rtt); + return -1; + } + + } + + retval = rawnet_wait(net, rtt_get_timeout(rtt)); + + switch(retval) { + + case RAWNET_PCAP_ERROR: + error_message("couldn't wait for packets: %s : %s", net->device, + strerror(errno)); + rtt_destroy(rtt); + return -1; + + case RAWNET_TIMEOUT: + + rtt_timeout(rtt); + if(!rtt_can_retry(rtt)) { + rtt_destroy(rtt); + return -1; + } + + if(update) /* update if needed. only called after timeout. */ + update(arg); + + send_packet = 1; + break; + + case RAWNET_OK: + + rawnet_get_packet(net); + + if(!check) /* no check? return 0 anyway (we want + * any packet it seems). */ + return 0; + + if(check(arg)) { /* if we have a check + * then check packet. */ + rtt_destroy(rtt); + return 0; /* it's good. let's return. */ + } + + /* otherwise we should just continue. */ + break; + + default: + error_message("invalid return from rawnet_send_packet() -- this is a bug report it please"); + break; + } + } } Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sniff.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-sniff.c 9 Feb 2002 16:34:42 -0000 1.5 --- dhcp-sniff.c 16 Feb 2002 17:54:33 -0000 1.6 *************** *** 79,83 **** /* It's ok not to set ports since we're not writing any packets. */ ! net = net_create(interface_name, filter_buff, 0, 0, 1); if(net == NULL) --- 79,83 ---- /* It's ok not to set ports since we're not writing any packets. */ ! net = rawnet_create(interface_name, filter_buff, 0, 0, 1); if(net == NULL) |
From: Thamer Al-H. <act...@us...> - 2002-02-15 09:19:55
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv27679 Modified Files: COST Makefile.am Makefile.in TODO dhcp-agent.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-interface.c dhcp-sysconf.c Log Message: ported dhcp-agent to use libdnet-1.1; it's broken though -- looks like i found a bug in libdnet; Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** COST 15 Feb 2002 02:00:24 -0000 1.4 --- COST 15 Feb 2002 09:19:52 -0000 1.5 *************** *** 1,10 **** In writing dhcp-agent I suffered the following: ! Feb - March 2001 (Current values as of the Feb 9) 24 pots of coffee; 132 camel filter cigarettes; 12 diet cokes (cutting down); 845 mp3s (thanks stephanie); 18 historical trips ! to the wash room; 16 showers; one pretty geekette; one job offer ! :-) Jan - Feb 2001 --- 1,10 ---- In writing dhcp-agent I suffered the following: ! Feb - March 2001 (Current values as of the Feb 14) 24 pots of coffee; 132 camel filter cigarettes; 12 diet cokes (cutting down); 845 mp3s (thanks stephanie); 18 historical trips ! to the wash room; 16 showers; lost one pretty geekette; got one ! job offer; moving up in the world... Jan - Feb 2001 Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.am 15 Feb 2002 02:00:24 -0000 1.9 --- Makefile.am 15 Feb 2002 09:19:52 -0000 1.10 *************** *** 22,26 **** dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h --- 22,26 ---- dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.in 15 Feb 2002 02:00:24 -0000 1.9 --- Makefile.in 15 Feb 2002 09:19:52 -0000 1.10 *************** *** 86,90 **** ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h --- 86,90 ---- ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TODO 14 Feb 2002 10:06:53 -0000 1.8 --- TODO 15 Feb 2002 09:19:52 -0000 1.9 *************** *** 48,53 **** convention where name could be the name of the process, module, or function. - -- rawnet's packet construction isn't squeaky clean -- make a new - source file called dhcp-build-packets.c and polish it up -- rawnet and the dhcp client control are foobared by a fake mac address. check, fix, clean. --- 48,52 ---- convention where name could be the name of the process, module, or function. -- rawnet and the dhcp client control are foobared by a fake mac address. check, fix, clean. + -- clean up dhcp-packet-build.c Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** dhcp-agent.h 15 Feb 2002 02:00:24 -0000 1.27 --- dhcp-agent.h 15 Feb 2002 09:19:52 -0000 1.28 *************** *** 329,336 **** } client_conf_t; ! /* interface control object is just a typedef of ! * dnet's intf_t for now. */ ! typedef intf_t interface_control_t; /* Client data object. */ --- 329,342 ---- } client_conf_t; ! /* interface control object: ! * we store dnet's interface handle, ! * and interface_entry structure. ! * We need the entry structure ! */ ! typedef struct { ! intf_t *interface_handle; ! struct intf_entry *interface_entry; ! } interface_control_t; /* Client data object. */ *************** *** 809,819 **** /* interface control */ ! extern interface_control_t *create_interface_control(void); ! extern int interface_is_up(interface_control_t *ic, char *name); ! extern int interface_up(interface_control_t *ic, char *name, uint32_t addr, ! uint32_t netmask, int mtu); ! extern int interface_down(interface_control_t *ic, char *name); extern void destroy_interface_control(interface_control_t *ic); ! extern int interface_get_ip_addr(interface_control_t *ic, char *name, uint32_t *addr); /* client states */ --- 815,824 ---- /* interface control */ ! extern interface_control_t *create_interface_control(char *name); ! extern int interface_is_up(interface_control_t *ic); ! extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); ! extern int interface_down(interface_control_t *ic); extern void destroy_interface_control(interface_control_t *ic); ! extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); /* client states */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-control.c 11 Feb 2002 18:02:24 -0000 1.12 --- dhcp-client-control.c 15 Feb 2002 09:19:52 -0000 1.13 *************** *** 113,117 **** char filter_buff[GENERIC_BUFFSIZE]; eth_addr_t interface_addr; ! #ifdef HAVE_UNAME struct utsname utsname; --- 113,118 ---- char filter_buff[GENERIC_BUFFSIZE]; eth_addr_t interface_addr; ! int retval; ! #ifdef HAVE_UNAME struct utsname utsname; *************** *** 122,126 **** dc->state = 0; dc->interface = strdup(interface); ! dc->interface_control = create_interface_control(); dc->conf = create_client_conf(dc); dc->cache = create_client_cache(dc); --- 123,127 ---- dc->state = 0; dc->interface = strdup(interface); ! dc->interface_control = create_interface_control(interface); dc->conf = create_client_conf(dc); dc->cache = create_client_cache(dc); *************** *** 133,144 **** /* We need to bring the interface up, * even if its not initialized properly. */ ! ! if(!interface_is_up(dc->interface_control, dc->interface) ! && interface_up(dc->interface_control, dc->interface, INADDR_ANY, 0xffffffff, -1)) { ! error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno)); ! destroy_dhcp_client_control(dc); ! return NULL; } ! /* Get port numbers from services db. */ --- 134,159 ---- /* We need to bring the interface up, * even if its not initialized properly. */ ! ! retval = interface_is_up(dc->interface_control); ! ! switch(retval) { ! ! case -1: ! destroy_dhcp_client_control(dc); ! return NULL; ! ! case 0: ! if(interface_up(dc->interface_control, INADDR_ANY, 0xffffffff, -1)) { ! ! error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno)); ! destroy_dhcp_client_control(dc); ! return NULL; ! } ! ! case 1: /* is up: fallthrough. */ ! default: ! break; } ! /* Get port numbers from services db. */ *************** *** 228,232 **** if(dc->interface_control) ! intf_close(dc->interface_control); if(dc->class_id) --- 243,247 ---- if(dc->interface_control) ! destroy_interface_control(dc->interface_control); if(dc->class_id) Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client-states.c 15 Feb 2002 02:00:24 -0000 1.16 --- dhcp-client-states.c 15 Feb 2002 09:19:52 -0000 1.17 *************** *** 108,112 **** if(rawnet_get_interface_hw_addr(dc->rawnet, &client_hw_addr) || ! interface_get_ip_addr(dc->interface_control, dc->interface, &client_ip_addr)) { error_message("could get get hardware and ip addresses after initialization."); return -1; --- 108,112 ---- if(rawnet_get_interface_hw_addr(dc->rawnet, &client_hw_addr) || ! interface_get_ip_addr(dc->interface_control, &client_ip_addr)) { error_message("could get get hardware and ip addresses after initialization."); return -1; Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client.c 11 Feb 2002 18:02:24 -0000 1.14 --- dhcp-client.c 15 Feb 2002 09:19:52 -0000 1.15 *************** *** 33,40 **** { info_message("shutting down."); ! client_release(dc); ! if(interface_down(dc->interface_control, dc->interface)) ! error_message("warning: could not bring interface down."); ! delete_pid_file(dc->interface); exit(0); --- 33,44 ---- { info_message("shutting down."); ! ! if(dc) { /* only do clean up if we can. */ ! client_release(dc); ! if(interface_down(dc->interface_control)) ! error_message("warning: could not bring interface down."); ! ! delete_pid_file(dc->interface); ! } exit(0); *************** *** 336,340 **** if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered fatal error. cannot continue. exiting"); ! do_shutdown(dc); } --- 340,344 ---- if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered fatal error. cannot continue. exiting"); ! do_shutdown(NULL); } *************** *** 365,369 **** if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered a fatal error. cannot continue. exiting"); ! do_shutdown(dc); } --- 369,373 ---- if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered a fatal error. cannot continue. exiting"); ! do_shutdown(NULL); } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-interface.c 8 Feb 2002 01:37:29 -0000 1.10 --- dhcp-interface.c 15 Feb 2002 09:19:52 -0000 1.11 *************** *** 27,38 **** #include <dhcp-agent.h> - static struct intf_info info; - /* Internal utilities */ ! static int interface_get_info(interface_control_t *ic, char *name) { ! if(intf_get(ic, name, &info) < 0) { ! error_message("could not lookup interface %s : %d", name, strerror(errno)); return -1; } --- 27,37 ---- #include <dhcp-agent.h> /* Internal utilities */ ! static int interface_get_info(interface_control_t *ic) { ! ! if(intf_get(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry->intf_name, strerror(errno)); return -1; } *************** *** 41,48 **** } ! static int interface_set_info(interface_control_t *ic, char *name) { ! if(intf_set(ic, name, &info) < 0) { ! error_message("could not lookup interface %s : %d", name, strerror(errno)); return -1; } --- 40,47 ---- } ! static int interface_set_info(interface_control_t *ic) { ! if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("could not lookup interface %s : %d", ic->interface_entry->intf_name, strerror(errno)); return -1; } *************** *** 53,88 **** /* Initialize interface handle. */ ! interface_control_t *create_interface_control(void) { ! interface_control_t *ic; /* typedef'd from intf_t */ ! ! ic = intf_open(); ! if(ic == NULL) /* XXX -- update to dnet's error strings when dnet has some */ fatal_error("could not acquire interface handler"); ! ! return ic; } void destroy_interface_control(interface_control_t *ic) { ! intf_close(ic); } /* Check to see if an interface is up. */ ! int interface_is_up(interface_control_t *ic, char *name) { ! if(interface_get_info(ic, name)) ! return 0; ! return(info.intf_flags&INTF_FLAG_UP); } /* bring an interface up */ ! int interface_up(interface_control_t *ic, char *name, uint32_t addr, uint32_t netmask, int mtu) { ! if(interface_get_info(ic, name)) return -1; --- 52,97 ---- /* Initialize interface handle. */ ! interface_control_t *create_interface_control(char *name) { ! interface_control_t *ic; ! ! ic = xmalloc(sizeof(interface_control_t)); ! ! ic->interface_handle = intf_open(); ! if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */ fatal_error("could not acquire interface handler"); ! ! ic->interface_entry = xmalloc(1024); ! memset(ic->interface_entry, 0, sizeof(struct intf_entry)); ! ic->interface_entry->intf_len = 1024; ! ! strlcpy(ic->interface_entry->intf_name, name, sizeof(ic->interface_entry->intf_name) -1); ! ic->interface_entry->intf_name[sizeof(ic->interface_entry->intf_name) -1] = 0; ! ! return ic; } void destroy_interface_control(interface_control_t *ic) { ! intf_close(ic->interface_handle); ! xfree(ic); } /* Check to see if an interface is up. */ ! int interface_is_up(interface_control_t *ic) { ! if(interface_get_info(ic)) ! return -1; ! return(ic->interface_entry->intf_flags&INTF_FLAG_UP); } /* bring an interface up */ ! int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu) { ! if(interface_get_info(ic)) return -1; *************** *** 90,114 **** if(addr != INADDR_ANY) { ! ! info.intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &info.intf_addr.addr_bits); ! memcpy(&info.intf_addr.addr_ip, &addr, IP_ADDR_LEN); ! info.intf_info |= INTF_INFO_ADDR; ! ! } else ! info.intf_info &= ~INTF_INFO_ADDR; /* Set mtu to default if not passed. */ if(mtu != -1) ! info.intf_mtu = mtu; else ! info.intf_mtu = DEFAULT_MTU; ! info.intf_info |= INTF_INFO_MTU; ! info.intf_info |= INTF_INFO_FLAGS; ! info.intf_flags |= INTF_FLAG_UP; ! if(interface_set_info(ic, name)) return -1; --- 99,117 ---- if(addr != INADDR_ANY) { ! ic->interface_entry->intf_addr->addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr->addr_bits); ! memcpy(&ic->interface_entry->intf_addr->addr_ip, &addr, IP_ADDR_LEN); ! } /* Set mtu to default if not passed. */ if(mtu != -1) ! ic->interface_entry->intf_mtu = mtu; else ! ic->interface_entry->intf_mtu = DEFAULT_MTU; ! ic->interface_entry->intf_flags |= INTF_FLAG_UP; ! if(interface_set_info(ic)) return -1; *************** *** 117,129 **** /* take down an interface. */ ! int interface_down(interface_control_t *ic, char *name) { ! if(interface_get_info(ic, name)) return -1; ! info.intf_flags &= ~INTF_FLAG_UP; ! if(interface_set_info(ic, name)) return -1; --- 120,132 ---- /* take down an interface. */ ! int interface_down(interface_control_t *ic) { ! if(interface_get_info(ic)) return -1; ! ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; ! if(interface_set_info(ic)) return -1; *************** *** 132,143 **** /* get ip address of an interface. */ ! int interface_get_ip_addr(interface_control_t *ic, char *name, uint32_t *addr) { ! if(interface_get_info(ic, name)) return -1; ! memcpy(addr, &info.intf_addr.addr_ip, IP_ADDR_LEN); return 0; } - --- 135,145 ---- /* get ip address of an interface. */ ! int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr) { ! if(interface_get_info(ic)) return -1; ! memcpy(addr, &ic->interface_entry->intf_addr->addr_ip, IP_ADDR_LEN); return 0; } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-sysconf.c 9 Feb 2002 23:29:37 -0000 1.7 --- dhcp-sysconf.c 15 Feb 2002 09:19:52 -0000 1.8 *************** *** 98,106 **** int sysconf_routers(void *value, dhcp_client_control_t *dc) { ! struct addr addr, gw; uint32_t *addr_val; route_t *rt; list_t *routers; ! /* FIXME: insert ICMP ping checks so we can find * the best router and use it. --- 98,106 ---- int sysconf_routers(void *value, dhcp_client_control_t *dc) { ! struct route_entry r_entry; uint32_t *addr_val; route_t *rt; list_t *routers; ! /* FIXME: insert ICMP ping checks so we can find * the best router and use it. *************** *** 108,124 **** */ ! memset(&addr, 0, sizeof(addr)); ! memset(&gw, 0, sizeof(gw)); routers = value; addr_val = routers->data; ! addr.addr_type = ADDR_TYPE_IP; ! addr.addr_bits = 0; ! addr.addr_ip = 0; ! gw.addr_type = ADDR_TYPE_IP; ! gw.addr_bits = 0; ! memcpy(&gw.addr_ip, addr_val, IP_ADDR_LEN); rt = route_open(); --- 108,124 ---- */ ! memset(&r_entry.route_dst, 0, sizeof(r_entry.route_dst)); ! memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); routers = value; addr_val = routers->data; ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); rt = route_open(); *************** *** 126,130 **** return -1; ! if(route_add(rt, &addr, &gw) < 0) { route_close(rt); return -1; --- 126,130 ---- return -1; ! if(route_add(rt, &r_entry) < 0) { route_close(rt); return -1; *************** *** 227,231 **** fatal_error("do not have enough settings for interface configuration!"); ! if(interface_up(dc->interface_control, dc->interface, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); --- 227,231 ---- fatal_error("do not have enough settings for interface configuration!"); ! if(interface_up(dc->interface_control, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); *************** *** 286,290 **** make_file_public_read("/etc/resolv.conf"); } - return; --- 286,289 ---- |
From: Thamer Al-H. <act...@us...> - 2002-02-15 02:00:28
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv31286 Modified Files: COST Makefile.am Makefile.in THANKS dhcp-agent.h dhcp-client-states.c dhcp-net.c Added Files: dhcp-packet-build.c Log Message: moved packet building routines to dhcp-packet-build.c --- NEW FILE: dhcp-packet-build.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-packet-build.c,v 1.1 2002/02/15 02:00:24 actmodern Exp $ * * Copyright 2001 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Packet building routines: * Utility routines wrapped around the packet objects. * */ #include <dhcp-agent.h> /* constants we need. */ static const eth_addr_t eth_null = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; static const uint32_t ip_addr_broadcast = 0xffffffff; /* * * * * * * * * * * * * * * * Packet writing routines. * * * * * * * * * * * * * * * */ static void write_packet_dhcp(rawnet_t *net) { char *packet_ptr; /* Dump packet images for DHCP. */ packet_ptr = net->packet_data; memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); packet_ptr += ETH_HDR_LEN; ip_write_packet_image(net->ip_p, packet_ptr); packet_ptr += (ip_get_hl(net->ip_p)); udp_write_packet_image(net->udp_p, packet_ptr); packet_ptr += UDP_HDR_LEN; dhcp_write_packet_image(net->dhcp_p, packet_ptr); /* Run the IP checksum routine. */ ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); return; } static void write_packet_arp(rawnet_t *net) { char *packet_ptr; /* Dump packet images for ARP/UNARP. */ packet_ptr = net->packet_data; memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); packet_ptr += ETH_HDR_LEN; arp_write_packet_image(net->arp_p, packet_ptr); return; } static void write_packet_icmp(rawnet_t *net) { unsigned char *packet_ptr; /* Dump packet images for ICMP. */ packet_ptr = net->packet_data; memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); packet_ptr += ETH_HDR_LEN; ip_write_packet_image(net->ip_p, packet_ptr); packet_ptr += (ip_get_hl(net->ip_p)); icmp_write_packet_image(net->icmp_p, packet_ptr); ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); return; } static void write_packet(rawnet_t *net) { switch(net->type) { case RAWNET_DHCP: write_packet_dhcp(net); break; case RAWNET_ARP: write_packet_arp(net); break; case RAWNET_ICMP: write_packet_icmp(net); break; default: warn_message("warning: invalid packet type passed to write_packet() -- this is a bug report it please."); break; } return; } /* * * * * * * * * * * * * Ethernet Routines. * * * * * * * * * * * * */ /* build ethernet header with broadcast destination address. */ static void build_eth_broadcast(rawnet_t *net, eth_addr_t client_hw_addr, uint16_t type) { eth_set_dst_address(net->ether_p, eth_broadcast); eth_set_src_address(net->ether_p, client_hw_addr); eth_set_type(net->ether_p, type); return; } /* * * * * * * * * * * * * ARP/UNARP Routines. * * * * * * * * * * * * */ /* Build ARP packet: write out all the members. */ static void build_arp(rawnet_t *net, uint16_t opcode, eth_addr_t sender_hw_addr, uint32_t sender_ip_addr, eth_addr_t target_hw_addr, uint32_t target_ip_addr, uint8_t hardware_len) /* for unarp it's 0 */ { arp_set_hardware_type(net->arp_p, ARP_HRD_ETH); arp_set_protocol_type(net->arp_p, ARP_PRO_IP); arp_set_hardware_len(net->arp_p, hardware_len); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); arp_set_op(net->arp_p, opcode); arp_set_sender_hardware_address(net->arp_p, sender_hw_addr); arp_set_sender_protocol_address(net->arp_p, sender_ip_addr); arp_set_target_hardware_address(net->arp_p, target_hw_addr); arp_set_target_protocol_address(net->arp_p, target_ip_addr); return; } /* Build ARP Proc: Do all the work for an arp packet. */ static void build_arp_proc(rawnet_t *net, uint16_t opcode, eth_addr_t sender_hw_addr, uint32_t sender_ip_addr, eth_addr_t target_hw_addr, uint32_t target_ip_addr) { build_eth_broadcast(net, sender_hw_addr, ETH_TYPE_ARP); build_arp(net, opcode, sender_hw_addr, sender_ip_addr, target_hw_addr, target_ip_addr, ETH_ADDR_LEN); net->type = RAWNET_ARP; net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; write_packet(net); return; } /* Interface routines to ARP/UNARP building. */ /* Build ARP reply. */ void build_arp_reply(rawnet_t *net, uint32_t source_addr, uint32_t dest_addr, eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr) { build_arp_proc(net, ARP_OP_REPLY, source_hw_addr, source_addr, dest_hw_addr, dest_addr); return; } /* Build ARP reply with broadcast destination hardware address. */ void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) { build_arp_reply(net, source_addr, ip_addr_broadcast, source_hw_addr, eth_broadcast); return; } /* only one way to build unarp, so don't procify it. */ void build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) { build_eth_broadcast(net, source_hw_addr, ETH_TYPE_ARP); build_arp(net, ARP_OP_REPLY, eth_null, source_addr, eth_null, ip_addr_broadcast, 0); net->type = RAWNET_ARP; net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; write_packet(net); return; } /* * * * * * * * * * * * * * * * * Internet Protocol routines. * * * * * * * * * * * * * * * * */ static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len, uint8_t protocol) { ip_set_hl(net->ip_p, IP_HDR_LEN); ip_set_tos(net->ip_p, IP_TOS_RELIABILITY); ip_set_len(net->ip_p, ip_len); ip_set_id(net->ip_p, IP_DF); ip_set_off(net->ip_p, 0); ip_set_ttl(net->ip_p, IP_TTL_MAX); ip_set_proto(net->ip_p, protocol); /* Do checksum later. */ ip_set_source_addr(net->ip_p, 0); ip_set_dest_addr(net->ip_p, ip_addr_broadcast); return; } /* * * * * * * * * * * UDP routines. * * * * * * * * * * */ static void build_udp(rawnet_t *net, uint16_t udp_len) { udp_set_src_port(net->udp_p, net->src_port); udp_set_dst_port(net->udp_p, net->dst_port); udp_set_len(net->udp_p, udp_len); /* libdnet sets this properly for us. */ udp_set_cksum(net->udp_p, 0); return; } /* * * * * * * * * * * DHCP routines. * * * * * * * * * * */ static void build_dhcp(rawnet_t *net, uint32_t xid, uint16_t secs, eth_addr_t client_hw_addr, uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, uint32_t giaddr, list_t *options, unsigned char bootp_type) { dhcp_set_op(net->dhcp_p, bootp_type); dhcp_set_htype(net->dhcp_p, DLT_EN10MB); dhcp_set_hlen(net->dhcp_p, ETH_ADDR_LEN); dhcp_set_hops(net->dhcp_p, 0); dhcp_set_xid(net->dhcp_p, xid); dhcp_set_secs(net->dhcp_p, secs); dhcp_set_flag_broadcast(net->dhcp_p); dhcp_set_ciaddr(net->dhcp_p, ciaddr); dhcp_set_yiaddr(net->dhcp_p, yiaddr); dhcp_set_siaddr(net->dhcp_p, siaddr); dhcp_set_giaddr(net->dhcp_p, giaddr); dhcp_clear_chaddr(net->dhcp_p); dhcp_set_chaddr(net->dhcp_p, (unsigned char *)&client_hw_addr, ETH_ADDR_LEN); dhcp_clear_sname(net->dhcp_p); dhcp_clear_filename(net->dhcp_p); dhcp_set_magic_cookie(net->dhcp_p); dhcp_set_options(net->dhcp_p, options); return; } static void build_dhcp_proc(rawnet_t *net, uint32_t xid, time_t secs, uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, uint32_t giaddr, list_t *options, unsigned char bootp_type) { uint16_t ip_len, udp_len; int total_len; dhcp_purge(net->dhcp_p); /* clear up old options. */ /* Calculate the total length of the packet * including IP header but not datalink header. * This goes into ip_len */ ip_len = IP_HDR_LEN + /* IP Header length. */ UDP_HDR_LEN + /* UDP Header length. */ DHCP_FIXEDHDR_LEN + /* DHCP fixed header. */ 4 + /* magic cookie length. */ dhcp_get_options_len(options); /* options length. */ udp_len = ip_len - IP_HDR_LEN; total_len = ip_len + ETH_HDR_LEN; /* It is possible that we exceeded MTU. * * On smaller MTUs (once we configure it and not * hardcode it) it may be possible. So keep * this check in. XXX -- fixme: check for * UDP size, and overload DHCP when it * goes over that size. * */ if(total_len > DEFAULT_MTU) fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); build_ip_broadcast(net, ip_len, IP_PROTO_UDP); build_udp(net, udp_len); build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); /* Write packet. */ net->type = RAWNET_DHCP; net->packet_len = total_len; write_packet(net); return; } /* Create a dhcp discover message. */ void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) { build_dhcp_proc(net, xid, secs, 0, 0, 0, 0, options, DHCP_BOOTP_REQUEST); } /* Create dhcp request message. */ void build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) { build_dhcp_proc(net, xid, secs, 0, 0, 0, 0, options, DHCP_BOOTP_REQUEST); } /* Create icmp packet: procify this so we can use it for all other icmp building. */ static void build_icmp_header_proc(rawnet_t *net, uint8_t icmp_type, uint8_t icmp_code) { icmp_set_type(net->icmp_p, icmp_type); icmp_set_code(net->icmp_p, icmp_code); icmp_clear_cksum(net->icmp_p); return; } /* Create icmp mask reply/request packet: procify this to act as * a subroutine for the icmp mask interface routines. */ static void build_icmp_mask_proc(rawnet_t *net, uint8_t icmp_type, uint32_t icmp_id, uint32_t icmp_seq, uint32_t mask) { build_icmp_header_proc(net, icmp_type, 0); icmp_mask_set_seq(net->icmp_p, icmp_id); icmp_mask_set_seq(net->icmp_p, icmp_seq); icmp_mask_set_mask(net->icmp_p, mask); return; } /* build icmp mask request packet. */ void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq) { int ip_len = ICMP_HDR_LEN + 12 + IP_HDR_LEN; /* 12 bytes for the mask request. */ build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); net->type = RAWNET_ICMP; net->packet_len = ETH_HDR_LEN + ip_len; write_packet(net); } /* build icmp mask reply packet. */ void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask) { int ip_len = IP_HDR_LEN + ICMP_HDR_LEN + 12; /* 12 bytes for the mask reply. */ build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); net->type = RAWNET_ICMP; net->packet_len = ETH_HDR_LEN + ip_len; write_packet(net); } Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** COST 11 Feb 2002 18:02:24 -0000 1.3 --- COST 15 Feb 2002 02:00:24 -0000 1.4 *************** *** 3,9 **** Feb - March 2001 (Current values as of the Feb 9) ! 18 pots of coffee; 86 camel filter cigarettes; 8 diet cokes ! (cutting down); 845 mp3s (thanks stephanie); 12 historical trips ! to the wash room; 10 showers; one pretty geekette; Jan - Feb 2001 --- 3,10 ---- Feb - March 2001 (Current values as of the Feb 9) ! 24 pots of coffee; 132 camel filter cigarettes; 12 diet cokes ! (cutting down); 845 mp3s (thanks stephanie); 18 historical trips ! to the wash room; 16 showers; one pretty geekette; one job offer ! :-) Jan - Feb 2001 Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.am 9 Feb 2002 15:50:30 -0000 1.8 --- Makefile.am 15 Feb 2002 02:00:24 -0000 1.9 *************** *** 20,24 **** dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 20,24 ---- dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c \ dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c \ ! dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.in 9 Feb 2002 15:50:30 -0000 1.8 --- Makefile.in 15 Feb 2002 02:00:24 -0000 1.9 *************** *** 83,87 **** dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c --- 83,87 ---- dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcpclient_SOURCES = dhcp-client.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c dhcp-daemon.c dhcp-client-cache.c dhcp-cache-entry.c dhcp-client-control.c dhcp-interface.c dhcp-client-conf.c @DHCP_SNPRINTF@ dhcp-files.c dhcp-client-states.c dhcp-options-strings.c dhcp-convert.c dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c *************** *** 114,118 **** dhcp-cache-entry.o dhcp-client-control.o dhcp-interface.o \ dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ ! dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = --- 114,119 ---- dhcp-cache-entry.o dhcp-client-control.o dhcp-interface.o \ dhcp-client-conf.o dhcp-files.o dhcp-client-states.o \ ! dhcp-options-strings.o dhcp-convert.o dhcp-sysconf.o dhcp-rtt.o \ ! dhcp-packet-build.o dhcpclient_DEPENDENCIES = dhcpclient_LDFLAGS = *************** *** 142,148 **** .deps/dhcp-files.P .deps/dhcp-icmp.P .deps/dhcp-interface.P \ .deps/dhcp-ip.P .deps/dhcp-list.P .deps/dhcp-log.P .deps/dhcp-net.P \ ! .deps/dhcp-options-strings.P .deps/dhcp-print.P .deps/dhcp-rtt.P \ ! .deps/dhcp-sniff.P .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P \ ! .deps/dhcp-udp.P .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) --- 143,150 ---- .deps/dhcp-files.P .deps/dhcp-icmp.P .deps/dhcp-interface.P \ .deps/dhcp-ip.P .deps/dhcp-list.P .deps/dhcp-log.P .deps/dhcp-net.P \ ! .deps/dhcp-options-strings.P .deps/dhcp-packet-build.P \ ! .deps/dhcp-print.P .deps/dhcp-rtt.P .deps/dhcp-sniff.P \ ! .deps/dhcp-sniffer-ohandlers.P .deps/dhcp-sysconf.P .deps/dhcp-udp.P \ ! .deps/dhcp-util.P SOURCES = $(dhcpsniff_SOURCES) $(dhcpclient_SOURCES) OBJECTS = $(dhcpsniff_OBJECTS) $(dhcpclient_OBJECTS) Index: THANKS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/THANKS,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** THANKS 1 Feb 2002 00:42:03 -0000 1.2 --- THANKS 15 Feb 2002 02:00:24 -0000 1.3 *************** *** 12,13 **** --- 12,15 ---- -- The Tcpdump Group for their work on libpcap + + -- Bill Traynor for Solaris x86. Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** dhcp-agent.h 14 Feb 2002 10:43:34 -0000 1.26 --- dhcp-agent.h 15 Feb 2002 02:00:24 -0000 1.27 *************** *** 489,502 **** extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); ! extern void rawnet_build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void rawnet_build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void rawnet_build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); ! extern void rawnet_build_arp_reply(rawnet_t *net, uint32_t source_addr, uint32_t dest_addr, eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr); ! extern void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); --- 489,502 ---- extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); ! extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); ! extern void build_arp_reply(rawnet_t *net, uint32_t source_addr, uint32_t dest_addr, eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr); ! extern void build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); *************** *** 506,511 **** extern int rawnet_is_valid(rawnet_t *net); ! extern void rawnet_build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); ! extern void rawnet_build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); extern int rawnet_up(rawnet_t *net); --- 506,511 ---- extern int rawnet_is_valid(rawnet_t *net); ! extern void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); ! extern void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); extern int rawnet_up(rawnet_t *net); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client-states.c 12 Feb 2002 15:23:59 -0000 1.15 --- dhcp-client-states.c 15 Feb 2002 02:00:24 -0000 1.16 *************** *** 126,130 **** { ! rawnet_build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); --- 126,130 ---- { ! build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); *************** *** 135,139 **** static void client_broadcast_unarp(dhcp_client_control_t *dc) { ! rawnet_build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); --- 135,139 ---- static void client_broadcast_unarp(dhcp_client_control_t *dc) { ! build_unarp(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); *************** *** 243,250 **** dhcp_client_update_secs(dc); ! /* Our options cleared by rawnet_build_* since they are passed * down and later purged. */ ! rawnet_build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); if(client_transact(dc, 1, client_discover_check)) { --- 243,250 ---- dhcp_client_update_secs(dc); ! /* Our options cleared by build_* since they are passed * down and later purged. */ ! build_dhcp_discover(dc->rawnet, dc->xid, dc->secs, options); if(client_transact(dc, 1, client_discover_check)) { *************** *** 294,301 **** options = join_lists(options, cache_options); ! /* Our options cleared by rawnet_build_* since they are passed * down and later purged. */ ! rawnet_build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); if(client_transact(dc, 1, client_request_check)) { --- 294,301 ---- options = join_lists(options, cache_options); ! /* Our options cleared by build_* since they are passed * down and later purged. */ ! build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); if(client_transact(dc, 1, client_request_check)) { *************** *** 389,396 **** options = join_lists(options, cache_options); ! /* Our options cleared by rawnet_build_* since they are passed * down and later purged. */ ! rawnet_build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); if(rawnet_send_packet(dc->rawnet) < 0) { --- 389,396 ---- options = join_lists(options, cache_options); ! /* Our options cleared by build_* since they are passed * down and later purged. */ ! build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); if(rawnet_send_packet(dc->rawnet) < 0) { Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-net.c 14 Feb 2002 10:06:53 -0000 1.13 --- dhcp-net.c 15 Feb 2002 02:00:24 -0000 1.14 *************** *** 63,72 **** #include <dhcp-agent.h> - /* constants we need. */ - - static const eth_addr_t eth_null = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; - static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; - static const uint32_t ip_addr_broadcast = 0xffffffff; - /* Get port number for named service. */ --- 63,66 ---- *************** *** 413,783 **** } - /* Build routines. - * Convenient utility routines - * to build the kind of packets - * we need. */ - - static void build_arp(rawnet_t *net, - uint16_t opcode, - eth_addr_t sender_hw_addr, - uint32_t sender_ip_addr, - eth_addr_t target_hw_addr, - uint32_t target_ip_addr, - uint8_t hardware_len) /* for unarp it's 0 */ - { - - arp_set_hardware_type(net->arp_p, ARP_HRD_ETH); - arp_set_protocol_type(net->arp_p, ARP_PRO_IP); - arp_set_hardware_len(net->arp_p, hardware_len); - arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); - arp_set_op(net->arp_p, opcode); - arp_set_sender_hardware_address(net->arp_p, sender_hw_addr); - arp_set_sender_protocol_address(net->arp_p, sender_ip_addr); - arp_set_target_hardware_address(net->arp_p, target_hw_addr); - arp_set_target_protocol_address(net->arp_p, target_ip_addr); - - return; - } - - static void build_eth_broadcast(rawnet_t *net, - eth_addr_t client_hw_addr, - uint16_t type) - - { - eth_set_dst_address(net->ether_p, eth_broadcast); - eth_set_src_address(net->ether_p, client_hw_addr); - eth_set_type(net->ether_p, type); - - return; - } - - static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len, uint8_t protocol) - { - ip_set_hl(net->ip_p, IP_HDR_LEN); - ip_set_tos(net->ip_p, IP_TOS_RELIABILITY); - ip_set_len(net->ip_p, ip_len); - ip_set_id(net->ip_p, IP_DF); - ip_set_off(net->ip_p, 0); - ip_set_ttl(net->ip_p, IP_TTL_MAX); - ip_set_proto(net->ip_p, protocol); - - /* Do checksum later. */ - - ip_set_source_addr(net->ip_p, 0); - ip_set_dest_addr(net->ip_p, ip_addr_broadcast); - - return; - } - - static void build_udp(rawnet_t *net, uint16_t udp_len) - { - - udp_set_src_port(net->udp_p, net->src_port); - udp_set_dst_port(net->udp_p, net->dst_port); - udp_set_len(net->udp_p, udp_len); - - /* libdnet sets this properly for us. */ - - udp_set_cksum(net->udp_p, 0); - - return; - } - - static void build_dhcp(rawnet_t *net, - uint32_t xid, - uint16_t secs, - eth_addr_t client_hw_addr, - uint32_t ciaddr, - uint32_t yiaddr, - uint32_t siaddr, - uint32_t giaddr, - list_t *options, - unsigned char bootp_type) - { - - dhcp_set_op(net->dhcp_p, bootp_type); - dhcp_set_htype(net->dhcp_p, DLT_EN10MB); - dhcp_set_hlen(net->dhcp_p, ETH_ADDR_LEN); - dhcp_set_hops(net->dhcp_p, 0); - dhcp_set_xid(net->dhcp_p, xid); - dhcp_set_secs(net->dhcp_p, secs); - - dhcp_set_flag_broadcast(net->dhcp_p); - dhcp_set_ciaddr(net->dhcp_p, ciaddr); - dhcp_set_yiaddr(net->dhcp_p, yiaddr); - dhcp_set_siaddr(net->dhcp_p, siaddr); - dhcp_set_giaddr(net->dhcp_p, giaddr); - - dhcp_clear_chaddr(net->dhcp_p); - dhcp_set_chaddr(net->dhcp_p, (unsigned char *)&client_hw_addr, ETH_ADDR_LEN); - - dhcp_clear_sname(net->dhcp_p); - dhcp_clear_filename(net->dhcp_p); - - dhcp_set_magic_cookie(net->dhcp_p); - dhcp_set_options(net->dhcp_p, options); - - return; - } - - static void rawnet_write_packet_dhcp(rawnet_t *net) - { - char *packet_ptr; - - /* Dump packet images for DHCP. */ - - packet_ptr = net->packet_data; - memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ - - eth_write_packet_image(net->ether_p, packet_ptr); - packet_ptr += ETH_HDR_LEN; - - ip_write_packet_image(net->ip_p, packet_ptr); - packet_ptr += (ip_get_hl(net->ip_p)); - - udp_write_packet_image(net->udp_p, packet_ptr); - packet_ptr += UDP_HDR_LEN; - - dhcp_write_packet_image(net->dhcp_p, packet_ptr); - - /* Run the IP checksum routine. */ - - ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); - - return; - } - - static void rawnet_write_packet_arp(rawnet_t *net) - { - char *packet_ptr; - - /* Dump packet images for ARP/UNARP. */ - - packet_ptr = net->packet_data; - memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ - - eth_write_packet_image(net->ether_p, packet_ptr); - packet_ptr += ETH_HDR_LEN; - - arp_write_packet_image(net->arp_p, packet_ptr); - - return; - } - - static void rawnet_write_packet_icmp(rawnet_t *net) - { - unsigned char *packet_ptr; - - /* Dump packet images for ICMP. */ - - packet_ptr = net->packet_data; - memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ - - eth_write_packet_image(net->ether_p, packet_ptr); - packet_ptr += ETH_HDR_LEN; - - ip_write_packet_image(net->ip_p, packet_ptr); - packet_ptr += (ip_get_hl(net->ip_p)); - - icmp_write_packet_image(net->icmp_p, packet_ptr); - - ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); - - return; - } - - static void rawnet_write_packet(rawnet_t *net) - { - - switch(net->type) { - - case RAWNET_DHCP: - rawnet_write_packet_dhcp(net); - break; - - case RAWNET_ARP: - rawnet_write_packet_arp(net); - break; - - case RAWNET_ICMP: - rawnet_write_packet_icmp(net); - break; - - default: - warn_message("warning: invalid send type -- this is a bug report it please."); - break; - } - - return; - } - - - static void rawnet_build_dhcp_proc(rawnet_t *net, uint32_t xid, time_t secs, - uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, - uint32_t giaddr, list_t *options, unsigned char bootp_type) - { - uint16_t ip_len, udp_len; - int total_len; - - dhcp_purge(net->dhcp_p); /* clear up old options. */ - - /* Calculate the total length of the packet - * including IP header but not datalink header. - * This goes into ip_len */ - - ip_len = IP_HDR_LEN + /* IP Header length. */ - UDP_HDR_LEN + /* UDP Header length. */ - DHCP_FIXEDHDR_LEN + /* DHCP fixed header. */ - 4 + /* magic cookie length. */ - dhcp_get_options_len(options); /* options length. */ - - udp_len = ip_len - IP_HDR_LEN; - total_len = ip_len + ETH_HDR_LEN; - - /* It is possible that we exceeded MTU. - * - * On smaller MTUs (once we configure it and not - * hardcode it) it may be possible. So keep - * this check in. XXX -- fixme: check for - * UDP size, and overload DHCP when it - * goes over that size. - * - */ - - if(total_len > DEFAULT_MTU) - fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); - - build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); - build_ip_broadcast(net, ip_len, IP_PROTO_UDP); - build_udp(net, udp_len); - build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); - - /* Write packet. */ - - net->type = RAWNET_DHCP; - net->packet_len = total_len; - - rawnet_write_packet(net); - - return; - } - - static void build_arp_proc(rawnet_t *net, - uint16_t opcode, - eth_addr_t sender_hw_addr, - uint32_t sender_ip_addr, - eth_addr_t target_hw_addr, - uint32_t target_ip_addr) - { - build_eth_broadcast(net, sender_hw_addr, ETH_TYPE_ARP); - build_arp(net, opcode, sender_hw_addr, sender_ip_addr, target_hw_addr, - target_ip_addr, ETH_ADDR_LEN); - - net->type = RAWNET_ARP; - net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; - - rawnet_write_packet(net); - return; - } - - void rawnet_build_arp_reply(rawnet_t *net, - uint32_t source_addr, - uint32_t dest_addr, - eth_addr_t source_hw_addr, - eth_addr_t dest_hw_addr) - { - build_arp_proc(net, ARP_OP_REPLY, source_hw_addr, source_addr, dest_hw_addr, dest_addr); - return; - } - - void rawnet_build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) - { - - rawnet_build_arp_reply(net, source_addr, ip_addr_broadcast, - source_hw_addr, eth_broadcast); - return; - } - - /* only one way to build unarp, so don't procify it. */ - - void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr) - { - build_eth_broadcast(net, source_hw_addr, ETH_TYPE_ARP); - build_arp(net, ARP_OP_REPLY, eth_null, source_addr, eth_null, ip_addr_broadcast, 0); - - net->type = RAWNET_ARP; - net->packet_len = ETH_HDR_LEN + ARP_ETHIP_LEN + ARP_HDR_LEN; - - rawnet_write_packet(net); - - return; - } - - /* Create a dhcp discover message. */ - - void rawnet_build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) - { - rawnet_build_dhcp_proc(net, xid, secs, 0, 0, 0, 0, options, DHCP_BOOTP_REQUEST); - } - - /* Create dhcp request message. */ - - void rawnet_build_dhcp_request(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) - { - rawnet_build_dhcp_proc(net, xid, secs, 0, 0, 0, 0, options, DHCP_BOOTP_REQUEST); - } - - /* Create icmp packet: procify this so we can use it for all other icmp building. */ - static void rawnet_build_icmp_header_proc(rawnet_t *net, uint8_t icmp_type, uint8_t icmp_code) - { - icmp_set_type(net->icmp_p, icmp_type); - icmp_set_code(net->icmp_p, icmp_code); - icmp_clear_cksum(net->icmp_p); - - return; - } - - /* Create icmp mask reply/request packet: procify this to act as - a subroutine for the icmp mask interface routines. */ - static void rawnet_build_icmp_mask_proc(rawnet_t *net, uint8_t icmp_type, uint32_t icmp_id, - uint32_t icmp_seq, uint32_t mask) - { - rawnet_build_icmp_header_proc(net, icmp_type, 0); - icmp_mask_set_seq(net->icmp_p, icmp_id); - icmp_mask_set_seq(net->icmp_p, icmp_seq); - icmp_mask_set_mask(net->icmp_p, mask); - - return; - } - - /* build icmp mask request packet. */ - void rawnet_build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq) - { - int ip_len = ICMP_HDR_LEN + 12 + IP_HDR_LEN; /* 12 bytes for the mask request. */ - - build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); - build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); - rawnet_build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); - - net->type = RAWNET_ICMP; - net->packet_len = ETH_HDR_LEN + ip_len; - - rawnet_write_packet(net); - } - - /* build icmp mask reply packet. */ - void rawnet_build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask) - { - int ip_len = IP_HDR_LEN + ICMP_HDR_LEN + 12; /* 12 bytes for the mask reply. */ - - build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); - build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); - rawnet_build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); - - net->type = RAWNET_ICMP; - net->packet_len = ETH_HDR_LEN + ip_len; - - rawnet_write_packet(net); - } /* Just update the seconds field. --- 407,410 ---- |
From: Thamer Al-H. <act...@us...> - 2002-02-14 10:43:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv5818 Modified Files: config.h.in configure configure.in dhcp-agent.h dhcp-daemon.c Log Message: fixed to do file descriptor limit checking properly; Index: config.h.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/config.h.in,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** config.h.in 2 Feb 2002 15:28:46 -0000 1.5 --- config.h.in 14 Feb 2002 10:43:34 -0000 1.6 *************** *** 16,19 **** --- 16,22 ---- #undef HAVE_GETOPT_H + /* Define if you have the `getrusage' function. */ + #undef HAVE_GETRUSAGE + /* Define if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H *************** *** 33,36 **** --- 36,42 ---- /* Define if you have the `strdup' function. */ #undef HAVE_STRDUP + + /* Define if you have the `sysconf' function. */ + #undef HAVE_SYSCONF /* Define if you have the <sys/utsname.h> header file. */ Index: configure =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** configure 2 Feb 2002 15:28:47 -0000 1.9 --- configure 14 Feb 2002 10:43:34 -0000 1.10 *************** *** 2378,2382 **** done ! for ac_func in strdup uname calloc daemon rename do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` --- 2378,2382 ---- done ! for ac_func in strdup uname calloc daemon rename sysconf getrusage do ac_ac_var=`echo "ac_cv_func_$ac_func" | $ac_tr_sh` Index: configure.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** configure.in 2 Feb 2002 15:28:47 -0000 1.9 --- configure.in 14 Feb 2002 10:43:34 -0000 1.10 *************** *** 32,36 **** dnl check for functions ! AC_CHECK_FUNCS(strdup uname calloc daemon rename) AC_CHECK_FUNCS(sprintf vsnprintf, --- 32,36 ---- dnl check for functions ! AC_CHECK_FUNCS(strdup uname calloc daemon rename sysconf getrusage) AC_CHECK_FUNCS(sprintf vsnprintf, Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** dhcp-agent.h 14 Feb 2002 10:06:53 -0000 1.25 --- dhcp-agent.h 14 Feb 2002 10:43:34 -0000 1.26 *************** *** 116,119 **** --- 116,124 ---- # define MAX_OPTIONS_HANDLED 62 + /* sensible default for max descriptors -- we use this if we + can't find it through other means (sysconf/getrusage) */ + + #define SENSIBLE_DESCRIPTOR_MAX 128 + /* type string limits. */ Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-daemon.c 14 Feb 2002 10:06:53 -0000 1.4 --- dhcp-daemon.c 14 Feb 2002 10:43:34 -0000 1.5 *************** *** 117,120 **** --- 117,123 ---- { long i, max_descriptors; + #ifdef RLIMIT_NOFILES + struct rlimit usage_limit; + #endif /* If we have daemon() use it. */ *************** *** 168,189 **** /* If we have sysconf and _SC_OPEN_MAX * use them */ ! ! #ifdef _SC_OPEN_MAX max_descriptors = sysconf(_SC_OPEN_MAX); #elif MAX_FILES max_descriptors = MAX_FILES; ! #elif RLIMIT_NOFILES ! max_descriptors = getrusage(RLIMIT_NOFILES); ! #else /* If we don't have any of these ! * use something big like 128. */ ! ! max_descriptors = 128; ! #endif ! ! /* FIXME: we should be closing all descriptors ! * but we're not. */ for(i = 0;i < max_descriptors;i++) { --- 171,206 ---- /* If we have sysconf and _SC_OPEN_MAX * use them */ ! ! ! #ifdef HAVE_SYSCONF ! max_descriptors = sysconf(_SC_OPEN_MAX); + + if(max_descriptors <= 0) /* indeterminate or error. */ + max_descriptors = SENSIBLE_DESCRIPTOR_MAX; + + /* Otherwise check for getrusage and use it. */ + + #elif HAVE_GETRUSAGE + + if(getrusage(RLIMIT_NOFILES, &usage_limit) < 0) + max_descriptors = SENSIBLE_DESCRIPTOR_MAX; + + max_descriptors = usage_limit.rlim_cur; + + /* If we have neither of the above see if MAX_FILES is defined. */ #elif MAX_FILES + max_descriptors = MAX_FILES; ! ! /* If we have none of the above just use our sensible default. */ ! #else /* _SC_OPEN_MAX */ /* If we don't have any of these ! * use our sensible default. */ ! max_descriptors = SENSIBLE_DESCRIPTOR_MAX; ! ! #endif /* _SC_OPEN_MAX */ for(i = 0;i < max_descriptors;i++) { |
From: Thamer Al-H. <act...@us...> - 2002-02-14 10:06:58
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv29302 Modified Files: TODO dhcp-agent.h dhcp-daemon.c dhcp-icmp.c dhcp-net.c Log Message: fixed up rawnet a bit and added build icmp routines to it; fixed up daemon a bit; both these need a lot more work; Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TODO 11 Feb 2002 18:02:24 -0000 1.7 --- TODO 14 Feb 2002 10:06:53 -0000 1.8 *************** *** 45,46 **** --- 45,53 ---- clean up in areas where it seems prudent. or come up with guidelines we can stick to. + -- fixup error messages to use "name : name : name : error" + convention where name could be the name of the process, + module, or function. + -- rawnet's packet construction isn't squeaky clean -- make a new + source file called dhcp-build-packets.c and polish it up + -- rawnet and the dhcp client control are foobared by a fake mac + address. check, fix, clean. Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** dhcp-agent.h 12 Feb 2002 15:23:59 -0000 1.24 --- dhcp-agent.h 14 Feb 2002 10:06:53 -0000 1.25 *************** *** 274,278 **** uint16_t src_port, dst_port; /* udp ports for writing packets. */ ! unsigned char *client_hw_addr; /* used for faking client mac address. */ int promiscious; /* run in promiscious mode flag. */ --- 274,278 ---- uint16_t src_port, dst_port; /* udp ports for writing packets. */ ! eth_addr_t hw_addr; /* used for faking client mac address. */ int promiscious; /* run in promiscious mode flag. */ *************** *** 408,412 **** #define DHCP_BROADCAST_FLAG 0x8000 ! /* Option tags. Just PAD and END */ # define TAG_PAD 0 --- 408,412 ---- #define DHCP_BROADCAST_FLAG 0x8000 ! /* Option tags. */ # define TAG_PAD 0 *************** *** 493,498 **** eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr); ! void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); --- 493,498 ---- eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr); ! extern void rawnet_build_unarp(rawnet_t *net, uint32_t source_addr, ! eth_addr_t source_hw_addr); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); *************** *** 501,504 **** --- 501,507 ---- extern int rawnet_is_valid(rawnet_t *net); + extern void rawnet_build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); + extern void rawnet_build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); + extern int rawnet_up(rawnet_t *net); extern void rawnet_down(rawnet_t *net); *************** *** 720,726 **** extern icmp_obj *icmp_create(void); extern void icmp_destroy(icmp_obj *icmp); extern void icmp_set_type(icmp_obj *icmp, uint8_t type); extern void icmp_set_code(icmp_obj *icmp, uint8_t code); ! extern void icmp_set_cksum(icmp_obj *icmp, uint16_t cksum); extern void icmp_mask_set_id(icmp_obj *icmp, uint32_t id); extern void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq); --- 723,730 ---- extern icmp_obj *icmp_create(void); extern void icmp_destroy(icmp_obj *icmp); + extern void icmp_set_type(icmp_obj *icmp, uint8_t type); extern void icmp_set_code(icmp_obj *icmp, uint8_t code); ! extern void icmp_clear_cksum(icmp_obj *icmp); extern void icmp_mask_set_id(icmp_obj *icmp, uint32_t id); extern void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq); *************** *** 728,731 **** --- 732,739 ---- extern void icmp_echo_set_id(icmp_obj *icmp, uint32_t id); extern void icmp_echo_set_seq(icmp_obj *icmp, uint32_t seq); + + extern uint8_t icmp_get_type(icmp_obj *icmp); + + extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); /* Alignment functions. */ Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-daemon.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-daemon.c 5 Feb 2002 13:47:38 -0000 1.3 --- dhcp-daemon.c 14 Feb 2002 10:06:53 -0000 1.4 *************** *** 82,118 **** */ ! void go_background(char *dir) ! { ! long i, max_descriptors; ! ! /* If we have daemon() use it. */ ! #ifdef HAVE_DAEMON ! daemon(0 , 0); ! #else ! ! /* Take process into the background. ! * ! * There are seven steps we need to ! * take. ! */ ! /* Step 1: fork out of current parent. */ switch(fork()) { case -1: ! /* Not good. ! * ! * And our problem is logging hasn't been setup yet, ! * open the log up and log an error. ! * ! */ ! ! init_log(binname); ! fatal_error("initialization: fork: %s", strerror(errno)); case 0: ! /* We're the child. Just break out of here. */ ! break; default: --- 82,103 ---- */ ! /* The name describes the function: we fork and only return as ! the child. Useful utility routine. */ ! #ifndef HAVE_DAEMON ! static void do_fork_and_return_as_child(void) ! { switch(fork()) { case -1: ! /* Not good. */ ! /* Also we haven't opened logging yet, so do it now and exit. */ ! init_log(binname); ! fatal_error("initialization: fork: %s", strerror(errno)); case 0: ! /* We're the child. Just break out of here. */ ! break; default: *************** *** 125,129 **** } ! /* Step 2: Grab a new session. */ setsid(); /* Get new session. */ --- 110,137 ---- } ! return; ! } ! #endif /* HAVE_DAEMON */ ! ! void go_background(char *dir) ! { ! long i, max_descriptors; ! ! /* If we have daemon() use it. */ ! #ifdef HAVE_DAEMON ! daemon(0 , 0); ! #else ! ! /* Take process into the background. ! * ! * There are seven steps we need to ! * take. ! */ ! ! /* Step 1: fork out of current parent. */ ! do_fork_and_return_as_child(); ! ! /* Step 2: Grab a new session and relieve ourselves of ! session leadership. */ setsid(); /* Get new session. */ *************** *** 133,156 **** * of the responsibility of being * a session leader. */ - - - switch(fork()) { - - case -1: - /* Not good. */ - init_log(binname); - fatal_error("initialization: fork: %s", strerror(errno)); - - case 0: - /* We're the child. Just break out of here. */ - break; - - default: - /* We're the parent. - * Die. - */ - exit(0); ! } #endif --- 141,146 ---- * of the responsibility of being * a session leader. */ ! do_fork_and_return_as_child(); #endif Index: dhcp-icmp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-icmp.c 12 Feb 2002 15:23:59 -0000 1.3 --- dhcp-icmp.c 14 Feb 2002 10:06:53 -0000 1.4 *************** *** 39,42 **** --- 39,49 ---- } + /* get routines. */ + uint8_t icmp_get_type(icmp_obj *icmp) + { + return(icmp->icmp_header.icmp_type); + } + + /* set routines. */ void icmp_set_type(icmp_obj *icmp, uint8_t type) { *************** *** 49,55 **** } ! void icmp_clear_cksum(icmp_obj *icmp, uint16_t cksum) { ! icmp->icmp_header.icmp_cksum = cksum; } --- 56,62 ---- } ! void icmp_clear_cksum(icmp_obj *icmp) { ! memset(&icmp->icmp_header.icmp_cksum, 0, sizeof(icmp->icmp_header.icmp_cksum)); } *************** *** 119,123 **** packet += sizeof(icmp->icmp_header.icmp_cksum); ! switch(ntohl(icmp->icmp_header.icmp_type)) { --- 126,130 ---- packet += sizeof(icmp->icmp_header.icmp_cksum); ! switch(icmp->icmp_header.icmp_type) { Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-net.c 9 Feb 2002 16:34:42 -0000 1.12 --- dhcp-net.c 14 Feb 2002 10:06:53 -0000 1.13 *************** *** 222,241 **** net->dhcp_p = dhcp_create(); return net; } void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char *mac_addr; ! ! if(net->client_hw_addr != NULL) ! xfree(net->client_hw_addr); ! mac_addr = xmalloc(ETH_ADDR_LEN); if(hex_string_to_value(mac_string, mac_addr)) fatal_error("malformed mac_string for fake client hw addr. please check mac address."); ! ! net->client_hw_addr = mac_addr; ! return; } --- 222,250 ---- net->dhcp_p = dhcp_create(); + /* For now we use the real hardware address in hw_addr. + * rawnet_use_fake_hw_addr can always be called to change + * this. */ + + rawnet_get_interface_hw_addr(net, &net->hw_addr); + return net; } + /* Use a fake hardware address (diagnostic purposes). We need to + * reinitialize our rawnet to use promiscious packet + * capturing. */ + void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char *mac_addr; ! ! mac_addr = xmalloc(ETH_ADDR_LEN); + if(hex_string_to_value(mac_string, mac_addr)) fatal_error("malformed mac_string for fake client hw addr. please check mac address."); ! memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); ! xfree(mac_addr); ! return; } *************** *** 271,277 **** dhcp_destroy(net->dhcp_p); - if(net->client_hw_addr) - xfree(net->client_hw_addr); - xfree(net); --- 280,283 ---- *************** *** 446,450 **** } ! static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len) { ip_set_hl(net->ip_p, IP_HDR_LEN); --- 452,456 ---- } ! static void build_ip_broadcast(rawnet_t *net, uint16_t ip_len, uint8_t protocol) { ip_set_hl(net->ip_p, IP_HDR_LEN); *************** *** 454,458 **** ip_set_off(net->ip_p, 0); ip_set_ttl(net->ip_p, IP_TTL_MAX); ! ip_set_proto(net->ip_p, IP_PROTO_UDP); /* Do checksum later. */ --- 460,464 ---- ip_set_off(net->ip_p, 0); ip_set_ttl(net->ip_p, IP_TTL_MAX); ! ip_set_proto(net->ip_p, protocol); /* Do checksum later. */ *************** *** 559,562 **** --- 565,590 ---- } + static void rawnet_write_packet_icmp(rawnet_t *net) + { + unsigned char *packet_ptr; + + /* Dump packet images for ICMP. */ + + packet_ptr = net->packet_data; + memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ + + eth_write_packet_image(net->ether_p, packet_ptr); + packet_ptr += ETH_HDR_LEN; + + ip_write_packet_image(net->ip_p, packet_ptr); + packet_ptr += (ip_get_hl(net->ip_p)); + + icmp_write_packet_image(net->icmp_p, packet_ptr); + + ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); + + return; + } + static void rawnet_write_packet(rawnet_t *net) { *************** *** 572,575 **** --- 600,607 ---- break; + case RAWNET_ICMP: + rawnet_write_packet_icmp(net); + break; + default: warn_message("warning: invalid send type -- this is a bug report it please."); *************** *** 587,600 **** uint16_t ip_len, udp_len; int total_len; - eth_addr_t client_hw_addr; - - - /* Used for faking source mac address. */ - - if(net->client_hw_addr) - memcpy(&client_hw_addr, net->client_hw_addr, ETH_ADDR_LEN); - else - eth_get(net->eth, &client_hw_addr); /* FIXME: redundant since we already got it higher up in - * the code. */ dhcp_purge(net->dhcp_p); /* clear up old options. */ --- 619,622 ---- *************** *** 626,633 **** fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); ! build_eth_broadcast(net, client_hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len); build_udp(net, udp_len); ! build_dhcp(net, xid, secs, client_hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); /* Write packet. */ --- 648,655 ---- fatal_error("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); ! build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); ! build_ip_broadcast(net, ip_len, IP_PROTO_UDP); build_udp(net, udp_len); ! build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); /* Write packet. */ *************** *** 706,709 **** --- 728,784 ---- } + /* Create icmp packet: procify this so we can use it for all other icmp building. */ + static void rawnet_build_icmp_header_proc(rawnet_t *net, uint8_t icmp_type, uint8_t icmp_code) + { + icmp_set_type(net->icmp_p, icmp_type); + icmp_set_code(net->icmp_p, icmp_code); + icmp_clear_cksum(net->icmp_p); + + return; + } + + /* Create icmp mask reply/request packet: procify this to act as + a subroutine for the icmp mask interface routines. */ + static void rawnet_build_icmp_mask_proc(rawnet_t *net, uint8_t icmp_type, uint32_t icmp_id, + uint32_t icmp_seq, uint32_t mask) + { + rawnet_build_icmp_header_proc(net, icmp_type, 0); + icmp_mask_set_seq(net->icmp_p, icmp_id); + icmp_mask_set_seq(net->icmp_p, icmp_seq); + icmp_mask_set_mask(net->icmp_p, mask); + + return; + } + + /* build icmp mask request packet. */ + void rawnet_build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq) + { + int ip_len = ICMP_HDR_LEN + 12 + IP_HDR_LEN; /* 12 bytes for the mask request. */ + + build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); + build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); + rawnet_build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); + + net->type = RAWNET_ICMP; + net->packet_len = ETH_HDR_LEN + ip_len; + + rawnet_write_packet(net); + } + + /* build icmp mask reply packet. */ + void rawnet_build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask) + { + int ip_len = IP_HDR_LEN + ICMP_HDR_LEN + 12; /* 12 bytes for the mask reply. */ + + build_eth_broadcast(net, net->hw_addr, ETH_TYPE_IP); + build_ip_broadcast(net, ip_len, IP_PROTO_ICMP); + rawnet_build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); + + net->type = RAWNET_ICMP; + net->packet_len = ETH_HDR_LEN + ip_len; + + rawnet_write_packet(net); + } + /* Just update the seconds field. * *************** *** 729,733 **** memcpy(packet, &secs, 2); ! ip_checksum((net->packet_data + ETH_HDR_LEN), net->packet_len - ETH_HDR_LEN); return; --- 804,808 ---- memcpy(packet, &secs, 2); ! ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); return; |
From: Thamer Al-H. <act...@us...> - 2002-02-12 15:38:07
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv27877 Modified Files: dhcp-agent.h dhcp-align.c dhcp-client-states.c dhcp-icmp.c Log Message: icmp echo routines added; fixed up timeout logging to be more brief; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dhcp-agent.h 11 Feb 2002 18:02:24 -0000 1.23 --- dhcp-agent.h 12 Feb 2002 15:23:59 -0000 1.24 *************** *** 720,723 **** --- 720,731 ---- extern icmp_obj *icmp_create(void); extern void icmp_destroy(icmp_obj *icmp); + extern void icmp_set_type(icmp_obj *icmp, uint8_t type); + extern void icmp_set_code(icmp_obj *icmp, uint8_t code); + extern void icmp_set_cksum(icmp_obj *icmp, uint16_t cksum); + extern void icmp_mask_set_id(icmp_obj *icmp, uint32_t id); + extern void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq); + extern void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask); + extern void icmp_echo_set_id(icmp_obj *icmp, uint32_t id); + extern void icmp_echo_set_seq(icmp_obj *icmp, uint32_t seq); /* Alignment functions. */ *************** *** 727,730 **** --- 735,741 ---- extern void align_udp(const unsigned char *data, struct udp_hdr *udp); extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); + extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); + extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); + extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); /* Linked List routines. */ Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-align.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-align.c 3 Feb 2002 16:56:00 -0000 1.3 --- dhcp-align.c 12 Feb 2002 15:23:59 -0000 1.4 *************** *** 159,160 **** --- 159,196 ---- return; } + + void align_icmp(const unsigned char *data, struct icmp_hdr *header) + { + memcpy(&header->icmp_type, data, sizeof(header->icmp_type)); + data += sizeof(header->icmp_type); + + memcpy(&header->icmp_code, data, sizeof(header->icmp_code)); + data += sizeof(header->icmp_code); + + memcpy(&header->icmp_cksum, data, sizeof(header->icmp_cksum)); + + return; + } + + void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header) + { + memcpy(&header->icmp_id, data, sizeof(header->icmp_id)); + data += sizeof(header->icmp_id); + + memcpy(&header->icmp_seq, data, sizeof(header->icmp_seq)); + data += sizeof(header->icmp_seq); + + memcpy(&header->icmp_mask, data, sizeof(header->icmp_mask)); + + return; + } + + void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header) + { + memcpy(&header->icmp_id, data, sizeof(header->icmp_id)); + data += sizeof(header->icmp_id); + + memcpy(&header->icmp_seq, data, sizeof(header->icmp_seq)); + + return; + } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-states.c 9 Feb 2002 16:48:49 -0000 1.14 --- dhcp-client-states.c 12 Feb 2002 15:23:59 -0000 1.15 *************** *** 35,39 **** static RETSIGTYPE handle_alarm(int i) { ! have_alarm = 1; return (RETSIGTYPE) 0; } --- 35,39 ---- static RETSIGTYPE handle_alarm(int i) { ! have_alarm= 1; return (RETSIGTYPE) 0; } *************** *** 324,328 **** return -1; } ! do_sysconf(options, dc); cache_entry_purge_list(options); --- 324,333 ---- return -1; } ! ! /* Before doing a sysconf, let's make sure no one on the ! * local subnet is using our address. Do an ARP request ! * on the local subnet. and check to see if the address ! * is already taken. */ ! do_sysconf(options, dc); cache_entry_purge_list(options); *************** *** 377,384 **** options = client_build_option_list(NULL, DHCP_RELEASE_TM, dc->client_id, dc->class_id); cache_options = client_cache_load_option_network_list(dc->cache, 0); ! if(cache_options == NULL) { ! error_message("Could not load cache! This is not good!"); return -1; - } options = join_lists(options, cache_options); --- 382,389 ---- options = client_build_option_list(NULL, DHCP_RELEASE_TM, dc->client_id, dc->class_id); cache_options = client_cache_load_option_network_list(dc->cache, 0); ! if(cache_options == NULL) ! /* if we have no cache we probably timed out ! * somewhere. Just return. */ return -1; options = join_lists(options, cache_options); Index: dhcp-icmp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-icmp.c 9 Feb 2002 23:29:37 -0000 1.2 --- dhcp-icmp.c 12 Feb 2002 15:23:59 -0000 1.3 *************** *** 49,53 **** } ! void icmp_set_cksum(icmp_obj *icmp, uint16_t cksum) { icmp->icmp_header.icmp_cksum = cksum; --- 49,53 ---- } ! void icmp_clear_cksum(icmp_obj *icmp, uint16_t cksum) { icmp->icmp_header.icmp_cksum = cksum; *************** *** 69,72 **** --- 69,82 ---- } + void icmp_echo_set_id(icmp_obj *icmp, uint32_t id) + { + icmp->icmp_msg.echo.icmp_id = htonl(id); + } + + void icmp_echo_set_seq(icmp_obj *icmp, uint32_t seq) + { + icmp->icmp_msg.echo.icmp_seq = htonl(seq); + } + static void icmp_write_mask_packet_image(icmp_obj *icmp, unsigned char *packet) { *************** *** 85,88 **** --- 95,110 ---- } + static void icmp_write_echo_packet_image(icmp_obj *icmp, unsigned char *packet) + { + memcpy(packet, &icmp->icmp_msg.echo.icmp_id, + sizeof(icmp->icmp_msg.echo.icmp_id)); + packet += sizeof(icmp->icmp_msg.echo.icmp_id); + + memcpy(packet, &icmp->icmp_msg.echo.icmp_seq, + sizeof(icmp->icmp_msg.echo.icmp_seq)); + + return; + } + void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet) { *************** *** 90,94 **** memcpy(packet, &icmp->icmp_header.icmp_type, sizeof(icmp->icmp_header.icmp_type)); packet += sizeof(icmp->icmp_header.icmp_type); ! memcpy(packet, &icmp->icmp_header.icmp_code, sizeof(icmp->icmp_header.icmp_code)); packet += sizeof(icmp->icmp_header.icmp_code); --- 112,116 ---- memcpy(packet, &icmp->icmp_header.icmp_type, sizeof(icmp->icmp_header.icmp_type)); packet += sizeof(icmp->icmp_header.icmp_type); ! memcpy(packet, &icmp->icmp_header.icmp_code, sizeof(icmp->icmp_header.icmp_code)); packet += sizeof(icmp->icmp_header.icmp_code); *************** *** 99,103 **** switch(ntohl(icmp->icmp_header.icmp_type)) { ! /* both mask types have the same construction. */ case ICMP_MASK: /* fall through. */ --- 121,130 ---- switch(ntohl(icmp->icmp_header.icmp_type)) { ! ! case ICMP_ECHO: /* fall through */ ! case ICMP_ECHOREPLY: ! ! icmp_write_echo_packet_image(icmp, packet); ! break; case ICMP_MASK: /* fall through. */ *************** *** 114,115 **** --- 141,170 ---- return; } + + void icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet) + { + align_icmp(packet, &icmp->icmp_header); + packet += ICMP_HDR_LEN; + + switch(icmp->icmp_header.icmp_type) { + + case ICMP_ECHO: + case ICMP_ECHOREPLY: + + align_icmp_echo(packet, &icmp->icmp_msg.echo); + break; + + case ICMP_MASK: + case ICMP_MASKREPLY: + + align_icmp_mask(packet, &icmp->icmp_msg.mask); + break; + + default: + /* can't handle any other type. */ + break; + } + + return; + } + |
From: Thamer Al-H. <act...@us...> - 2002-02-11 18:02:28
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv6998 Modified Files: CAVEATS COST TODO dhcp-agent.h dhcp-client-conf.c dhcp-client-control.c dhcp-client.c dhcpclient.1 Log Message: added promiscious mode option; fixed up config code a bit for more things to come; updated man page Index: CAVEATS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/CAVEATS,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CAVEATS 1 Feb 2002 18:31:17 -0000 1.2 --- CAVEATS 11 Feb 2002 18:02:24 -0000 1.3 *************** *** 1,9 **** -- dhcpclient may act funny with interfaces with mtu's larger or ! smaller than 1500. this will be fixed in future releases. -- dhcpclient may exceed the recommended udp size of 576 bytes. this ! needs to be fixed. It currently does not overload bootp fields to ! make up for this. -- dhcpclient spoofing mac address may not work on all systems or NICs. test to be sure. --- 1,14 ---- + Sorry folks, still lots of caveats to watch out for. + -- dhcpclient may act funny with interfaces with mtu's larger or ! smaller than 1500. this will be fixed in future releases. -- dhcpclient may exceed the recommended udp size of 576 bytes. this ! needs to be fixed. It currently does not overload bootp fields to ! make up for this. -- dhcpclient spoofing mac address may not work on all systems or NICs. test to be sure. + + -- dhcpclient's icmp mask discovery has not been tested. Please report + success if you use this feature (send me a patch too for any bugs). Index: COST =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** COST 5 Feb 2002 02:00:59 -0000 1.2 --- COST 11 Feb 2002 18:02:24 -0000 1.3 *************** *** 1,7 **** In writing dhcp-agent I suffered the following: ! Feb - March 2001 ! [ todo ] Jan - Feb 2001 --- 1,9 ---- In writing dhcp-agent I suffered the following: ! Feb - March 2001 (Current values as of the Feb 9) ! 18 pots of coffee; 86 camel filter cigarettes; 8 diet cokes ! (cutting down); 845 mp3s (thanks stephanie); 12 historical trips ! to the wash room; 10 showers; one pretty geekette; Jan - Feb 2001 Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TODO 9 Feb 2002 16:34:42 -0000 1.6 --- TODO 11 Feb 2002 18:02:24 -0000 1.7 *************** *** 1,8 **** - - highest priority: - - get the client to be unconditionaly compliant with rfc2131. - under-engineer the client. too much code and too many code-features. - Things that need to be done for RFC compliance: --- 1,2 ---- Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** dhcp-agent.h 9 Feb 2002 23:29:37 -0000 1.22 --- dhcp-agent.h 11 Feb 2002 18:02:24 -0000 1.23 *************** *** 218,221 **** --- 218,225 ---- } dhcp_obj; + /* default configuration */ + + #define DISCOVER_OFFER_RETRIES 3 + /* * Other packet objects. *************** *** 317,321 **** unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ ! } client_conf_t; --- 321,325 ---- unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ ! int discover_offer_retries; /* amount of times we're willing to keep rediscovering before giving up. */ } client_conf_t; *************** *** 344,347 **** --- 348,352 ---- unsigned char *client_hw_addr; int state; + int discover_offer_retries; } dhcp_client_control_t; *************** *** 764,768 **** /* dhcp client control */ ! extern dhcp_client_control_t *create_dhcp_client_control(char *interface); extern void destroy_dhcp_client_control(dhcp_client_control_t *dc); extern void dhcp_client_update_secs(dhcp_client_control_t *dc); --- 769,773 ---- /* dhcp client control */ ! extern dhcp_client_control_t *create_dhcp_client_control(char *interface, int promiscious); extern void destroy_dhcp_client_control(dhcp_client_control_t *dc); extern void dhcp_client_update_secs(dhcp_client_control_t *dc); Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-conf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-conf.c 8 Feb 2002 01:37:29 -0000 1.4 --- dhcp-client-conf.c 11 Feb 2002 18:02:24 -0000 1.5 *************** *** 53,57 **** client_conf_reset_options(cc); cc->interface = dc->interface; ! return cc; } --- 53,57 ---- client_conf_reset_options(cc); cc->interface = dc->interface; ! cc->discover_offer_retries = DISCOVER_OFFER_RETRIES; return cc; } *************** *** 67,79 **** } ! static int dump_config_options(client_conf_t *cc) { int i; FILE *fp; - char *fname; - fname = get_conf_options_fname(cc); fp = file_open_or_create_safe(fname, "w"); - xfree(fname); if(fp == NULL) --- 67,76 ---- } ! static int dump_config_options(client_conf_t *cc, char *fname) { int i; FILE *fp; fp = file_open_or_create_safe(fname, "w"); if(fp == NULL) *************** *** 105,117 **** } ! static int client_conf_load_options(client_conf_t *cc) { - char *fname; FILE *fp; int i; - fname = get_conf_options_fname(cc); fp = file_open_or_create_safe(fname, "r"); - xfree(fname); if(fp == NULL) --- 102,111 ---- } ! static int client_conf_load_options(client_conf_t *cc, char *fname) { FILE *fp; int i; fp = file_open_or_create_safe(fname, "r"); if(fp == NULL) *************** *** 143,146 **** --- 137,163 ---- } + /* load configuration file or call applicable default setter, + also call dump_defaults if file does not exist */ + + static int load_client_conf_proc(char *fname, + client_conf_t *cc, int (*load_conf)(client_conf_t *cc, char *fname), + void (*use_defaults)(client_conf_t *cc), + int (*dump_defaults)(client_conf_t *cc, char *fname)) + { + int retval; + + if(!file_exists(fname)) { + /* it doesn't exist. strap default. */ + use_defaults(cc); + /* and dump to file. */ + retval = dump_config_options(cc, fname); + } else { + /* read conf data from file. */ + retval = load_conf(cc, fname); + } + + return retval; + } + int load_client_conf(client_conf_t *cc) { *************** *** 149,167 **** int retval; client_conf_reset_options(cc); /* check for options file. */ fname = get_conf_options_fname(cc); ! ! if(!file_exists(fname)) { ! /* it doesn't exist. use default options. */ ! use_default_options(cc); ! /* and dump it to file. */ ! retval = dump_config_options(cc); ! } else { ! /* read options file. */ ! retval = client_conf_load_options(cc); ! } ! xfree(fname); ! return retval; } --- 166,177 ---- int retval; + /* load up options file. */ + client_conf_reset_options(cc); /* check for options file. */ fname = get_conf_options_fname(cc); ! retval = load_client_conf_proc(fname, cc, client_conf_load_options, use_default_options, dump_config_options); xfree(fname); ! ! return(retval); } Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client-control.c 9 Feb 2002 16:34:42 -0000 1.11 --- dhcp-client-control.c 11 Feb 2002 18:02:24 -0000 1.12 *************** *** 24,27 **** --- 24,29 ---- #include <dhcp-agent.h> + /* Utility routines to update counters and time stamps. */ + /* Update seconds field for dhcp discover packets. */ void dhcp_client_update_secs(dhcp_client_control_t *dc) *************** *** 38,42 **** } ! /* create client id from a string in the format of 0x:0x:0x:0x:0x:0x */ static unsigned char *create_fake_client_id(unsigned char *mac_string) { --- 40,59 ---- } ! /* dhcp reset discover offer retries. */ ! void dhcp_client_reset_discover_offer_retries(dhcp_client_control_t *dc) ! { ! dc->discover_offer_retries = 0; ! } ! ! /* dhcp increment and check whether we should give up on discover offer retries. */ ! int dhcp_client_discover_offer_can_retry(dhcp_client_control_t *dc) ! { ! dc->discover_offer_retries++; ! if(dc->discover_offer_retries > dc->conf->discover_offer_retries) ! return 1; ! ! return 0; ! } ! /* create client id from a string in the format of xx:xx:xx:xx:xx:xx */ static unsigned char *create_fake_client_id(unsigned char *mac_string) { *************** *** 90,94 **** /* create client control object */ ! dhcp_client_control_t *create_dhcp_client_control(char *interface) { dhcp_client_control_t *dc; --- 107,111 ---- /* create client control object */ ! dhcp_client_control_t *create_dhcp_client_control(char *interface, int promiscious) { dhcp_client_control_t *dc; *************** *** 147,151 **** dport, sport); ! if((dc->rawnet = net_create(interface, filter_buff, sport, dport, 0)) == NULL) { destroy_dhcp_client_control(dc); return NULL; --- 164,168 ---- dport, sport); ! if((dc->rawnet = net_create(interface, filter_buff, sport, dport, promiscious)) == NULL) { destroy_dhcp_client_control(dc); return NULL; *************** *** 160,163 **** --- 177,184 ---- dhcp_client_reset_secs(dc); dhcp_client_update_secs(dc); + + /* discover offer retries. */ + dhcp_client_reset_discover_offer_retries(dc); + #ifdef HAVE_UNAME uname(&utsname); *************** *** 174,178 **** dc->client_id = create_client_id(interface_addr); ! return dc; } --- 195,199 ---- dc->client_id = create_client_id(interface_addr); ! dc->discover_offer_retries = 0; /* reset discover offer. */ return dc; } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client.c 8 Feb 2002 17:04:32 -0000 1.13 --- dhcp-client.c 11 Feb 2002 18:02:24 -0000 1.14 *************** *** 177,181 **** /* A race condition exists between the discover and request state. * So we can't hup the client and tell it the cache has been deleted. */ ! error_message("dhcpclient already running. i won't delete cache until it's shutdown."); return; } --- 177,182 ---- /* A race condition exists between the discover and request state. * So we can't hup the client and tell it the cache has been deleted. */ ! error_message("dhcpclient already running."); ! error_message("i won't delete cache until it's shutdown."); return; } *************** *** 222,226 **** int state; unsigned char want_background = 1; ! static char *fake_hw_addr = NULL; while((c = getopt(argc, argv, "gcdavim:kwh:l:")) != -1) { --- 223,228 ---- int state; unsigned char want_background = 1; ! char *fake_hw_addr = NULL; ! int promiscious = 0; while((c = getopt(argc, argv, "gcdavim:kwh:l:")) != -1) { *************** *** 263,267 **** exit(0); ! case 'l': if(set_verbosity_level(atoi(optarg))) { --- 265,269 ---- exit(0); ! case 'l': if(set_verbosity_level(atoi(optarg))) { *************** *** 272,275 **** --- 274,282 ---- break; + case 'p': + + promiscious = 1; + break; + case 'h': /* fall through. */ default: *************** *** 327,331 **** setup_interrupt_handlers(); /* setup signal handling */ ! if((dc = create_dhcp_client_control(interface)) == NULL) { error_message("encountered fatal error. cannot continue. exiting"); do_shutdown(dc); --- 334,338 ---- setup_interrupt_handlers(); /* setup signal handling */ ! if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered fatal error. cannot continue. exiting"); do_shutdown(dc); *************** *** 356,360 **** * we lose them after we fork in go_background. */ ! if((dc = create_dhcp_client_control(interface)) == NULL) { error_message("encountered a fatal error. cannot continue. exiting"); do_shutdown(dc); --- 363,367 ---- * we lose them after we fork in go_background. */ ! if((dc = create_dhcp_client_control(interface, promiscious)) == NULL) { error_message("encountered a fatal error. cannot continue. exiting"); do_shutdown(dc); Index: dhcpclient.1 =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcpclient.1,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcpclient.1 7 Feb 2002 18:41:47 -0000 1.7 --- dhcpclient.1 11 Feb 2002 18:02:24 -0000 1.8 *************** *** 21,27 **** safe to run more than one dhcpclient per interface. Currently only the basic networking DHCP options are handled. The interfaces IP ! address, routing, and domain name system are setup. .Sh OPTIONS .Bl -tag .It Op Ar -i interface name Specifies a the name of an interface dhcpsniff will use. otherwise --- 21,32 ---- safe to run more than one dhcpclient per interface. Currently only the basic networking DHCP options are handled. The interfaces IP ! address, the routing table, and the domain name system are setup. .Sh OPTIONS .Bl -tag + .It Op -p + Run in promiscious mode (implicit with -m flag). You should only + use this option if the system you are using dhcpclient on is + sufficiently broken that it needs promiscious mode to receive + packets with libpcap. .It Op Ar -i interface name Specifies a the name of an interface dhcpsniff will use. otherwise |
From: Thamer Al-H. <act...@us...> - 2002-02-09 23:29:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv6508 Modified Files: dhcp-agent.h dhcp-icmp.c dhcp-sysconf.c Log Message: added icmp routines for mask discovery; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-agent.h 9 Feb 2002 16:34:42 -0000 1.21 --- dhcp-agent.h 9 Feb 2002 23:29:37 -0000 1.22 *************** *** 240,244 **** typedef struct { ! int dummy; } icmp_obj; --- 240,245 ---- typedef struct { ! struct icmp_hdr icmp_header; ! union icmp_msg icmp_msg; } icmp_obj; Index: dhcp-icmp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-icmp.c 29 Jan 2002 18:05:05 -0000 1.1.1.1 --- dhcp-icmp.c 9 Feb 2002 23:29:37 -0000 1.2 *************** *** 38,39 **** --- 38,115 ---- xfree(icmp); } + + void icmp_set_type(icmp_obj *icmp, uint8_t type) + { + icmp->icmp_header.icmp_type = type; + } + + void icmp_set_code(icmp_obj *icmp, uint8_t code) + { + icmp->icmp_header.icmp_code = code; + } + + void icmp_set_cksum(icmp_obj *icmp, uint16_t cksum) + { + icmp->icmp_header.icmp_cksum = cksum; + } + + void icmp_mask_set_id(icmp_obj *icmp, uint32_t id) + { + icmp->icmp_msg.mask.icmp_id = htonl(id); + } + + void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq) + { + icmp->icmp_msg.mask.icmp_seq = htonl(seq); + } + + void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask) + { + icmp->icmp_msg.mask.icmp_mask = htonl(mask); + } + + static void icmp_write_mask_packet_image(icmp_obj *icmp, unsigned char *packet) + { + memcpy(packet, &icmp->icmp_msg.mask.icmp_id, + sizeof(icmp->icmp_msg.mask.icmp_id)); + packet += sizeof(icmp->icmp_msg.mask.icmp_id); + + memcpy(packet, &icmp->icmp_msg.mask.icmp_seq, + sizeof(icmp->icmp_msg.mask.icmp_seq)); + packet += sizeof(icmp->icmp_msg.mask.icmp_seq); + + memcpy(packet, &icmp->icmp_msg.mask.icmp_mask, + sizeof(icmp->icmp_msg.mask.icmp_mask)); + + return; + } + + void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet) + { + + memcpy(packet, &icmp->icmp_header.icmp_type, sizeof(icmp->icmp_header.icmp_type)); + packet += sizeof(icmp->icmp_header.icmp_type); + + memcpy(packet, &icmp->icmp_header.icmp_code, sizeof(icmp->icmp_header.icmp_code)); + packet += sizeof(icmp->icmp_header.icmp_code); + + memcpy(packet, &icmp->icmp_header.icmp_cksum, sizeof(icmp->icmp_header.icmp_cksum)); + packet += sizeof(icmp->icmp_header.icmp_cksum); + + switch(ntohl(icmp->icmp_header.icmp_type)) { + + /* both mask types have the same construction. */ + + case ICMP_MASK: /* fall through. */ + case ICMP_MASKREPLY: + + icmp_write_mask_packet_image(icmp, packet); + break; + + default: + /* major error if we actually get here. */ + fatal_error("icmp_write_packet_image() called with improper settings on icmp packet! aborting!"); + } + + return; + } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-sysconf.c 9 Feb 2002 15:50:30 -0000 1.6 --- dhcp-sysconf.c 9 Feb 2002 23:29:37 -0000 1.7 *************** *** 27,30 **** --- 27,35 ---- #include <dhcp-agent.h> + /* Only use handlers here which can be done in any order. + * Some special handlers are done in a particular order + * before we run these routines. + */ + sysconf_handler sysconf_handlers[] = { { NULL, }, /* 0 */ /* Pad -- don't handle here. */ |
From: Thamer Al-H. <act...@us...> - 2002-02-09 16:48:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv8650 Modified Files: dhcp-client-states.c Log Message: minor fix; heh; parse error; forgot to build before commiting last time. sorry; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-states.c 9 Feb 2002 16:34:42 -0000 1.13 --- dhcp-client-states.c 9 Feb 2002 16:48:49 -0000 1.14 *************** *** 265,269 **** add_to_list(dc->rawnet->dhcp_p->options, dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); ! p /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { --- 265,269 ---- add_to_list(dc->rawnet->dhcp_p->options, dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); ! /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { |
From: Thamer Al-H. <act...@us...> - 2002-02-09 16:34:46
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv5884 Modified Files: TODO dhcp-agent.h dhcp-client-control.c dhcp-client-states.c dhcp-net.c dhcp-sniff.c Log Message: removed promiscious mode from client; Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TODO 9 Feb 2002 15:50:30 -0000 1.5 --- TODO 9 Feb 2002 16:34:42 -0000 1.6 *************** *** 28,34 **** -- proper error handling in packet objects. possibly generic codes with an error buff (?). - -- make splice_string better: make it use stdarg - -- fix rawnet so it doesn't hardcode ports. - -- dhcp packet overloading. -- add a isascii() and a strcasecmp() for portability -- redo dhcp-client-conf to be better. --- 28,31 ---- Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-agent.h 9 Feb 2002 15:50:30 -0000 1.20 --- dhcp-agent.h 9 Feb 2002 16:34:42 -0000 1.21 *************** *** 270,274 **** dst_port; /* udp ports for writing packets. */ unsigned char *client_hw_addr; /* used for faking client mac address. */ ! /* * Data objects --- 270,275 ---- dst_port; /* udp ports for writing packets. */ unsigned char *client_hw_addr; /* used for faking client mac address. */ ! int promiscious; /* run in promiscious mode flag. */ ! /* * Data objects *************** *** 469,473 **** extern int resolv(char *address, uint32_t *addr); ! extern rawnet_t *net_create(char *device, char *filter, int sport, int dport); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); --- 470,474 ---- extern int resolv(char *address, uint32_t *addr); ! extern rawnet_t *net_create(char *device, char *filter, int sport, int dport, int promiscious); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-control.c 9 Feb 2002 15:50:30 -0000 1.10 --- dhcp-client-control.c 9 Feb 2002 16:34:42 -0000 1.11 *************** *** 146,151 **** "arp or icmp or (udp and (src port %d or dst port %d))", dport, sport); ! ! if((dc->rawnet = net_create(interface, filter_buff, sport, dport)) == NULL) { destroy_dhcp_client_control(dc); return NULL; --- 146,151 ---- "arp or icmp or (udp and (src port %d or dst port %d))", dport, sport); ! ! if((dc->rawnet = net_create(interface, filter_buff, sport, dport, 0)) == NULL) { destroy_dhcp_client_control(dc); return NULL; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-states.c 3 Feb 2002 16:56:00 -0000 1.12 --- dhcp-client-states.c 9 Feb 2002 16:34:42 -0000 1.13 *************** *** 265,269 **** add_to_list(dc->rawnet->dhcp_p->options, dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); ! /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { --- 265,269 ---- add_to_list(dc->rawnet->dhcp_p->options, dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); ! p /* dump cache file. */ if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-net.c 8 Feb 2002 01:37:29 -0000 1.11 --- dhcp-net.c 9 Feb 2002 16:34:42 -0000 1.12 *************** *** 171,175 **** rawnet_t *net_create(char *device, char *filter, ! int dhcp_src_port, int dhcp_dst_port) { rawnet_t *net; --- 171,176 ---- rawnet_t *net_create(char *device, char *filter, ! int dhcp_src_port, int dhcp_dst_port, ! int promiscious) { rawnet_t *net; *************** *** 181,184 **** --- 182,186 ---- net->pcap_filter = strdup(filter); net->packet_data = xcalloc(DEFAULT_MTU); /* XXX -- fixme make mtu configurable. */ + net->promiscious = promiscious; /* Get the interface and make sure its an ethernet interface or *************** *** 194,198 **** /* get pcap handler */ ! net->pcap = initialize_pcap_device(device, filter, 1); if(net->pcap == NULL) { rawnet_destroy(net); --- 196,200 ---- /* get pcap handler */ ! net->pcap = initialize_pcap_device(device, filter, promiscious); if(net->pcap == NULL) { rawnet_destroy(net); *************** *** 295,299 **** { ! net->pcap = initialize_pcap_device(net->device, net->pcap_filter, 1); if(net->pcap == NULL) { return -1; --- 297,301 ---- { ! net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscious); if(net->pcap == NULL) { return -1; Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sniff.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sniff.c 8 Feb 2002 01:37:29 -0000 1.4 --- dhcp-sniff.c 9 Feb 2002 16:34:42 -0000 1.5 *************** *** 79,83 **** /* It's ok not to set ports since we're not writing any packets. */ ! net = net_create(interface_name, filter_buff, 0, 0); if(net == NULL) --- 79,83 ---- /* It's ok not to set ports since we're not writing any packets. */ ! net = net_create(interface_name, filter_buff, 0, 0, 1); if(net == NULL) |
From: Thamer Al-H. <act...@us...> - 2002-02-09 16:22:38
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv3537 Modified Files: dhcp-convert.c dhcp-files.c Log Message: bug fix; integer to network conversion in client now works; Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-convert.c 9 Feb 2002 15:50:30 -0000 1.6 --- dhcp-convert.c 9 Feb 2002 16:22:35 -0000 1.7 *************** *** 726,733 **** fatal_error("illegal size passed to string_int_to_network()!"); } switch(size) { ! ! case sizeof(uint32_t): val = string_to_uint32(s); --- 726,735 ---- fatal_error("illegal size passed to string_int_to_network()!"); } + + } else { switch(size) { ! ! case sizeof(uint32_t): val = string_to_uint32(s); *************** *** 736,740 **** break; ! case sizeof(uint16_t): val = string_to_uint16(s); *(uint16_t *)net_val = htons(*(uint16_t *)val); --- 738,743 ---- break; ! case sizeof(uint16_t): ! val = string_to_uint16(s); *(uint16_t *)net_val = htons(*(uint16_t *)val); *************** *** 742,746 **** break; ! default: /* ditto on the b0rkination. */ fatal_error("illegal size passed to string_int_to_network()!"); --- 745,749 ---- break; ! default: /* ditto on the b0rkination. */ fatal_error("illegal size passed to string_int_to_network()!"); Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-files.c 8 Feb 2002 17:04:32 -0000 1.4 --- dhcp-files.c 9 Feb 2002 16:22:35 -0000 1.5 *************** *** 170,174 **** else { line_buff[string_size] = 0; - warn_message("string read: %s",line_buff); return 0; } --- 170,173 ---- |
From: Thamer Al-H. <act...@us...> - 2002-02-09 15:50:34
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv24534 Modified Files: Makefile.am Makefile.in TODO dhcp-agent.h dhcp-client-control.c dhcp-convert.c dhcp-sysconf.c dhcp-util.c Log Message: added splice_many_strings for things like class-id; Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 8 Feb 2002 17:04:32 -0000 1.7 --- Makefile.am 9 Feb 2002 15:50:30 -0000 1.8 *************** *** 22,26 **** dhcp-sysconf.c dhcp-rtt.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 22,26 ---- dhcp-sysconf.c dhcp-rtt.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.in 8 Feb 2002 17:04:32 -0000 1.7 --- Makefile.in 9 Feb 2002 15:50:30 -0000 1.8 *************** *** 86,90 **** ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 86,90 ---- ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TODO 8 Feb 2002 18:15:52 -0000 1.4 --- TODO 9 Feb 2002 15:50:30 -0000 1.5 *************** *** 26,36 **** -- good idea to add config file handlers in sysconf array so config files can be handled. instead of doing it explicitly. - -- do_sysconf() is jumping hoops serializing and unserializing, - best to load up the strings and pass them in their serialized - state. -- proper error handling in packet objects. possibly generic codes with an error buff (?). - -- clean up code and document more. - -- fixup all magic numbers. -- make splice_string better: make it use stdarg -- fix rawnet so it doesn't hardcode ports. --- 26,31 ---- Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-agent.h 8 Feb 2002 18:15:52 -0000 1.19 --- dhcp-agent.h 9 Feb 2002 15:50:30 -0000 1.20 *************** *** 527,530 **** --- 527,531 ---- extern void info_message(char *fmt, ...); extern char *splice_string(char *s1, char *s2); + extern char *splice_many_strings(int num, char *s, ...); extern void trim_string(char *s); extern int string_matches(char *s1, char *s2); Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-control.c 8 Feb 2002 01:37:29 -0000 1.9 --- dhcp-client-control.c 9 Feb 2002 15:50:30 -0000 1.10 *************** *** 160,167 **** dhcp_client_reset_secs(dc); dhcp_client_update_secs(dc); - #ifdef HAVE_UNAME uname(&utsname); ! dc->class_id = splice_string(utsname.sysname, utsname.release); #else /* HAVE_UNAME */ dc->class_id = strdup("Unknown"); --- 160,166 ---- dhcp_client_reset_secs(dc); dhcp_client_update_secs(dc); #ifdef HAVE_UNAME uname(&utsname); ! dc->class_id = splice_many_strings(4, utsname.sysname, utsname.nodename, utsname.release, utsname.version, utsname.machine); #else /* HAVE_UNAME */ dc->class_id = strdup("Unknown"); Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-convert.c 8 Feb 2002 17:04:32 -0000 1.5 --- dhcp-convert.c 9 Feb 2002 15:50:30 -0000 1.6 *************** *** 639,650 **** case sizeof(int32_t): ! *(int32_t *)val = strtol(s, NULL, 10); break; case sizeof(int16_t): ! *(int16_t *)val = (uint16_t)atoi(s); /* this is safe ! * because we're always getting our ! * own serialized values. they should decay fine. ! * don't use this on strings gotten from the network. */ break; default: --- 639,650 ---- case sizeof(int32_t): ! *(int32_t *)val = (int32_t)strtol(s, NULL, 10); break; case sizeof(int16_t): ! *(int16_t *)val = (int16_t)atoi(s); /* this is safe ! * because we're always getting our ! * own serialized values. they should decay fine. ! * don't use this on strings gotten from the network. */ break; default: *************** *** 659,663 **** case sizeof(uint32_t): ! *(uint32_t *)val = strtoul(s, NULL, 10); break; --- 659,663 ---- case sizeof(uint32_t): ! *(uint32_t *)val = (uint32_t)strtoul(s, NULL, 10); break; Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-sysconf.c 8 Feb 2002 17:04:32 -0000 1.5 --- dhcp-sysconf.c 9 Feb 2002 15:50:30 -0000 1.6 *************** *** 28,32 **** sysconf_handler sysconf_handlers[] = { ! { NULL, }, /* 0 */ { NULL, }, /* 1 */ /* Subnet mask -- don't handle here.*/ { NULL, }, /* 2 */ /* time offset. */ --- 28,32 ---- sysconf_handler sysconf_handlers[] = { ! { NULL, }, /* 0 */ /* Pad -- don't handle here. */ { NULL, }, /* 1 */ /* Subnet mask -- don't handle here.*/ { NULL, }, /* 2 */ /* time offset. */ *************** *** 72,92 **** { NULL, }, /* 43 */ /* netbios over tcp/ip */ { NULL, }, /* 44 */ ! { NULL, }, /* 45 */ ! { NULL, }, /* 46 */ ! { NULL, }, /* 47 */ ! { NULL, }, /* 48 */ ! { NULL, }, /* 49 */ ! { NULL, }, /* 50 */ ! { NULL, }, /* 51 */ ! { NULL, }, /* 52 */ ! { NULL, }, /* 53 */ ! { NULL, }, /* 54 */ ! { NULL, }, /* 55 */ ! { NULL, }, /* 56 */ ! { NULL, }, /* 57 */ ! { NULL, }, /* 58 */ ! { NULL, }, /* 59 */ ! { NULL, }, /* 60 */ ! { NULL, }, /* 61 */ }; --- 72,92 ---- { NULL, }, /* 43 */ /* netbios over tcp/ip */ { NULL, }, /* 44 */ ! { NULL, }, /* 45 */ ! { NULL, }, /* 46 */ ! { NULL, }, /* 47 */ ! { NULL, }, /* 48 */ ! { NULL, }, /* 49 */ ! { NULL, }, /* 50 */ ! { NULL, }, /* 51 */ ! { NULL, }, /* 52 */ ! { NULL, }, /* 53 */ ! { NULL, }, /* 54 */ ! { NULL, }, /* 55 */ ! { NULL, }, /* 56 */ ! { NULL, }, /* 57 */ ! { NULL, }, /* 58 */ ! { NULL, }, /* 59 */ ! { NULL, }, /* 60 */ ! { NULL, }, /* 61 */ }; Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-util.c 8 Feb 2002 17:04:32 -0000 1.7 --- dhcp-util.c 9 Feb 2002 15:50:30 -0000 1.8 *************** *** 272,279 **** * Splice two strings together. * - * XXX: todo see if we can get this to work - * with stdarg so that an infinite amount - * of strings can be passed. - * */ --- 272,275 ---- *************** *** 295,298 **** --- 291,321 ---- } + /* interface to splice_string. */ + + char *splice_many_strings(int num, char *string, ...) + { + va_list ap; + char *s, *tmp; + char *new_string; + + new_string = strdup(string); + + if(num <= 1) + return new_string; /* be nice to stupid callers. */ + + va_start(ap, string); + + while(num--) { + s = va_arg(ap, char *); + tmp = new_string; + new_string = splice_string(new_string, s); + xfree(tmp); + } + + va_end(ap); + + return new_string; + } + /* trim preprending and trailing space. also get rid of newlines. */ void trim_string(char *s) |
From: Thamer Al-H. <act...@us...> - 2002-02-08 18:15:56
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv30938 Modified Files: TODO dhcp-agent.h dhcp-com.c Log Message: dhcpclient now can read options if overloaded in sname of file bootp fields; Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TODO 30 Jan 2002 20:24:09 -0000 1.3 --- TODO 8 Feb 2002 18:15:52 -0000 1.4 *************** *** 10,15 **** extend over 255 octets) - -- deal with option overloads onto the bootp header. - major todos: --- 10,13 ---- Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-agent.h 7 Feb 2002 18:41:47 -0000 1.18 --- dhcp-agent.h 8 Feb 2002 18:15:52 -0000 1.19 *************** *** 408,411 **** --- 408,412 ---- # define TAG_DHCP_SUBNET_MASK 1 # define TAG_DHCP_REQUEST_IP_ADDRESS 50 + # define TAG_DHCP_OPTION_OVERLOAD 52 # define TAG_DHCP_MESSAGE_TYPE 53 # define TAG_DHCP_SERVER_IDENTIFIER 54 *************** *** 415,418 **** --- 416,425 ---- # define TAG_DHCP_CLIENT_ID 61 + /* DHCP overload option values. */ + + #define DHCP_OVERLOAD_FILE 1 + #define DHCP_OVERLOAD_SNAME 2 + #define DHCP_OVERLOAD_BOTH 3 + /* NetBIOS Scope Node Types */ *************** *** 620,623 **** --- 627,632 ---- extern int dhcp_have_atleast_requested_options(dhcp_obj *dhcp, unsigned char *option); extern int dhcp_have_option(dhcp_obj *dhcp, unsigned char tag); + extern int dhcp_is_file_overload(dhcp_obj *dhcp); + extern int dhcp_is_sname_overload(dhcp_obj *dhcp); extern dhcp_option *dhcp_build_parameter_request_list_option(unsigned char *requested_options); Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-com.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-com.c 3 Feb 2002 16:56:00 -0000 1.3 --- dhcp-com.c 8 Feb 2002 18:15:52 -0000 1.4 *************** *** 132,166 **** } ! /* read packet image. */ ! int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { unsigned char optlen; dhcp_option *option; - - /* Get the fixedheader or if not - * possible return an error. */ - - if(len < DHCP_FIXEDHDR_LEN) - return -1; - else - align_dhcphdr(dhcp_packet, &dhcp->fixedheader); ! len -= DHCP_FIXEDHDR_LEN; ! dhcp_packet += DHCP_FIXEDHDR_LEN; ! ! /* Copy out magic cookie. 4 octets. */ ! ! if(len >= 4) ! memcpy(&dhcp->magic_cookie, dhcp_packet, 4); ! else { ! memset(&dhcp->magic_cookie, 0, 4); /* set it to 0 so it doesn't pass test. */ ! return 0; ! } ! ! len -= 4; ! dhcp_packet += 4; ! ! /* ! * Now try and copy all the options. * We do no parsing at this point * since we may not require all --- 132,141 ---- } ! static void dhcp_read_options_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { unsigned char optlen; dhcp_option *option; ! /* Try and copy all the options. * We do no parsing at this point * since we may not require all *************** *** 202,205 **** --- 177,223 ---- dhcp->options_seek = dhcp->options; + + return; + } + + /* read packet image. */ + int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) + { + /* Get the fixedheader or if not + * possible return an error. */ + + if(len < DHCP_FIXEDHDR_LEN) + return -1; + else + align_dhcphdr(dhcp_packet, &dhcp->fixedheader); + + len -= DHCP_FIXEDHDR_LEN; + dhcp_packet += DHCP_FIXEDHDR_LEN; + + /* Copy out magic cookie. 4 octets. */ + + if(len >= 4) + memcpy(&dhcp->magic_cookie, dhcp_packet, 4); + else { + memset(&dhcp->magic_cookie, 0, 4); /* set it to 0 so it doesn't pass test. */ + return 0; + } + + len -= 4; + dhcp_packet += 4; + + /* read options placed after cookie. */ + dhcp_read_options_image(dhcp, dhcp_packet, len); + + /* We need to check file before sname to be compliant. */ + + /* Now check if we have options overload in file field + * and read options as necesssary. */ + if(dhcp_is_file_overload(dhcp)) + dhcp_read_options_image(dhcp, dhcp->fixedheader.file, DHCP_FILE_SIZE); + + /* Ditto on the sname field. */ + if(dhcp_is_sname_overload(dhcp)) + dhcp_read_options_image(dhcp, dhcp->fixedheader.sname, DHCP_SNAME_SIZE); return 0; *************** *** 388,391 **** --- 406,450 ---- } + /* get the overload which may be for file, sname, or both. */ + static unsigned char dhcp_get_overload_option(dhcp_obj *dhcp) + { + dhcp_option *option; + + dhcp_reset_option_seek(dhcp); + + while((option = dhcp_get_next_option(dhcp)) != NULL) { + if(option->tag == TAG_DHCP_OPTION_OVERLOAD) { + return *(option->data); + } + } + + return 0; + } + + /* options overloaded on file field? */ + int dhcp_is_file_overload(dhcp_obj *dhcp) + { + unsigned char overload_val = dhcp_get_overload_option(dhcp); + + if(overload_val == DHCP_OVERLOAD_FILE || + overload_val == DHCP_OVERLOAD_BOTH) + return 1; + else + return 0; + } + + /* options overloaded on sname field? */ + int dhcp_is_sname_overload(dhcp_obj *dhcp) + { + unsigned char overload_val = dhcp_get_overload_option(dhcp); + + if(overload_val == DHCP_OVERLOAD_SNAME || + overload_val == DHCP_OVERLOAD_BOTH) + return 1; + else + return 0; + } + + /* Check if we have at least the requested options: * count up the number of options we want, then |
From: Thamer Al-H. <act...@us...> - 2002-02-08 17:04:36
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv8818 Modified Files: Makefile.am Makefile.in dhcp-client.c dhcp-convert.c dhcp-files.c dhcp-sysconf.c dhcp-util.c Log Message: fixed up logging; dhcp-files now handles variable length strings properly; Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.am 1 Feb 2002 18:31:17 -0000 1.6 --- Makefile.am 8 Feb 2002 17:04:32 -0000 1.7 *************** *** 22,26 **** dhcp-sysconf.c dhcp-rtt.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h --- 22,26 ---- dhcp-sysconf.c dhcp-rtt.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.in 1 Feb 2002 18:31:17 -0000 1.6 --- Makefile.in 8 Feb 2002 17:04:32 -0000 1.7 *************** *** 86,90 **** ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h config.h --- 86,90 ---- ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client.c 7 Feb 2002 18:41:47 -0000 1.12 --- dhcp-client.c 8 Feb 2002 17:04:32 -0000 1.13 *************** *** 26,30 **** int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ ! char *binname = NULL; /* we need a name. */ char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ --- 26,30 ---- int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ ! char *binname = "dhcpclient"; /* we need a name. */ char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ *************** *** 144,147 **** --- 144,148 ---- } + info_message("killed client on pid: %u", pid); return; } *************** *** 223,227 **** static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "cdavim:kwh:l:")) != -1) { switch(c) { --- 224,228 ---- static char *fake_hw_addr = NULL; ! while((c = getopt(argc, argv, "gcdavim:kwh:l:")) != -1) { switch(c) { *************** *** 278,282 **** } ! binname = argv[0]; info_message("starting for interface %s", interface); --- 279,283 ---- } ! info_message("(C) 2001 Thamer Al-Harbash <tm...@wh...>"); info_message("starting for interface %s", interface); Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-convert.c 5 Feb 2002 02:00:59 -0000 1.4 --- dhcp-convert.c 8 Feb 2002 17:04:32 -0000 1.5 *************** *** 192,196 **** string_addr_list_to_network, purge_list_internal }, /* 44 */ /* NetBIOS over TCP/IP Name Server */ { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 45 */ /* NetBIOS over TCP/IP Name Server */ { network_byte_to_string_byte, string_byte_to_byte, string_byte_to_network, xfree }, /* 46 */ /* NetBIOS over TCP/IP Node Type. */ --- 192,196 ---- string_addr_list_to_network, purge_list_internal }, /* 44 */ /* NetBIOS over TCP/IP Name Server */ { network_addr_list_to_string, string_to_addr_list, ! string_addr_list_to_network, purge_list_internal }, /* 45 */ /* NetBIOS over TCP/IP Datagram Dist Server */ { network_byte_to_string_byte, string_byte_to_byte, string_byte_to_network, xfree }, /* 46 */ /* NetBIOS over TCP/IP Node Type. */ *************** *** 539,543 **** char *s = NULL; char *string = NULL; ! if(len == 0 || len%sizeof(uint16_t)) --- 539,543 ---- char *s = NULL; char *string = NULL; ! if(len == 0 || len%sizeof(uint16_t)) Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-files.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-files.c 5 Feb 2002 13:47:38 -0000 1.3 --- dhcp-files.c 8 Feb 2002 17:04:32 -0000 1.4 *************** *** 25,29 **** #include <dhcp-agent.h> ! static char buff[GENERIC_BUFFSIZE]; static char *var_name = NULL; static char *var_val = NULL; --- 25,29 ---- #include <dhcp-agent.h> ! static char *line_buff = NULL; static char *var_name = NULL; static char *var_val = NULL; *************** *** 79,83 **** case PARSE_DOUBLE_STRINGS: ! s = strchr(buff, '='); if(s == NULL) return -1; --- 79,83 ---- case PARSE_DOUBLE_STRINGS: ! s = strchr(line_buff, '='); if(s == NULL) return -1; *************** *** 87,91 **** if(*s == '\0' || *s == '\n' || *s == '\r') return -1; ! var_name = buff; var_val = s; --- 87,91 ---- if(*s == '\0' || *s == '\n' || *s == '\r') return -1; ! var_name = line_buff; var_val = s; *************** *** 99,104 **** case PARSE_SINGLE_STRING: ! trim_string(buff); ! var_name = buff; if(!isascii(*var_name)) --- 99,104 ---- case PARSE_SINGLE_STRING: ! trim_string(line_buff); ! var_name = line_buff; if(!isascii(*var_name)) *************** *** 114,124 **** } int file_get_var_string(FILE *fp) { ! if(fgets(buff, sizeof(buff), fp) == NULL) return 1; ! else return 0; } --- 114,176 ---- } + /* Get the next string from the file. + * In order to do this for variable length strings which may be + * very long or very short we do a walk ahead till we find the + * newline character and then read everything up to it. + * We need to do this to support options which are larger + * than 255 octets which we may receive. + * + * Should we worry about size limits? No. An IP packet cannot be + * bigger than 65535 bytes, and we're most likely receiving a + * little under 600 bytes from the UDP packet. We can handle both + * such sizes reasonably well. + * + */ + int file_get_var_string(FILE *fp) { + long begin_line_seek, end_line_seek; + int c; + unsigned char have_line = 0; + size_t string_size; ! begin_line_seek = ftell(fp); ! ! if(line_buff != NULL) { ! /* free up old string. */ ! xfree(line_buff); ! line_buff = NULL; ! } ! ! while((c = fgetc(fp)) != EOF) { ! if(c == '\n') { ! have_line = 1; ! break; ! } ! } ! ! if(!have_line) return 1; ! ! end_line_seek = ftell(fp); ! ! /* Our buffer needs to be as big as the line plus ! * one for the null termination. */ ! ! string_size = (end_line_seek - begin_line_seek); ! line_buff = xmalloc(string_size + 1); ! ! /* seek back. */ ! fseek(fp, begin_line_seek, SEEK_SET); ! ! ! /* all done. read up! */ ! if(fread(line_buff, sizeof(char), string_size, fp) != string_size) ! return 1; ! else { ! line_buff[string_size] = 0; ! warn_message("string read: %s",line_buff); return 0; + } } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sysconf.c 1 Feb 2002 18:31:17 -0000 1.4 --- dhcp-sysconf.c 8 Feb 2002 17:04:32 -0000 1.5 *************** *** 23,27 **** */ ! /* Configure host or internal structures. */ #include <dhcp-agent.h> --- 23,27 ---- */ ! /* Configure host internal structures. */ #include <dhcp-agent.h> *************** *** 29,77 **** sysconf_handler sysconf_handlers[] = { { NULL, }, /* 0 */ ! { NULL, }, /* 1 */ ! { NULL, }, /* 2 */ ! { sysconf_routers, }, /* 3 */ ! { NULL, }, /* 4 */ ! { NULL, }, /* 5 */ ! { sysconf_domain_name_servers, }, /* 6 */ ! { NULL, }, /* 7 */ ! { NULL, }, /* 8 */ ! { NULL, }, /* 9 */ ! { NULL, }, /* 10 */ ! { NULL, }, /* 11 */ ! { NULL, }, /* 12 */ ! { NULL, }, /* 13 */ ! { NULL, }, /* 14 */ ! { sysconf_domain_name, }, /* 15 */ ! { NULL, }, /* 16 */ ! { NULL, }, /* 17 */ ! { NULL, }, /* 18 */ ! { NULL, }, /* 17 */ ! { NULL, }, /* 18 */ ! { NULL, }, /* 19 */ ! { NULL, }, /* 20 */ ! { NULL, }, /* 21 */ ! { NULL, }, /* 23 */ ! { NULL, }, /* 24 */ ! { NULL, }, /* 25 */ ! { NULL, }, /* 26 */ ! { NULL, }, /* 27 */ ! { NULL, }, /* 28 */ ! { NULL, }, /* 29 */ ! { NULL, }, /* 30 */ ! { NULL, }, /* 31 */ ! { NULL, }, /* 32 */ ! { NULL, }, /* 33 */ ! { NULL, }, /* 34 */ ! { NULL, }, /* 35 */ ! { NULL, }, /* 36 */ ! { NULL, }, /* 37 */ ! { NULL, }, /* 38 */ ! { NULL, }, /* 39 */ ! { NULL, }, /* 40 */ ! { NULL, }, /* 41 */ ! { NULL, }, /* 42 */ ! { NULL, }, /* 43 */ ! { NULL, }, /* 44 */ { NULL, }, /* 45 */ { NULL, }, /* 46 */ --- 29,75 ---- sysconf_handler sysconf_handlers[] = { { NULL, }, /* 0 */ ! { NULL, }, /* 1 */ /* Subnet mask -- don't handle here.*/ ! { NULL, }, /* 2 */ /* time offset. */ ! { sysconf_routers, }, /* 3 */ /* routers. */ ! { NULL, }, /* 4 */ /* time server. */ ! { NULL, }, /* 5 */ /* name server (old). */ ! { sysconf_domain_name_servers, }, /* 6 */ /* domain name servers. */ ! { NULL, }, /* 7 */ /* mit-lcs log server. */ ! { NULL, }, /* 8 */ /* cookie servers. */ ! { NULL, }, /* 9 */ /* lpr servers. */ ! { NULL, }, /* 10 */ /* impress server. */ ! { NULL, }, /* 11 */ /* resource location server. */ ! { NULL, }, /* 12 */ /* host name option. */ ! { NULL, }, /* 13 */ /* boot file size option. */ ! { NULL, }, /* 14 */ /* merit dump file. */ ! { sysconf_domain_name, }, /* 15 */ /* domain name. */ ! { NULL, }, /* 16 */ /* swap server. */ ! { NULL, }, /* 17 */ /* root path. */ ! { NULL, }, /* 18 */ /* extension path */ ! { NULL, }, /* 19 */ /* ip forwarding. */ ! { NULL, }, /* 20 */ /* non local source routing. */ ! { NULL, }, /* 21 */ /* policy filter option. */ ! { NULL, }, /* 23 */ /* maximum dgram reassembly. */ ! { NULL, }, /* 24 */ /* mtu aging timeout. */ ! { NULL, }, /* 25 */ /* mtu plateau table. */ ! { NULL, }, /* 26 */ /* interface mtu */ ! { NULL, }, /* 27 */ /* subnets are local. */ ! { NULL, }, /* 28 */ /* broadcast address. */ ! { NULL, }, /* 29 */ /* perform mask discovery. */ ! { NULL, }, /* 30 */ /* mask supplier. */ ! { NULL, }, /* 31 */ /* perform router discovery. */ ! { NULL, }, /* 32 */ /* router soliciation address. */ ! { NULL, }, /* 33 */ /* static route. */ ! { NULL, }, /* 34 */ /* trailer encapsulation. */ ! { NULL, }, /* 35 */ /* arp cache timeout. */ ! { NULL, }, /* 36 */ /* ethernet encapsulation. */ ! { NULL, }, /* 37 */ /* tcp default ttl. */ ! { NULL, }, /* 38 */ /* tcp keepalive garbage option. */ ! { NULL, }, /* 39 */ /* network information service domain. */ ! { NULL, }, /* 40 */ /* network time protocol servers. */ ! { NULL, }, /* 41 */ /* vendor specific. */ ! { NULL, }, /* 42 */ /* netbios over TCP/IP name server. */ ! { NULL, }, /* 43 */ /* netbios over tcp/ip */ ! { NULL, }, /* 44 */ { NULL, }, /* 45 */ { NULL, }, /* 46 */ *************** *** 202,209 **** if(have_addr && have_netmask) /* if we're done finding both, break out. */ break; ! continue; } ! if(string_matches(dhcp_options_strings[TAG_DHCP_SUBNET_MASK], ce->name)) { --- 200,207 ---- if(have_addr && have_netmask) /* if we're done finding both, break out. */ break; ! continue; } ! if(string_matches(dhcp_options_strings[TAG_DHCP_SUBNET_MASK], ce->name)) { Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-util.c 8 Feb 2002 01:37:29 -0000 1.6 --- dhcp-util.c 8 Feb 2002 17:04:32 -0000 1.7 *************** *** 51,55 **** va_list ap; ! if(verbosity_level <= QUIET_VERBOSITY_LEVEL) return; --- 51,55 ---- va_list ap; ! if(verbosity_level == QUIET_VERBOSITY_LEVEL) return; *************** *** 59,63 **** if(interactive == 1) { ! fprintf(stderr, "error: %s", msgbuff); fprintf(stderr,"\n"); } else --- 59,63 ---- if(interactive == 1) { ! fprintf(stderr, "%s: error: %s", binname, msgbuff); fprintf(stderr,"\n"); } else *************** *** 72,76 **** va_list ap; ! if(verbosity_level <= QUIET_VERBOSITY_LEVEL) return; --- 72,76 ---- va_list ap; ! if(verbosity_level == QUIET_VERBOSITY_LEVEL) return; *************** *** 80,84 **** if(interactive == 1) { ! fprintf(stderr, "fatal error: %s", msgbuff); fprintf(stderr,"\n"); } else --- 80,84 ---- if(interactive == 1) { ! fprintf(stderr, "%s: fatal error: %s", binname, msgbuff); fprintf(stderr,"\n"); } else *************** *** 94,98 **** va_list ap; ! if(verbosity_level <= ERROR_VERBOSITY_LEVEL) return; --- 94,98 ---- va_list ap; ! if(verbosity_level < ERROR_VERBOSITY_LEVEL) return; *************** *** 102,106 **** if(interactive == 1) { ! fprintf(stdout, "%s", msgbuff); fprintf(stdout,"\n"); } else --- 102,106 ---- if(interactive == 1) { ! fprintf(stdout, "%s: %s", binname, msgbuff); fprintf(stdout,"\n"); } else *************** *** 115,119 **** va_list ap; ! if(verbosity_level <= WARNING_VERBOSITY_LEVEL) return; --- 115,119 ---- va_list ap; ! if(verbosity_level < WARNING_VERBOSITY_LEVEL) return; *************** *** 123,127 **** if(interactive == 1) { ! fprintf(stdout, "warning: %s", msgbuff); fprintf(stdout,"\n"); } else --- 123,127 ---- if(interactive == 1) { ! fprintf(stdout, "%s warning: %s", binname, msgbuff); fprintf(stdout,"\n"); } else *************** *** 136,140 **** va_list ap; ! if(verbosity_level <= DEBUG_VERBOSITY_LEVEL) return; --- 136,140 ---- va_list ap; ! if(verbosity_level < DEBUG_VERBOSITY_LEVEL) return; *************** *** 144,148 **** if(interactive == 1) { ! fprintf(stdout, "debug: %s", msgbuff); fprintf(stdout,"\n"); } else --- 144,148 ---- if(interactive == 1) { ! fprintf(stdout, "%s: debug: %s", binname, msgbuff); fprintf(stdout,"\n"); } else |