Module Name:    src
Committed By:   roy
Date:           Tue Apr 21 09:55:33 UTC 2020

Modified Files:
        src/external/bsd/dhcpcd/dist/src: dhcp.c dhcp6.c dhcpcd.c if-bsd.c
            if-options.c ipv6.c ipv6nd.c

Log Message:
Sync


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/external/bsd/dhcpcd/dist/src/dhcp.c
cvs rdiff -u -r1.17 -r1.18 src/external/bsd/dhcpcd/dist/src/dhcp6.c
cvs rdiff -u -r1.34 -r1.35 src/external/bsd/dhcpcd/dist/src/dhcpcd.c
cvs rdiff -u -r1.18 -r1.19 src/external/bsd/dhcpcd/dist/src/if-bsd.c \
    src/external/bsd/dhcpcd/dist/src/ipv6nd.c
cvs rdiff -u -r1.22 -r1.23 src/external/bsd/dhcpcd/dist/src/if-options.c
cvs rdiff -u -r1.10 -r1.11 src/external/bsd/dhcpcd/dist/src/ipv6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/dhcpcd/dist/src/dhcp.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp.c:1.35 src/external/bsd/dhcpcd/dist/src/dhcp.c:1.36
--- src/external/bsd/dhcpcd/dist/src/dhcp.c:1.35	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcp.c	Tue Apr 21 09:55:33 2020
@@ -3494,8 +3494,9 @@ dhcp_packet(struct interface *ifp, uint8
 			    __func__, ifp->name);
 			return;
 		}
-		data += fl;
 		len -= fl;
+		/* Move the data to avoid alignment errors. */
+		memmove(data, data + fl, len);
 	}
 
 	/* Validate filter. */
@@ -3608,15 +3609,18 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, str
 		.iov_base = buf,
 		.iov_len = sizeof(buf),
 	};
+	union {
+		struct cmsghdr hdr;
 #ifdef IP_RECVIF
-	unsigned char ctl[CMSG_SPACE(sizeof(struct sockaddr_dl))] = { 0 };
+		uint8_t buf[CMSG_SPACE(sizeof(struct sockaddr_dl))];
 #else
-	unsigned char ctl[CMSG_SPACE(sizeof(struct in_pktinfo))] = { 0 };
+		uint8_t buf[CMSG_SPACE(sizeof(struct in_pktinfo))];
 #endif
+	} cmsgbuf = { .buf = { 0 } };
 	struct msghdr msg = {
 	    .msg_name = &from, .msg_namelen = sizeof(from),
 	    .msg_iov = &iov, .msg_iovlen = 1,
-	    .msg_control = ctl, .msg_controllen = sizeof(ctl),
+	    .msg_control = buf, .msg_controllen = sizeof(cmsgbuf.buf),
 	};
 	int s;
 	ssize_t bytes;

