Module Name:    src
Committed By:   roy
Date:           Wed Jul 19 13:53:03 UTC 2023

Modified Files:
        src/external/bsd/dhcpcd/dist/src: bpf.c dhcp.c dhcp6.c dhcpcd.c
            if-bsd.c if-options.c privsep.c script.c

Log Message:
Sync with dhcpcd-10.0.2


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/external/bsd/dhcpcd/dist/src/bpf.c
cvs rdiff -u -r1.47 -r1.48 src/external/bsd/dhcpcd/dist/src/dhcp.c
cvs rdiff -u -r1.29 -r1.30 src/external/bsd/dhcpcd/dist/src/dhcp6.c \
    src/external/bsd/dhcpcd/dist/src/if-bsd.c
cvs rdiff -u -r1.50 -r1.51 src/external/bsd/dhcpcd/dist/src/dhcpcd.c
cvs rdiff -u -r1.33 -r1.34 src/external/bsd/dhcpcd/dist/src/if-options.c
cvs rdiff -u -r1.14 -r1.15 src/external/bsd/dhcpcd/dist/src/privsep.c
cvs rdiff -u -r1.15 -r1.16 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/bpf.c
diff -u src/external/bsd/dhcpcd/dist/src/bpf.c:1.19 src/external/bsd/dhcpcd/dist/src/bpf.c:1.20
--- src/external/bsd/dhcpcd/dist/src/bpf.c:1.19	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/bpf.c	Wed Jul 19 13:53:03 2023
@@ -610,16 +610,19 @@ static const struct bpf_insn bpf_bootp_b
 #define BPF_BOOTP_BASE_LEN	__arraycount(bpf_bootp_base)
 
 static const struct bpf_insn bpf_bootp_read[] = {
-	/* Make sure it's from and to the right port. */
-	BPF_STMT(BPF_LD + BPF_W + BPF_IND, 0),
-	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (BOOTPS << 16) + BOOTPC, 1, 0),
+	/* Make sure it's to the right port.
+	 * RFC2131 makes no mention of enforcing a source port. */
+	BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct udphdr, uh_dport)),
+	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTPC, 1, 0),
 	BPF_STMT(BPF_RET + BPF_K, 0),
 };
 #define BPF_BOOTP_READ_LEN	__arraycount(bpf_bootp_read)
 
 #ifdef BIOCSETWF
 static const struct bpf_insn bpf_bootp_write[] = {
-	/* Make sure it's from and to the right port. */
+	/* Make sure it's from and to the right port.
+	 * RFC2131 makes no mention of encforcing a source port,
+	 * but dhcpcd does enforce it for sending. */
 	BPF_STMT(BPF_LD + BPF_W + BPF_IND, 0),
 	BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (BOOTPC << 16) + BOOTPS, 1, 0),
 	BPF_STMT(BPF_RET + BPF_K, 0),

