From 3ede5fbe3398b2e563da76447097ce5b945e5ba1 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Wed, 18 Feb 2015 07:31:19 -0500 Subject: [PATCH] Handle the release and renew signals again. --- src/ndhc.c | 17 +---------------- src/state.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/state.h | 9 ++++++++- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/ndhc.c b/src/ndhc.c index f33167e..1d4e5bc 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -183,12 +183,6 @@ static void setup_signals_ndhc(void) epoll_add(cs.epollFd, cs.signalFd); } -enum { - SIGNAL_NONE = 0, - SIGNAL_RENEW, - SIGNAL_RELEASE -}; - static int signal_dispatch(void) { struct signalfd_siginfo si; @@ -379,22 +373,13 @@ static void do_ndhc_work(void) continue; } - // XXX: Make these work again. See xmit_release(), print_release(), - // and frenew(). -#if 0 - if (sev_signal == SIGNAL_RENEW) - force_renew_action(&cs); - else if (sev_signal == SIGNAL_RELEASE) - force_release_action(&cs); -#endif - nowts = curms(); long long arp_wake_ts = arp_get_wake_ts(); int dhcp_ok = dhcp_handle(&cs, nowts, sev_dhcp, &dhcp_packet, dhcp_msgtype, dhcp_srcaddr, sev_arp, force_fingerprint, cs.dhcp_wake_ts <= nowts, - arp_wake_ts <= nowts); + arp_wake_ts <= nowts, sev_signal); if (sev_arp) arp_reply_clear(); diff --git a/src/state.c b/src/state.c index e0b6bf4..9ac61a3 100644 --- a/src/state.c +++ b/src/state.c @@ -438,13 +438,18 @@ static int ifup_action(struct client_state_t cs[static 1]) int dhcp_handle(struct client_state_t cs[static 1], long long nowts, int sev_dhcp, struct dhcpmsg dhcp_packet[static 1], uint8_t dhcp_msgtype, uint32_t dhcp_srcaddr, int sev_arp, - bool force_fingerprint, bool dhcp_timeout, bool arp_timeout) + bool force_fingerprint, bool dhcp_timeout, bool arp_timeout, + int sev_signal) { scrBegin; reinit: // We're in the SELECTING state here. for (;;) { int ret = COR_SUCCESS; + if (sev_signal == SIGNAL_RELEASE) { + print_release(cs); + goto skip_to_released; + } if (sev_dhcp) { int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr, false); @@ -469,6 +474,10 @@ reinit: int ret; skip_to_requesting: ret = COR_SUCCESS; + if (sev_signal == SIGNAL_RELEASE) { + print_release(cs); + goto skip_to_released; + } if (sev_dhcp) { int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr, true); @@ -505,6 +514,10 @@ skip_to_requesting: for (;;) { int ret; ret = COR_SUCCESS; + if (sev_signal == SIGNAL_RELEASE) { + print_release(cs); + goto skip_to_released; + } if (sev_dhcp) { // XXX: Maybe I can think of something to do here. Would // be more relevant if we tracked multiple dhcp servers. @@ -554,6 +567,25 @@ skip_to_requesting: // We're in the BOUND, RENEWING, or REBINDING states here. for (;;) { int ret = COR_SUCCESS; + if (sev_signal) { + if (sev_signal == SIGNAL_RELEASE) { + int r = xmit_release(cs); + if (r) { + ret = COR_ERROR; + scrReturn(ret); + continue; + } + goto skip_to_released; + } + if (sev_signal == SIGNAL_RENEW) { + int r = frenew(cs, true); + if (r) { + ret = COR_ERROR; + scrReturn(ret); + continue; + } + } + } if (sev_dhcp && is_renewing(cs, nowts)) { int r = extend_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr); if (r == ANP_SUCCESS || r == ANP_IGNORE) { @@ -675,9 +707,25 @@ skip_to_requesting: } sev_dhcp = false; goto reinit; + // We're in the RELEASED state here. + for (;;) { + int ret; +skip_to_released: + ret = COR_SUCCESS; + if (sev_signal == SIGNAL_RENEW) { + int r = frenew(cs, false); + if (r) { + ret = COR_ERROR; + scrReturn(ret); + continue; + } + break; + } + scrReturn(ret); + } + sev_dhcp = false; + goto reinit; scrFinish(COR_SUCCESS); - // XXX: xmit_release -> acquire_lease - // XXX: Continue to clean up the ARP code. } diff --git a/src/state.h b/src/state.h index ea0c5d1..b5fa4b7 100644 --- a/src/state.h +++ b/src/state.h @@ -34,10 +34,17 @@ #define COR_SUCCESS 0 #define COR_ERROR -1 +enum { + SIGNAL_NONE = 0, + SIGNAL_RENEW, + SIGNAL_RELEASE +}; + int dhcp_handle(struct client_state_t cs[static 1], long long nowts, int sev_dhcp, struct dhcpmsg dhcp_packet[static 1], uint8_t dhcp_msgtype, uint32_t dhcp_srcaddr, int sev_arp, - bool force_fingerprint, bool dhcp_timeout, bool arp_timeout); + bool force_fingerprint, bool dhcp_timeout, bool arp_timeout, + int sev_signal); #endif