Index: src/external/bsd/dhcpcd/dist/src/dhcp6.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.17 src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.18
--- src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.17	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcp6.c	Tue Apr 21 09:55:33 2020
@@ -1585,6 +1585,7 @@ dhcp6_startdiscover(void *arg)
 {
 	struct interface *ifp;
 	struct dhcp6_state *state;
+	int llevel;
 
 	ifp = arg;
 	state = D6_STATE(ifp);
@@ -1592,7 +1593,11 @@ dhcp6_startdiscover(void *arg)
 	if (state->reason == NULL || strcmp(state->reason, "TIMEOUT6") != 0)
 		dhcp6_delete_delegates(ifp);
 #endif
-	loginfox("%s: soliciting a DHCPv6 lease", ifp->name);
+	if (state->new == NULL && !state->failed)
+		llevel = LOG_INFO;
+	else
+		llevel = LOG_DEBUG;
+	logmessage(llevel, "%s: soliciting a DHCPv6 lease", ifp->name);
 	state->state = DH6S_DISCOVER;
 	state->RTC = 0;
 	state->IMD = SOL_MAX_DELAY;
@@ -1616,11 +1621,15 @@ dhcp6_startinform(void *arg)
 {
 	struct interface *ifp;
 	struct dhcp6_state *state;
+	int llevel;
 
 	ifp = arg;
 	state = D6_STATE(ifp);
-	if (state->new == NULL || ifp->options->options & DHCPCD_DEBUG)
-		loginfox("%s: requesting DHCPv6 information", ifp->name);
+	if (state->new == NULL && !state->failed)
+		llevel = LOG_INFO;
+	else
+		llevel = LOG_DEBUG;
+	logmessage(llevel, "%s: requesting DHCPv6 information", ifp->name);
 	state->state = DH6S_INFORM;
 	state->RTC = 0;
 	state->IMD = INF_MAX_DELAY;
@@ -1677,6 +1686,8 @@ dhcp6_fail(struct interface* ifp)
 {
 	struct dhcp6_state *state = D6_STATE(ifp);
 
+	state->failed = true;
+
 	/* RFC3315 18.1.2 says that prior addresses SHOULD be used on failure.
 	 * RFC2131 3.2.3 says that MAY chose to use the prior address.
 	 * Because dhcpcd was written first for RFC2131, we have the LASTLEASE
@@ -1711,33 +1722,43 @@ dhcp6_fail(struct interface* ifp)
 	}
 }
 
+static int
+dhcp6_failloglevel(struct interface *ifp)
+{
+	const struct dhcp6_state *state = D6_CSTATE(ifp);
+
+	return state->failed ? LOG_DEBUG : LOG_ERR;
+}
+
 static void
 dhcp6_failconfirm(void *arg)
 {
-	struct interface *ifp;
+	struct interface *ifp = arg;
+	int llevel = dhcp6_failloglevel(ifp);
 
-	ifp = arg;
-	logerrx("%s: failed to confirm prior address", ifp->name);
+	logmessage(llevel, "%s: failed to confirm prior DHCPv6 address",
+	    ifp->name);
 	dhcp6_fail(ifp);
 }
 
 static void
 dhcp6_failrequest(void *arg)
 {
-	struct interface *ifp;
+	struct interface *ifp = arg;
+	int llevel = dhcp6_failloglevel(ifp);
 
-	ifp = arg;
-	logerrx("%s: failed to request address", ifp->name);
+	logmessage(llevel, "%s: failed to request DHCPv6 address", ifp->name);
 	dhcp6_fail(ifp);
 }
 
 static void
 dhcp6_failinform(void *arg)
 {
-	struct interface *ifp;
+	struct interface *ifp = arg;
+	int llevel = dhcp6_failloglevel(ifp);
 
-	ifp = arg;
-	logerrx("%s: failed to request information", ifp->name);
+	logmessage(llevel, "%s: failed to request DHCPv6 information",
+	    ifp->name);
 	dhcp6_fail(ifp);
 }
 
@@ -1745,10 +1766,9 @@ dhcp6_failinform(void *arg)
 static void
 dhcp6_failrebind(void *arg)
 {
-	struct interface *ifp;
+	struct interface *ifp = arg;
 
-	ifp = arg;
-	logerrx("%s: failed to rebind prior delegation", ifp->name);
+	logerrx("%s: failed to rebind prior DHCPv6 delegation", ifp->name);
 	dhcp6_fail(ifp);
 }
 
@@ -3124,6 +3144,7 @@ dhcp6_bind(struct interface *ifp, const 
 			state->state = DH6S_INFORMED;
 		else
 			state->state = DH6S_BOUND;
+		state->failed = false;
 
 		if (state->renew && state->renew != ND6_INFINITE_LIFETIME)
 			eloop_timeout_add_sec(ifp->ctx->eloop,
@@ -3621,11 +3642,14 @@ dhcp6_recv(struct dhcpcd_ctx *ctx, struc
 		.iov_base = buf,
 		.iov_len = sizeof(buf),
 	};
-	unsigned char ctl[CMSG_SPACE(sizeof(struct in6_pktinfo))] = { 0 };
+	union {
+		struct cmsghdr hdr;
+		uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
+	} cmsgbuf = { .buf = { 0 } };
 	struct msghdr msg = {
 	    .msg_name = &from, .msg_namelen = sizeof(from),
 	    .msg_iov = &iov, .msg_iovlen = 1,
-	    .msg_control = ctl, .msg_controllen = sizeof(ctl),
+	    .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
 	};
 	int s;
 	ssize_t bytes;
@@ -3857,6 +3881,7 @@ dhcp6_start(struct interface *ifp, enum 
 gogogo:
 	state->state = init_state;
 	state->lerror = 0;
+	state->failed = false;
 	dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
 	    AF_INET6, ifp);
 	if (ipv6_linklocal(ifp) == NULL) {

Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.34 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.35
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.34	Wed Apr 15 15:54:18 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c	Tue Apr 21 09:55:33 2020
@@ -2274,6 +2274,7 @@ printpidfile:
 			loglevel = ctx.options & DHCPCD_INACTIVE ?
 			    LOG_DEBUG : LOG_ERR;
 			logmessage(loglevel, "no valid interfaces found");
+			dhcpcd_daemonise(&ctx);
 		} else
 			goto exit_failure;
 		if (!(ctx.options & DHCPCD_LINK)) {

Index: src/external/bsd/dhcpcd/dist/src/if-bsd.c
diff -u src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.18 src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.19
--- src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.18	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/if-bsd.c	Tue Apr 21 09:55:33 2020
@@ -1015,28 +1015,21 @@ if_ioctl6(struct dhcpcd_ctx *ctx, unsign
 int
 if_address6(unsigned char cmd, const struct ipv6_addr *ia)
 {
-	struct in6_aliasreq ifa;
+	struct in6_aliasreq ifa = { .ifra_flags = 0 };
 	struct in6_addr mask;
 	struct dhcpcd_ctx *ctx = ia->iface->ctx;
 
-	memset(&ifa, 0, sizeof(ifa));
 	strlcpy(ifa.ifra_name, ia->iface->name, sizeof(ifa.ifra_name));
-	/*
-	 * We should not set IN6_IFF_TENTATIVE as the kernel should be
-	 * able to work out if it's a new address or not.
-	 *
-	 * We should set IN6_IFF_AUTOCONF, but the kernel won't let us.
-	 * This is probably a safety measure, but still it's not entirely right
-	 * either.
-	 */
-#if 0
-	if (ia->autoconf)
-		ifa.ifra_flags |= IN6_IFF_AUTOCONF;
-#endif
 #if defined(__FreeBSD__) || defined(__DragonFly__)
+	/* This is a bug - the kernel should work this out. */
 	if (ia->addr_flags & IN6_IFF_TENTATIVE)
 		ifa.ifra_flags |= IN6_IFF_TENTATIVE;
 #endif
+// #if (defined(__NetBSD__) && __NetBSD_Version__ >= 999005700) ||
+#if    (defined(__OpenBSD__) && OpenBSD >= 201605)
+	if (ia->flags & IPV6_AF_AUTOCONF)
+		ifa.ifra_flags |= IN6_IFF_AUTOCONF;
+#endif
 #ifdef IPV6_MANAGETEMPADDR
 	if (ia->flags & IPV6_AF_TEMPORARY)
 		ifa.ifra_flags |= IN6_IFF_TEMPORARY;
@@ -1626,7 +1619,6 @@ if_machinearch(char *str, size_t len)
 
 #ifdef INET6
 #if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)) || \
-    defined(IPV6CTL_USETEMPADDR) || defined(IPV6CTL_TEMPVLTIME) || \
     defined(IPV6CTL_FORWARDING)
 #define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
 #define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
@@ -1687,8 +1679,7 @@ if_applyra(const struct ra *rap)
 #endif
 }
 
-#ifdef IPV6_MANAGETEMPADDR
-#if !defined(IPV6CTL_TEMPVLTIME) && !defined(__OpenBSD__)
+#ifndef IPV6CTL_FORWARDING
 #define get_inet6_sysctlbyname(code) inet6_sysctlbyname(code, 0, 0)
 #define set_inet6_sysctlbyname(code, val) inet6_sysctlbyname(code, val, 1)
 static int
@@ -1708,81 +1699,6 @@ inet6_sysctlbyname(const char *name, int
 }
 #endif
 
-#ifdef __OpenBSD__
-int
-ip6_use_tempaddr(const char *ifname)
-{
-	int s, r;
-	struct ifreq ifr;
-
-	s = socket(PF_INET6, SOCK_DGRAM, 0); /* XXX Not efficient */
-	if (s == -1)
-		return -1;
-	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	r = ioctl(s, SIOCGIFXFLAGS, &ifr);
-	close(s);
-	if (r == -1)
-		return -1;
-	return ifr.ifr_flags & IFXF_INET6_NOPRIVACY ? 0 : 1;
-}
-
-int
-ip6_temp_preferred_lifetime(__unused const char *ifname)
-{
-
-	return TEMP_PREFERRED_LIFETIME;
-}
-
-int
-ip6_temp_valid_lifetime(__unused const char *ifname)
-{
-
-	return TEMP_VALID_LIFETIME;
-}
-
-#else /* __OpenBSD__ */
-
-int
-ip6_use_tempaddr(__unused const char *ifname)
-{
-	int val;
-
-#ifdef IPV6CTL_USETEMPADDR
-	val = get_inet6_sysctl(IPV6CTL_USETEMPADDR);
-#else
-	val = get_inet6_sysctlbyname("net.inet6.ip6.use_tempaddr");
-#endif
-	return val == -1 ? 0 : val;
-}
-
-int
-ip6_temp_preferred_lifetime(__unused const char *ifname)
-{
-	int val;
-
-#ifdef IPV6CTL_TEMPPLTIME
-	val = get_inet6_sysctl(IPV6CTL_TEMPPLTIME);
-#else
-	val = get_inet6_sysctlbyname("net.inet6.ip6.temppltime");
-#endif
-	return val < 0 ? TEMP_PREFERRED_LIFETIME : val;
-}
-
-int
-ip6_temp_valid_lifetime(__unused const char *ifname)
-{
-	int val;
-
-#ifdef IPV6CTL_TEMPVLTIME
-	val = get_inet6_sysctl(IPV6CTL_TEMPVLTIME);
-#else
-	val = get_inet6_sysctlbyname("net.inet6.ip6.tempvltime");
-#endif
-	return val < 0 ? TEMP_VALID_LIFETIME : val;
-}
-#endif /* !__OpenBSD__ */
-#endif
-
 int
 ip6_forwarding(__unused const char *ifname)
 {
@@ -1946,7 +1862,7 @@ if_setup_inet6(const struct interface *i
 		logerr("%s: set_ifxflags", ifp->name);
 #endif
 
-#if defined(IPV6CTL_ACCEPT_RTADV) || defined(ND6_IFF_ACCEPT_RTADV)
+#ifdef SIOCSRTRFLUSH_IN6
 	/* Flush the kernel knowledge of advertised routers
 	 * and prefixes so the kernel does not expire prefixes
 	 * and default routes we are trying to own. */
@@ -1957,12 +1873,14 @@ if_setup_inet6(const struct interface *i
 		strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
 		if (if_ioctl6(ifp->ctx, SIOCSRTRFLUSH_IN6,
 		    &ifr, sizeof(ifr)) == -1 &&
-		    errno != ENOTSUP)
-			logwarn("SIOCSRTRFLUSH_IN6");
+		    errno != ENOTSUP && errno != ENOTTY)
+			logwarn("SIOCSRTRFLUSH_IN6 %d", errno);
+#ifdef SIOCSPFXFLUSH_IN6
 		if (if_ioctl6(ifp->ctx, SIOCSPFXFLUSH_IN6,
 		    &ifr, sizeof(ifr)) == -1 &&
-		    errno != ENOTSUP)
+		    errno != ENOTSUP && errno != ENOTTY)
 			logwarn("SIOCSPFXFLUSH_IN6");
+#endif
 	}
 #endif
 }
Index: src/external/bsd/dhcpcd/dist/src/ipv6nd.c
diff -u src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.18 src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.19
--- src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.18	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6nd.c	Tue Apr 21 09:55:33 2020
@@ -1169,7 +1169,8 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 	 * much needless log spam. */
 	if (rap->willexpire)
 		new_data = true;
-	loglevel = new_data || !rap->isreachable ? LOG_INFO : LOG_DEBUG,
+	loglevel = new_rap || rap->willexpire || !rap->isreachable ?
+	    LOG_INFO : LOG_DEBUG,
 	logmessage(loglevel, "%s: Router Advertisement from %s",
 	    ifp->name, rap->sfrom);
 
@@ -1337,7 +1338,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 #ifdef IPV6_MANAGETEMPADDR
 			/* RFC4941 Section 3.3.3 */
 			if (ia->flags & IPV6_AF_AUTOCONF &&
-			    ip6_use_tempaddr(ia->iface->name) &&
+			    ia->iface->options->options & DHCPCD_SLAACTEMP &&
 			    IA6_CANAUTOCONF(ia))
 			{
 				if (!new_ia) {
@@ -1908,11 +1909,15 @@ ipv6nd_handledata(void *arg)
 		.iov_base = buf,
 		.iov_len = sizeof(buf),
 	};
-	unsigned char ctl[CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int))] = { 0 };
+	union {
+		struct cmsghdr hdr;
+		uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo)) +
+		    CMSG_SPACE(sizeof(int))];
+	} cmsgbuf = { .buf = { 0 } };
 	struct msghdr msg = {
 	    .msg_name = &from, .msg_namelen = sizeof(from),
 	    .msg_iov = &iov, .msg_iovlen = 1,
-	    .msg_control = ctl, .msg_controllen = sizeof(ctl),
+	    .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
 	};
 	ssize_t len;
 

