[dhcp-agent-commits] dhcp-agent/src Makefile.am,1.7,1.8 dhcp-client-cache.c,1.3,1.4 dhcp-client-cach
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv17456/src Modified Files: Makefile.am dhcp-client-cache.c dhcp-client-cache.h dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-com.c dhcp-librawnet.h dhcp-libutil.h dhcp-sysconf.c dhcp-sysconf.h dhcp-timer.c Log Message: fixed timers; fixed up client-cache a bit Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 15 Nov 2002 21:06:47 -0000 1.7 --- Makefile.am 19 Nov 2002 19:44:43 -0000 1.8 *************** *** 60,64 **** dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ --- 60,64 ---- dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil -lefence dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-cache.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-client-cache.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 36,41 **** #include "dhcp-options-strings.h" /* constructor. */ ! client_cache_t *create_client_cache(const char *interface) { client_cache_t *cc; --- 36,45 ---- #include "dhcp-options-strings.h" + /* * * * * * * * * * * * * * * * * * + * Destroy/Create/Purge routines. * + * * * * * * * * * * * * * * * * * */ + /* constructor. */ ! client_cache_t *client_cache_create(const char *interface) { client_cache_t *cc; *************** *** 48,53 **** } /* purges list in cache object. */ ! void purge_cache(client_cache_t *cc) { list_t *list_ptr, *tmp; --- 52,58 ---- } + /* FIXME: make it use destroy_list. */ /* purges list in cache object. */ ! void client_cache_purge(client_cache_t *cc) { list_t *list_ptr, *tmp; *************** *** 73,77 **** { if(cc->vars) ! purge_cache(cc); xfree(cc); --- 78,82 ---- { if(cc->vars) ! client_cache_purge(cc); xfree(cc); *************** *** 79,82 **** --- 84,176 ---- } + /* * * * * * * * * * * * * * * + * Cache Filename Routines. * + * * * * * * * * * * * * * * */ + + static char *get_fname_proc(const client_cache_t *cc, const char *suffix) + { + char *fname; + stringbuffer *sb = create_stringbuffer(); + stringbuffer_aprintf(sb, "%s.%s", cc->interface, suffix); + + fname = xstrdup(stringbuffer_getstring(sb)); /* FIXME: use a stringbuffer associated creation routine. */ + destroy_stringbuffer(sb); + + return fname; + } + + static char *get_fname(const client_cache_t *cc) + { + return (get_fname_proc(cc, "cache")); + } + + static char *get_fname_tmp(client_cache_t *cc) + { + return (get_fname_proc(cc, "cache.tmp")); + } + + /* * * * * * * * * * * * + * Cache Manipulation * + * * * * * * * * * * * */ + + /* update cache: move temp cache over real cache. */ + void client_cache_update(client_cache_t *cc) + { + char *fname_tmp, *fname; + + fname_tmp = get_fname_tmp(cc); + fname = get_fname(cc); + + move_file(fname_tmp, fname); + + xfree(fname); + xfree(fname_tmp); + + return; + } + + /* delete old temporary cache. */ + void client_cache_delete_tmp_cache(client_cache_t *cc) + { + char *fname = get_fname_tmp(cc); + + delete_file(fname); + xfree(fname); + + return; + } + + /* delete cache. */ + void client_cache_delete_cache(client_cache_t *cc) + { + char *fname = get_fname(cc); + + delete_file(fname); + xfree(fname); + + return; + } + + /* check if cache is empty. */ + int client_cache_is_empty(client_cache_t *cc) + { + int retval; + char *fname; + + fname = get_fname(cc); + if(file_exists(fname)) + retval = 1; + else + retval = 0; + + xfree(fname); + + return retval; + } + + /* * * * * * * * * * * + * Cache load/dump * + * * * * * * * * * * */ + /* read next cache entry from file. */ static cache_entry_t *read_next_cache_var(varfile_t *varfile) *************** *** 108,113 **** } ! /* Load up cache from filename. */ ! static int load_client_cache_proc(client_cache_t *cc, char *filename) { varfile_t *varfile; --- 202,207 ---- } ! /* Load up cache from file named by filename. */ ! static int client_cache_load_proc(client_cache_t *cc, char *filename) { varfile_t *varfile; *************** *** 130,165 **** } - /* filename creation routines. */ - static char *get_fname(client_cache_t *cc) - { - char *fname; - stringbuffer *sb = create_stringbuffer(); - stringbuffer_aprintf(sb, "%s.%s", cc->interface, "cache"); - - fname = xstrdup(stringbuffer_getstring(sb)); - destroy_stringbuffer(sb); - - return fname; - } - - static char *get_fname_tmp(client_cache_t *cc) - { - char *fname; - stringbuffer *sb = create_stringbuffer(); - stringbuffer_aprintf(sb, "%s.%s", cc->interface, "cache.tmp"); - - fname = xstrdup(stringbuffer_getstring(sb)); - destroy_stringbuffer(sb); - - return fname; - } - /* load cache (interface) */ ! int load_client_cache(client_cache_t *cc, unsigned char use_tmp) { char *fname; int retval; ! purge_cache(cc); if(use_tmp) --- 224,234 ---- } /* load cache (interface) */ ! static int client_cache_load(client_cache_t *cc, unsigned char use_tmp) { char *fname; int retval; ! client_cache_purge(cc); if(use_tmp) *************** *** 168,172 **** fname = get_fname(cc); ! retval = load_client_cache_proc(cc, fname); xfree(fname); --- 237,241 ---- fname = get_fname(cc); ! retval = client_cache_load_proc(cc, fname); xfree(fname); *************** *** 174,199 **** } ! /* check to see if cache is empty: ! * as long as the cache file exists ! * we're always guaranteed a cache ! * except on filesystem corruption. ! * in that case we can't do much except ! * complain. using file_exists() is ! * as good as it gets. ! */ ! int client_cache_is_empty(client_cache_t *cc) ! { ! int retval = 0; ! char *fname; ! ! fname = get_fname(cc); ! if(file_exists(fname)) ! retval = 1; ! xfree(fname); ! return retval; } ! /* work horse routine to convert from serialized state to network datum. */ static void *convert_to_network(unsigned char tag, char *string) { --- 243,257 ---- } ! /* * * * * * * * * * * * * * ! * Conversion work horses: * ! * * * * * * * * * * * * * */ ! /* convert to internal datums. */ ! static void *convert_to_internal(unsigned char tag, char *string) ! { ! return NULL; } ! /* convert to network. */ static void *convert_to_network(unsigned char tag, char *string) { *************** *** 218,221 **** --- 276,295 ---- } + /* convert only timer options to serialized form. */ + static void *convert_timers_to_string(unsigned char tag, char *string) + { + cache_entry_t *ce; + + /* we have three timers we care about */ + if(tag == TAG_DHCP_IP_ADDRESS_LEASE_TIME || + tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { + + ce = create_cache_entry(dhcp_options_strings[tag], string); + return ce; + } + + return NULL; + } + /* * Convert options from cache serialized form to whatever form convert_func, returns. *************** *** 259,265 **** } ! /* dump options into file. here we take data in network form and dump them in serialized form. ! * we always do this to the temp file. ! */ int client_cache_dump_options(client_cache_t *cc, list_t *options) { --- 333,340 ---- } ! /* dump options into file. here we take data in network form and ! * dump them in serialized form. we always do this to the temp ! * file. the list should contain pointers to dhcp_option_t datums ! * in network byte order. */ int client_cache_dump_options(client_cache_t *cc, list_t *options) { *************** *** 309,313 **** } ! /* work horse load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void *(*convert_func) (unsigned char tag, --- 384,388 ---- } ! /* work horse load options and convert routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void *(*convert_func) (unsigned char tag, *************** *** 317,329 **** list_t *options; ! if(load_client_cache(cc, use_tmp) < 0) return NULL; options = get_cache_options_list_proc(cc, convert_func); ! purge_cache(cc); return options; } /* load options and return network list. */ list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) --- 392,409 ---- list_t *options; ! if(client_cache_load(cc, use_tmp) < 0) return NULL; options = get_cache_options_list_proc(cc, convert_func); ! client_cache_purge(cc); return options; } + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Main conversion interface. These routines will load, convert, * + * and return the options in whichever format we want. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + /* load options and return network list. */ list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) *************** *** 332,376 **** } ! /* load options and return serialized list. */ ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) ! { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); ! } ! ! /* update cache: move temp cache over real cache. */ ! void client_cache_update(client_cache_t *cc) { ! char *fname_tmp, *fname; ! ! fname_tmp = get_fname_tmp(cc); ! fname = get_fname(cc); ! ! move_file(fname_tmp, fname); ! ! xfree(fname); ! xfree(fname_tmp); ! ! return; } ! /* delete old temporary cache. */ ! void client_cache_delete_tmp_cache(client_cache_t *cc) { ! char *fname = get_fname_tmp(cc); ! ! delete_file(fname); ! xfree(fname); ! ! return; } ! /* delete cache. */ ! void client_cache_delete_cache(client_cache_t *cc) { ! char *fname = get_fname(cc); ! ! delete_file(fname); ! xfree(fname); ! ! return; } --- 412,430 ---- } ! /* load options and return internal datum list. */ ! list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_internal)); } ! /* load options and return serialized list. */ ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); } ! /* load timer options and return them in internal list. */ ! list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_timers_to_string)); } Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-cache.h 16 Nov 2002 00:23:42 -0000 1.2 --- dhcp-client-cache.h 19 Nov 2002 19:44:44 -0000 1.3 *************** *** 34,48 **** /* prototypes. */ ! extern client_cache_t *create_client_cache(const char *interface); ! extern void purge_cache(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); ! extern int load_client_cache(client_cache_t *cc, unsigned char use_tmp); extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); ! extern void client_cache_update(client_cache_t *cc); ! extern void client_cache_delete_tmp_cache(client_cache_t *cc); ! extern void client_cache_delete_cache(client_cache_t *cc); #endif /* DHCP_CLIENT_CACHE_H */ --- 34,50 ---- /* prototypes. */ ! extern client_cache_t *client_cache_create(const char *interface); ! extern void client_cache_purge(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); ! extern void client_cache_update(client_cache_t *cc); ! extern void client_cache_delete_tmp_cache(client_cache_t *cc); ! extern void client_cache_delete_cache(client_cache_t *cc); extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); + extern list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); ! extern list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, ! unsigned char use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-conf.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-client-conf.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 23,26 **** --- 23,28 ---- */ + /* THIS ENTIRE THING NEEDS TO BE REDONE. */ + #define MODULE_NAME "dhcp-client-conf" *************** *** 215,217 **** --- 217,225 ---- return (retval); + } + + /* return the bit array indexing the options we want. */ + uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) + { + return cc->options; } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-conf.h 16 Nov 2002 00:23:42 -0000 1.2 --- dhcp-client-conf.h 19 Nov 2002 19:44:44 -0000 1.3 *************** *** 40,43 **** --- 40,44 ---- extern void client_conf_destroy(client_conf_t *cc); extern int load_client_conf(client_conf_t *cc); + extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-control.c 16 Nov 2002 00:23:42 -0000 1.4 --- dhcp-client-control.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 140,154 **** dc->interface = xstrdup(interface); dc->conf = create_client_conf(dc->interface); ! dc->cache = create_client_cache(dc->interface); dc->timer = create_timer(); if(load_client_conf(dc->conf) < 0) { ERROR_MESSAGE("could not read client conf."); - destroy_dhcp_client_control(dc); - return NULL; - } - - if(load_client_cache(dc->cache, 0) < 0) { - ERROR_MESSAGE("could not read client cache."); destroy_dhcp_client_control(dc); return NULL; --- 140,148 ---- dc->interface = xstrdup(interface); dc->conf = create_client_conf(dc->interface); ! dc->cache = client_cache_create(dc->interface); dc->timer = create_timer(); if(load_client_conf(dc->conf) < 0) { ERROR_MESSAGE("could not read client conf."); destroy_dhcp_client_control(dc); return NULL; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-states.c 16 Nov 2002 00:23:42 -0000 1.4 --- dhcp-client-states.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 62,67 **** } /* 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; --- 62,75 ---- } + static dhcp_option_t *client_build_parameter_request_list(dhcp_client_control_t *dc) + { + dhcp_option_t *option; + + option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); + return option; + } + /* This is used for both requests and discovery. */ ! static list_t *client_build_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 69,78 **** char *hostname; - if(opts != NULL) { - /* parameter_request_list */ - option = dhcp_build_parameter_request_list_option(opts); - options = add_to_list(options, option); - } - /* dhcp max DHCP message size: * should go into globconf. */ --- 77,80 ---- *************** *** 100,104 **** /* 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; --- 102,106 ---- /* Create DHCP DISCOVER option list. */ ! static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 106,114 **** 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); --- 108,119 ---- dhcp_option_t *option; + option = client_build_parameter_request_list(dc); + options = add_to_list(options, option); + /* dhcp message type. */ option = dhcp_build_message_type(DHCP_DISCOVER_TM); options = add_to_list(options, option); ! requested_options = client_build_option_list(dc); options = join_lists(options, requested_options); *************** *** 117,121 **** /* 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; --- 122,126 ---- /* Create DHCP REQUEST option list. */ ! static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 127,131 **** options = add_to_list(options, option); ! requested_options = client_build_option_list(opts, dc); options = join_lists(options, requested_options); --- 132,136 ---- options = add_to_list(options, option); ! requested_options = client_build_option_list(dc); options = join_lists(options, requested_options); *************** *** 133,136 **** --- 138,162 ---- } + /* Create DHCP REBIND option list. */ + static list_t *client_build_renew_option_list(dhcp_client_control_t *dc) + { + list_t *options = NULL; + dhcp_option_t *option; + + /* dhcp message type. */ + option = dhcp_build_message_type(DHCP_REQUEST_TM); + 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); + + return options; + } + + /****************** + * Check Routines * + ******************/ + /* Check the requested options. * We use the globconf option. */ *************** *** 156,163 **** } - /****************** - * Check Routines * - ******************/ - /* Basic DHCP test on incoming rawnet packet. */ static int client_check_dhcp(dhcp_client_control_t *dc) --- 182,185 ---- *************** *** 206,209 **** --- 228,238 ---- } + static int client_check_renew(void *arg) + { + /* we're expecting the same as request :-) */ + return (client_check_request(arg)); + + } + /************* * Utilities.* *************** *** 220,223 **** --- 249,270 ---- } + static void client_setup_timers(dhcp_client_control_t *dc) + { + list_t *timer_options; + + timer_options = client_cache_load_option_timer_string_list(dc->cache, 0); + + if(timer_options == NULL) { + FATAL_MESSAGE("no timers to setup. we should have least one: lease time"); + exit(1); + } + + reinitialize_timer(dc->timer); + do_sysconf(timer_options, dc, 0); + cache_entry_purge_list(timer_options); + + return; + } + /************* * ARP/UNARP.* *************** *** 276,280 **** int retval; ! options = client_build_discover_option_list(dc->conf->options, dc); /* when we begin transmitting discover_offer we setup our secs field. --- 323,327 ---- int retval; ! options = client_build_discover_option_list(dc); /* when we begin transmitting discover_offer we setup our secs field. *************** *** 346,350 **** /* 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); --- 393,397 ---- /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); *************** *** 368,372 **** case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); return STATE_FATAL_ERROR; --- 415,419 ---- case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP request."); return STATE_FATAL_ERROR; *************** *** 449,453 **** */ ! do_sysconf(options, dc); cache_entry_purge_list(options); --- 496,500 ---- */ ! do_sysconf(options, dc, 1); cache_entry_purge_list(options); *************** *** 459,463 **** } ! /* wait for renewal time. */ int client_wait(dhcp_client_control_t *dc) { --- 506,510 ---- } ! /* wait for timers and other interrupts . */ int client_wait(dhcp_client_control_t *dc) { *************** *** 476,490 **** suspend_for_interrupts(); ! rawnet_up(dc->rawnet); ! ! /* Update our DHCP secs datum since we're renewing after this. */ ! dhcp_client_reset_secs(dc); ! dhcp_client_update_secs(dc); ! return STATE_REQUEST_ACK; /* if we didn't get an ALARM it's ! * probably a HUP or a TERM. in ! * either case we can return ! * STATE_REQUEST_ACK here. */ } --- 523,537 ---- suspend_for_interrupts(); ! /* bring the raw network devices back up. we'll probably ! * need them: FIXME, revamp into one network module that uses ! * raw or user level networking depending on our interface's ! * state */ ! rawnet_up(dc->rawnet); ! return STATE_FATAL_ERROR; /* it doesn't matter what we return here really. ! * since we're supposed to detect an interrupt ! * as soon as we get back. set as fatal error ! * to catch any bugs. */ } *************** *** 518,520 **** --- 565,608 ---- exit(0); + } + + /* do a rebind. */ + int client_renew(dhcp_client_control_t *dc) + { + list_t *options; + int retval; + options = client_build_renew_option_list(dc); + + build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->sip_addr, dc->shw_addr); + + retval = + rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, RECOMMENDED_MAX_SECS_WAIT); + switch (retval) { + + case RAWNET_TIMEOUT: + ERROR_MESSAGE("timeout on DHCP request."); + return STATE_FATAL_ERROR; + + case RAWNET_OK: + break; + + case RAWNET_ERROR: + ERROR_MESSAGE("received error from raw network handler."); + return STATE_FATAL_ERROR; + + default: + FATAL_MESSAGE + ("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); + } + + /* if we got a pack we only need to setup our timers. */ + if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) { + client_setup_timers(dc); + } + + /* in the end we return to waiting. if we didn't get an ACK + * here we'll fall into rebind time at the next timer + * trigger. */ + + return STATE_WAIT; } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client.c 16 Nov 2002 00:23:42 -0000 1.5 --- dhcp-client.c 19 Nov 2002 19:44:44 -0000 1.6 *************** *** 83,91 **** client_wait, client_release, client_fatal_error, client_do_shutdown, }; - /* global vars affecting other code. */ int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ --- 83,91 ---- client_wait, client_release, + client_renew, client_fatal_error, client_do_shutdown, }; /* global vars affecting other code. */ int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ *************** *** 239,245 **** --- 239,249 ---- case INTERRUPT_ALARM: + switch (timer_get_current_id(dc->timer)) { case TIMER_RENEW: + state = STATE_RENEW; + break; + case TIMER_IP_LEASE: state = STATE_DISCOVER_OFFER; *************** *** 249,254 **** state = STATE_REQUEST_ACK; break; - } default: --- 253,261 ---- state = STATE_REQUEST_ACK; break; + default: + FATAL_MESSAGE("invalid timer type caught. this is a bug. report me."); + } + break; default: *************** *** 333,337 **** /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc->interface); /* now delete. */ --- 340,344 ---- /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = client_cache_create(dc->interface); /* now delete. */ Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client.h 16 Nov 2002 00:23:43 -0000 1.4 --- dhcp-client.h 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 69,74 **** #define STATE_WAIT 3 #define STATE_RELEASE 4 ! #define STATE_FATAL_ERROR 5 ! #define STATE_DO_SHUTDOWN 6 /* timer IDs. */ --- 69,76 ---- #define STATE_WAIT 3 #define STATE_RELEASE 4 ! #define STATE_RENEW 5 ! #define STATE_FATAL_ERROR 6 ! #define STATE_DO_SHUTDOWN 7 ! /* timer IDs. */ *************** *** 83,86 **** --- 85,89 ---- extern int client_wait(dhcp_client_control_t *dc); extern int client_release(dhcp_client_control_t *dc); + extern int client_renew(dhcp_client_control_t *dc); extern int client_setup(dhcp_client_control_t *dc); extern int client_fatal_error(dhcp_client_control_t *dc); Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-com.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-com.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 514,518 **** /* accept bit array telling us which options to build the request option. */ ! dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options) { unsigned char i, j; --- 514,518 ---- /* accept bit array telling us which options to build the request option. */ ! dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options) { unsigned char i, j; Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-librawnet.h 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-librawnet.h 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 435,439 **** extern uint32_t dhcp_gen_xid(void); ! extern dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options); extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); extern dhcp_option_t *dhcp_build_message_type(unsigned char type); --- 435,439 ---- extern uint32_t dhcp_gen_xid(void); ! extern dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options); extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); extern dhcp_option_t *dhcp_build_message_type(unsigned char type); *************** *** 443,446 **** --- 443,447 ---- extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); extern dhcp_option_t *dhcp_build_hostname(char *hostname); + /* Ether obj routines. */ Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-libutil.h 16 Nov 2002 00:23:43 -0000 1.6 --- dhcp-libutil.h 19 Nov 2002 19:44:44 -0000 1.7 *************** *** 193,196 **** --- 193,197 ---- extern int timer_purge(timer_keeper_t); extern uint32_t timer_get_current_id(timer_keeper_t *timer); + extern void reinitialize_timer(timer_keeper_t *timer); /* var file. */ Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sysconf.c 16 Nov 2002 00:23:44 -0000 1.4 --- dhcp-sysconf.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 42,45 **** --- 42,54 ---- #include "dhcp-options-strings.h" + + static int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); + static int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); + static int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); + static int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); + static int client_setup_lease_time(void *value, dhcp_client_control_t *dc); + static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc); + static int client_setup_renew_time(void *value, dhcp_client_control_t *dc); + /* Only use handlers here which can be done in any order. * Some special handlers are done in a particular order *************** *** 155,167 **** {NULL, NULL, SYSCONF_UNSET,} , /* 50 Requested IP Address. */ ! {sysconf_setup_lease_time, ! NULL, SYSCONF_UNSET,} , /* 51 IP Address Lease Time. */ ! {sysconf_setup_renew_time, ! NULL, SYSCONF_UNSET,} ! , /* 52 Renewal Time (T1). */ ! {sysconf_setup_rebind_time, ! NULL, SYSCONF_UNSET,} ! , /* 53 Rebind Time. (T2). */ {NULL, NULL, SYSCONF_UNSET,} , /* 54 */ --- 164,173 ---- {NULL, NULL, SYSCONF_UNSET,} , /* 50 Requested IP Address. */ ! {client_setup_lease_time, NULL, SYSCONF_UNSET,} , /* 51 IP Address Lease Time. */ ! {NULL, SYSCONF_UNSET,} ! , /* 52 */ ! {NULL, SYSCONF_UNSET,} ! , /* 53 */ {NULL, NULL, SYSCONF_UNSET,} , /* 54 */ *************** *** 172,179 **** {NULL, NULL, SYSCONF_UNSET,} , /* 57 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 58 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 59 */ {NULL, NULL, SYSCONF_UNSET,} , /* 60 */ --- 178,185 ---- {NULL, NULL, SYSCONF_UNSET,} , /* 57 */ ! {client_setup_renew_time, NULL, SYSCONF_UNSET,} ! , /* 58 Renewal Time (T1). */ ! {client_setup_rebind_time, NULL, SYSCONF_UNSET,} ! , /* 59 Rebind Time (T2). */ {NULL, NULL, SYSCONF_UNSET,} , /* 60 */ *************** *** 182,212 **** }; ! static int sysconf_setup_u32_timer(uint32_t seconds, int id, dhcp_client_control_t *dc) ! { ! timer_add_trigger(dc->timer, seconds, id); ! return 0; ! } ! ! int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_IP_LEASE, dc); return 0; } ! int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_REBIND, dc); return 0; } ! int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_RENEW, dc); return 0; } --- 188,212 ---- }; ! static int client_setup_lease_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_IP_LEASE); return 0; } ! static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_REBIND); return 0; } ! static int client_setup_renew_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_RENEW); return 0; } *************** *** 406,410 **** /* XXX - handle return value elsewhere. */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc) { list_t *list_ptr; --- 406,410 ---- /* XXX - handle return value elsewhere. */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface) { list_t *list_ptr; *************** *** 420,424 **** * is likely required for the others to work. */ ! sysconf_setup_interface(options, dc); /* Now walk through the other options, performing setup and --- 420,425 ---- * is likely required for the others to work. */ ! if(do_interface) ! sysconf_setup_interface(options, dc); /* Now walk through the other options, performing setup and Index: dhcp-sysconf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-sysconf.h 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-sysconf.h 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 40,51 **** /* System configuration routines. */ ! extern int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); --- 40,44 ---- /* System configuration routines. */ ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-timer.c 15 Nov 2002 21:06:47 -0000 1.3 --- dhcp-timer.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 37,49 **** static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { ! uint32_t *trigger1, *trigger2; trigger1 = trigger1_p; trigger2 = trigger2_p; ! if(trigger1 > trigger2) return 1; ! if(trigger1 < trigger2) return -1; --- 37,49 ---- static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { ! timer_trigger_t *trigger1, *trigger2; trigger1 = trigger1_p; trigger2 = trigger2_p; ! if(trigger1->seconds > trigger2->seconds) return 1; ! if(trigger1->seconds < trigger2->seconds) return -1; *************** *** 51,54 **** --- 51,77 ---- } + /* create a new trigger. */ + static timer_trigger_t *create_trigger(uint32_t trigger_time, uint32_t id) + { + timer_trigger_t *trigger = xmalloc(sizeof(timer_trigger_t)); + + trigger->seconds = trigger_time; + trigger->id = id; + + return trigger; + } + + /* destroy a trigger. */ + static void destroy_trigger(timer_trigger_t *trigger) + { + xfree(trigger); + } + + /* destroy a trigger in a list. */ + static void destroy_trigger_l(void *trigger) + { + destroy_trigger(trigger); + } + /* create a new timer keeper. */ timer_keeper_t *create_timer(void) *************** *** 65,69 **** void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, NULL); xfree(timer); --- 88,92 ---- void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, destroy_trigger_l); xfree(timer); *************** *** 71,82 **** } /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time, uint32_t id) { ! timer_trigger_t *trigger = xmalloc(sizeof(timer_trigger_t)); ! ! trigger->seconds = trigger_time; ! trigger->id = id; ! timer->triggers = add_to_list(timer->triggers, trigger); --- 94,107 ---- } + void reinitialize_timer(timer_keeper_t *timer) + { + purge_list(timer->triggers, NULL); + timer->triggers = NULL; + } + /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time, uint32_t id) { ! timer_trigger_t *trigger = create_trigger(trigger_time, id); timer->triggers = add_to_list(timer->triggers, trigger); *************** *** 99,103 **** timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); ! xfree(trigger); return 0; --- 124,128 ---- timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); ! destroy_trigger(trigger); return 0; |