]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Don't set address lifetimes when extending leases
authorRoy Marples <roy@marples.name>
Tue, 1 Sep 2020 10:56:53 +0000 (11:56 +0100)
committerRoy Marples <roy@marples.name>
Tue, 1 Sep 2020 10:56:53 +0000 (11:56 +0100)
Otherwise the kernel WILL remove them.
dhcpcd already manages address removal when needed because
some OS's do not support address lifetimes even for IPv6.

While here apply the same logic to IPv6.

src/ipv4.c
src/ipv6.c

index c6a76ea3367d590cac8f149f0f09aa247f59775d..0590eb0dd7d75f1cfc84b911c0adf466471e92b5 100644 (file)
@@ -711,9 +711,18 @@ ipv4_daddaddr(struct interface *ifp, const struct dhcp_lease *lease)
 {
        struct dhcp_state *state;
        struct ipv4_addr *ia;
+       uint32_t vltime, pltime;
+
+       if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
+               /* We don't want the kernel to expire the address. */
+               vltime = pltime = DHCP_INFINITE_LIFETIME;
+       } else {
+               vltime = lease->leasetime;
+               pltime = lease->rebindtime;
+       }
 
        ia = ipv4_addaddr(ifp, &lease->addr, &lease->mask, &lease->brd,
-           lease->leasetime, lease->rebindtime);
+           vltime, pltime);
        if (ia == NULL)
                return -1;
 
index 1cd02bec7966fee7f80e5d2b21938acad7a8a185..5442ebdedc3ad8b26c817991f95f2d6c1597600b 100644 (file)
@@ -679,6 +679,14 @@ ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
        /* Adjust plftime and vltime based on acquired time */
        pltime = ia->prefix_pltime;
        vltime = ia->prefix_vltime;
+
+       if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
+               /* We don't want the kernel to expire the address.
+                * The saved times will be re-applied to the ia
+                * before exiting this function. */
+               ia->prefix_vltime = ia->prefix_pltime = ND6_INFINITE_LIFETIME;
+       }
+
        if (timespecisset(&ia->acquired) &&
            (ia->prefix_pltime != ND6_INFINITE_LIFETIME ||
            ia->prefix_vltime != ND6_INFINITE_LIFETIME))