From 3f496f79974f9e3922ee6080ec0ce4996d46e666 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Tue, 5 Jul 2011 18:18:57 -0400 Subject: [PATCH] Clean up frenew(). It should only perform work in DS_RELEASED and DS_BOUND. --- ndhc/options.c | 3 ++- ndhc/state.c | 44 +++++++++++++++----------------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/ndhc/options.c b/ndhc/options.c index f325b51..45eee32 100644 --- a/ndhc/options.c +++ b/ndhc/options.c @@ -1,5 +1,5 @@ /* options.c - DHCP options handling - * Time-stamp: <2011-07-04 21:37:34 njk> + * Time-stamp: <2011-07-05 16:11:32 njk> * * (c) 2004-2011 Nicholas J. Kain * @@ -167,6 +167,7 @@ static uint8_t *do_get_option_data(uint8_t *buf, ssize_t buflen, int code, return NULL; } +// XXX: Never concatenates options. If this is added, refer to RFC3396. // Get an option with bounds checking (warning, result is not aligned) // optlen will be equal to the length of the option data. uint8_t *get_option_data(struct dhcpmsg *packet, int code, ssize_t *optlen) diff --git a/ndhc/state.c b/ndhc/state.c index f9e1bfb..9f4b0c9 100644 --- a/ndhc/state.c +++ b/ndhc/state.c @@ -38,15 +38,15 @@ typedef struct { } dhcp_state_t; dhcp_state_t dhcp_states[] = { - { selecting_packet, selecting_timeout, 0, frelease}, // SELECTING - { an_packet, requesting_timeout, frenew, frelease}, // REQUESTING - { 0, bound_timeout, frenew, nfrelease}, // BOUND - { an_packet, renewing_timeout, frenew, nfrelease}, // RENEWING - { an_packet, rebinding_timeout, frenew, nfrelease}, // REBINDING - { 0, bound_gw_check_timeout, frenew, anfrelease}, // BOUND_GW_CHECK - { 0, collision_check_timeout, frenew, anfrelease}, // COLLISION_CHECK - { 0, released_timeout, frenew, frelease}, // RELEASED - { 0, 0, 0, 0}, // NUM_STATES + { selecting_packet, selecting_timeout, 0, frelease}, // SELECTING + { an_packet, requesting_timeout, 0, frelease}, // REQUESTING + { 0, bound_timeout, frenew, nfrelease}, // BOUND + { an_packet, renewing_timeout, 0, nfrelease}, // RENEWING + { an_packet, rebinding_timeout, 0, nfrelease}, // REBINDING + { 0, bound_gw_check_timeout, 0, anfrelease}, // BOUND_GW_CHECK + { 0, collision_check_timeout, 0, anfrelease}, // COLLISION_CHECK + { 0, released_timeout, frenew, frelease}, // RELEASED + { 0, 0, 0, 0}, // NUM_STATES }; static unsigned int num_dhcp_requests; @@ -274,26 +274,12 @@ static void frelease(struct client_state_t *cs) static void frenew(struct client_state_t *cs) { log_line("Forcing a DHCP renew..."); - switch (cs->dhcpState) { - case DS_BOUND: - cs->dhcpState = DS_RENEWING; - set_listen_cooked(cs); - send_renew(cs); - break; - case DS_RELEASED: - set_listen_raw(cs); - cs->dhcpState = DS_SELECTING; - break; - case DS_BOUND_GW_CHECK: - case DS_COLLISION_CHECK: - case DS_RENEWING: - case DS_REBINDING: - break; - default: - return; - } - num_dhcp_requests = 0; - cs->timeout = 0; + if (cs->dhcpState == DS_BOUND) { + cs->dhcpState = DS_RENEWING; + set_listen_cooked(cs); + send_renew(cs); + } else if (cs->dhcpState == DS_RELEASED) + reinit_selecting(cs, 0); } void ifup_action(struct client_state_t *cs)