[Dhcp-agent-commits] CVS: dhcp-agent dhcp-agent.h,1.13,1.14 dhcp-arp.c,1.4,1.5 dhcp-client-states.c,
Status: Alpha
Brought to you by:
actmodern
From: Thamer Al-H. <act...@us...> - 2002-02-02 12:28:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv26656 Modified Files: dhcp-agent.h dhcp-arp.c dhcp-client-states.c dhcp-net.c Log Message: implemented unarp in client; no idea if its actually working in a useful way; need to test against something that handles unarp; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-agent.h 2002/02/02 00:48:06 1.13 --- dhcp-agent.h 2002/02/02 12:28:05 1.14 *************** *** 471,474 **** --- 471,476 ---- 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); Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-arp.c 2002/02/02 00:48:06 1.4 --- dhcp-arp.c 2002/02/02 12:28:05 1.5 *************** *** 123,125 **** return; } - --- 123,124 ---- Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-states.c 2002/02/02 00:48:06 1.9 --- dhcp-client-states.c 2002/02/02 12:28:05 1.10 *************** *** 26,29 **** --- 26,32 ---- #include <dhcp-agent.h> + static uint32_t client_ip_addr; + static eth_addr_t client_hw_addr; + static sig_atomic_t have_alarm = 0; *************** *** 88,91 **** --- 91,111 ---- } + /* 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, dc->interface, &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 *************** *** 97,116 **** static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { - uint32_t ip_addr; - eth_addr_t hw_addr; - - /* Get our IP address from rawnet. - * We don't get it from the cache. - * This is quicker, and since it should be - * setup it's more correct. - */ - - if(rawnet_get_interface_hw_addr(dc->rawnet, &hw_addr) || - interface_get_ip_addr(dc->interface_control, dc->interface, &ip_addr)) { - error_message("warning: could get get hardware and ip addresses to generate arp reply. this is bad, but i'll keep going."); - return; - } ! rawnet_build_arp_reply_broadcast(dc->rawnet, ip_addr, hw_addr); rawnet_send_packet(dc->rawnet); --- 117,122 ---- static void client_broadcast_arp_reply(dhcp_client_control_t *dc) { ! rawnet_build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr); rawnet_send_packet(dc->rawnet); *************** *** 118,121 **** --- 124,137 ---- } + /* UNARP (rfc 1868). This makes us more network friendly. */ + + 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); + + return; + } + /* Send and wait for reply. */ *************** *** 296,299 **** --- 312,318 ---- do_sysconf(options, dc); cache_entry_purge_list(options); + + if(client_update_addresses(dc)) + return -1; client_broadcast_arp_reply(dc); *************** *** 360,363 **** --- 379,387 ---- client_cache_delete_cache(dc->cache); + /* We should still have our interface up, so go ahead and send UNARP before + * bringing it down later. */ + + client_broadcast_unarp(dc); + return 0; /* called from do_shutdown() so no real state returned */ } Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-net.c 2002/02/02 00:48:06 1.8 --- dhcp-net.c 2002/02/02 12:28:05 1.9 *************** *** 65,69 **** /* constants we need. */ ! static const eth_addr_t eth_broadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; static const uint32_t ip_addr_broadcast = 0xffffffff; --- 65,70 ---- /* 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; *************** *** 414,423 **** uint32_t sender_ip_addr, eth_addr_t target_hw_addr, ! uint32_t target_ip_addr) { 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, ETH_ADDR_LEN); arp_set_protocol_len(net->arp_p, IP_ADDR_LEN); arp_set_op(net->arp_p, opcode); --- 415,425 ---- 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); *************** *** 645,649 **** { 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); net->type = RAWNET_ARP; --- 647,652 ---- { 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; *************** *** 672,675 **** --- 675,693 ---- } + /* 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. */ |