Index: src/external/bsd/dhcpcd/dist/src/dhcp.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp.c:1.47 src/external/bsd/dhcpcd/dist/src/dhcp.c:1.48
--- src/external/bsd/dhcpcd/dist/src/dhcp.c:1.47	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/dhcp.c	Wed Jul 19 13:53:03 2023
@@ -3436,8 +3436,8 @@ is_packet_udp_bootp(void *packet, size_t
 	if (ip_hlen + ntohs(udp.uh_ulen) > plen)
 		return false;
 
-	/* Check it's to and from the right ports. */
-	if (udp.uh_dport != htons(BOOTPC) || udp.uh_sport != htons(BOOTPS))
+	/* Check it's to the right port. */
+	if (udp.uh_dport != htons(BOOTPC))
 		return false;
 
 	return true;

Index: src/external/bsd/dhcpcd/dist/src/dhcp6.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.29 src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.30
--- src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.29	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/dhcp6.c	Wed Jul 19 13:53:03 2023
@@ -1667,10 +1667,7 @@ dhcp6_startinform(void *arg)
 
 	ifp = arg;
 	state = D6_STATE(ifp);
-	if (state->new_start || (state->new == NULL && !state->failed))
-		llevel = LOG_INFO;
-	else
-		llevel = LOG_DEBUG;
+	llevel = state->failed ? LOG_DEBUG : LOG_INFO;
 	logmessage(llevel, "%s: requesting DHCPv6 information", ifp->name);
 	state->state = DH6S_INFORM;
 	state->RTC = 0;
@@ -3069,7 +3066,7 @@ dhcp6_bind(struct interface *ifp, const 
 	int loglevel;
 	struct timespec now;
 
-	if (state->state == DH6S_RENEW && !state->new_start) {
+	if (state->state == DH6S_RENEW) {
 		loglevel = LOG_DEBUG;
 		TAILQ_FOREACH(ia, &state->addrs, next) {
 			if (ia->flags & IPV6_AF_NEW) {
@@ -3968,8 +3965,10 @@ dhcp6_start(struct interface *ifp, enum 
 			{
 				/* We don't want log spam when the RA
 				 * has just adjusted it's prefix times. */
-				if (state->state != DH6S_INFORMED)
+				if (state->state != DH6S_INFORMED) {
 					state->new_start = true;
+					state->failed = false;
+				}
 				dhcp6_startinform(ifp);
 			}
 			break;
Index: src/external/bsd/dhcpcd/dist/src/if-bsd.c
diff -u src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.29 src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.30
--- src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.29	Thu Apr 27 13:21:59 2023
+++ src/external/bsd/dhcpcd/dist/src/if-bsd.c	Wed Jul 19 13:53:03 2023
@@ -154,6 +154,9 @@ if_opensockets_os(struct dhcpcd_ctx *ctx
 #ifdef RTM_CHGADDR
 	    RTM_CHGADDR,
 #endif
+#ifdef RTM_DESYNC
+	    RTM_DESYNC,
+#endif
 	    RTM_NEWADDR, RTM_DELADDR
 	};
 #ifdef ROUTE_MSGFILTER
@@ -1332,6 +1335,11 @@ if_ifa(struct dhcpcd_ctx *ctx, const str
 		      ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
 		return -1;
 
+	/* All BSD's set IFF_UP on the interface when adding an address.
+	 * But not all BSD's emit this via RTM_IFINFO when they do this ... */
+	if (ifam->ifam_type == RTM_NEWADDR && !(ifp->flags & IFF_UP))
+		dhcpcd_handlecarrier(ifp, ifp->carrier, ifp->flags | IFF_UP);
+
 	switch (rti_info[RTAX_IFA]->sa_family) {
 	case AF_LINK:
 	{
@@ -1755,10 +1763,9 @@ ip6_forwarding(__unused const char *ifna
 static int
 if_af_attach(const struct interface *ifp, int af)
 {
-	struct if_afreq ifar;
+	struct if_afreq ifar = { .ifar_af = af };
 
 	strlcpy(ifar.ifar_name, ifp->name, sizeof(ifar.ifar_name));
-	ifar.ifar_af = af;
 	return if_ioctl6(ifp->ctx, SIOCIFAFATTACH, &ifar, sizeof(ifar));
 }
 #endif
@@ -1832,23 +1839,20 @@ if_disable_rtadv(void)
 void
 if_setup_inet6(const struct interface *ifp)
 {
+#ifdef ND6_NDI_FLAGS
 	struct priv *priv;
 	int s;
-#ifdef ND6_NDI_FLAGS
 	struct in6_ndireq nd;
 	int flags;
-#endif
 
 	priv = (struct priv *)ifp->ctx->priv;
 	s = priv->pf_inet6_fd;
 
-#ifdef ND6_NDI_FLAGS
 	memset(&nd, 0, sizeof(nd));
 	strlcpy(nd.ifname, ifp->name, sizeof(nd.ifname));
 	if (ioctl(s, SIOCGIFINFO_IN6, &nd) == -1)
 		logerr("%s: SIOCGIFINFO_FLAGS", ifp->name);
 	flags = (int)nd.ndi.flags;
-#endif
 
 #ifdef ND6_IFF_AUTO_LINKLOCAL
 	/* Unlike the kernel, dhcpcd make make a stable private address. */
@@ -1878,14 +1882,13 @@ if_setup_inet6(const struct interface *i
 #endif
 #endif
 
-#ifdef ND6_NDI_FLAGS
 	if (nd.ndi.flags != (uint32_t)flags) {
 		nd.ndi.flags = (uint32_t)flags;
 		if (if_ioctl6(ifp->ctx, SIOCSIFINFO_FLAGS,
 		    &nd, sizeof(nd)) == -1)
 			logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
 	}
-#endif
+#endif /* ND6_NDI_FLAGS */
 
 	/* Enabling IPv6 by whatever means must be the
 	 * last action undertaken to ensure kernel RS and

Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.50 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.51
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.50	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c	Wed Jul 19 13:53:03 2023
@@ -256,7 +256,7 @@ dhcpcd_ifafwaiting(const struct interfac
 		bool foundaddr = ipv6_hasaddr(ifp);
 
 		if (opts & DHCPCD_WAITIP6 && !foundaddr)
-			return AF_INET;
+			return AF_INET6;
 		if (foundaddr)
 			foundany = true;
 	}
@@ -1816,8 +1816,11 @@ dhcpcd_stderr_cb(void *arg, unsigned sho
 	char log[BUFSIZ];
 	ssize_t len;
 
-	if (events != ELE_READ)
-		logerrx("%s: unexpected event 0x%04x", __func__, events);
+	if (events & ELE_HANGUP)
+		eloop_exit(ctx->eloop, EXIT_SUCCESS);
+
+	if (!(events & ELE_READ))
+		return;
 
 	len = read(ctx->stderr_fd, log, sizeof(log));
 	if (len == -1) {

Index: src/external/bsd/dhcpcd/dist/src/if-options.c
diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.33 src/external/bsd/dhcpcd/dist/src/if-options.c:1.34
--- src/external/bsd/dhcpcd/dist/src/if-options.c:1.33	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/if-options.c	Wed Jul 19 13:53:03 2023
@@ -958,11 +958,16 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		break;
 	case 'w':
 		ifo->options |= DHCPCD_WAITIP;
-		if (arg != NULL && arg[0] != '\0') {
-			if (arg[0] == '4' || arg[1] == '4')
+		p = UNCONST(arg);
+		// Generally it's --waitip=46, but some expect
+		// --waitip="4 6" to work as well.
+		// It's easier to allow it rather than have confusing docs.
+		while (p != NULL && p[0] != '\0') {
+			if (p[0] == '4' || p[1] == '4')
 				ifo->options |= DHCPCD_WAITIP4;
-			if (arg[0] == '6' || arg[1] == '6')
+			if (p[0] == '6' || p[1] == '6')
 				ifo->options |= DHCPCD_WAITIP6;
+			p = strskipwhite(++p);
 		}
 		break;
 	case 'y':

Index: src/external/bsd/dhcpcd/dist/src/privsep.c
diff -u src/external/bsd/dhcpcd/dist/src/privsep.c:1.14 src/external/bsd/dhcpcd/dist/src/privsep.c:1.15
--- src/external/bsd/dhcpcd/dist/src/privsep.c:1.14	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/privsep.c	Wed Jul 19 13:53:03 2023
@@ -1069,8 +1069,7 @@ nobufs:
 }
 
 ssize_t
-ps_recvmsg(struct dhcpcd_ctx *ctx, int rfd, unsigned short events,
-    uint16_t cmd, int wfd)
+ps_recvmsg(int rfd, unsigned short events, uint16_t cmd, int wfd)
 {
 	struct sockaddr_storage ss = { .ss_family = AF_UNSPEC };
 	uint8_t controlbuf[sizeof(struct sockaddr_storage)] = { 0 };
@@ -1089,22 +1088,15 @@ ps_recvmsg(struct dhcpcd_ctx *ctx, int r
 		logerrx("%s: unexpected event 0x%04x", __func__, events);
 
 	len = recvmsg(rfd, &msg, 0);
-	if (len == -1)
+	if (len == -1) {
 		logerr("%s: recvmsg", __func__);
-	if (len == -1 || len == 0) {
-		if (ctx->options & DHCPCD_FORKED)
-			eloop_exit(ctx->eloop,
-			    len != -1 ? EXIT_SUCCESS : EXIT_FAILURE);
 		return len;
 	}
 
 	iov[0].iov_len = (size_t)len;
 	len = ps_sendcmdmsg(wfd, cmd, &msg);
-	if (len == -1) {
+	if (len == -1)
 		logerr("%s: ps_sendcmdmsg", __func__);
-		if (ctx->options & DHCPCD_FORKED)
-			eloop_exit(ctx->eloop, EXIT_FAILURE);
-	}
 	return len;
 }
 

Index: src/external/bsd/dhcpcd/dist/src/script.c
diff -u src/external/bsd/dhcpcd/dist/src/script.c:1.15 src/external/bsd/dhcpcd/dist/src/script.c:1.16
--- src/external/bsd/dhcpcd/dist/src/script.c:1.15	Fri Apr 21 16:54:26 2023
+++ src/external/bsd/dhcpcd/dist/src/script.c	Wed Jul 19 13:53:03 2023
@@ -764,7 +764,7 @@ script_runreason(const struct interface 
 #ifdef PRIVSEP
 	if (ctx->options & DHCPCD_PRIVSEP) {
 		if (ps_root_script(ctx,
-		    ctx->script_buf, ctx->script_buflen) == -1)
+		    ctx->script_buf, (size_t)buflen) == -1)
 			logerr(__func__);
 		goto send_listeners;
 	}

Reply via email to