From a9c807c1df378e59405d2101b07fcddce492ad43 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Mon, 4 Jul 2011 22:59:07 -0400 Subject: [PATCH] Rename DS_ARP_CHECK to the less confusing DS_COLLISION_CHECK. Call arp_reopen_fd() if reading from the arp fd fails in any state other than AS_COLLISION_CHECK or AS_GW_CHECK. --- ndhc/arp.c | 8 +++----- ndhc/state.c | 6 +++--- ndhc/state.h | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ndhc/arp.c b/ndhc/arp.c index d0a559b..25f6eb9 100644 --- a/ndhc/arp.c +++ b/ndhc/arp.c @@ -1,5 +1,5 @@ /* arp.c - arp ping checking - * Time-stamp: <2011-07-04 22:51:19 njk> + * Time-stamp: <2011-07-04 22:57:35 njk> * * Copyright 2010-2011 Nicholas J. Kain * @@ -316,7 +316,7 @@ int arp_check(struct client_state_t *cs, struct dhcpmsg *packet) if (arp_ip_anon_ping(cs, arp_dhcp_packet.yiaddr) == -1) return -1; cs->arpPrevState = cs->dhcpState; - cs->dhcpState = DS_ARP_CHECK; + cs->dhcpState = DS_COLLISION_CHECK; cs->timeout = 2000; memcpy(&arp_dhcp_packet, packet, sizeof (struct dhcpmsg)); arpreply_clear(); @@ -378,8 +378,6 @@ void arp_success(struct client_state_t *cs) cs->dhcpState = DS_BOUND; cs->init = 0; if (cs->arpPrevState == DS_RENEWING || cs->arpPrevState == DS_REBINDING) { - // XXX We need to be smarter about this and only issue an ifchange if - // the lease has actually changed. ifchange_bind(&arp_dhcp_packet); arp_switch_state(cs, AS_DEFENSE); } else { @@ -475,7 +473,7 @@ void handle_arp_response(struct client_state_t *cs) case AS_COLLISION_CHECK: arp_failed(cs); break; case AS_GW_CHECK: arp_gw_failed(cs); break; default: - // XXX: close and re-open the FD in ALL cases + arp_reopen_fd(cs); break; } } else diff --git a/ndhc/state.c b/ndhc/state.c index 6770380..45bec46 100644 --- a/ndhc/state.c +++ b/ndhc/state.c @@ -42,7 +42,7 @@ dhcp_state_t dhcp_states[] = { { an_packet, renewing_timeout, frenew, nfrelease}, // RENEWING { an_packet, rebinding_timeout, frenew, nfrelease}, // REBINDING { 0, arp_gw_failed, frenew, anfrelease}, // BOUND_GW_CHECK - { 0, arp_success, frenew, anfrelease}, // ARP_CHECK + { 0, arp_success, frenew, anfrelease}, // COLLISION_CHECK { 0, released_timeout, frenew, frelease}, // RELEASED { 0, 0, 0, 0}, // NUM_STATES }; @@ -173,7 +173,7 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet, cs->renewTime = cs->lease >> 1; cs->rebindTime = (cs->lease * 0x7) >> 3; // * 0.875 - // Can transition from DS_ARP_CHECK to DS_BOUND or DS_SELECTING. + // Can transition from DS_COLLISION_CHECK to DS_BOUND or DS_SELECTING. if (arp_check(cs, packet) == -1) { log_warning("arp_check failed to make arp socket, retrying lease"); reinit_selecting(cs, 3000); @@ -263,7 +263,7 @@ static void frenew(struct client_state_t *cs) set_listen_cooked(cs); send_renew(cs); break; - case DS_ARP_CHECK: + case DS_COLLISION_CHECK: // Cancel arp ping in progress and treat as previous state. if (arp_close_fd(cs)) cs->dhcpState = cs->arpPrevState; diff --git a/ndhc/state.h b/ndhc/state.h index 5bcf8f8..ecd65d2 100644 --- a/ndhc/state.h +++ b/ndhc/state.h @@ -11,7 +11,7 @@ typedef enum { DS_RENEWING, DS_REBINDING, DS_BOUND_GW_CHECK, - DS_ARP_CHECK, + DS_COLLISION_CHECK, DS_RELEASED, DS_NUM_STATES, } dhcp_states_t;