Module Name: src
Committed By: roy
Date: Mon Dec 28 13:57:40 UTC 2020
Modified Files:
src/external/bsd/dhcpcd/dist/hooks: 20-resolv.conf
src/external/bsd/dhcpcd/dist/src: dhcp.c dhcp6.c dhcpcd.c if-bsd.c
if-options.c ipv6nd.c privsep.c script.c
Log Message:
Sync with dhcpcd-9.4.0
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/external/bsd/dhcpcd/dist/hooks/20-resolv.conf
cvs rdiff -u -r1.44 -r1.45 src/external/bsd/dhcpcd/dist/src/dhcp.c
cvs rdiff -u -r1.26 -r1.27 src/external/bsd/dhcpcd/dist/src/dhcp6.c \
src/external/bsd/dhcpcd/dist/src/ipv6nd.c
cvs rdiff -u -r1.47 -r1.48 src/external/bsd/dhcpcd/dist/src/dhcpcd.c
cvs rdiff -u -r1.25 -r1.26 src/external/bsd/dhcpcd/dist/src/if-bsd.c
cvs rdiff -u -r1.30 -r1.31 src/external/bsd/dhcpcd/dist/src/if-options.c
cvs rdiff -u -r1.11 -r1.12 src/external/bsd/dhcpcd/dist/src/privsep.c
cvs rdiff -u -r1.12 -r1.13 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/hooks/20-resolv.conf
diff -u src/external/bsd/dhcpcd/dist/hooks/20-resolv.conf:1.5 src/external/bsd/dhcpcd/dist/hooks/20-resolv.conf:1.6
--- src/external/bsd/dhcpcd/dist/hooks/20-resolv.conf:1.5 Fri Nov 20 13:24:58 2020
+++ src/external/bsd/dhcpcd/dist/hooks/20-resolv.conf Mon Dec 28 13:57:40 2020
@@ -7,9 +7,15 @@
# or dnsmasq. This is important as the libc resolver isn't that powerful.
resolv_conf_dir="$state_dir/resolv.conf"
+nocarrier_roaming_dir="$state_dir/roaming"
NL="
"
: ${resolvconf:=resolvconf}
+if type "$resolvconf" >/dev/null 2>&1; then
+ have_resolvconf=true
+else
+ have_resolvconf=false
+fi
build_resolv_conf()
{
@@ -164,7 +170,7 @@ add_resolv_conf()
for x in ${new_domain_name_servers}; do
conf="${conf}nameserver $x$NL"
done
- if type "$resolvconf" >/dev/null 2>&1; then
+ if $have_resolvconf; then
[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
printf %s "$conf" | "$resolvconf" -a "$ifname"
return $?
@@ -180,7 +186,7 @@ add_resolv_conf()
remove_resolv_conf()
{
- if type "$resolvconf" >/dev/null 2>&1; then
+ if $have_resolvconf; then
"$resolvconf" -d "$ifname" -f
else
if [ -e "$resolv_conf_dir/$ifname" ]; then
@@ -199,7 +205,18 @@ BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
esac
if $if_configured; then
- if $if_up || [ "$reason" = ROUTERADVERT ]; then
+ if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
+ # avoid calling resolvconf -c on CARRIER unless we roam
+ mkdir -p "$nocarrier_roaming_dir"
+ echo " " >"$nocarrier_roaming_dir/$interface"
+ "$resolvconf" -C "$interface.*"
+ elif $have_resolvconf && [ "$reason" = CARRIER ]; then
+ # Not all resolvconf implementations support -c
+ if [ -e "$nocarrier_roaming_dir/$interface" ]; then
+ rm -f "$nocarrier_roaming_dir/$interface"
+ "$resolvconf" -c "$interface.*"
+ fi
+ elif $if_up || [ "$reason" = ROUTERADVERT ]; then
add_resolv_conf
elif $if_down; then
remove_resolv_conf
Index: src/external/bsd/dhcpcd/dist/src/dhcp.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp.c:1.44 src/external/bsd/dhcpcd/dist/src/dhcp.c:1.45
--- src/external/bsd/dhcpcd/dist/src/dhcp.c:1.44 Sat Nov 28 14:27:20 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcp.c Mon Dec 28 13:57:40 2020
@@ -3886,20 +3886,9 @@ dhcp_init(struct interface *ifp)
state->clientid = NULL;
if (ifo->options & DHCPCD_ANONYMOUS) {
- uint8_t duid[DUID_LEN];
- uint8_t duid_len;
-
- duid_len = (uint8_t)duid_make(duid, ifp, DUID_LL);
- if (duid_len != 0) {
- state->clientid = malloc((size_t)duid_len + 6);
- if (state->clientid == NULL)
- goto eexit;
- state->clientid[0] =(uint8_t)(duid_len + 5);
- state->clientid[1] = 255; /* RFC 4361 */
- memcpy(state->clientid + 2, ifo->iaid, 4);
- memset(state->clientid + 2, 0, 4); /* IAID */
- memcpy(state->clientid + 6, duid, duid_len);
- }
+ /* Removing the option could show that we want anonymous.
+ * As such keep it as it's already in the hwaddr field. */
+ goto make_clientid;
} else if (*ifo->clientid) {
state->clientid = malloc((size_t)(ifo->clientid[0] + 1));
if (state->clientid == NULL)
@@ -3917,6 +3906,7 @@ dhcp_init(struct interface *ifp)
memcpy(state->clientid + 6, ifp->ctx->duid,
ifp->ctx->duid_len);
} else {
+make_clientid:
len = (uint8_t)(ifp->hwlen + 1);
state->clientid = malloc((size_t)len + 1);
if (state->clientid == NULL)
Index: src/external/bsd/dhcpcd/dist/src/dhcp6.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.26 src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.27
--- src/external/bsd/dhcpcd/dist/src/dhcp6.c:1.26 Sat Nov 28 14:27:20 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcp6.c Mon Dec 28 13:57:40 2020
@@ -2065,7 +2065,8 @@ dhcp6_checkstatusok(const struct interfa
state->lerror = code;
errno = 0;
- if (code != 0 && ifp->ctx->options & DHCPCD_TEST)
+ /* code cannot be D6_STATUS_OK, so there is a failure */
+ if (ifp->ctx->options & DHCPCD_TEST)
eloop_exit(ifp->ctx->eloop, EXIT_FAILURE);
return (int)code;
Index: src/external/bsd/dhcpcd/dist/src/ipv6nd.c
diff -u src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.26 src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.27
--- src/external/bsd/dhcpcd/dist/src/ipv6nd.c:1.26 Fri Nov 20 13:24:58 2020
+++ src/external/bsd/dhcpcd/dist/src/ipv6nd.c Mon Dec 28 13:57:40 2020
@@ -1155,7 +1155,6 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
return;
}
-#ifdef NOCARRIER_PRESERVE_IP
/*
* Because we preserve RA's and expire them quickly after
* carrier up, it's important to reset the kernels notion of
@@ -1168,7 +1167,6 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx,
}
if (rap != NULL && rap->willexpire)
ipv6nd_applyra(ifp);
-#endif
TAILQ_FOREACH(rap, ctx->ra_routers, next) {
if (ifp == rap->iface &&
Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.47 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.48
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.47 Sat Nov 28 14:27:20 2020
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c Mon Dec 28 13:57:40 2020
@@ -695,36 +695,55 @@ dhcpcd_reportssid(struct interface *ifp)
loginfox("%s: connected to Access Point: %s", ifp->name, pssid);
}
+static void
+dhcpcd_nocarrier_roaming(struct interface *ifp)
+{
+
+ loginfox("%s: carrier lost - roaming", ifp->name);
+
+#ifdef ARP
+ arp_drop(ifp);
+#endif
+#ifdef INET
+ dhcp_abort(ifp);
+#endif
+#ifdef DHCP6
+ dhcp6_abort(ifp);
+#endif
+
+ rt_build(ifp->ctx, AF_UNSPEC);
+ script_runreason(ifp, "NOCARRIER_ROAMING");
+}
+
void
dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags)
{
bool was_link_up = if_is_link_up(ifp);
+ bool was_roaming = if_roaming(ifp);
ifp->carrier = carrier;
ifp->flags = flags;
if (!if_is_link_up(ifp)) {
- if (!was_link_up || !ifp->active)
+ if (!ifp->active || (!was_link_up && !was_roaming))
+ return;
+
+ /*
+ * If the interface is roaming (generally on wireless)
+ * then while we are not up, we are not down either.
+ * Preserve the network state until we either disconnect
+ * or re-connect.
+ */
+ if (!ifp->options->randomise_hwaddr && if_roaming(ifp)) {
+ dhcpcd_nocarrier_roaming(ifp);
return;
+ }
+
loginfox("%s: carrier lost", ifp->name);
script_runreason(ifp, "NOCARRIER");
-#ifdef NOCARRIER_PRESERVE_IP
- if (ifp->flags & IFF_UP &&
- !(ifp->options->options & DHCPCD_ANONYMOUS))
- {
-#ifdef ARP
- arp_drop(ifp);
-#endif
-#ifdef INET
- dhcp_abort(ifp);
-#endif
-#ifdef DHCP6
- dhcp6_abort(ifp);
-#endif
- } else
-#endif
- dhcpcd_drop(ifp, 0);
- if (ifp->options->options & DHCPCD_ANONYMOUS) {
+ dhcpcd_drop(ifp, 0);
+
+ if (ifp->options->randomise_hwaddr) {
bool is_up = ifp->flags & IFF_UP;
if (is_up)
@@ -734,6 +753,7 @@ dhcpcd_handlecarrier(struct interface *i
if (is_up)
if_up(ifp);
}
+
return;
}
@@ -774,9 +794,7 @@ dhcpcd_handlecarrier(struct interface *i
memcmp(ifp->ssid, ossid, ifp->ssid_len)) && ifp->active)
{
dhcpcd_reportssid(ifp);
-#ifdef NOCARRIER_PRESERVE_IP
dhcpcd_drop(ifp, 0);
-#endif
#ifdef IPV4LL
ipv4ll_reset(ifp);
#endif
@@ -788,17 +806,17 @@ dhcpcd_handlecarrier(struct interface *i
dhcpcd_initstate(ifp, 0);
script_runreason(ifp, "CARRIER");
+
#ifdef INET6
-#ifdef NOCARRIER_PRESERVE_IP
/* Set any IPv6 Routers we remembered to expire faster than they
* would normally as we maybe on a new network. */
ipv6nd_startexpire(ifp);
-#endif
#ifdef IPV6_MANAGETEMPADDR
/* RFC4941 Section 3.5 */
ipv6_regentempaddrs(ifp);
#endif
#endif
+
dhcpcd_startinterface(ifp);
}
@@ -951,22 +969,22 @@ dhcpcd_prestartinterface(void *arg)
{
struct interface *ifp = arg;
struct dhcpcd_ctx *ctx = ifp->ctx;
- bool anondown;
+ bool randmac_down;
if (ifp->carrier <= LINK_DOWN &&
- ifp->options->options & DHCPCD_ANONYMOUS &&
+ ifp->options->randomise_hwaddr &&
ifp->flags & IFF_UP)
{
if_down(ifp);
- anondown = true;
+ randmac_down = true;
} else
- anondown = false;
+ randmac_down = false;
if ((!(ctx->options & DHCPCD_MASTER) ||
- ifp->options->options & DHCPCD_IF_UP || anondown) &&
+ ifp->options->options & DHCPCD_IF_UP || randmac_down) &&
!(ifp->flags & IFF_UP))
{
- if (ifp->options->options & DHCPCD_ANONYMOUS &&
+ if (ifp->options->randomise_hwaddr &&
if_randomisemac(ifp) == -1)
logerr(__func__);
if (if_up(ifp) == -1)
@@ -1161,8 +1179,10 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *c
socklen = sizeof(rcvbuflen);
if (getsockopt(ctx->link_fd, SOL_SOCKET,
- SO_RCVBUF, &rcvbuflen, &socklen) == -1)
+ SO_RCVBUF, &rcvbuflen, &socklen) == -1) {
+ logerr("%s: getsockopt", __func__);
rcvbuflen = 0;
+ }
#ifdef __linux__
else
rcvbuflen /= 2;
@@ -1239,8 +1259,9 @@ dhcpcd_handlehwaddr(struct interface *if
}
if (ifp->hwtype != hwtype) {
- loginfox("%s: hardware address type changed from %d to %d",
- ifp->name, ifp->hwtype, hwtype);
+ if (ifp->active)
+ loginfox("%s: hardware address type changed"
+ " from %d to %d", ifp->name, ifp->hwtype, hwtype);
ifp->hwtype = hwtype;
}
@@ -1248,8 +1269,12 @@ dhcpcd_handlehwaddr(struct interface *if
(hwlen == 0 || memcmp(ifp->hwaddr, hwaddr, hwlen) == 0))
return;
- loginfox("%s: new hardware address: %s", ifp->name,
- hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
+ if (ifp->active) {
+ loginfox("%s: old hardware address: %s", ifp->name,
+ hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
+ loginfox("%s: new hardware address: %s", ifp->name,
+ hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
+ }
ifp->hwlen = hwlen;
if (hwaddr != NULL)
memcpy(ifp->hwaddr, hwaddr, hwlen);
@@ -2257,10 +2282,10 @@ printpidfile:
if (ctx.stdin_valid && freopen(_PATH_DEVNULL, "w", stdin) == NULL)
logwarn("freopen stdin");
+#if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
if (!(ctx.options & DHCPCD_DAEMONISE))
goto start_master;
-#if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
if (xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, fork_fd) == -1 ||
(ctx.stderr_valid &&
xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, stderr_fd) == -1))
Index: src/external/bsd/dhcpcd/dist/src/if-bsd.c
diff -u src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.25 src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.26
--- src/external/bsd/dhcpcd/dist/src/if-bsd.c:1.25 Mon Oct 12 14:09:03 2020
+++ src/external/bsd/dhcpcd/dist/src/if-bsd.c Mon Dec 28 13:57:40 2020
@@ -410,6 +410,21 @@ if_carrier(struct interface *ifp, const
return LINK_DOWN;
}
+bool
+if_roaming(struct interface *ifp)
+{
+
+/* Check for NetBSD as a safety measure.
+ * If other BSD's gain IN_IFF_TENTATIVE check they re-do DAD
+ * when the carrier comes up again. */
+#if defined(IN_IFF_TENTATIVE) && defined(__NetBSD__)
+ return ifp->flags & IFF_UP && ifp->carrier == LINK_DOWN;
+#else
+ UNUSED(ifp);
+ return false;
+#endif
+}
+
static void
if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp)
{
Index: src/external/bsd/dhcpcd/dist/src/if-options.c
diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.30 src/external/bsd/dhcpcd/dist/src/if-options.c:1.31
--- src/external/bsd/dhcpcd/dist/src/if-options.c:1.30 Sat Nov 28 14:27:20 2020
+++ src/external/bsd/dhcpcd/dist/src/if-options.c Mon Dec 28 13:57:40 2020
@@ -120,6 +120,7 @@ const struct option cf_options[] = {
{"ipv4only", no_argument, NULL, '4'},
{"ipv6only", no_argument, NULL, '6'},
{"anonymous", no_argument, NULL, O_ANONYMOUS},
+ {"randomise_hwaddr",no_argument, NULL, O_RANDOMISE_HWADDR},
{"arping", required_argument, NULL, O_ARPING},
{"destination", required_argument, NULL, O_DESTINATION},
{"fallback", required_argument, NULL, O_FALLBACK},
@@ -1304,6 +1305,9 @@ parse_option(struct dhcpcd_ctx *ctx, con
#endif
break;
+ case O_RANDOMISE_HWADDR:
+ ifo->randomise_hwaddr = true;
+ break;
#ifdef INET
case O_ARPING:
while (arg != NULL) {
Index: src/external/bsd/dhcpcd/dist/src/privsep.c
diff -u src/external/bsd/dhcpcd/dist/src/privsep.c:1.11 src/external/bsd/dhcpcd/dist/src/privsep.c:1.12
--- src/external/bsd/dhcpcd/dist/src/privsep.c:1.11 Fri Nov 20 13:24:58 2020
+++ src/external/bsd/dhcpcd/dist/src/privsep.c Mon Dec 28 13:57:40 2020
@@ -581,7 +581,9 @@ ps_mastersandbox(struct dhcpcd_ctx *ctx,
}
logerr("%s: %s", __func__, sandbox);
return -1;
- } else if (ctx->options & DHCPCD_LAUNCHER)
+ } else if (ctx->options & DHCPCD_LAUNCHER ||
+ ((!(ctx->options & DHCPCD_DAEMONISE)) &&
+ ctx->options & DHCPCD_MASTER))
logdebugx("sandbox: %s", sandbox);
return 0;
}
Index: src/external/bsd/dhcpcd/dist/src/script.c
diff -u src/external/bsd/dhcpcd/dist/src/script.c:1.12 src/external/bsd/dhcpcd/dist/src/script.c:1.13
--- src/external/bsd/dhcpcd/dist/src/script.c:1.12 Fri Nov 20 13:24:58 2020
+++ src/external/bsd/dhcpcd/dist/src/script.c Mon Dec 28 13:57:40 2020
@@ -74,6 +74,9 @@ static const char * const if_params[] =
NULL
};
+static const char * true_str = "true";
+static const char * false_str = "false";
+
void
if_printoptions(void)
{
@@ -228,6 +231,10 @@ make_env(struct dhcpcd_ctx *ctx, const s
const struct if_options *ifo;
const struct interface *ifp2;
int af;
+ bool is_stdin = ifp->name[0] == '\0';
+ const char *if_up, *if_down;
+ rb_tree_t ifaces;
+ struct rt *rt;
#ifdef INET
const struct dhcp_state *state;
#ifdef IPV4LL
@@ -237,7 +244,6 @@ make_env(struct dhcpcd_ctx *ctx, const s
#ifdef DHCP6
const struct dhcp6_state *d6_state;
#endif
- bool is_stdin = ifp->name[0] == '\0';
#ifdef HAVE_OPEN_MEMSTREAM
if (ctx->script_fp == NULL) {
@@ -276,6 +282,7 @@ make_env(struct dhcpcd_ctx *ctx, const s
if (efprintf(fp, "pid=%d", getpid()) == -1)
goto eexit;
}
+
if (!is_stdin) {
if (efprintf(fp, "reason=%s", reason) == -1)
goto eexit;
@@ -326,6 +333,7 @@ make_env(struct dhcpcd_ctx *ctx, const s
else if (strcmp(reason, "PREINIT") == 0 ||
strcmp(reason, "CARRIER") == 0 ||
strcmp(reason, "NOCARRIER") == 0 ||
+ strcmp(reason, "NOCARRIER_ROAMING") == 0 ||
strcmp(reason, "UNKNOWN") == 0 ||
strcmp(reason, "DEPARTED") == 0 ||
strcmp(reason, "STOPPED") == 0)
@@ -382,34 +390,45 @@ make_env(struct dhcpcd_ctx *ctx, const s
if (ifp->ctx->options & DHCPCD_DUMPLEASE)
goto dumplease;
+ rb_tree_init(&ifaces, &rt_compare_proto_ops);
+ TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
+ if (!ifp2->active)
+ continue;
+ rt = rt_new(UNCONST(ifp2));
+ if (rt == NULL)
+ goto eexit;
+ if (rb_tree_insert_node(&ifaces, rt) != rt)
+ goto eexit;
+ }
if (fprintf(fp, "interface_order=") == -1)
goto eexit;
- TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
- if (ifp2 != TAILQ_FIRST(ifp->ctx->ifaces)) {
- if (fputc(' ', fp) == EOF)
- return -1;
- }
- if (fprintf(fp, "%s", ifp2->name) == -1)
- return -1;
+ RB_TREE_FOREACH(rt, &ifaces) {
+ if (rt != RB_TREE_MIN(&ifaces) &&
+ fprintf(fp, "%s", " ") == -1)
+ goto eexit;
+ if (fprintf(fp, "%s", rt->rt_ifp->name) == -1)
+ goto eexit;
}
+ rt_headclear(&ifaces, AF_UNSPEC);
if (fputc('\0', fp) == EOF)
- return -1;
+ goto eexit;
if (strcmp(reason, "STOPPED") == 0) {
- if (efprintf(fp, "if_up=false") == -1)
- goto eexit;
- if (efprintf(fp, "if_down=%s",
- ifo->options & DHCPCD_RELEASE ? "true" : "false") == -1)
- goto eexit;
+ if_up = false_str;
+ if_down = ifo->options & DHCPCD_RELEASE ? true_str : false_str;
} else if (strcmp(reason, "TEST") == 0 ||
strcmp(reason, "PREINIT") == 0 ||
strcmp(reason, "CARRIER") == 0 ||
strcmp(reason, "UNKNOWN") == 0)
{
- if (efprintf(fp, "if_up=false") == -1)
- goto eexit;
- if (efprintf(fp, "if_down=false") == -1)
- goto eexit;
+ if_up = false_str;
+ if_down = false_str;
+ } else if (strcmp(reason, "NOCARRIER") == 0) {
+ if_up = false_str;
+ if_down = true_str;
+ } else if (strcmp(reason, "NOCARRIER_ROAMING") == 0) {
+ if_up = true_str;
+ if_down = false_str;
} else if (1 == 2 /* appease ifdefs */
#ifdef INET
|| (protocol == PROTO_DHCP && state && state->new)
@@ -426,16 +445,17 @@ make_env(struct dhcpcd_ctx *ctx, const s
#endif
)
{
- if (efprintf(fp, "if_up=true") == -1)
- goto eexit;
- if (efprintf(fp, "if_down=false") == -1)
- goto eexit;
+ if_up = true_str;
+ if_down = false_str;
} else {
- if (efprintf(fp, "if_up=false") == -1)
- goto eexit;
- if (efprintf(fp, "if_down=true") == -1)
- goto eexit;
+ if_up = false_str;
+ if_down = true_str;
}
+ if (efprintf(fp, "if_up=%s", if_up) == -1)
+ goto eexit;
+ if (efprintf(fp, "if_down=%s", if_down) == -1)
+ goto eexit;
+
if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) {
if (efprintf(fp, "if_afwaiting=%d", af) == -1)
goto eexit;