[dhcp-agent-commits] dhcp-agent/src dhcp-client-control.c,1.16,1.17 dhcp-client-states.c,1.30,1.31 d
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-05-25 02:18:31
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22288/src Modified Files: dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h Log Message: dhcp-client now properly clears or downs the interface where appropriate Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client-control.c 5 May 2003 01:26:49 -0000 1.16 --- dhcp-client-control.c 25 May 2003 02:18:27 -0000 1.17 *************** *** 313,330 **** } - /* Utility routine to bring down interface. we need this because - * we have to be explicit about bringing down the interface. 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. 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; - } - /* set the server address. */ --- 313,316 ---- Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** dhcp-client-states.c 23 May 2003 03:31:16 -0000 1.30 --- dhcp-client-states.c 25 May 2003 02:18:28 -0000 1.31 *************** *** 449,452 **** --- 449,485 ---- } + /* utility routine that should zap our configuration and leave us + * with an interface with no real address on it. */ + static void client_unconfigure(dhcp_client_control_t *dc) + { + list_t *options; + ip_addr_t ip_addr; + + /* load our cache and call sysconf with DO_SHUTDOWN to + * unconfigure us. */ + + options = client_cache_load_options(dc->cache, 0); + do_sysconf(options, dc, STATE_DO_SHUTDOWN); + dhcp_opt_destroy_option_list(options); + + /* get what our current IP address is. */ + if(rawnet_get_ip_addr(dc->rawnet, &ip_addr)) { + FATAL_MESSAGE("could not get ip address from interface."); + } + + /* check if we have a real address or not. */ + if(ip_addr != 0) { + + /* call UNARP first. */ + client_broadcast_unarp(dc); + + /* zap our ip address. */ + rawnet_interface_up(dc->rawnet, 0, 0, CLIENT_DEFAULT_MTU, 1); + } + + /* we're done. */ + return; + } + /****************************** * DHCP client state routines * *************** *** 557,561 **** if(list_get_len(cache_options) == 0) { ! ERROR_MESSAGE("could not load cache."); return STATE_FATAL_ERROR; } --- 590,595 ---- if(list_get_len(cache_options) == 0) { ! ERROR_MESSAGE("could not load cache, or cache is empty."); ! ERROR_MESSAGE("try running with -c option to delete cache."); return STATE_FATAL_ERROR; } *************** *** 621,644 **** } - 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; - } - - /* create an empty list of options since this is a release. */ - options = list_create(); - - /* run the release hook. */ - do_sysconf(options, dc, STATE_DO_SHUTDOWN); - - list_destroy(options, NULL); - - /* since we're releasing the lease we should down the interface */ - dhcp_client_interface_down(dc); - /* called from do_shutdown() so no real state returned. * however if we do take the return value into consideration --- 655,658 ---- *************** *** 760,778 **** int client_do_shutdown(dhcp_client_control_t *dc) { ! list_t *cached_options; ! ! INFO_MESSAGE("shutting down"); if(dc) { /* only do clean up if we can. */ ! /* load what we can from the cache. */ ! cached_options = client_cache_load_options(dc->cache, 0); ! do_sysconf(cached_options, dc, STATE_DO_SHUTDOWN); ! dhcp_opt_destroy_option_list(cached_options); ! client_release(dc); file_delete_pid(dc->interface); dhcp_client_control_destroy(dc); } --- 774,799 ---- int client_do_shutdown(dhcp_client_control_t *dc) { ! INFO_MESSAGE("shutting down."); if(dc) { /* only do clean up if we can. */ ! /* send our a release. */ ! client_release(dc); ! /* unconfigure everything including our interface. */ ! client_unconfigure(dc); ! /* since we're releasing the lease we should down the interface */ ! INFO_MESSAGE("bringing down interface."); ! rawnet_down(dc->rawnet); ! rawnet_interface_down(dc->rawnet); ! ! /* delete the PID file. */ file_delete_pid(dc->interface); + + /* delete our cache. */ + client_cache_delete_cache(dc->cache); + dhcp_client_control_destroy(dc); } *************** *** 819,830 **** /* 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; } --- 840,866 ---- /* 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); ! return STATE_WAIT; ! } else if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM)) { ! ! /* we've been told our lease is no good. */ ! ! /* unconfigure everything including our interface. */ ! client_unconfigure(dc); ! ! /* delete our cache. */ ! client_cache_delete_cache(dc->cache); ! ! return STATE_DISCOVER_OFFER; ! ! } else { ! ! ERROR_MESSAGE("received neither NACK nor ACK -- this should never happen because of higher filters."); ! FATAL_MESSAGE("I shouldn't be here. this is a bug report me."); ! exit(1); /* get rid of compiler warning. */ ! } } *************** *** 870,876 **** dhcp_client_set_server_hw_address(dc, eth_get_src_addr(dc->rawnet->ether_p)); ! } ! return STATE_WAIT; } --- 906,929 ---- dhcp_client_set_server_hw_address(dc, eth_get_src_addr(dc->rawnet->ether_p)); ! return STATE_WAIT; ! } else if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM)) { ! ! /* we've been told our lease is no good. */ ! ! /* unconfigure everything including our interface. */ ! client_unconfigure(dc); ! ! /* delete our cache. */ ! client_cache_delete_cache(dc->cache); ! ! return STATE_DISCOVER_OFFER; ! ! } else { ! ! ERROR_MESSAGE("received neither NACK nor ACK -- this should never happen because of higher filters."); ! FATAL_MESSAGE("I shouldn't be here. this is a bug report me."); ! exit(1); /* get rid of compiler warning. */ ! } } *************** *** 882,883 **** --- 935,937 ---- return 0; } + Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** dhcp-client.c 20 May 2003 01:43:42 -0000 1.26 --- dhcp-client.c 25 May 2003 02:18:28 -0000 1.27 *************** *** 454,458 **** if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s", interface); ! client_states[STATE_DO_SHUTDOWN] (NULL); } --- 454,458 ---- if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s", interface); ! client_states[STATE_DO_SHUTDOWN](NULL); } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client.h 11 May 2003 07:49:26 -0000 1.14 --- dhcp-client.h 25 May 2003 02:18:28 -0000 1.15 *************** *** 119,124 **** extern void dhcp_client_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr); - extern void dhcp_client_interface_down(dhcp_client_control_t *dc); - extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); --- 119,122 ---- |