Module Name:    src
Committed By:   roy
Date:           Thu Jul  2 13:59:19 UTC 2020

Modified Files:
        src/external/bsd/dhcpcd/dist/src: dhcp6.c dhcpcd.c if-bsd.c
            if-options.c ipv6.c ipv6.h ipv6nd.c logerr.c privsep.c script.c

Log Message:
Sync


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/external/bsd/dhcpcd/dist/src/dhcp6.c \
    src/external/bsd/dhcpcd/dist/src/ipv6nd.c
cvs rdiff -u -r1.39 -r1.40 src/external/bsd/dhcpcd/dist/src/dhcpcd.c
cvs rdiff -u -r1.22 -r1.23 src/external/bsd/dhcpcd/dist/src/if-bsd.c
cvs rdiff -u -r1.25 -r1.26 src/external/bsd/dhcpcd/dist/src/if-options.c
cvs rdiff -u -r1.12 -r1.13 src/external/bsd/dhcpcd/dist/src/ipv6.c
cvs rdiff -u -r1.11 -r1.12 src/external/bsd/dhcpcd/dist/src/ipv6.h
cvs rdiff -u -r1.5 -r1.6 src/external/bsd/dhcpcd/dist/src/logerr.c \
    src/external/bsd/dhcpcd/dist/src/privsep.c
