From a831c552c4dc33fa3b88ca07dd0c83c69c363bcc Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 30 Aug 2020 09:07:35 +0100 Subject: [PATCH] DHCP: When extending the lease, re-enter the DISCOVER phase. --- src/dhcp.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/dhcp.c b/src/dhcp.c index 6c816273..0f863d6d 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -1869,13 +1869,15 @@ dhcp_discover(void *arg) state->state = DHS_DISCOVER; dhcp_new_xid(ifp); eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); - if (ifo->fallback) - eloop_timeout_add_sec(ifp->ctx->eloop, - ifo->reboot, dhcp_fallback, ifp); -#ifdef IPV4LL - else if (ifo->options & DHCPCD_IPV4LL) - eloop_timeout_add_sec(ifp->ctx->eloop, - ifo->reboot, ipv4ll_start, ifp); + if (!(state->added & STATE_EXPIRED)) { + if (ifo->fallback) + eloop_timeout_add_sec(ifp->ctx->eloop, + ifo->reboot, dhcp_fallback, ifp); + #ifdef IPV4LL + else if (ifo->options & DHCPCD_IPV4LL) + eloop_timeout_add_sec(ifp->ctx->eloop, + ifo->reboot, ipv4ll_start, ifp); + } #endif if (ifo->options & DHCPCD_REQUEST) loginfox("%s: soliciting a DHCP lease (requesting %s)", @@ -1896,34 +1898,22 @@ dhcp_request(void *arg) send_request(ifp); } -static void -dhcp_expire1(struct interface *ifp) -{ - struct dhcp_state *state = D_STATE(ifp); - - eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); - dhcp_drop(ifp, "EXPIRE"); - dhcp_unlink(ifp->ctx, state->leasefile); - state->interval = 0; - if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier > LINK_DOWN) - dhcp_discover(ifp); -} - static void dhcp_expire(void *arg) { struct interface *ifp = arg; + struct dhcp_state *state = D_STATE(ifp); if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) { - struct dhcp_state *state = D_STATE(ifp); - logwarnx("%s: DHCP lease expired, extending lease", ifp->name); state->added |= STATE_EXPIRED; - return; + } else { + logerrx("%s: DHCP lease expired", ifp->name); + dhcp_drop(ifp, "EXPIRE"); + dhcp_unlink(ifp->ctx, state->leasefile); } - - logerrx("%s: DHCP lease expired", ifp->name); - dhcp_expire1(ifp); + state->interval = 0; + dhcp_discover(ifp); } #if defined(ARP) || defined(IN_IFF_DUPLICATED) -- 2.47.2