From f3744ac95affd7eb05bb963292945dade2bf0b9b Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 19 Jul 2023 15:48:06 +0100 Subject: [PATCH] Import dhcpcd-10.0.2 with the following changes: * BSD: When we get RTM_NEWADDR the interface must have IFF_UP * BSD: Fix non INET6 builds * DHCP: Don't enforce the message came port 67 * privsep: Allow zero length messages through * dhcpcd: deal with HANGUP and EPIPE better * dhcpcd: Fix waitip address family * privsep: Check if we have a root process before sending it stuff * privsep: Only unlink control sockets if we created them * common: Improve valid_domain and check correct return * common: Allow hwaddr_ntoa to print an empty string * privsep: Send only what we have put in the buffer to script env --- contrib/dhcpcd/README.md | 4 +-- contrib/dhcpcd/compat/pidfile.c | 6 ++-- contrib/dhcpcd/compat/rb.c | 12 ++++--- contrib/dhcpcd/src/bpf.c | 11 ++++--- contrib/dhcpcd/src/common.c | 8 +++-- contrib/dhcpcd/src/control.c | 41 ++++++++++++++++-------- contrib/dhcpcd/src/defs.h | 2 +- contrib/dhcpcd/src/dhcp-common.c | 23 ++++++------- contrib/dhcpcd/src/dhcp.c | 4 +-- contrib/dhcpcd/src/dhcp6.c | 11 +++---- contrib/dhcpcd/src/dhcpcd-embedded.c | 6 ++++ contrib/dhcpcd/src/dhcpcd-embedded.h | 4 +-- contrib/dhcpcd/src/dhcpcd.c | 9 ++++-- contrib/dhcpcd/src/eloop.c | 4 +++ contrib/dhcpcd/src/if-bsd.c | 31 ++++++++++-------- contrib/dhcpcd/src/if-options.c | 11 +++++-- contrib/dhcpcd/src/privsep-bpf.c | 2 +- contrib/dhcpcd/src/privsep-bsd.c | 10 +++--- contrib/dhcpcd/src/privsep-control.c | 48 +++++++++++----------------- contrib/dhcpcd/src/privsep-inet.c | 26 +++++++-------- contrib/dhcpcd/src/privsep-root.c | 62 +++++++++++++++++++----------------- contrib/dhcpcd/src/privsep.c | 14 ++------ contrib/dhcpcd/src/privsep.h | 4 ++- contrib/dhcpcd/src/script.c | 2 +- 24 files changed, 191 insertions(+), 164 deletions(-) diff --git a/contrib/dhcpcd/README.md b/contrib/dhcpcd/README.md index 85d1a0c207..2f31d38a55 100644 --- a/contrib/dhcpcd/README.md +++ b/contrib/dhcpcd/README.md @@ -92,5 +92,5 @@ dhcpcd-9 defaults the run directory to `/var/run/dhcpcd` instead of ## ChangeLog We no longer supply a ChangeLog. However, you're more than welcome to read the -[commit log](https://roy.marples.name/git/dhcpcd/log) and -[archived release announcements](https://roy.marples.name/archives/dhcpcd-discuss/). +[commit log](https://github.com/NetworkConfiguration/dhcpcd/commits) and +[release announcements](https://github.com/NetworkConfiguration/dhcpcd/releases). diff --git a/contrib/dhcpcd/compat/pidfile.c b/contrib/dhcpcd/compat/pidfile.c index 9dfd9c468a..8d2e5a838c 100644 --- a/contrib/dhcpcd/compat/pidfile.c +++ b/contrib/dhcpcd/compat/pidfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: pidfile.c,v 1.14 2016/04/12 20:40:43 roy Exp $ */ +/* $NetBSD: pidfile.c,v 1.16 2021/08/01 15:29:29 andvar Exp $ */ /*- * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc. @@ -131,7 +131,7 @@ pidfile_varrun_path(char *path, size_t len, const char *bname) } /* Returns the process ID inside path on success, otherwise -1. - * If no path is given, use the last pidfile path, othewise the default one. */ + * If no path is given, use the last pidfile path, otherwise the default one. */ pid_t pidfile_read(const char *path) { @@ -239,7 +239,7 @@ return_pid: if (errno == EAGAIN) { /* The pidfile is locked, return the process ID * it contains. - * If sucessful, set errno to EEXIST. */ + * If successful, set errno to EEXIST. */ if ((pid = pidfile_read(path)) != -1) errno = EEXIST; } else diff --git a/contrib/dhcpcd/compat/rb.c b/contrib/dhcpcd/compat/rb.c index 3c0bed5f70..4dfbd0d292 100644 --- a/contrib/dhcpcd/compat/rb.c +++ b/contrib/dhcpcd/compat/rb.c @@ -1,4 +1,4 @@ -/* $NetBSD: rb.c,v 1.14 2019/03/08 09:14:54 roy Exp $ */ +/* $NetBSD: rb.c,v 1.16 2021/09/16 21:29:41 andvar Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -32,6 +32,10 @@ #include "config.h" #include "common.h" +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #if !defined(_KERNEL) && !defined(_STANDALONE) #include #include @@ -44,10 +48,10 @@ #define KASSERT(s) do { } while (/*CONSTCOND*/ 0) #define __rbt_unused __unused #endif -__RCSID("$NetBSD: rb.c,v 1.14 2019/03/08 09:14:54 roy Exp $"); +__RCSID("$NetBSD: rb.c,v 1.16 2021/09/16 21:29:41 andvar Exp $"); #else #include -__KERNEL_RCSID(0, "$NetBSD: rb.c,v 1.14 2019/03/08 09:14:54 roy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rb.c,v 1.16 2021/09/16 21:29:41 andvar Exp $"); #ifndef DIAGNOSTIC #define __rbt_unused __unused #else @@ -312,7 +316,7 @@ rb_tree_insert_node(struct rb_tree *rbt, void *object) KASSERT(rb_tree_check_node(rbt, self, NULL, true)); } - /* Succesfully inserted, return our node pointer. */ + /* Successfully inserted, return our node pointer. */ return object; } diff --git a/contrib/dhcpcd/src/bpf.c b/contrib/dhcpcd/src/bpf.c index b75bfb04ca..caf9fda6c3 100644 --- a/contrib/dhcpcd/src/bpf.c +++ b/contrib/dhcpcd/src/bpf.c @@ -610,16 +610,19 @@ static const struct bpf_insn bpf_bootp_base[] = { #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), diff --git a/contrib/dhcpcd/src/common.c b/contrib/dhcpcd/src/common.c index 553825ef7f..34746d2496 100644 --- a/contrib/dhcpcd/src/common.c +++ b/contrib/dhcpcd/src/common.c @@ -46,10 +46,15 @@ hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen) const unsigned char *hp, *ep; char *p; - if (buf == NULL || hwlen == 0) + /* Allow a hwlen of 0 to be an empty string. */ + if (buf == NULL || buflen == 0) { + errno = ENOBUFS; return NULL; + } if (hwlen * 3 > buflen) { + /* We should still terminate the string just in case. */ + buf[0] = '\0'; errno = ENOBUFS; return NULL; } @@ -57,7 +62,6 @@ hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen) hp = hwaddr; ep = hp + hwlen; p = buf; - while (hp < ep) { if (hp != hwaddr) *p ++= ':'; diff --git a/contrib/dhcpcd/src/control.c b/contrib/dhcpcd/src/control.c index 0b7133e231..5325ac3509 100644 --- a/contrib/dhcpcd/src/control.c +++ b/contrib/dhcpcd/src/control.c @@ -94,22 +94,28 @@ control_free(struct fd_list *fd) } static void +control_hangup(struct fd_list *fd) +{ + +#ifdef PRIVSEP + if (IN_PRIVSEP(fd->ctx)) { + if (ps_ctl_sendeof(fd) == -1) + logerr(__func__); + } +#endif + control_free(fd); +} + +static void control_handle_read(struct fd_list *fd) { char buffer[1024]; ssize_t bytes; bytes = read(fd->fd, buffer, sizeof(buffer) - 1); - if (bytes == -1) + if (bytes == -1) { logerr(__func__); - if (bytes == -1 || bytes == 0) { -#ifdef PRIVSEP - if (IN_PRIVSEP(fd->ctx)) { - if (ps_ctl_sendeof(fd) == -1) - logerr(__func__); - } -#endif - control_free(fd); + control_hangup(fd); return; } @@ -158,8 +164,11 @@ control_handle_write(struct fd_list *fd) } if (writev(fd->fd, iov, iov_len) == -1) { - logerr("%s: write", __func__); - control_free(fd); + if (errno != EPIPE && errno != ENOTCONN) { + // We don't get ELE_HANGUP for some reason + logerr("%s: write", __func__); + } + control_hangup(fd); return; } @@ -194,13 +203,15 @@ control_handle_data(void *arg, unsigned short events) { struct fd_list *fd = arg; - if (!(events & (ELE_READ | ELE_WRITE))) + if (!(events & (ELE_READ | ELE_WRITE | ELE_HANGUP))) logerrx("%s: unexpected event 0x%04x", __func__, events); if (events & ELE_WRITE && !(events & ELE_HANGUP)) control_handle_write(fd); if (events & ELE_READ) control_handle_read(fd); + if (events & ELE_HANGUP) + control_hangup(fd); } void @@ -487,9 +498,11 @@ control_stop(struct dhcpcd_ctx *ctx) #ifdef PRIVSEP if (IN_PRIVSEP_SE(ctx)) { - if (ps_root_unlink(ctx, ctx->control_sock) == -1) + if (ctx->control_sock[0] != '\0' && + ps_root_unlink(ctx, ctx->control_sock) == -1) retval = -1; - if (ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1) + if (ctx->control_sock_unpriv[0] != '\0' && + ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1) retval = -1; return retval; } else if (ctx->options & DHCPCD_FORKED) diff --git a/contrib/dhcpcd/src/defs.h b/contrib/dhcpcd/src/defs.h index fd6db667d6..c0d2e61b90 100644 --- a/contrib/dhcpcd/src/defs.h +++ b/contrib/dhcpcd/src/defs.h @@ -29,7 +29,7 @@ #define CONFIG_H #define PACKAGE "dhcpcd" -#define VERSION "10.0.1" +#define VERSION "10.0.2" #ifndef PRIVSEP_USER # define PRIVSEP_USER "_" PACKAGE diff --git a/contrib/dhcpcd/src/dhcp-common.c b/contrib/dhcpcd/src/dhcp-common.c index ef33d2466e..679af24328 100644 --- a/contrib/dhcpcd/src/dhcp-common.c +++ b/contrib/dhcpcd/src/dhcp-common.c @@ -413,26 +413,23 @@ decode_rfc1035(char *out, size_t len, const uint8_t *p, size_t pl) } /* Check for a valid name as per RFC952 and RFC1123 section 2.1 */ -static int +static ssize_t valid_domainname(char *lbl, int type) { - char *slbl, *lst; + char *slbl = lbl, *lst = NULL; unsigned char c; - int start, len, errset; + int len = 0; + bool start = true, errset = false; if (lbl == NULL || *lbl == '\0') { errno = EINVAL; return 0; } - slbl = lbl; - lst = NULL; - start = 1; - len = errset = 0; for (;;) { c = (unsigned char)*lbl++; if (c == '\0') - return 1; + return lbl - slbl - 1; if (c == ' ') { if (lbl - 1 == slbl) /* No space at start */ break; @@ -440,7 +437,7 @@ valid_domainname(char *lbl, int type) break; /* Skip to the next label */ if (!start) { - start = 1; + start = true; lst = lbl - 1; } if (len) @@ -459,13 +456,13 @@ valid_domainname(char *lbl, int type) { if (++len > NS_MAXLABEL) { errno = ERANGE; - errset = 1; + errset = true; break; } } else break; if (start) - start = 0; + start = false; } if (!errset) @@ -473,7 +470,7 @@ valid_domainname(char *lbl, int type) if (lst) { /* At least one valid domain, return it */ *lst = '\0'; - return 1; + return lst - slbl; } return 0; } @@ -665,7 +662,7 @@ print_option(FILE *fp, const char *prefix, const struct dhcp_opt *opt, goto err; if (sl == 0) goto done; - if (valid_domainname(domain, opt->type) == -1) + if (!valid_domainname(domain, opt->type)) goto err; return efprintf(fp, "%s", domain); } diff --git a/contrib/dhcpcd/src/dhcp.c b/contrib/dhcpcd/src/dhcp.c index 233bd10736..edd1c011bb 100644 --- a/contrib/dhcpcd/src/dhcp.c +++ b/contrib/dhcpcd/src/dhcp.c @@ -3436,8 +3436,8 @@ is_packet_udp_bootp(void *packet, size_t plen) 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; diff --git a/contrib/dhcpcd/src/dhcp6.c b/contrib/dhcpcd/src/dhcp6.c index 1131f70f1c..e7767ca744 100644 --- a/contrib/dhcpcd/src/dhcp6.c +++ b/contrib/dhcpcd/src/dhcp6.c @@ -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 char *op, const char *sfrom) 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 DH6S init_state) { /* 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; diff --git a/contrib/dhcpcd/src/dhcpcd-embedded.c b/contrib/dhcpcd/src/dhcpcd-embedded.c index 13f6b02ab9..1b2f7ea4c5 100644 --- a/contrib/dhcpcd/src/dhcpcd-embedded.c +++ b/contrib/dhcpcd/src/dhcpcd-embedded.c @@ -235,6 +235,7 @@ const char dhcpcd_embedded_conf[] = "define 100 string posix_timezone\n" "define 101 string tzdb_timezone\n" "define 108 uint32 ipv6_only_preferred\n" +"define 114 string captive_portal_uri\n" "define 116 byte auto_configure\n" "define 117 array uint16 name_service_search\n" "define 118 ipaddress subnet_selection\n" @@ -280,6 +281,8 @@ const char dhcpcd_embedded_conf[] = "embed ipaddress primary\n" "embed ipaddress secondary\n" "embed array domain domains\n" +"define 147 domain dots_ri\n" +"define 148 array ipaddress dots_address\n" "define 150 array ipaddress tftp_servers\n" "define 161 string mudurl\n" "define 208 binhex pxelinux_magic\n" @@ -490,6 +493,9 @@ const char dhcpcd_embedded_conf[] = "encap 90 option\n" "encap 92 option\n" "define6 112 string mudurl\n" +"define6 103 string captive_portal_uri\n" +"define6 141 domain dots_ri\n" +"define6 142 array ip6address dots_address\n" #endif "\0"; diff --git a/contrib/dhcpcd/src/dhcpcd-embedded.h b/contrib/dhcpcd/src/dhcpcd-embedded.h index 3596e08d48..5bb3a874f4 100644 --- a/contrib/dhcpcd/src/dhcpcd-embedded.h +++ b/contrib/dhcpcd/src/dhcpcd-embedded.h @@ -30,9 +30,9 @@ #define INITDEFINENDS 6 #define INITDEFINE6S 14 #else -#define INITDEFINES 125 +#define INITDEFINES 128 #define INITDEFINENDS 7 -#define INITDEFINE6S 69 +#define INITDEFINE6S 72 #endif extern const char dhcpcd_embedded_conf[]; diff --git a/contrib/dhcpcd/src/dhcpcd.c b/contrib/dhcpcd/src/dhcpcd.c index d663c383e8..e06733d318 100644 --- a/contrib/dhcpcd/src/dhcpcd.c +++ b/contrib/dhcpcd/src/dhcpcd.c @@ -256,7 +256,7 @@ dhcpcd_ifafwaiting(const struct interface *ifp) 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 short events) 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) { diff --git a/contrib/dhcpcd/src/eloop.c b/contrib/dhcpcd/src/eloop.c index 0af001ba41..32a90c77ee 100644 --- a/contrib/dhcpcd/src/eloop.c +++ b/contrib/dhcpcd/src/eloop.c @@ -153,6 +153,10 @@ #include #endif +#ifndef __arraycount +# define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) +#endif + /* * Allow a backlog of signals. * If you use many eloops in the same process, they should all diff --git a/contrib/dhcpcd/src/if-bsd.c b/contrib/dhcpcd/src/if-bsd.c index aba8eb721e..bab33c2ca6 100644 --- a/contrib/dhcpcd/src/if-bsd.c +++ b/contrib/dhcpcd/src/if-bsd.c @@ -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 @@ -167,15 +170,13 @@ if_opensockets_os(struct dhcpcd_ctx *ctx) #ifdef INET6 priv->pf_inet6_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); -#ifdef PRIVSEP_RIGHTS - if (IN_PRIVSEP(ctx)) - ps_rights_limit_ioctl(priv->pf_inet6_fd); -#endif /* Don't return an error so we at least work on kernels witout INET6 * even though we expect INET6 support. * We will fail noisily elsewhere anyway. */ -#else - priv->pf_inet6_fd = -1; +#ifdef PRIVSEP_RIGHTS + if (priv->pf_inet6_fd != -1 && IN_PRIVSEP(ctx)) + ps_rights_limit_ioctl(priv->pf_inet6_fd); +#endif #endif ctx->link_fd = xsocket(PF_ROUTE, SOCK_RAW | SOCK_CXNB, AF_UNSPEC); @@ -234,8 +235,10 @@ if_closesockets_os(struct dhcpcd_ctx *ctx) struct priv *priv; priv = (struct priv *)ctx->priv; +#ifdef INET6 if (priv->pf_inet6_fd != -1) close(priv->pf_inet6_fd); +#endif #if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE) /*NetBSD */ if (priv->pf_link_fd != -1) close(priv->pf_link_fd); @@ -1332,6 +1335,11 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam) 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 *ifname) 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 *ifp) #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 diff --git a/contrib/dhcpcd/src/if-options.c b/contrib/dhcpcd/src/if-options.c index 1ef9cc9927..bb1c1fca57 100644 --- a/contrib/dhcpcd/src/if-options.c +++ b/contrib/dhcpcd/src/if-options.c @@ -958,11 +958,16 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, 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': diff --git a/contrib/dhcpcd/src/privsep-bpf.c b/contrib/dhcpcd/src/privsep-bpf.c index 2e92026f50..989400902d 100644 --- a/contrib/dhcpcd/src/privsep-bpf.c +++ b/contrib/dhcpcd/src/privsep-bpf.c @@ -328,7 +328,7 @@ ps_bpf_send(const struct interface *ifp, const struct in_addr *ia, if (ia != NULL) psm.ps_id.psi_addr.psa_in_addr = *ia; - return ps_sendpsmdata(ctx, ctx->ps_root->psp_fd, &psm, data, len); + return ps_sendpsmdata(ctx, PS_ROOT_FD(ctx), &psm, data, len); } #ifdef ARP diff --git a/contrib/dhcpcd/src/privsep-bsd.c b/contrib/dhcpcd/src/privsep-bsd.c index b005f93f7e..755ad6d530 100644 --- a/contrib/dhcpcd/src/privsep-bsd.c +++ b/contrib/dhcpcd/src/privsep-bsd.c @@ -301,7 +301,7 @@ ps_root_ioctldom(struct dhcpcd_ctx *ctx, uint16_t domain, unsigned long request, void *data, size_t len) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, domain, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), domain, request, data, len) == -1) return -1; return ps_root_readerror(ctx, data, len); @@ -327,7 +327,7 @@ ssize_t ps_root_route(struct dhcpcd_ctx *ctx, void *data, size_t len) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_ROUTE, 0, data, len) == -1) + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_ROUTE, 0, data, len) == -1) return -1; return ps_root_readerror(ctx, data, len); } @@ -346,7 +346,7 @@ ps_root_indirectioctl(struct dhcpcd_ctx *ctx, unsigned long request, strlcpy(buf, ifname, IFNAMSIZ); memcpy(buf + IFNAMSIZ, data, len); - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IOCTLINDIRECT, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IOCTLINDIRECT, request, buf, IFNAMSIZ + len) == -1) return -1; return ps_root_readerror(ctx, data, len); @@ -358,7 +358,7 @@ ssize_t ps_root_ifignoregroup(struct dhcpcd_ctx *ctx, const char *ifname) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IFIGNOREGRP, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IFIGNOREGRP, 0, ifname, strlen(ifname) + 1) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -400,7 +400,7 @@ ps_root_sysctl(struct dhcpcd_ctx *ctx, p += newlen; } - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_SYSCTL, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SYSCTL, flags, buf, (size_t)(p - buf)) == -1) return -1; diff --git a/contrib/dhcpcd/src/privsep-control.c b/contrib/dhcpcd/src/privsep-control.c index abea50240a..38f18c4ec1 100644 --- a/contrib/dhcpcd/src/privsep-control.c +++ b/contrib/dhcpcd/src/privsep-control.c @@ -64,27 +64,13 @@ ps_ctl_startcb(struct ps_process *psp) ctx->options & DHCPCD_MANAGER ? NULL : *ctx->ifv, af); } -static ssize_t -ps_ctl_recvmsgcb(void *arg, struct ps_msghdr *psm, __unused struct msghdr *msg) -{ - struct dhcpcd_ctx *ctx = arg; - - if (psm->ps_cmd != PS_CTL_EOF) { - errno = ENOTSUP; - return -1; - } - - ctx->ps_control_client = NULL; - return 0; -} - static void ps_ctl_recvmsg(void *arg, unsigned short events) { struct ps_process *psp = arg; if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events, - ps_ctl_recvmsgcb, psp->psp_ctx) == -1) + NULL, psp->psp_ctx) == -1) logerr(__func__); } @@ -175,22 +161,26 @@ ps_ctl_recv(void *arg, unsigned short events) char buf[BUFSIZ]; ssize_t len; - if (!(events & ELE_READ)) + if (!(events & (ELE_READ | ELE_HANGUP))) logerrx("%s: unexpected event 0x%04x", __func__, events); - len = read(ctx->ps_ctl->psp_work_fd, buf, sizeof(buf)); - if (len == 0) - return; - if (len == -1) { - logerr("%s: read", __func__); - eloop_exit(ctx->eloop, EXIT_FAILURE); - return; + if (events & ELE_READ) { + len = read(ctx->ps_ctl->psp_work_fd, buf, sizeof(buf)); + if (len == -1) + logerr("%s: read", __func__); + else if (len == 0) + // FIXME: Why does this happen? + ; + else if (ctx->ps_control_client == NULL) + logerrx("%s: clientfd #%d disconnected (len=%zd)", + __func__, ctx->ps_ctl->psp_work_fd, len); + else { + errno = 0; + if (control_queue(ctx->ps_control_client, + buf, (size_t)len) == -1) + logerr("%s: control_queue", __func__); + } } - if (ctx->ps_control_client == NULL) /* client disconnected */ - return; - errno = 0; - if (control_queue(ctx->ps_control_client, buf, (size_t)len) == -1) - logerr("%s: control_queue", __func__); } static void @@ -205,8 +195,6 @@ ps_ctl_listen(void *arg, unsigned short events) logerrx("%s: unexpected event 0x%04x", __func__, events); len = read(ctx->ps_control->fd, buf, sizeof(buf)); - if (len == 0) - return; if (len == -1) { logerr("%s: read", __func__); eloop_exit(ctx->eloop, EXIT_FAILURE); diff --git a/contrib/dhcpcd/src/privsep-inet.c b/contrib/dhcpcd/src/privsep-inet.c index ec239e86ae..5895a5730c 100644 --- a/contrib/dhcpcd/src/privsep-inet.c +++ b/contrib/dhcpcd/src/privsep-inet.c @@ -53,7 +53,7 @@ ps_inet_recvbootp(void *arg, unsigned short events) { struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->udp_rfd, events, + if (ps_recvmsg(ctx->udp_rfd, events, PS_BOOTP, ctx->ps_inet->psp_fd) == -1) logerr(__func__); } @@ -68,13 +68,13 @@ ps_inet_recvra(void *arg, unsigned short events) struct rs_state *state = RS_STATE(ifp); struct dhcpcd_ctx *ctx = ifp->ctx; - if (ps_recvmsg(ctx, state->nd_fd, events, + if (ps_recvmsg(state->nd_fd, events, PS_ND, ctx->ps_inet->psp_fd) == -1) logerr(__func__); #else struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->nd_fd, events, + if (ps_recvmsg(ctx->nd_fd, events, PS_ND, ctx->ps_inet->psp_fd) == -1) logerr(__func__); #endif @@ -87,7 +87,7 @@ ps_inet_recvdhcp6(void *arg, unsigned short events) { struct dhcpcd_ctx *ctx = arg; - if (ps_recvmsg(ctx, ctx->dhcp6_rfd, events, + if (ps_recvmsg(ctx->dhcp6_rfd, events, PS_DHCP6, ctx->ps_inet->psp_fd) == -1) logerr(__func__); } @@ -387,7 +387,7 @@ ps_inet_recvinbootp(void *arg, unsigned short events) { struct ps_process *psp = arg; - if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, events, + if (ps_recvmsg(psp->psp_work_fd, events, PS_BOOTP, psp->psp_ctx->ps_data_fd) == -1) logerr(__func__); } @@ -430,7 +430,7 @@ ps_inet_recvin6nd(void *arg) { struct ps_process *psp = arg; - if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, + if (ps_recvmsg(psp->psp_work_fd, PS_ND, psp->psp_ctx->ps_data_fd) == -1) logerr(__func__); } @@ -470,7 +470,7 @@ ps_inet_recvin6dhcp6(void *arg, unsigned short events) { struct ps_process *psp = arg; - if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, events, + if (ps_recvmsg(psp->psp_work_fd, events, PS_DHCP6, psp->psp_ctx->ps_data_fd) == -1) logerr(__func__); } @@ -622,7 +622,7 @@ ps_inet_in_docmd(struct ipv4_addr *ia, uint16_t cmd, const struct msghdr *msg) }, }; - return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg); + return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg); } ssize_t @@ -644,7 +644,7 @@ ps_inet_sendbootp(struct interface *ifp, const struct msghdr *msg) { struct dhcpcd_ctx *ctx = ifp->ctx; - return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_BOOTP, 0, msg); + return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_BOOTP, 0, msg); } #endif /* INET */ @@ -663,7 +663,7 @@ ps_inet_ifp_docmd(struct interface *ifp, uint16_t cmd, const struct msghdr *msg) }, }; - return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg); + return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg); } ssize_t @@ -692,7 +692,7 @@ ps_inet_sendnd(struct interface *ifp, const struct msghdr *msg) { struct dhcpcd_ctx *ctx = ifp->ctx; - return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_ND, 0, msg); + return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_ND, 0, msg); } #endif @@ -711,7 +711,7 @@ ps_inet_in6_docmd(struct ipv6_addr *ia, uint16_t cmd, const struct msghdr *msg) }, }; - return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg); + return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg); } ssize_t @@ -733,7 +733,7 @@ ps_inet_senddhcp6(struct interface *ifp, const struct msghdr *msg) { struct dhcpcd_ctx *ctx = ifp->ctx; - return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_DHCP6, 0, msg); + return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_DHCP6, 0, msg); } #endif /* DHCP6 */ #endif /* INET6 */ diff --git a/contrib/dhcpcd/src/privsep-root.c b/contrib/dhcpcd/src/privsep-root.c index c635182129..eb2b3eef68 100644 --- a/contrib/dhcpcd/src/privsep-root.c +++ b/contrib/dhcpcd/src/privsep-root.c @@ -97,7 +97,7 @@ ps_root_readerrorcb(void *arg, unsigned short events) goto out; \ } while (0 /* CONSTCOND */) - len = readv(ctx->ps_root->psp_fd, iov, __arraycount(iov)); + len = readv(PS_ROOT_FD(ctx), iov, __arraycount(iov)); if (len == -1) PSR_ERROR(errno); else if ((size_t)len < sizeof(*psr_error)) @@ -115,14 +115,15 @@ ps_root_readerror(struct dhcpcd_ctx *ctx, void *data, size_t len) .psr_ctx = ctx, .psr_data = data, .psr_datalen = len, }; + int fd = PS_ROOT_FD(ctx); - if (eloop_event_add(ctx->ps_eloop, ctx->ps_root->psp_fd, ELE_READ, + if (eloop_event_add(ctx->ps_eloop, fd, ELE_READ, ps_root_readerrorcb, &psr_ctx) == -1) return -1; eloop_enter(ctx->ps_eloop); eloop_start(ctx->ps_eloop, &ctx->sigset); - eloop_event_delete(ctx->ps_eloop, ctx->ps_root->psp_fd); + eloop_event_delete(ctx->ps_eloop, fd); errno = psr_ctx.psr_error.psr_errno; return psr_ctx.psr_error.psr_result; @@ -145,8 +146,7 @@ ps_root_mreaderrorcb(void *arg, unsigned short events) if (events != ELE_READ) logerrx("%s: unexpected event 0x%04x", __func__, events); - len = recv(ctx->ps_root->psp_fd, - psr_error, sizeof(*psr_error), MSG_PEEK); + len = recv(PS_ROOT_FD(ctx), psr_error, sizeof(*psr_error), MSG_PEEK); if (len == -1) PSR_ERROR(errno); else if ((size_t)len < sizeof(*psr_error)) @@ -163,7 +163,7 @@ ps_root_mreaderrorcb(void *arg, unsigned short events) iov[1].iov_len = psr_ctx->psr_datalen; } - len = readv(ctx->ps_root->psp_fd, iov, __arraycount(iov)); + len = readv(PS_ROOT_FD(ctx), iov, __arraycount(iov)); if (len == -1) PSR_ERROR(errno); else if ((size_t)len != sizeof(*psr_error) + psr_ctx->psr_datalen) @@ -180,14 +180,15 @@ ps_root_mreaderror(struct dhcpcd_ctx *ctx, void **data, size_t *len) struct psr_ctx psr_ctx = { .psr_ctx = ctx, }; + int fd = PS_ROOT_FD(ctx); - if (eloop_event_add(ctx->ps_eloop, ctx->ps_root->psp_fd, ELE_READ, + if (eloop_event_add(ctx->ps_eloop, fd, ELE_READ, ps_root_mreaderrorcb, &psr_ctx) == -1) return -1; eloop_enter(ctx->ps_eloop); eloop_start(ctx->ps_eloop, &ctx->sigset); - eloop_event_delete(ctx->ps_eloop, ctx->ps_root->psp_fd); + eloop_event_delete(ctx->ps_eloop, fd); errno = psr_ctx.psr_error.psr_errno; *data = psr_ctx.psr_data; @@ -210,12 +211,13 @@ ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result, { .iov_base = data, .iov_len = len }, }; ssize_t err; + int fd = PS_ROOT_FD(ctx); #ifdef PRIVSEP_DEBUG logdebugx("%s: result %zd errno %d", __func__, result, errno); #endif - err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov)); + err = writev(fd, iov, __arraycount(iov)); /* Error sending the message? Try sending the error of sending. */ if (err == -1) { @@ -225,7 +227,7 @@ ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result, psr.psr_errno = errno; iov[1].iov_base = NULL; iov[1].iov_len = 0; - err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov)); + err = writev(fd, iov, __arraycount(iov)); } return err; @@ -960,13 +962,15 @@ ps_root_stop(struct dhcpcd_ctx *ctx) * log dhcpcd exits because the latter requires the former. * So we just log the intent to exit. * Even sending this will be a race to exit. */ - logdebugx("%s%s%s will exit from PID %d", - psp->psp_ifname, - psp->psp_ifname[0] != '\0' ? ": " : "", - psp->psp_name, psp->psp_pid); + if (psp) { + logdebugx("%s%s%s will exit from PID %d", + psp->psp_ifname, + psp->psp_ifname[0] != '\0' ? ": " : "", + psp->psp_name, psp->psp_pid); - if (ps_stopprocess(psp) == -1) - return -1; + if (ps_stopprocess(psp) == -1) + return -1; + } /* else the root process has already exited :( */ return ps_stopwait(ctx); } @@ -978,7 +982,7 @@ ps_root_stopprocesses(struct dhcpcd_ctx *ctx) if (!(IN_PRIVSEP_SE(ctx))) return 0; - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_STOPPROCS, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_STOPPROCS, 0, NULL, 0) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -988,7 +992,7 @@ ssize_t ps_root_script(struct dhcpcd_ctx *ctx, const void *data, size_t len) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_SCRIPT, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SCRIPT, 0, data, len) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -998,7 +1002,7 @@ ssize_t ps_root_ioctl(struct dhcpcd_ctx *ctx, ioctl_request_t req, void *data, size_t len) { - int fd = ctx->ps_root->psp_fd; + int fd = PS_ROOT_FD(ctx); #ifdef IOCTL_REQUEST_TYPE unsigned long ulreq = 0; @@ -1016,7 +1020,7 @@ ssize_t ps_root_unlink(struct dhcpcd_ctx *ctx, const char *file) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_UNLINK, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_UNLINK, 0, file, strlen(file) + 1) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -1026,7 +1030,7 @@ ssize_t ps_root_readfile(struct dhcpcd_ctx *ctx, const char *file, void *data, size_t len) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_READFILE, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_READFILE, 0, file, strlen(file) + 1) == -1) return -1; return ps_root_readerror(ctx, data, len); @@ -1047,7 +1051,7 @@ ps_root_writefile(struct dhcpcd_ctx *ctx, const char *file, mode_t mode, } memcpy(buf + flen, data, len); - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_WRITEFILE, mode, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_WRITEFILE, mode, buf, flen + len) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -1057,7 +1061,7 @@ ssize_t ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_FILEMTIME, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_FILEMTIME, 0, file, strlen(file) + 1) == -1) return -1; return ps_root_readerror(ctx, time, sizeof(*time)); @@ -1067,7 +1071,7 @@ ssize_t ps_root_logreopen(struct dhcpcd_ctx *ctx) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_LOGREOPEN, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_LOGREOPEN, 0, NULL, 0) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -1084,7 +1088,7 @@ ps_root_getifaddrs(struct dhcpcd_ctx *ctx, struct ifaddrs **ifahead) size_t len; ssize_t err; - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_GETIFADDRS, 0, NULL, 0) == -1) return -1; err = ps_root_mreaderror(ctx, &buf, &len); @@ -1159,7 +1163,7 @@ ssize_t ps_root_ip6forwarding(struct dhcpcd_ctx *ctx, const char *ifname) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IP6FORWARDING, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IP6FORWARDING, 0, ifname, ifname != NULL ? strlen(ifname) + 1 : 0) == -1) return -1; return ps_root_readerror(ctx, NULL, 0); @@ -1171,7 +1175,7 @@ int ps_root_getauthrdm(struct dhcpcd_ctx *ctx, uint64_t *rdm) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_AUTH_MONORDM, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_AUTH_MONORDM, 0, rdm, sizeof(*rdm))== -1) return -1; return (int)ps_root_readerror(ctx, rdm, sizeof(*rdm)); @@ -1183,7 +1187,7 @@ int ps_root_dev_initialised(struct dhcpcd_ctx *ctx, const char *ifname) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_DEV_INITTED, 0, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_INITTED, 0, ifname, strlen(ifname) + 1)== -1) return -1; return (int)ps_root_readerror(ctx, NULL, 0); @@ -1193,7 +1197,7 @@ int ps_root_dev_listening(struct dhcpcd_ctx * ctx) { - if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_DEV_LISTENING, + if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_LISTENING, 0, NULL, 0) == -1) return -1; return (int)ps_root_readerror(ctx, NULL, 0); diff --git a/contrib/dhcpcd/src/privsep.c b/contrib/dhcpcd/src/privsep.c index 765756d766..b11c0351c2 100644 --- a/contrib/dhcpcd/src/privsep.c +++ b/contrib/dhcpcd/src/privsep.c @@ -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 rfd, unsigned short events, 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; } diff --git a/contrib/dhcpcd/src/privsep.h b/contrib/dhcpcd/src/privsep.h index a4289325ec..34d18dcf7b 100644 --- a/contrib/dhcpcd/src/privsep.h +++ b/contrib/dhcpcd/src/privsep.h @@ -113,6 +113,8 @@ #define PRIVSEP_RIGHTS #endif +#define PS_ROOT_FD(ctx) ((ctx)->ps_root ? (ctx)->ps_root->psp_fd : -1) + #ifdef __linux__ # include # if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) @@ -211,7 +213,7 @@ ssize_t ps_sendmsg(struct dhcpcd_ctx *, int, uint16_t, unsigned long, const struct msghdr *); ssize_t ps_sendcmd(struct dhcpcd_ctx *, int, uint16_t, unsigned long, const void *data, size_t len); -ssize_t ps_recvmsg(struct dhcpcd_ctx *, int, unsigned short, uint16_t, int); +ssize_t ps_recvmsg(int, unsigned short, uint16_t, int); ssize_t ps_recvpsmsg(struct dhcpcd_ctx *, int, unsigned short, ssize_t (*callback)(void *, struct ps_msghdr *, struct msghdr *), void *); diff --git a/contrib/dhcpcd/src/script.c b/contrib/dhcpcd/src/script.c index 94101d4d62..2ef99e38f7 100644 --- a/contrib/dhcpcd/src/script.c +++ b/contrib/dhcpcd/src/script.c @@ -764,7 +764,7 @@ script_runreason(const struct interface *ifp, const char *reason) #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; } -- 2.11.4.GIT