]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Always add the leased address
authorRoy Marples <roy@marples.name>
Mon, 22 Jul 2019 12:34:10 +0000 (13:34 +0100)
committerRoy Marples <roy@marples.name>
Mon, 22 Jul 2019 12:34:10 +0000 (13:34 +0100)
This is needed so that the lifetimes are refreshed.
While here, set the pltime to the renewal time.

src/dhcp.c
src/ipv4.c

index 812651a3c1cf70d7f717ce4a15bd94942dd2a7cc..474f60c3213a4d261f4b3ae1a96c4b5e907db400 100644 (file)
@@ -2347,7 +2347,7 @@ dhcp_arp_address(struct interface *ifp)
                        get_lease(ifp, &l, state->offer, state->offer_len);
                        /* Add the address now, let the kernel handle DAD. */
                        ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd,
-                           l.leasetime, l.leasetime);
+                           l.leasetime, l.renewaltime);
                } else
                        loginfox("%s: waiting for DAD on %s",
                            ifp->name, inet_ntoa(addr));
index 06a5dabff7899b4ea89f10ce295ce557db90e6e4..793828cd2fe53fd7e6e74d244c05c5fe166d5437 100644 (file)
@@ -685,7 +685,7 @@ ipv4_daddaddr(struct interface *ifp, const struct dhcp_lease *lease)
        struct ipv4_addr *ia;
 
        ia = ipv4_addaddr(ifp, &lease->addr, &lease->mask, &lease->brd,
-           lease->leasetime, lease->leasetime);
+           lease->leasetime, lease->renewaltime);
        if (ia == NULL)
                return -1;
 
@@ -703,7 +703,6 @@ ipv4_applyaddr(void *arg)
        struct dhcp_lease *lease;
        struct if_options *ifo = ifp->options;
        struct ipv4_addr *ia;
-       int r;
 
        if (state == NULL)
                return;
@@ -728,25 +727,16 @@ ipv4_applyaddr(void *arg)
                return;
        }
 
+#if __linux__
        /* If the netmask or broadcast is different, re-add the addresss */
        ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
-       if (ia &&
-           ia->mask.s_addr == lease->mask.s_addr &&
-           ia->brd.s_addr == lease->brd.s_addr)
-               logdebugx("%s: IP address %s already exists",
-                   ifp->name, ia->saddr);
-       else {
-#if __linux__
-               /* Linux does not change netmask/broadcast address
-                * for re-added addresses, so we need to delete the old one
-                * first. */
-               if (ia != NULL)
-                       ipv4_deladdr(ia, 0);
+       if (ia != NULL &&
+           (ia->mask.s_addr != lease->mask.s_addr ||
+           ia->brd.s_addr != lease->brd.s_addr))
+               ipv4_deladdr(ia, 0);
 #endif
-               r = ipv4_daddaddr(ifp, lease);
-               if (r == -1 && errno != EEXIST)
-                       return;
-       }
+       if (ipv4_daddaddr(ifp, lease) == -1 && errno != EEXIST)
+               return;
 
        ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
        if (ia == NULL) {