Index: src/external/bsd/dhcpcd/dist/src/if-options.c
diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.22 src/external/bsd/dhcpcd/dist/src/if-options.c:1.23
--- src/external/bsd/dhcpcd/dist/src/if-options.c:1.22	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/if-options.c	Tue Apr 21 09:55:33 2020
@@ -2193,12 +2193,20 @@ invalid_token:
 		break;
 	case O_SLAAC:
 		ARG_REQUIRED;
+		np = strwhite(arg);
+		if (np != NULL) {
+			*np++ = '\0';
+			np = strskipwhite(np);
+		}
 		if (strcmp(arg, "private") == 0 ||
 		    strcmp(arg, "stableprivate") == 0 ||
 		    strcmp(arg, "stable") == 0)
 			ifo->options |= DHCPCD_SLAACPRIVATE;
 		else
 			ifo->options &= ~DHCPCD_SLAACPRIVATE;
+		if (np != NULL &&
+		    (strcmp(np, "temp") == 0 || strcmp(np, "temporary") == 0))
+			ifo->options |= DHCPCD_SLAACTEMP;
 		break;
 	case O_BOOTP:
 		ifo->options |= DHCPCD_BOOTP;

Index: src/external/bsd/dhcpcd/dist/src/ipv6.c
diff -u src/external/bsd/dhcpcd/dist/src/ipv6.c:1.10 src/external/bsd/dhcpcd/dist/src/ipv6.c:1.11
--- src/external/bsd/dhcpcd/dist/src/ipv6.c:1.10	Mon Apr 13 15:46:26 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6.c	Tue Apr 21 09:55:33 2020
@@ -744,7 +744,7 @@ ipv6_addaddr1(struct ipv6_addr *ia, cons
 	if (ia->flags & IPV6_AF_TEMPORARY &&
 	    ia->prefix_pltime &&
 	    ia->prefix_vltime &&
-	    ip6_use_tempaddr(ifp->name))
+	    ifp->options->options & DHCPCD_SLAACTEMP)
 		eloop_timeout_add_sec(ifp->ctx->eloop,
 		    ia->prefix_pltime - REGEN_ADVANCE,
 		    ipv6_regentempaddr, ia);
