changeset 5428:ab53e42710ae draft

DHCP: When extending the lease, re-enter the DISCOVER phase.
author Roy Marples <roy@marples.name>
date Sun, 30 Aug 2020 09:07:35 +0100
parents f6d641a87e0a
children 4729f8db7842
files src/dhcp.c
diffstat 1 files changed, 16 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp.c	Sun Aug 30 08:28:44 2020 +0100
+++ b/src/dhcp.c	Sun Aug 30 09:07:35 2020 +0100
@@ -1869,13 +1869,15 @@
 	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)",
@@ -1897,33 +1899,21 @@
 }
 
 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)