changeset 5548:bcca2ff28a64 draft

DHCP: Only listen to the address if we successfully added it Fixes an issue on Linux where the headers advertise something newer than what the kernel actually provides.
author Roy Marples <roy@marples.name>
date Mon, 23 Nov 2020 13:22:20 +0000
parents c9182c3618e6
children 6d72dc67a984
files src/dhcp.c src/ipv4.c src/ipv4.h
diffstat 3 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp.c	Sat Nov 21 12:01:21 2020 +0000
+++ b/src/dhcp.c	Mon Nov 23 13:22:20 2020 +0000
@@ -2364,13 +2364,14 @@
 		return;
 	}
 
+	/* Add the address */
+	if (ipv4_applyaddr(ifp) == NULL)
+		return;
+
 	/* Close the BPF filter as we can now receive DHCP messages
 	 * on a UDP socket. */
 	dhcp_closebpf(ifp);
 
-	/* Add the address */
-	ipv4_applyaddr(ifp);
-
 openudp:
 	/* If not in master mode, open an address specific socket. */
 	if (ctx->options & DHCPCD_MASTER ||
--- a/src/ipv4.c	Sat Nov 21 12:01:21 2020 +0000
+++ b/src/ipv4.c	Mon Nov 23 13:22:20 2020 +0000
@@ -728,7 +728,7 @@
 	return 0;
 }
 
-void
+struct ipv4_addr *
 ipv4_applyaddr(void *arg)
 {
 	struct interface *ifp = arg;
@@ -738,7 +738,7 @@
 	struct ipv4_addr *ia;
 
 	if (state == NULL)
-		return;
+		return NULL;
 
 	lease = &state->lease;
 	if (state->new == NULL) {
@@ -757,7 +757,7 @@
 			script_runreason(ifp, state->reason);
 		} else
 			rt_build(ifp->ctx, AF_INET);
-		return;
+		return NULL;
 	}
 
 	ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
@@ -783,22 +783,22 @@
 #endif
 #ifndef IP_LIFETIME
 		if (ipv4_daddaddr(ifp, lease) == -1 && errno != EEXIST)
-			return;
+			return NULL;
 #endif
 	}
 #ifdef IP_LIFETIME
 	if (ipv4_daddaddr(ifp, lease) == -1 && errno != EEXIST)
-		return;
+		return NULL;
 #endif
 
 	ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
 	if (ia == NULL) {
 		logerrx("%s: added address vanished", ifp->name);
-		return;
+		return NULL;
 	}
 #if defined(ARP) && defined(IN_IFF_NOTUSEABLE)
 	if (ia->addr_flags & IN_IFF_NOTUSEABLE)
-		return;
+		return NULL;
 #endif
 
 	/* Delete the old address if different */
@@ -820,6 +820,7 @@
 		script_runreason(ifp, state->reason);
 		dhcpcd_daemonise(ifp->ctx);
 	}
+	return ia;
 }
 
 void
--- a/src/ipv4.h	Sat Nov 21 12:01:21 2020 +0000
+++ b/src/ipv4.h	Mon Nov 23 13:22:20 2020 +0000
@@ -135,7 +135,7 @@
 struct ipv4_addr *ipv4_addaddr(struct interface *,
     const struct in_addr *, const struct in_addr *, const struct in_addr *,
     uint32_t, uint32_t);
-void ipv4_applyaddr(void *);
+struct ipv4_addr *ipv4_applyaddr(void *);
 
 struct ipv4_addr *ipv4_iffindaddr(struct interface *,
     const struct in_addr *, const struct in_addr *);