changeset 5432:d7cc41338b01 draft

DHCP: Don't set address lifetimes when extending leases 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.
author Roy Marples <roy@marples.name>
date Tue, 01 Sep 2020 11:56:53 +0100
parents f8d95f002758
children f41e780ef9c2
files src/ipv4.c src/ipv6.c
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ipv4.c	Mon Aug 31 06:51:27 2020 +0100
+++ b/src/ipv4.c	Tue Sep 01 11:56:53 2020 +0100
@@ -711,9 +711,18 @@
 {
 	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;
 
--- a/src/ipv6.c	Mon Aug 31 06:51:27 2020 +0100
+++ b/src/ipv6.c	Tue Sep 01 11:56:53 2020 +0100
@@ -679,6 +679,14 @@
 	/* 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))