[dhcp-agent-commits] dhcp-agent Makefile.am,1.30,1.31 Makefile.in,1.32,1.33 dhcp-agent.h,1.69,1.70 d
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-10-21 01:02:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv9994 Modified Files: Makefile.am Makefile.in dhcp-agent.h dhcp-arp-discovery.c dhcp-client-control.c dhcp-client-states.c dhcp-com.c dhcp-eth.c dhcp-icmp-discovery.c dhcp-net.c dhcp-packet-build.c dhcp-print.c Log Message: first stab at incorporating proper unicast support -- needs more work Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Makefile.am 13 Oct 2002 16:29:42 -0000 1.30 --- Makefile.am 21 Oct 2002 01:02:48 -0000 1.31 *************** *** 23,27 **** dhcp-parser.c dhcp-varfile.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 23,30 ---- dhcp-parser.c dhcp-varfile.c ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ ! ! # Use this to include efence (dev only). ! #LDADD=-lefence noinst_HEADERS = dhcp-agent.h config.h Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Makefile.in 13 Oct 2002 16:29:42 -0000 1.32 --- Makefile.in 21 Oct 2002 01:02:48 -0000 1.33 *************** *** 106,111 **** ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ -lefence noinst_HEADERS = dhcp-agent.h config.h --- 106,114 ---- ! dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ ! + # Use this to include efence (dev only). + #LDADD=-lefence noinst_HEADERS = dhcp-agent.h config.h Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** dhcp-agent.h 14 Oct 2002 15:52:32 -0000 1.69 --- dhcp-agent.h 21 Oct 2002 01:02:48 -0000 1.70 *************** *** 122,125 **** --- 122,129 ---- */ + /* Max message size option default. */ + + # define MAX_MESSAGE_SIZE 576 + /* max options handled. */ *************** *** 144,153 **** /* Verbosity levels. */ ! #define QUIET_VERBOSITY_LEVEL 0 ! #define ERROR_VERBOSITY_LEVEL 1 ! #define NORMAL_VERBOSITY_LEVEL 2 ! #define WARNING_VERBOSITY_LEVEL 3 ! #define DEBUG_VERBOSITY_LEVEL 4 ! #define MAX_VERBOSITY_LEVEL DEBUG_VERBOSITY_LEVEL /* * * * * * * * * * * --- 148,153 ---- /* Verbosity levels. */ ! enum verbosity { QUIET_VERBOSITY_LEVEL = 0, ERROR_VERBOSITY_LEVEL, NORMAL_VERBOSITY_LEVEL, ! WARNING_VERBOSITY_LEVEL, DEBUG_VERBOSITY_LEVEL, MAX_VERBOSITY_LEVEL }; /* * * * * * * * * * * *************** *** 278,285 **** struct timeval tstamp; /* timestamp. */ ! 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 promiscuous; /* run in promiscuous mode flag. */ interface_control_t *intf_handle; /* interface control handle. */ --- 278,287 ---- struct timeval tstamp; /* timestamp. */ ! eth_addr_t chw_addr; /* our hardware address. */ ! ip_addr_t cip_addr; /* our ip address. */ ! ! eth_addr_t *fake_hw_addr; /* our fake hardware address. */ ! ! int promiscuous; /* run in promiscuous mode flag. */ interface_control_t *intf_handle; /* interface control handle. */ *************** *** 336,346 **** rawnet_t *rawnet; /* raw network handle */ ! client_cache_t *cache; /* cache */ ! client_conf_t *conf; /* configuration. */ ! uint32_t xid; /* unique xid */ ! time_t started; /* the amount of milliseconds since we started. */ ! time_t secs; /* secs -- used to save secs value. */ ! uint32_t renewal_time; /* when to renew lease (secs). */ char *interface; /* interface name. */ --- 338,348 ---- rawnet_t *rawnet; /* raw network handle */ ! client_cache_t *cache; /* cache */ ! client_conf_t *conf; /* configuration. */ ! uint32_t xid; /* unique xid */ ! time_t started; /* the amount of milliseconds since we started. */ ! time_t secs; /* secs -- used to save secs value. */ ! uint32_t renewal_time; /* when to renew lease (secs). */ char *interface; /* interface name. */ *************** *** 348,351 **** --- 350,357 ---- int state; /* our current state. */ int discover_offer_retries; /* counter for retries on discover_offer */ + + ip_addr_t sip_addr; /* server's ip address. */ + eth_addr_t shw_addr; /* server's hardware address. */ + } dhcp_client_control_t; *************** *** 529,534 **** /* packet building routines. */ 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); --- 535,546 ---- /* packet building routines. */ + /* dhcp packet routines. */ extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, ! ip_addr_t sip_addr, eth_addr_t shw_addr); ! extern void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); ! extern void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); ! ! /* arp packet routines. */ extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); *************** *** 547,550 **** --- 559,564 ---- extern void build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); + + /* icmp packet routines. */ 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); *************** *** 606,609 **** --- 620,624 ---- extern void dhcp_set_secs(dhcp_obj *dhcp, uint16_t secs); extern void dhcp_set_flag_broadcast(dhcp_obj *dhcp); + extern void dhcp_unset_flag_broadcast(dhcp_obj *dhcp); extern void dhcp_set_ciaddr(dhcp_obj *dhcp, uint32_t ciaddr); extern void dhcp_set_yiaddr(dhcp_obj *dhcp, uint32_t yiaddr); *************** *** 634,637 **** --- 649,653 ---- extern int dhcp_is_file_overload(dhcp_obj *dhcp); extern int dhcp_is_sname_overload(dhcp_obj *dhcp); + extern uint32_t dhcp_gen_xid(void); extern dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options); *************** *** 643,647 **** extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); extern dhcp_option_t *dhcp_build_hostname(char *hostname); ! extern uint32_t dhcp_gen_xid(void); /* Ether obj routines. */ --- 659,663 ---- extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); extern dhcp_option_t *dhcp_build_hostname(char *hostname); ! /* Ether obj routines. */ *************** *** 652,657 **** extern void eth_write_packet_image(eth_obj *eth, unsigned char *packet); ! extern unsigned char *eth_get_src_address(eth_obj *eth); ! extern unsigned char *eth_get_dst_address(eth_obj *eth); extern uint16_t eth_get_type(eth_obj *eth); --- 668,673 ---- extern void eth_write_packet_image(eth_obj *eth, unsigned char *packet); ! extern eth_addr_t eth_get_src_address(eth_obj *eth); ! extern eth_addr_t eth_get_dst_address(eth_obj *eth); extern uint16_t eth_get_type(eth_obj *eth); *************** *** 782,785 **** --- 798,804 ---- extern void dhcp_client_interface_down(dhcp_client_control_t *dc); extern void dhcp_client_update_xid(dhcp_client_control_t *dc); + + extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); + extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); /* dhcp client conf */ Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-arp-discovery.c 12 Oct 2002 22:54:50 -0000 1.9 --- dhcp-arp-discovery.c 21 Oct 2002 01:02:48 -0000 1.10 *************** *** 80,84 **** * hardware address so we get a reply back. */ ! build_arp_request(net, net->ip_addr, address, net->hw_addr); while(retries--) { --- 80,84 ---- * hardware address so we get a reply back. */ ! build_arp_request(net, net->cip_addr, address, net->chw_addr); while(retries--) { Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** dhcp-client-control.c 14 Oct 2002 15:52:33 -0000 1.27 --- dhcp-client-control.c 21 Oct 2002 01:02:48 -0000 1.28 *************** *** 239,247 **** if(dc->client_id) xfree(dc->client_id); ! 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 --- 239,247 ---- if(dc->client_id) xfree(dc->client_id); ! xfree(dc); } ! /* Utility routine to bring down interface. * we need this because we have to be explicit * about it. We can't do this at the time we *************** *** 256,259 **** --- 256,276 ---- { rawnet_interface_down(dc->rawnet); + return; + } + + /* set and clear server address. + * this is useful for unicasting and for RELEASE. */ + + void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr) + { + memcpy(&dc->sip_addr, &ip_addr, sizeof(ip_addr_t)); + + return; + } + + void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr) + { + memcpy(&dc->shw_addr, ð_addr, sizeof(eth_addr_t)); + return; } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** dhcp-client-states.c 14 Oct 2002 15:52:33 -0000 1.40 --- dhcp-client-states.c 21 Oct 2002 01:02:48 -0000 1.41 *************** *** 34,64 **** #include <dhcp-net.h> ! /* Check the requested options. ! * We use the globconf option. */ ! static int client_check_requested_options(dhcp_client_control_t *dc) { ! const char *policy = glob_conf_get_val(CLIENT_OPTION_POLICY); ! return 1; ! if(policy == NULL) ! policy = "atleast"; ! if(string_matches(policy, "exact")) ! return(dhcp_have_exact_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); ! else if(string_matches(policy, "atleast")) ! return(dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); ! else /* bad policy : warn and use atleast */ { ! WARN_MESSAGE("%s : set to bad value %s : going to use \"atleast\""); ! return(dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); ! } } ! /* Along with the parameter request list we always build these options ! * upon creating new dhcp packets. */ ! ! static list_t *client_build_option_list(unsigned char *opts, unsigned char message_type, ! unsigned char *client_id, unsigned char *class_id) { list_t *options = NULL; --- 34,61 ---- #include <dhcp-net.h> ! /*************************** ! * Option List Generation. * ! ***************************/ ! /* Create DHCP RELEASE option list. */ ! static list_t *client_build_release_option_list(dhcp_client_control_t *dc) { ! list_t *options = NULL; ! dhcp_option_t *option; ! /* client_id: RFC2131 says we MAY */ ! option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); ! options = add_to_list(options, option); ! ! /* dhcp message type. */ ! option = dhcp_build_message_type(DHCP_RELEASE_TM); ! options = add_to_list(options, option); ! return options; } ! /* This is used for both requests and discovery. */ ! static list_t *client_build_option_list(unsigned char *opts, dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 70,92 **** option = dhcp_build_parameter_request_list_option(opts); options = add_to_list(options, option); ! } ! ! /* dhcp max DHCP message size. */ ! /* FIXME: when overloading and the mtu is fixed ! * we also need to fix this magic number. */ ! option = dhcp_build_max_message_size_option(576); options = add_to_list(options, option); - /* dhcp message type. */ - option = dhcp_build_message_type(message_type); - options = add_to_list(options, option); - /* client_id */ ! option = dhcp_build_client_id(client_id, (ETH_ADDR_LEN + 1)); options = add_to_list(options, option); /* class_id */ ! option = dhcp_build_class_id(class_id); options = add_to_list(options, option); --- 67,83 ---- option = dhcp_build_parameter_request_list_option(opts); options = add_to_list(options, option); ! } ! /* dhcp max DHCP message size: ! * should go into globconf. */ ! option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE); options = add_to_list(options, option); /* client_id */ ! option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); options = add_to_list(options, option); /* class_id */ ! option = dhcp_build_class_id(dc->class_id); options = add_to_list(options, option); *************** *** 102,105 **** --- 93,156 ---- } + /* Create DHCP DISCOVER option list. */ + static list_t *client_build_discover_option_list(unsigned char *opts, dhcp_client_control_t *dc) + { + list_t *options = NULL; + list_t *requested_options = NULL; + dhcp_option_t *option; + + /* dhcp message type. */ + option = dhcp_build_message_type(DHCP_DISCOVER_TM); + options = add_to_list(options, option); + + requested_options = client_build_option_list(opts, dc); + options = join_lists(options, requested_options); + + return options; + } + + /* Create DHCP REQUEST option list. */ + static list_t *client_build_request_option_list(unsigned char *opts, dhcp_client_control_t *dc) + { + list_t *options = NULL; + list_t *requested_options = NULL; + dhcp_option_t *option; + + /* dhcp message type. */ + option = dhcp_build_message_type(DHCP_REQUEST_TM); + options = add_to_list(options, option); + + requested_options = client_build_option_list(opts, dc); + options = join_lists(options, requested_options); + + return options; + } + + /* Check the requested options. + * We use the globconf option. */ + + static int client_check_requested_options(dhcp_client_control_t *dc) + { + const char *policy = glob_conf_get_val(CLIENT_OPTION_POLICY); + + return 1; + if(policy == NULL) + policy = "atleast"; + + if(string_matches(policy, "exact")) + return(dhcp_have_exact_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); + else if(string_matches(policy, "atleast")) + return(dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); + else /* bad policy : warn and use atleast */ { + WARN_MESSAGE("%s : set to bad value %s : going to use \"atleast\""); + return(dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); + } + + } + + /****************** + * Check Routines * + ******************/ + /* Basic DHCP test on incoming rawnet packet. */ static int client_check_dhcp(dhcp_client_control_t *dc) *************** *** 124,129 **** --- 175,188 ---- dhcp_client_control_t *dc = arg; + /* check for a valid dhcp packet. */ + if(client_check_dhcp(dc) && + + /* check that the type is an offer. */ + dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) && + + /* check if the requested options match what we want. */ + client_check_requested_options(dc)) return 1; *************** *** 145,148 **** --- 204,225 ---- } + /************* + * Utilities.* + *************/ + + /* 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; + } + + /************* + * ARP/UNARP.* + *************/ + /* * Use this to send out a broadcast reply claiming that we own the *************** *** 187,199 **** } ! /* 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; ! } /* do discover/offer transaction. */ --- 264,270 ---- } ! /****************************** ! * DHCP client state routines.* ! ******************************/ /* do discover/offer transaction. */ *************** *** 203,208 **** int retval; ! options = client_build_option_list(dc->conf->options, DHCP_DISCOVER_TM, ! dc->client_id, dc->class_id); /* when we begin transmitting discover_offer we setup our secs field. --- 274,278 ---- int retval; ! options = client_build_discover_option_list(dc->conf->options, dc); /* when we begin transmitting discover_offer we setup our secs field. *************** *** 241,245 **** FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } ! /* Check for two options before inserting them ourselves. * The server may have decided to be nice to us. */ --- 311,315 ---- FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } ! /* Check for two options before inserting them ourselves. * The server may have decided to be nice to us. */ *************** *** 274,278 **** /* Build options along with the options in our cache. */ ! options = client_build_option_list(NULL, DHCP_REQUEST_TM, dc->client_id, dc->class_id); cache_options = client_cache_load_option_network_list(dc->cache, 0); --- 344,348 ---- /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(NULL, dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); *************** *** 286,291 **** /* Our options cleared by build_* since they are passed * down and later purged. */ ! ! build_dhcp_request(dc->rawnet, dc->xid, dc->secs, options); retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request); --- 356,361 ---- /* Our options cleared by build_* since they are passed * down and later purged. */ ! ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request); *************** *** 311,321 **** * then we need to revert to discover/offer state. */ ! if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) return STATE_SETUP; ! else return STATE_DISCOVER_OFFER; } /* do setup (call do_sysconf) */ int client_setup(dhcp_client_control_t *dc) --- 381,426 ---- * then we need to revert to discover/offer state. */ ! if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) { ! ! /* save hardware and ip address of server. we need these later. */ ! dhcp_client_set_server_ip_address(dc, ip_get_source_addr(dc->rawnet->ip_p)); ! dhcp_client_set_server_hw_address(dc, eth_get_src_address(dc->rawnet->ether_p)); ! return STATE_SETUP; ! } else { return STATE_DISCOVER_OFFER; + } } + /* release lease. */ + int client_release(dhcp_client_control_t *dc) + { + list_t *options; + + options = client_build_release_option_list(dc); + + build_dhcp_release(dc->rawnet, dc->xid, options, dc->sip_addr, dc->shw_addr); + + if(rawnet_send_packet(dc->rawnet) < 0) { + ERROR_MESSAGE("could not send release."); + return STATE_FATAL_ERROR; + } + + client_cache_delete_cache(dc->cache); + + /* We should still have our interface up, so go ahead and send UNARP before + * bringing it down later. */ + + if(client_broadcast_unarp(dc) < 0) { + return STATE_FATAL_ERROR; + } + + /* 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 */ + } + /* do setup (call do_sysconf) */ int client_setup(dhcp_client_control_t *dc) *************** *** 379,420 **** * or a TERM. in either case we can * return STATE_REQUEST_ACK here. */ - } - - /* release lease. */ - int client_release(dhcp_client_control_t *dc) - { - list_t *options, *cache_options; - - 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 STATE_FATAL_ERROR; - - 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) { - ERROR_MESSAGE("could not send release."); - return STATE_FATAL_ERROR; - } - - client_cache_delete_cache(dc->cache); - - /* We should still have our interface up, so go ahead and send UNARP before - * bringing it down later. */ - - if(client_broadcast_unarp(dc) < 0) { - return STATE_FATAL_ERROR; - } - - /* 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 */ } --- 484,486 ---- Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-com.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-com.c 12 Oct 2002 22:54:50 -0000 1.13 --- dhcp-com.c 21 Oct 2002 01:02:48 -0000 1.14 *************** *** 626,629 **** --- 626,636 ---- } + /* dhcp flags: do conversion */ + void dhcp_unset_flag_broadcast(dhcp_obj *dhcp) + { + dhcp->fixedheader.flags = 0; + return; + } + /* dhcp ciaddr: no conversion necessary */ void dhcp_set_ciaddr(dhcp_obj *dhcp, uint32_t ciaddr) Index: dhcp-eth.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-eth.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-eth.c 12 Oct 2002 22:54:50 -0000 1.6 --- dhcp-eth.c 21 Oct 2002 01:02:48 -0000 1.7 *************** *** 45,56 **** } ! unsigned char *eth_get_src_address(eth_obj *eth) { ! return(eth->header.eth_src.data); } ! unsigned char *eth_get_dst_address(eth_obj *eth) { ! return(eth->header.eth_dst.data); } --- 45,56 ---- } ! eth_addr_t eth_get_src_address(eth_obj *eth) { ! return(eth->header.eth_src); } ! eth_addr_t eth_get_dst_address(eth_obj *eth) { ! return(eth->header.eth_dst); } Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-icmp-discovery.c 13 Oct 2002 22:17:14 -0000 1.19 --- dhcp-icmp-discovery.c 21 Oct 2002 01:02:48 -0000 1.20 *************** *** 126,130 **** seq = 1; ! build_icmp_echo_request(net, net->ip_addr, dest_addr, net->hw_addr, dest_mac, id, seq); gettimeofday(&before, NULL); --- 126,130 ---- seq = 1; ! build_icmp_echo_request(net, net->cip_addr, dest_addr, net->chw_addr, dest_mac, id, seq); gettimeofday(&before, NULL); Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** dhcp-net.c 14 Oct 2002 15:52:33 -0000 1.34 --- dhcp-net.c 21 Oct 2002 01:02:48 -0000 1.35 *************** *** 170,174 **** } ! memcpy(&net->ip_addr, &addr, IP_ADDR_LEN); /* set our IP address. */ return 0; } --- 170,174 ---- } ! memcpy(&net->cip_addr, &addr, IP_ADDR_LEN); /* set our IP address. */ return 0; } *************** *** 182,186 **** } ! memset(&net->ip_addr, 0, IP_ADDR_LEN); /* clear our IP address -- this isn't very useful though. */ return 0; } --- 182,186 ---- } ! memset(&net->cip_addr, 0, IP_ADDR_LEN); /* clear our IP address -- this isn't very useful though. */ return 0; } *************** *** 261,266 **** * address if the system supports it. */ ! rawnet_get_hw_addr(net, &net->hw_addr); ! rawnet_get_ip_addr(net, &net->ip_addr); /* Packet handler objects. --- 261,266 ---- * address if the system supports it. */ ! rawnet_get_hw_addr(net, &net->chw_addr); ! rawnet_get_ip_addr(net, &net->cip_addr); /* Packet handler objects. *************** *** 297,301 **** } ! memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN); /* now reinitialize in promiscuous mode */ --- 297,301 ---- } ! memcpy(net->chw_addr.data, mac_addr, ETH_ADDR_LEN); /* now reinitialize in promiscuous mode */ Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-packet-build.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-packet-build.c 13 Oct 2002 22:22:11 -0000 1.10 --- dhcp-packet-build.c 21 Oct 2002 01:02:48 -0000 1.11 *************** *** 309,322 **** * * * * * * * * * */ ! 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) { --- 309,323 ---- * * * * * * * * * */ ! static void build_dhcp_proc(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 broadcast, ! unsigned char bootp_type) { *************** *** 328,332 **** 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); --- 329,337 ---- dhcp_set_secs(net->dhcp_p, secs); ! if(broadcast) ! dhcp_set_flag_broadcast(net->dhcp_p); ! else ! dhcp_unset_flag_broadcast(net->dhcp_p); ! dhcp_set_ciaddr(net->dhcp_p, ciaddr); dhcp_set_yiaddr(net->dhcp_p, yiaddr); *************** *** 335,339 **** 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); --- 340,344 ---- dhcp_clear_chaddr(net->dhcp_p); ! dhcp_set_chaddr(net->dhcp_p, client_hw_addr.data, ETH_ADDR_LEN); dhcp_clear_sname(net->dhcp_p); *************** *** 346,352 **** } ! 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; --- 351,359 ---- } ! static void build_dhcp(rawnet_t *net, uint32_t xid, time_t secs, ! uint32_t ciaddr, uint32_t yiaddr, uint32_t siaddr, ! uint32_t giaddr, ip_addr_t server_ip_addr, eth_addr_t server_hw_addr, ! unsigned char broadcast, list_t *options, ! unsigned char bootp_type) { uint16_t ip_len, udp_len; *************** *** 381,388 **** FATAL_MESSAGE("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, 0); build_udp(net, udp_len); ! build_dhcp(net, xid, secs, net->hw_addr, ciaddr, yiaddr, siaddr, giaddr, options, bootp_type); /* Write packet. */ --- 388,403 ---- FATAL_MESSAGE("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); ! if(broadcast) ! build_eth_broadcast(net, net->chw_addr, ETH_TYPE_IP); ! else ! build_eth(net, net->chw_addr, server_hw_addr, ETH_TYPE_IP); ! ! if(broadcast) ! build_ip_broadcast(net, ip_len, IP_PROTO_UDP, 0); ! else ! build_ip(net, ip_len, IP_PROTO_UDP, net->cip_addr, server_ip_addr); ! build_udp(net, udp_len); ! build_dhcp_proc(net, xid, secs, net->chw_addr, ciaddr, yiaddr, siaddr, giaddr, options, broadcast, bootp_type); /* Write packet. */ *************** *** 396,411 **** } - /* 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, net->ip_addr, 0, 0, 0, options, DHCP_BOOTP_REQUEST); } /* Create icmp packet: procify this so we can use it for all other icmp building. */ --- 411,442 ---- } /* Create a dhcp discover message. */ void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) { ! build_dhcp(net, xid, secs, 0, 0, 0, 0, (ip_addr_t)0, eth_null, 1, options, DHCP_BOOTP_REQUEST); } ! /* Create dhcp request message: unicast */ ! void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, ip_addr_t sip_addr, ! eth_addr_t shw_addr) { ! build_dhcp(net, xid, secs, net->cip_addr, 0, 0, 0, sip_addr, shw_addr, 0, options, DHCP_BOOTP_REQUEST); } + /* Create dhcp request message: broadcast */ + void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) + { + build_dhcp(net, xid, secs, net->cip_addr, 0, 0, 0, (ip_addr_t)0, eth_null, 1, options, DHCP_BOOTP_REQUEST); + } + + /* Create dhcp release message. */ + void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr) + { + build_dhcp(net, xid, 0, net->cip_addr, 0, 0, 0, + sip_addr, shw_addr, 1, options, DHCP_BOOTP_REQUEST); + } + + /* * * * * * * * * * + * ICMP routines. * + * * * * * * * * * */ /* Create icmp packet: procify this so we can use it for all other icmp building. */ *************** *** 438,442 **** 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, 0); build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); --- 469,473 ---- int ip_len = ICMP_HDR_LEN + 12 + IP_HDR_LEN; /* 12 bytes for the mask request. */ ! build_eth_broadcast(net, net->chw_addr, ETH_TYPE_IP); build_ip_broadcast(net, ip_len, IP_PROTO_ICMP, 0); build_icmp_mask_proc(net, ICMP_MASK, id, seq, 0); *************** *** 453,457 **** 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, 0); build_icmp_mask_proc(net, ICMP_MASK, id, seq, subnet_mask); --- 484,488 ---- int ip_len = IP_HDR_LEN + ICMP_HDR_LEN + 12; /* 12 bytes for the mask reply. */ ! build_eth_broadcast(net, net->chw_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); Index: dhcp-print.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-print.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-print.c 12 Oct 2002 22:54:50 -0000 1.10 --- dhcp-print.c 21 Oct 2002 01:02:48 -0000 1.11 *************** *** 767,780 **** void print_eth_brief(eth_obj *eth) { ! unsigned char *src_eth_addr; ! unsigned char *dst_eth_addr; src_eth_addr = eth_get_src_address(eth); dst_eth_addr = eth_get_dst_address(eth); ! printf("smac: %x:%x:%x:%x:%x:%x ", src_eth_addr[0], src_eth_addr[1], src_eth_addr[2], ! src_eth_addr[3], src_eth_addr[4], src_eth_addr[5]); ! printf("dmac: %x:%x:%x:%x:%x:%x ", dst_eth_addr[0], dst_eth_addr[1], dst_eth_addr[2], ! dst_eth_addr[3], dst_eth_addr[4], dst_eth_addr[5]); return; --- 767,780 ---- void print_eth_brief(eth_obj *eth) { ! eth_addr_t src_eth_addr; ! eth_addr_t dst_eth_addr; src_eth_addr = eth_get_src_address(eth); dst_eth_addr = eth_get_dst_address(eth); ! printf("smac: %x:%x:%x:%x:%x:%x ", src_eth_addr.data[0], src_eth_addr.data[1], src_eth_addr.data[2], ! src_eth_addr.data[3], src_eth_addr.data[4], src_eth_addr.data[5]); ! printf("dmac: %x:%x:%x:%x:%x:%x ", dst_eth_addr.data[0], dst_eth_addr.data[1], dst_eth_addr.data[2], ! dst_eth_addr.data[3], dst_eth_addr.data[4], dst_eth_addr.data[5]); return; *************** *** 783,797 **** void print_eth_verbose(eth_obj *eth) { ! unsigned char *src_eth_addr; ! unsigned char *dst_eth_addr; ! src_eth_addr = eth_get_src_address(eth); dst_eth_addr = eth_get_dst_address(eth); printf("--------------------------Ethernet Header-----------------------------\n"); ! printf("SRC MAC: %x:%x:%x:%x:%x:%x", src_eth_addr[0], src_eth_addr[1], src_eth_addr[2], ! src_eth_addr[3], src_eth_addr[4], src_eth_addr[5]); ! printf(" DST MAC: %x:%x:%x:%x:%x:%x\n", dst_eth_addr[0], dst_eth_addr[1], dst_eth_addr[2], ! dst_eth_addr[3], dst_eth_addr[4], dst_eth_addr[5]); return; --- 783,795 ---- void print_eth_verbose(eth_obj *eth) { ! eth_addr_t src_eth_addr, dst_eth_addr; src_eth_addr = eth_get_src_address(eth); dst_eth_addr = eth_get_dst_address(eth); printf("--------------------------Ethernet Header-----------------------------\n"); ! printf("SRC MAC: %x:%x:%x:%x:%x:%x", src_eth_addr.data[0], src_eth_addr.data[1], src_eth_addr.data[2], ! src_eth_addr.data[3], src_eth_addr.data[4], src_eth_addr.data[5]); ! printf(" DST MAC: %x:%x:%x:%x:%x:%x\n", dst_eth_addr.data[0], dst_eth_addr.data[1], dst_eth_addr.data[2], ! dst_eth_addr.data[3], dst_eth_addr.data[4], dst_eth_addr.data[5]); return; |