]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: When extending the lease, re-enter the DISCOVER phase.
authorRoy Marples <roy@marples.name>
Sun, 30 Aug 2020 08:07:35 +0000 (09:07 +0100)
committerRoy Marples <roy@marples.name>
Sun, 30 Aug 2020 08:07:35 +0000 (09:07 +0100)
src/dhcp.c

index 6c816273ec8e5bf2ad87a979c1d27f74548eb573..0f863d6dbf47287192cc279f2d72aab90ebb424b 100644 (file)
@@ -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)