cvs rdiff -u -r1.8 -r1.9 src/external/bsd/dhcpcd/dist/src/script.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/dhcp6.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.21 src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.22
--- src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.21	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcp6.c	Thu Jul  2 13:59:19 2020
@@ -3183,14 +3183,12 @@ dhcp6_bind(struct interface *ifp, const 
 			state->state = DH6S_BOUND;
 		state->failed = false;
 
-		if ((state->renew != 0 || state->rebind != 0) &&
-		    state->renew != ND6_INFINITE_LIFETIME)
+		if (state->renew && state->renew != ND6_INFINITE_LIFETIME)
 			eloop_timeout_add_sec(ifp->ctx->eloop,
 			    state->renew,
 			    state->state == DH6S_INFORMED ?
 			    dhcp6_startinform : dhcp6_startrenew, ifp);
-		if ((state->rebind != 0 || state->expire != 0) &&
-		    state->rebind != ND6_INFINITE_LIFETIME)
+		if (state->rebind && state->rebind != ND6_INFINITE_LIFETIME)
 			eloop_timeout_add_sec(ifp->ctx->eloop,
 			    state->rebind, dhcp6_startrebind, ifp);
 		if (state->expire != ND6_INFINITE_LIFETIME)
Index: src/external/bsd/dhcpcd/dist/src/ipv6nd.c
diff -u src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.21 src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.22
--- src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.21	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6nd.c	Thu Jul  2 13:59:19 2020
@@ -61,6 +61,16 @@
 /* Debugging Router Solicitations is a lot of spam, so disable it */
 //#define DEBUG_RS
 
+#ifndef ND_RA_FLAG_HOME_AGENT
+#define	ND_RA_FLAG_HOME_AGENT	0x20	/* Home Agent flag in RA */
+#endif
+#ifndef ND_RA_FLAG_PROXY
+#define	ND_RA_FLAG_PROXY	0x04	/* Proxy */
+#endif
+#ifndef ND_OPT_PI_FLAG_ROUTER
+#define	ND_OPT_PI_FLAG_ROUTER	0x20	/* Router flag in PI */
+#endif
+
 #ifndef ND_OPT_RDNSS
 #define ND_OPT_RDNSS			25
 struct nd_opt_rdnss {           /* RDNSS option RFC 6106 */
@@ -1096,6 +1106,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 	uint32_t old_lifetime;
 	int ifmtu;
 	int loglevel;
+	unsigned int flags;
 #ifdef IPV6_MANAGETEMPADDR
 	bool new_ia;
 #endif
@@ -1299,13 +1310,15 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 		case ND_OPT_PREFIX_INFORMATION:
 			loglevel = new_data ? LOG_ERR : LOG_DEBUG;
 			if (ndo.nd_opt_len != 4) {
-				logmessage(loglevel, "%s: invalid option len for prefix",
+				logmessage(loglevel,
+				    "%s: invalid option len for prefix",
 				    ifp->name);
 				continue;
 			}
 			memcpy(&pi, p, sizeof(pi));
 			if (pi.nd_opt_pi_prefix_len > 128) {
-				logmessage(loglevel, "%s: invalid prefix len", ifp->name);
+				logmessage(loglevel, "%s: invalid prefix len",
+				    ifp->name);
 				continue;
 			}
 			/* nd_opt_pi_prefix is not aligned. */
@@ -1314,27 +1327,33 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 			if (IN6_IS_ADDR_MULTICAST(&pi_prefix) ||
 			    IN6_IS_ADDR_LINKLOCAL(&pi_prefix))
 			{
-				logmessage(loglevel, "%s: invalid prefix in RA", ifp->name);
+				logmessage(loglevel, "%s: invalid prefix in RA",
+				    ifp->name);
 				continue;
 			}
 			if (ntohl(pi.nd_opt_pi_preferred_time) >
 			    ntohl(pi.nd_opt_pi_valid_time))
 			{
-				logmessage(loglevel, "%s: pltime > vltime", ifp->name);
+				logmessage(loglevel, "%s: pltime > vltime",
+				    ifp->name);
 				continue;
 			}
+
+			flags = IPV6_AF_RAPFX;
+			/* If no flags are set, that means the prefix is
+			 * available via the router. */
+			if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
+				flags |= IPV6_AF_ONLINK;
+			if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO &&
+			    rap->iface->options->options &
+			    DHCPCD_IPV6RA_AUTOCONF)
+				flags |= IPV6_AF_AUTOCONF;
+			if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
+				flags |= IPV6_AF_ROUTER;
+
 			ia = ipv6nd_rapfindprefix(rap,
 			    &pi_prefix, pi.nd_opt_pi_prefix_len);
 			if (ia == NULL) {
-				unsigned int flags;
-
-				flags = IPV6_AF_RAPFX;
-				if (pi.nd_opt_pi_flags_reserved &
-				    ND_OPT_PI_FLAG_AUTO &&
-				    rap->iface->options->options &
-				    DHCPCD_IPV6RA_AUTOCONF)
-					flags |= IPV6_AF_AUTOCONF;
-
 				ia = ipv6_newaddr(rap->iface,
 				    &pi_prefix, pi.nd_opt_pi_prefix_len, flags);
 				if (ia == NULL)
@@ -1363,12 +1382,10 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
 #ifdef IPV6_MANAGETEMPADDR
 				new_ia = false;
 #endif
+				ia->flags |= flags;
 				ia->flags &= ~IPV6_AF_STALE;
 				ia->acquired = rap->acquired;
 			}
-			if (pi.nd_opt_pi_flags_reserved &
-			    ND_OPT_PI_FLAG_ONLINK)
-				ia->flags |= IPV6_AF_ONLINK;
 			ia->prefix_vltime =
 			    ntohl(pi.nd_opt_pi_valid_time);
 			ia->prefix_pltime =
@@ -1602,6 +1619,7 @@ ipv6nd_env(FILE *fp, const struct interf
 	struct nd_opt_hdr ndo;
 	struct ipv6_addr *ia;
 	struct timespec now;
+	int pref;
 
 	clock_gettime(CLOCK_MONOTONIC, &now);
 	i = n = 0;
@@ -1618,6 +1636,18 @@ ipv6nd_env(FILE *fp, const struct interf
 		if (efprintf(fp, "%s_now=%lld", ndprefix,
 		    (long long)now.tv_sec) == -1)
 			return -1;
+		if (efprintf(fp, "%s_hoplimit=%u", ndprefix, rap->hoplimit) == -1)
+			return -1;
+		pref = ipv6nd_rtpref(rap);
+		if (efprintf(fp, "%s_flags=%s%s%s%s%s", ndprefix,
+		    rap->flags & ND_RA_FLAG_MANAGED    ? "M" : "",
+		    rap->flags & ND_RA_FLAG_OTHER      ? "O" : "",
+		    rap->flags & ND_RA_FLAG_HOME_AGENT ? "H" : "",
+		    pref == RTPREF_HIGH ? "h" : pref == RTPREF_LOW ? "l" : "",
+		    rap->flags & ND_RA_FLAG_PROXY      ? "P" : "") == -1)
+			return -1;
+		if (efprintf(fp, "%s_lifetime=%u", ndprefix, rap->lifetime) == -1)
+			return -1;
 
 		/* Zero our indexes */
 		for (j = 0, opt = rap->iface->ctx->nd_opts;

Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.39 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.40
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.39	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c	Thu Jul  2 13:59:19 2020
@@ -339,6 +339,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
 	return 0;
 #else
 	int i;
+	unsigned int logopts = loggetopts();
 
 	if (ctx->options & DHCPCD_DAEMONISE &&
 	    !(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_NOWAITIP)))
@@ -359,7 +360,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
 		return;
 
 	/* Don't use loginfo because this makes no sense in a log. */
-	if (!(loggetopts() & LOGERR_QUIET))
+	if (!(logopts & LOGERR_QUIET))
 		(void)fprintf(stderr, "forked to background, child pid %d\n",
 		    getpid());
 	i = EXIT_SUCCESS;
@@ -369,16 +370,11 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
 	eloop_event_delete(ctx->eloop, ctx->fork_fd);
 	close(ctx->fork_fd);
 	ctx->fork_fd = -1;
-#ifdef PRIVSEP
-	if (ctx->options & DHCPCD_PRIVSEP) {
-		/* Aside from Linux, we don't have access to /dev/null */
-		fclose(stdout);
-		fclose(stderr);
-	} else
-#endif
-	{
-		(void)freopen(_PATH_DEVNULL, "w", stdout);
-		(void)freopen(_PATH_DEVNULL, "w", stderr);
+
+	if (isatty(loggeterrfd())) {
+		logopts &= ~LOGERR_ERR;
+		logsetopts(logopts);
+		logseterrfd(-1);
 	}
 #endif
 }
@@ -867,7 +863,6 @@ dhcpcd_startinterface(void *arg)
 {
 	struct interface *ifp = arg;
 	struct if_options *ifo = ifp->options;
-	int carrier;
 
 	if (ifo->options & DHCPCD_LINK) {
 		switch (ifp->carrier) {
@@ -879,19 +874,8 @@ dhcpcd_startinterface(void *arg)
 		case LINK_UNKNOWN:
 			/* No media state available.
 			 * Loop until both IFF_UP and IFF_RUNNING are set */
-			carrier = if_carrier(ifp);
-			if (carrier == LINK_UNKNOWN) {
-				if (IF_UPANDRUNNING(ifp))
-					carrier = LINK_UP;
-				else {
-					eloop_timeout_add_msec(ifp->ctx->eloop,
-					    IF_POLL_UP * MSEC_PER_SEC,
-					    dhcpcd_startinterface, ifp);
-					return;
-				}
-			}
-			dhcpcd_handlecarrier(ifp->ctx, carrier,
-			    ifp->flags, ifp->name);
+			if (ifo->poll == 0)
+				if_pollinit(ifp);
 			return;
 		}
 	}
@@ -979,6 +963,7 @@ static void
 dhcpcd_prestartinterface(void *arg)
 {
 	struct interface *ifp = arg;
+	struct dhcpcd_ctx *ctx = ifp->ctx;
 	bool anondown;
 
 	if (ifp->carrier == LINK_DOWN &&
@@ -990,7 +975,7 @@ dhcpcd_prestartinterface(void *arg)
 	} else
 		anondown = false;
 
-	if ((!(ifp->ctx->options & DHCPCD_MASTER) ||
+	if ((!(ctx->options & DHCPCD_MASTER) ||
 	    ifp->options->options & DHCPCD_IF_UP || anondown) &&
 	    !(ifp->flags & IFF_UP))
 	{
@@ -1001,6 +986,9 @@ dhcpcd_prestartinterface(void *arg)
 			logerr(__func__);
 	}
 
+	if (ifp->options->poll != 0)
+		if_pollinit(ifp);
+
 	dhcpcd_startinterface(ifp);
 }
 
@@ -1299,7 +1287,9 @@ reload_config(struct dhcpcd_ctx *ctx)
 	if ((ifo = read_config(ctx, NULL, NULL, NULL)) == NULL)
 		return;
 	add_options(ctx, NULL, ifo, ctx->argc, ctx->argv);
-	/* We need to preserve these two options. */
+	/* We need to preserve these options. */
+	if (ctx->options & DHCPCD_STARTED)
+		ifo->options |= DHCPCD_STARTED;
 	if (ctx->options & DHCPCD_MASTER)
 		ifo->options |= DHCPCD_MASTER;
 	if (ctx->options & DHCPCD_DAEMONISED)
@@ -1409,6 +1399,9 @@ dhcpcd_signal_cb(int sig, void *arg)
 	}
 
 	if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) {
+		if (sig == SIGHUP)
+			return;
+
 		pid_t pid = pidfile_read(ctx->pidfile);
 		if (pid == -1) {
 			if (errno != ENOENT)
@@ -1861,9 +1854,7 @@ main(int argc, char **argv)
 #endif
 #ifdef PRIVSEP
 	ctx.ps_root_fd = ctx.ps_data_fd = -1;
-#ifdef PRIVSEP_COMTROLLER
-	ctx.ps_ctl_fd = -1;
-#endif
+	ctx.ps_inet_fd = ctx.ps_control_fd = -1;
 	TAILQ_INIT(&ctx.ps_processes);
 #endif
 	rt_init(&ctx);
@@ -2210,7 +2201,9 @@ printpidfile:
 	}
 
 	loginfox(PACKAGE "-" VERSION " starting");
-	freopen(_PATH_DEVNULL, "r", stdin);
+	if (freopen(_PATH_DEVNULL, "r", stdin) == NULL)
+		logerr("%s: freopen stdin", __func__);
+
 
 #ifdef PRIVSEP
 	ps_init(&ctx);
@@ -2275,6 +2268,22 @@ printpidfile:
 		if_disable_rtadv();
 #endif
 
+	if (isatty(STDOUT_FILENO) &&
+	    freopen(_PATH_DEVNULL, "r", stdout) == NULL)
+		logerr("%s: freopen stdout", __func__);
+	if (isatty(STDERR_FILENO)) {
+		int fd = dup(STDERR_FILENO);
+
+		if (fd == -1)
+			logerr("%s: dup", __func__);
+		else if (logseterrfd(fd) == -1)
+			logerr("%s: logseterrfd", __func__);
+		else if (freopen(_PATH_DEVNULL, "r", stderr) == NULL) {
+			logseterrfd(-1);
+			logerr("%s: freopen stderr", __func__);
+		}
+	}
+
 	/* If we're not running in privsep, we need to create the DB
 	 * directory here. */
 	if (!(ctx.options & DHCPCD_PRIVSEP)) {
@@ -2328,7 +2337,7 @@ printpidfile:
 
 	/* Cache the default vendor option. */
 	if (dhcp_vendor(ctx.vendor, sizeof(ctx.vendor)) == -1)
-		logerrx("dhcp_vendor");
+		logerr("dhcp_vendor");
 
 	/* Start handling kernel messages for interfaces, addresses and
 	 * routes. */

Index: src/external/bsd/dhcpcd/dist/src/if-bsd.c
diff -u src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.22 src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.23
--- src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.22	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/if-bsd.c	Thu Jul  2 13:59:19 2020
@@ -358,6 +358,10 @@ if_carrier(struct interface *ifp)
 {
 	struct ifmediareq ifmr = { .ifm_status = 0 };
 
+	/* Not really needed, but the other OS update flags here also */
+	if (if_getflags(ifp) == -1)
+		return LINK_UNKNOWN;
+
 	strlcpy(ifmr.ifm_name, ifp->name, sizeof(ifmr.ifm_name));
 	if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFMEDIA, &ifmr) == -1 ||
 	    !(ifmr.ifm_status & IFM_AVALID))
@@ -1002,7 +1006,10 @@ if_address6(unsigned char cmd, const str
 	if (ia->addr_flags & IN6_IFF_TENTATIVE)
 		ifa.ifra_flags |= IN6_IFF_TENTATIVE;
 #endif
-#if !defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)
+#if (defined(__NetBSD__) || defined(__OpenBSD__)) && \
+    (defined(IPV6CTL_ACCEPT_RTADV) || defined(ND6_IFF_ACCEPT_RTADV))
+	/* These kernels don't accept userland setting IN6_IFF_AUTOCONF */
+#else
 	if (ia->flags & IPV6_AF_AUTOCONF)
 		ifa.ifra_flags |= IN6_IFF_AUTOCONF;
 #endif

Index: src/external/bsd/dhcpcd/dist/src/if-options.c
diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.25 src/external/bsd/dhcpcd/dist/src/if-options.c:1.26
--- src/external/bsd/dhcpcd/dist/src/if-options.c:1.25	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/if-options.c	Thu Jul  2 13:59:19 2020
@@ -55,6 +55,10 @@
 #include "logerr.h"
 #include "sa.h"
 
+#define	IN_CONFIG_BLOCK(ifo)	((ifo)->options & DHCPCD_FORKED)
+#define	SET_CONFIG_BLOCK(ifo)	((ifo)->options |= DHCPCD_FORKED)
+#define	CLEAR_CONFIG_BLOCK(ifo)	((ifo)->options &= ~DHCPCD_FORKED)
+
 const struct option cf_options[] = {
 	{"background",      no_argument,       NULL, 'b'},
 	{"script",          required_argument, NULL, 'c'},
@@ -158,6 +162,7 @@ const struct option cf_options[] = {
 	{"inactive",        no_argument,       NULL, O_INACTIVE},
 	{"mudurl",          required_argument, NULL, O_MUDURL},
 	{"link_rcvbuf",     required_argument, NULL, O_LINK_RCVBUF},
+	{"poll",            optional_argument, NULL, O_POLL},
 	{NULL,              0,                 NULL, '\0'}
 };
 
@@ -673,7 +678,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		break;
 	case 'c':
 		ARG_REQUIRED;
-		if (ifname != NULL) {
+		if (IN_CONFIG_BLOCK(ifo)) {
 			logerrx("%s: per interface scripts"
 			    " are no longer supported",
 			    ifname);
@@ -743,7 +748,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		ARG_REQUIRED;
 		/* per interface logging is not supported
 		 * don't want to overide the commandline */
-		if (ifname == NULL && ctx->logfile == NULL) {
+		if (!IN_CONFIG_BLOCK(ifo) && ctx->logfile == NULL) {
 			logclose();
 			ctx->logfile = strdup(arg);
 			logopen(ctx->logfile);
@@ -946,7 +951,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		break;
 	case 'z':
 		ARG_REQUIRED;
-		if (ifname == NULL)
+		if (!IN_CONFIG_BLOCK(ifo))
 			ctx->ifav = splitv(&ctx->ifac, ctx->ifav, arg);
 		break;
 	case 'A':
@@ -1192,7 +1197,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		break;
 	case 'Z':
 		ARG_REQUIRED;
-		if (ifname == NULL)
+		if (!IN_CONFIG_BLOCK(ifo))
 			ctx->ifdv = splitv(&ctx->ifdc, ctx->ifdv, arg);
 		break;
 	case '1':
@@ -1296,7 +1301,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 #endif
 	case O_IAID:
 		ARG_REQUIRED;
-		if (ifname == NULL) {
+		if (!IN_CONFIG_BLOCK(ifo)) {
 			logerrx("IAID must belong in an interface block");
 			return -1;
 		}
@@ -1338,7 +1343,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 			logwarnx("%s: IA_PD not compiled in", ifname);
 			return -1;
 #else
-			if (ifname == NULL) {
+			if (!IN_CONFIG_BLOCK(ifo)) {
 				logerrx("IA PD must belong in an "
 				    "interface block");
 				return -1;
@@ -1346,7 +1351,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 			i = D6_OPTION_IA_PD;
 #endif
 		}
-		if (ifname == NULL && arg) {
+		if (!IN_CONFIG_BLOCK(ifo) && arg) {
 			logerrx("IA with IAID must belong in an "
 			    "interface block");
 			return -1;
@@ -2192,6 +2197,18 @@ invalid_token:
 		}
 #endif
 		break;
+	case O_POLL:
+		if (arg == NULL) {
+			ifo->poll = IF_POLL_UP;
+			break;
+		}
+		ifo->poll = (unsigned long)
+		    strtou(arg, NULL, 0, 0, ULONG_MAX, &e);
+		if (e) {
+			logerrx("failed to convert poll %s", arg);
+			return -1;
+		}
+		break;
 	default:
 		return 0;
 	}
@@ -2322,6 +2339,8 @@ read_config(struct dhcpcd_ctx *ctx,
 	ifo->options |= DHCPCD_DHCP6;
 #endif
 
+	CLEAR_CONFIG_BLOCK(ifo);
+
 	vlen = strlcpy((char *)ifo->vendorclassid + 1, ctx->vendor,
 	    sizeof(ifo->vendorclassid) - 1);
 	ifo->vendorclassid[0] = (uint8_t)(vlen > 255 ? 0 : vlen);
@@ -2474,7 +2493,9 @@ read_config(struct dhcpcd_ctx *ctx,
 			had_block = 1;
 			new_block = 0;
 			ifo->options &= ~DHCPCD_WAITOPTS;
+			SET_CONFIG_BLOCK(ifo);
 		}
+
 		/* Start of an interface block, skip if not ours */
 		if (strcmp(option, "interface") == 0) {
 			char **n;
@@ -2544,6 +2565,7 @@ read_config(struct dhcpcd_ctx *ctx,
 
 	if (!had_block)
 		ifo->options &= ~DHCPCD_WAITOPTS;
+	CLEAR_CONFIG_BLOCK(ifo);
 	finish_config(ifo);
 	return ifo;
 }

Index: src/external/bsd/dhcpcd/dist/src/ipv6.c
diff -u src/external/bsd/dhcpcd/dist/src/ipv6.c:1.12 src/external/bsd/dhcpcd/dist/src/ipv6.c:1.13
--- src/external/bsd/dhcpcd/dist/src/ipv6.c:1.12	Sun May 31 12:52:11 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6.c	Thu Jul  2 13:59:19 2020
@@ -2130,6 +2130,7 @@ ipv6_regentempaddrs(void *arg)
 	/* Mark addresses for regen so we don't infinite loop. */
 	TAILQ_FOREACH(ia, &state->addrs, next) {
 		if (ia->flags & IPV6_AF_TEMPORARY &&
+		    ia->flags & IPV6_AF_ADDED &&
 		    !(ia->flags & IPV6_AF_STALE))
 			ia->flags |= IPV6_AF_REGEN;
 		else

Index: src/external/bsd/dhcpcd/dist/src/ipv6.h
diff -u src/external/bsd/dhcpcd/dist/src/ipv6.h:1.11 src/external/bsd/dhcpcd/dist/src/ipv6.h:1.12
--- src/external/bsd/dhcpcd/dist/src/ipv6.h:1.11	Sun May 31 12:52:11 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6.h	Thu Jul  2 13:59:19 2020
@@ -226,8 +226,9 @@ struct ipv6_addr {
 #define	IPV6_AF_RAPFX		(1U << 12)
 #define	IPV6_AF_EXTENDED	(1U << 13)
 #define	IPV6_AF_REGEN		(1U << 14)
+#define	IPV6_AF_ROUTER		(1U << 15)
 #ifdef IPV6_MANAGETEMPADDR
-#define	IPV6_AF_TEMPORARY	(1U << 15)
+#define	IPV6_AF_TEMPORARY	(1U << 16)
 #endif
 
 struct ll_callback {

Index: src/external/bsd/dhcpcd/dist/src/logerr.c
diff -u src/external/bsd/dhcpcd/dist/src/logerr.c:1.5 src/external/bsd/dhcpcd/dist/src/logerr.c:1.6
--- src/external/bsd/dhcpcd/dist/src/logerr.c:1.5	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/logerr.c	Thu Jul  2 13:59:19 2020
@@ -52,6 +52,7 @@
 struct logctx {
 	char		 log_buf[BUFSIZ];
 	unsigned int	 log_opts;
+	FILE		*log_err;
 #ifndef SMALL
 	FILE		*log_file;
 #ifdef LOGERR_TAG
@@ -116,6 +117,7 @@ logprintdate(FILE *stream)
 __printflike(3, 0) static int
 vlogprintf_r(struct logctx *ctx, FILE *stream, const char *fmt, va_list args)
 {
+	FILE *err;
 	int len = 0, e;
 	va_list a;
 #ifndef SMALL
@@ -124,8 +126,9 @@ vlogprintf_r(struct logctx *ctx, FILE *s
 	bool log_tag;
 #endif
 
-	if ((stream == stderr && ctx->log_opts & LOGERR_ERR_DATE) ||
-	    (stream != stderr && ctx->log_opts & LOGERR_LOG_DATE))
+	err = ctx->log_err == NULL ? stderr : ctx->log_err;
+	if ((stream == err && ctx->log_opts & LOGERR_ERR_DATE) ||
+	    (stream != err && ctx->log_opts & LOGERR_LOG_DATE))
 	{
 		if ((e = logprintdate(stream)) == -1)
 			return -1;
@@ -133,8 +136,8 @@ vlogprintf_r(struct logctx *ctx, FILE *s
 	}
 
 #ifdef LOGERR_TAG
-	log_tag = ((stream == stderr && ctx->log_opts & LOGERR_ERR_TAG) ||
-	    (stream != stderr && ctx->log_opts & LOGERR_LOG_TAG));
+	log_tag = ((stream == err && ctx->log_opts & LOGERR_ERR_TAG) ||
+	    (stream != err && ctx->log_opts & LOGERR_LOG_TAG));
 	if (log_tag) {
 		if (ctx->log_tag == NULL)
 			ctx->log_tag = getprogname();
@@ -144,8 +147,8 @@ vlogprintf_r(struct logctx *ctx, FILE *s
 	}
 #endif
 
-	log_pid = ((stream == stderr && ctx->log_opts & LOGERR_ERR_PID) ||
-	    (stream != stderr && ctx->log_opts & LOGERR_LOG_PID));
+	log_pid = ((stream == err && ctx->log_opts & LOGERR_ERR_PID) ||
+	    (stream != err && ctx->log_opts & LOGERR_LOG_PID));
 	if (log_pid) {
 		if ((e = fprintf(stream, "[%d]", getpid())) == -1)
 			return -1;
@@ -202,7 +205,12 @@ vlogmessage(int pri, const char *fmt, va
 	    (pri <= LOG_ERR ||
 	    (!(ctx->log_opts & LOGERR_QUIET) && pri <= LOG_INFO) ||
 	    (ctx->log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG)))
-		len = vlogprintf_r(ctx, stderr, fmt, args);
+	{
+		FILE *err;
+
+		err = ctx->log_err == NULL ? stderr : ctx->log_err;
+		len = vlogprintf_r(ctx, err, fmt, args);
+	}
 
 	if (!(ctx->log_opts & LOGERR_LOG))
 		return len;
@@ -363,6 +371,30 @@ logsettag(const char *tag)
 #endif
 
 int
+loggeterrfd(void)
+{
+	struct logctx *ctx = &_logctx;
+	FILE *err = ctx->log_err == NULL ? stderr : ctx->log_err;
+
+	return fileno(err);
+}
+
+int
+logseterrfd(int fd)
+{
+	struct logctx *ctx = &_logctx;
+
+	if (ctx->log_err != NULL)
+		fclose(ctx->log_err);
+	if (fd == -1) {
+		ctx->log_err = NULL;
+		return 0;
+	}
+	ctx->log_err = fdopen(fd, "a");
+	return ctx->log_err == NULL ? -1 : 0;
+}
+
+int
 logopen(const char *path)
 {
 	struct logctx *ctx = &_logctx;
Index: src/external/bsd/dhcpcd/dist/src/privsep.c
diff -u src/external/bsd/dhcpcd/dist/src/privsep.c:1.5 src/external/bsd/dhcpcd/dist/src/privsep.c:1.6
--- src/external/bsd/dhcpcd/dist/src/privsep.c:1.5	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/privsep.c	Thu Jul  2 13:59:19 2020
@@ -160,8 +160,9 @@ ps_dropprivs(struct dhcpcd_ctx *ctx)
 	}
 
 	/* Prohibit writing to files.
-	 * Obviously this won't work if we are using a logfile. */
-	if (ctx->logfile == NULL) {
+	 * Obviously this won't work if we are using a logfile
+	 * or redirecting stderr to a file. */
+	if (ctx->logfile == NULL && isatty(loggeterrfd())) {
 		if (setrlimit(RLIMIT_FSIZE, &rzero) == -1)
 			logerr("setrlimit RLIMIT_FSIZE");
 	}
@@ -365,13 +366,6 @@ ps_dostart(struct dhcpcd_ctx *ctx,
 	if (callback(recv_ctx) == -1)
 		goto errexit;
 
-	if (!(ctx->options & DHCPCD_DEBUG) &&
-	   (!(ctx->options & DHCPCD_TEST) || loggetopts() & LOGERR_QUIET))
-	{
-		(void)freopen(_PATH_DEVNULL, "w", stdout);
-		(void)freopen(_PATH_DEVNULL, "w", stderr);
-	}
-
 	if (flags & PSF_DROPPRIVS)
 		ps_dropprivs(ctx);
 

Index: src/external/bsd/dhcpcd/dist/src/script.c
diff -u src/external/bsd/dhcpcd/dist/src/script.c:1.8 src/external/bsd/dhcpcd/dist/src/script.c:1.9
--- src/external/bsd/dhcpcd/dist/src/script.c:1.8	Mon Jun 15 16:59:05 2020
+++ src/external/bsd/dhcpcd/dist/src/script.c	Thu Jul  2 13:59:19 2020
@@ -342,8 +342,13 @@ make_env(struct dhcpcd_ctx *ctx, const s
 	if (!is_stdin) {
 		if (efprintf(fp, "interface=%s", ifp->name) == -1)
 			goto eexit;
+		if (protocols[protocol] != NULL) {
+			if (efprintf(fp, "protocol=%s",
+			    protocols[protocol]) == -1)
+				goto eexit;
+		}
 	}
-	if (ifp->ctx->options & DHCPCD_DUMPLEASE)
+	if (ifp->ctx->options & DHCPCD_DUMPLEASE && protocol != PROTO_LINK)
 		goto dumplease;
 	if (efprintf(fp, "ifcarrier=%s",
 	    ifp->carrier == LINK_UNKNOWN ? "unknown" :
@@ -357,6 +362,22 @@ make_env(struct dhcpcd_ctx *ctx, const s
 		goto eexit;
 	if (efprintf(fp, "ifmtu=%d", if_getmtu(ifp)) == -1)
 		goto eexit;
+	if (ifp->wireless) {
+		char pssid[IF_SSIDLEN * 4];
+
+		if (print_string(pssid, sizeof(pssid), OT_ESCSTRING,
+		    ifp->ssid, ifp->ssid_len) != -1)
+		{
+			if (efprintf(fp, "ifssid=%s", pssid) == -1)
+				goto eexit;
+		}
+	}
+	if (*ifp->profile != '\0') {
+		if (efprintf(fp, "profile=%s", ifp->profile) == -1)
+			goto eexit;
+	}
+	if (ifp->ctx->options & DHCPCD_DUMPLEASE)
+		goto dumplease;
 
 	if (fprintf(fp, "interface_order=") == -1)
 		goto eexit;
@@ -412,10 +433,6 @@ make_env(struct dhcpcd_ctx *ctx, const s
 		if (efprintf(fp, "if_down=true") == -1)
 			goto eexit;
 	}
-	if (protocols[protocol] != NULL) {
-		if (efprintf(fp, "protocol=%s", protocols[protocol]) == -1)
-			goto eexit;
-	}
 	if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
 		if (efprintf(fp, "if_afwaiting=%d", af) == -1)
 			goto eexit;
@@ -434,20 +451,6 @@ make_env(struct dhcpcd_ctx *ctx, const s
 		if (efprintf(fp, "syslog_debug=true") == -1)
 			goto eexit;
 	}
-	if (*ifp->profile != '\0') {
-		if (efprintf(fp, "profile=%s", ifp->profile) == -1)
-			goto eexit;
-	}
-	if (ifp->wireless) {
-		char pssid[IF_SSIDLEN * 4];
-
-		if (print_string(pssid, sizeof(pssid), OT_ESCSTRING,
-		    ifp->ssid, ifp->ssid_len) != -1)
-		{
-			if (efprintf(fp, "ifssid=%s", pssid) == -1)
-				goto eexit;
-		}
-	}
 #ifdef INET
 	if (protocol == PROTO_DHCP && state && state->old) {
 		if (dhcp_env(fp, "old", ifp,

Reply via email to