[Dhcp-agent-commits] CVS: dhcp-agent Makefile.am,1.15,1.16 Makefile.in,1.15,1.16 dhcp-agent.h,1.34,1
Status: Alpha
Brought to you by:
actmodern
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); |