Clean up frenew(). It should only perform work in DS_RELEASED and DS_BOUND.

This commit is contained in:
Nicholas J. Kain 2011-07-05 18:18:57 -04:00
parent 04c380cd3b
commit 3f496f7997
2 changed files with 17 additions and 30 deletions

View File

@ -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 <njkain at gmail dot com>
*
@ -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)

View File

@ -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)