@@ -1866,7 +1866,7 @@ static void
 ipv6_regen_desync(struct interface *ifp, bool force)
 {
 	struct ipv6_state *state;
-	unsigned int max, pref;
+	unsigned int max;
 
 	state = IPV6_STATE(ifp);
 
@@ -1874,14 +1874,13 @@ ipv6_regen_desync(struct interface *ifp,
 	 * greater than TEMP_VALID_LIFETIME - REGEN_ADVANCE.
 	 * I believe this is an error and it should be never be greater than
 	 * TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE. */
-	pref = (unsigned int)ip6_temp_preferred_lifetime(ifp->name);
-	max = pref - REGEN_ADVANCE;
+	max = TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE;
 	if (state->desync_factor && !force && state->desync_factor < max)
 		return;
 	if (state->desync_factor == 0)
 		state->desync_factor =
 		    arc4random_uniform(MIN(MAX_DESYNC_FACTOR, max));
-	max = pref - state->desync_factor - REGEN_ADVANCE;
+	max = TEMP_PREFERRED_LIFETIME - state->desync_factor - REGEN_ADVANCE;
 	eloop_timeout_add_sec(ifp->ctx->eloop, max, ipv6_regentempaddrs, ifp);
 }
 
@@ -1917,7 +1916,6 @@ ipv6_createtempaddr(struct ipv6_addr *ia
 	struct ipv6_state *state;
 	struct interface *ifp = ia0->iface;
 	struct ipv6_addr *ia;
-	uint32_t i;
 
 	ia = ipv6_newaddr(ifp, &ia0->prefix, ia0->prefix_len,
 	    IPV6_AF_AUTOCONF | IPV6_AF_TEMPORARY);
@@ -1932,11 +1930,9 @@ ipv6_createtempaddr(struct ipv6_addr *ia
 
 	/* RFC4941 Section 3.3.4 */
 	state = IPV6_STATE(ia->iface);
-	i = (uint32_t)ip6_temp_preferred_lifetime(ifp->name) -
-	    state->desync_factor;
-	ia->prefix_pltime = MIN(ia0->prefix_pltime, i);
-	i = (uint32_t)ip6_temp_valid_lifetime(ifp->name);
-	ia->prefix_vltime = MIN(ia0->prefix_vltime, i);
+	ia->prefix_pltime = MIN(ia0->prefix_pltime,
+	    TEMP_PREFERRED_LIFETIME - state->desync_factor);
+	ia->prefix_vltime = MIN(ia0->prefix_vltime, TEMP_VALID_LIFETIME);
 	if (ia->prefix_pltime <= REGEN_ADVANCE ||
 	    ia->prefix_pltime > ia0->prefix_vltime)
 	{
@@ -1994,7 +1990,7 @@ ipv6_settemptime(struct ipv6_addr *ia, i
 			ext = (unsigned int)ia->acquired.tv_sec
 			    + ia->prefix_pltime;
 			max = (unsigned int)(ap->created.tv_sec +
-			    ip6_temp_preferred_lifetime(ap->iface->name) -
+			    TEMP_PREFERRED_LIFETIME -
 			    state->desync_factor);
 			if (ext < max)
 				ap->prefix_pltime = ia->prefix_pltime;
@@ -2006,7 +2002,7 @@ valid:
 			ext = (unsigned int)ia->acquired.tv_sec +
 			    ia->prefix_vltime;
 			max = (unsigned int)(ap->created.tv_sec +
-			    ip6_temp_valid_lifetime(ap->iface->name));
+			    TEMP_VALID_LIFETIME);
 			if (ext < max)
 				ap->prefix_vltime = ia->prefix_vltime;
 			else
@@ -2073,10 +2069,13 @@ ipv6_regentempaddrs(void *arg)
 	struct ipv6_state *state;
 	struct ipv6_addr *ia;
 
+	state = IPV6_STATE(ifp);
+	if (state == NULL)
+		return;
+
 	ipv6_regen_desync(ifp, true);
 
 	clock_gettime(CLOCK_MONOTONIC, &tv);
-	state = IPV6_STATE(ifp);
 	TAILQ_FOREACH(ia, &state->addrs, next) {
 		if (ia->flags & IPV6_AF_TEMPORARY &&
 		    !(ia->flags & IPV6_AF_STALE))

Reply via email to