From: Roy Marples Date: Mon, 23 Nov 2020 13:22:20 +0000 (+0000) Subject: DHCP: Only listen to the address if we successfully added it X-Git-Tag: v9.3.4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c1f6fe6343e3d3be8eb29ce7400f81f4b15df38;p=thirdparty%2Fdhcpcd.git 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. --- diff --git a/src/dhcp.c b/src/dhcp.c index e2e9accd..fdfd8b3d 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -2364,13 +2364,14 @@ dhcp_bind(struct interface *ifp) 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 || diff --git a/src/ipv4.c b/src/ipv4.c index 92ecdbd0..220b3330 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -728,7 +728,7 @@ ipv4_daddaddr(struct interface *ifp, const struct dhcp_lease *lease) return 0; } -void +struct ipv4_addr * ipv4_applyaddr(void *arg) { struct interface *ifp = arg; @@ -738,7 +738,7 @@ ipv4_applyaddr(void *arg) struct ipv4_addr *ia; if (state == NULL) - return; + return NULL; lease = &state->lease; if (state->new == NULL) { @@ -757,7 +757,7 @@ ipv4_applyaddr(void *arg) 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 @@ ipv4_applyaddr(void *arg) #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 @@ ipv4_applyaddr(void *arg) script_runreason(ifp, state->reason); dhcpcd_daemonise(ifp->ctx); } + return ia; } void diff --git a/src/ipv4.h b/src/ipv4.h index bb3d5b2c..c72418e3 100644 --- a/src/ipv4.h +++ b/src/ipv4.h @@ -135,7 +135,7 @@ int ipv4_deladdr(struct ipv4_addr *, int); 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 *);