Handle the release and renew signals again.

This commit is contained in:
Nicholas J. Kain 2015-02-18 07:31:19 -05:00
parent 731bd14f0a
commit 3ede5fbe33
3 changed files with 60 additions and 20 deletions

View File

@ -183,12 +183,6 @@ static void setup_signals_ndhc(void)
epoll_add(cs.epollFd, cs.signalFd); epoll_add(cs.epollFd, cs.signalFd);
} }
enum {
SIGNAL_NONE = 0,
SIGNAL_RENEW,
SIGNAL_RELEASE
};
static int signal_dispatch(void) static int signal_dispatch(void)
{ {
struct signalfd_siginfo si; struct signalfd_siginfo si;
@ -379,22 +373,13 @@ static void do_ndhc_work(void)
continue; 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(); nowts = curms();
long long arp_wake_ts = arp_get_wake_ts(); long long arp_wake_ts = arp_get_wake_ts();
int dhcp_ok = dhcp_handle(&cs, nowts, sev_dhcp, &dhcp_packet, int dhcp_ok = dhcp_handle(&cs, nowts, sev_dhcp, &dhcp_packet,
dhcp_msgtype, dhcp_srcaddr, dhcp_msgtype, dhcp_srcaddr,
sev_arp, force_fingerprint, sev_arp, force_fingerprint,
cs.dhcp_wake_ts <= nowts, cs.dhcp_wake_ts <= nowts,
arp_wake_ts <= nowts); arp_wake_ts <= nowts, sev_signal);
if (sev_arp) if (sev_arp)
arp_reply_clear(); arp_reply_clear();

View File

@ -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 dhcp_handle(struct client_state_t cs[static 1], long long nowts,
int sev_dhcp, struct dhcpmsg dhcp_packet[static 1], int sev_dhcp, struct dhcpmsg dhcp_packet[static 1],
uint8_t dhcp_msgtype, uint32_t dhcp_srcaddr, int sev_arp, 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; scrBegin;
reinit: reinit:
// We're in the SELECTING state here. // We're in the SELECTING state here.
for (;;) { for (;;) {
int ret = COR_SUCCESS; int ret = COR_SUCCESS;
if (sev_signal == SIGNAL_RELEASE) {
print_release(cs);
goto skip_to_released;
}
if (sev_dhcp) { if (sev_dhcp) {
int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype, int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype,
dhcp_srcaddr, false); dhcp_srcaddr, false);
@ -469,6 +474,10 @@ reinit:
int ret; int ret;
skip_to_requesting: skip_to_requesting:
ret = COR_SUCCESS; ret = COR_SUCCESS;
if (sev_signal == SIGNAL_RELEASE) {
print_release(cs);
goto skip_to_released;
}
if (sev_dhcp) { if (sev_dhcp) {
int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype, int r = selecting_packet(cs, dhcp_packet, dhcp_msgtype,
dhcp_srcaddr, true); dhcp_srcaddr, true);
@ -505,6 +514,10 @@ skip_to_requesting:
for (;;) { for (;;) {
int ret; int ret;
ret = COR_SUCCESS; ret = COR_SUCCESS;
if (sev_signal == SIGNAL_RELEASE) {
print_release(cs);
goto skip_to_released;
}
if (sev_dhcp) { if (sev_dhcp) {
// XXX: Maybe I can think of something to do here. Would // XXX: Maybe I can think of something to do here. Would
// be more relevant if we tracked multiple dhcp servers. // 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. // We're in the BOUND, RENEWING, or REBINDING states here.
for (;;) { for (;;) {
int ret = COR_SUCCESS; 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)) { if (sev_dhcp && is_renewing(cs, nowts)) {
int r = extend_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr); int r = extend_packet(cs, dhcp_packet, dhcp_msgtype, dhcp_srcaddr);
if (r == ANP_SUCCESS || r == ANP_IGNORE) { if (r == ANP_SUCCESS || r == ANP_IGNORE) {
@ -675,9 +707,25 @@ skip_to_requesting:
} }
sev_dhcp = false; sev_dhcp = false;
goto reinit; 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); scrFinish(COR_SUCCESS);
// XXX: xmit_release -> acquire_lease
// XXX: Continue to clean up the ARP code.
} }

View File

@ -34,10 +34,17 @@
#define COR_SUCCESS 0 #define COR_SUCCESS 0
#define COR_ERROR -1 #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 dhcp_handle(struct client_state_t cs[static 1], long long nowts,
int sev_dhcp, struct dhcpmsg dhcp_packet[static 1], int sev_dhcp, struct dhcpmsg dhcp_packet[static 1],
uint8_t dhcp_msgtype, uint32_t dhcp_srcaddr, int sev_arp, 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 #endif