summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-11-23 13:22:20 +0000
committerRoy Marples <roy@marples.name>2020-11-23 13:22:20 +0000
commit7c1f6fe6343e3d3be8eb29ce7400f81f4b15df38 (patch)
tree528c4df573e2a04cb547e291b6a28e2704a8710b
parent7751af5f3879781aef0e3f722eaef4811fdb81aa (diff)
downloaddhcpcd-7c1f6fe6343e3d3be8eb29ce7400f81f4b15df38.tar.xz
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.
-rw-r--r--src/dhcp.c7
-rw-r--r--src/ipv4.c15
-rw-r--r--src/ipv4.h2
3 files changed, 13 insertions, 11 deletions
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 *);