]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Only listen to the address if we successfully added it
authorRoy Marples <roy@marples.name>
Mon, 23 Nov 2020 13:22:20 +0000 (13:22 +0000)
committerRoy Marples <roy@marples.name>
Mon, 23 Nov 2020 13:22:20 +0000 (13:22 +0000)
Fixes an issue on Linux where the headers advertise something
newer than what the kernel actually provides.

src/dhcp.c
src/ipv4.c
src/ipv4.h

index e2e9accdcfc3d65a7061be1ba9243c422de8f792..fdfd8b3d208e834f8207a00d89d10d44198d0be1 100644 (file)
@@ -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 ||
index 92ecdbd0f1b10ec00a6a912f3cb6b508e8748d4c..220b33300e133b0c7b3d4e62d0a3c75c686f15c3 100644 (file)
@@ -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
index bb3d5b2c7a7448c742a3cee7c3f516cd27dfa3a0..c72418e381d511d8ecd200b0c0977446995dd96a 100644 (file)
@@ -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 *);