Update to dhcpcd-9.3.1 with the following changes:

* dhcpcd: carrier handling issue fixed from 9.3.0
 * dhcpcd: log if interface type is unsupported in debug
 * duid: memory leak fixed if UUID wanted but none available
 * privsep: fix receiving inet and no BPF running
 * privsep: allow gettimeofday for SECCOMP
 * privsep: fix stderr redirection again
This commit is contained in:
roy 2020-10-12 14:07:55 +00:00
parent b90aaaef64
commit b1246fe72f
19 changed files with 212 additions and 161 deletions

View File

@ -506,7 +506,7 @@ arp_announceaddr(struct dhcpcd_ctx *ctx, const struct in_addr *ia)
struct ipv4_addr *iap;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (!ifp->active || ifp->carrier <= LINK_DOWN)
if (!ifp->active || !if_is_link_up(ifp))
continue;
iap = ipv4_iffindaddr(ifp, ia, NULL);
if (iap == NULL)

View File

@ -29,7 +29,7 @@
#define CONFIG_H
#define PACKAGE "dhcpcd"
#define VERSION "9.3.0"
#define VERSION "9.3.1"
#ifndef PRIVSEP_USER
# define PRIVSEP_USER "_" PACKAGE

View File

@ -1712,7 +1712,7 @@ send_message(struct interface *ifp, uint8_t type,
if (callback == NULL) {
/* No carrier? Don't bother sending the packet. */
if (ifp->carrier <= LINK_DOWN)
if (!if_is_link_up(ifp))
return;
logdebugx("%s: sending %s with xid 0x%x",
ifp->name,
@ -1731,7 +1731,7 @@ send_message(struct interface *ifp, uint8_t type,
(arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC);
/* No carrier? Don't bother sending the packet.
* However, we do need to advance the timeout. */
if (ifp->carrier <= LINK_DOWN)
if (!if_is_link_up(ifp))
goto fail;
logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds",
ifp->name,
@ -2633,7 +2633,7 @@ dhcp_reboot(struct interface *ifp)
state->state = DHS_REBOOT;
state->interval = 0;
if (ifo->options & DHCPCD_LINK && ifp->carrier <= LINK_DOWN) {
if (ifo->options & DHCPCD_LINK && !if_is_link_up(ifp)) {
loginfox("%s: waiting for carrier", ifp->name);
return;
}
@ -2733,7 +2733,7 @@ dhcp_drop(struct interface *ifp, const char *reason)
state->state = DHS_RELEASE;
dhcp_unlink(ifp->ctx, state->leasefile);
if (ifp->carrier > LINK_DOWN &&
if (if_is_link_up(ifp) &&
state->new != NULL &&
state->lease.server.s_addr != INADDR_ANY)
{

View File

@ -1237,7 +1237,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
};
char uaddr[INET6_ADDRSTRLEN];
if (!callback && ifp->carrier <= LINK_DOWN)
if (!callback && !if_is_link_up(ifp))
return 0;
if (!IN6_IS_ADDR_UNSPECIFIED(&state->unicast)) {
@ -1298,7 +1298,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
+ (unsigned int)((float)state->RT
* ((float)lr / DHCP6_RAND_DIV));
if (ifp->carrier > LINK_DOWN)
if (if_is_link_up(ifp))
logdebugx("%s: %s %s (xid 0x%02x%02x%02x)%s%s,"
" next in %0.1f seconds",
ifp->name,
@ -1320,7 +1320,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
}
}
if (ifp->carrier <= LINK_DOWN)
if (!if_is_link_up(ifp))
return 0;
/* Update the elapsed time */
@ -2906,7 +2906,7 @@ dhcp6_delegate_prefix(struct interface *ifp)
if (ia->sla_len == 0) {
/* no SLA configured, so lets
* automate it */
if (ifd->carrier != LINK_UP) {
if (!if_is_link_up(ifd)) {
logdebugx(
"%s: has no carrier, cannot"
" delegate addresses",
@ -2922,7 +2922,7 @@ dhcp6_delegate_prefix(struct interface *ifp)
sla = &ia->sla[j];
if (strcmp(ifd->name, sla->ifname))
continue;
if (ifd->carrier != LINK_UP) {
if (!if_is_link_up(ifd)) {
logdebugx(
"%s: has no carrier, cannot"
" delegate addresses",
@ -4029,7 +4029,7 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason)
if (drop && options & DHCPCD_RELEASE &&
state->state != DH6S_DELEGATED)
{
if (ifp->carrier == LINK_UP &&
if (if_is_link_up(ifp) &&
state->state != DH6S_RELEASED &&
state->state != DH6S_INFORMED)
{

View File

@ -97,9 +97,6 @@ const int dhcpcd_signals_ignore[] = {
const size_t dhcpcd_signals_ignore_len = __arraycount(dhcpcd_signals_ignore);
#endif
#define IF_UPANDRUNNING(a) \
(((a)->flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING))
const char *dhcpcd_default_script = SCRIPT;
static void
@ -412,7 +409,7 @@ dhcpcd_drop(struct interface *ifp, int stop)
}
static void
stop_interface(struct interface *ifp)
stop_interface(struct interface *ifp, const char *reason)
{
struct dhcpcd_ctx *ctx;
@ -421,10 +418,7 @@ stop_interface(struct interface *ifp)
ifp->options->options |= DHCPCD_STOPPING;
dhcpcd_drop(ifp, 1);
if (ifp->options->options & DHCPCD_DEPARTED)
script_runreason(ifp, "DEPARTED");
else
script_runreason(ifp, "STOPPED");
script_runreason(ifp, reason == NULL ? "STOPPED" : reason);
/* Delete all timeouts for the interfaces */
eloop_q_timeout_delete(ctx->eloop, ELOOP_QUEUE_ALL, NULL, ifp);
@ -704,110 +698,108 @@ dhcpcd_reportssid(struct interface *ifp)
void
dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags)
{
bool nolink = ifp->options == NULL ||
!(ifp->options->options & DHCPCD_LINK);
bool was_link_up = if_is_link_up(ifp);
ifp->carrier = carrier;
ifp->flags = flags;
if (carrier == LINK_UNKNOWN) {
if (ifp->wireless)
carrier = LINK_DOWN;
else
carrier = IF_UPANDRUNNING(ifp) ? LINK_UP : LINK_DOWN;
}
if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
if (ifp->carrier != LINK_DOWN) {
if (!if_is_link_up(ifp)) {
if (!was_link_up || !ifp->active)
return;
loginfox("%s: carrier lost", ifp->name);
script_runreason(ifp, "NOCARRIER");
#ifdef NOCARRIER_PRESERVE_IP
if (ifp->flags & IFF_UP &&
(ifp->options == NULL ||
!(ifp->options->options & DHCPCD_ANONYMOUS)))
ifp->carrier = LINK_DOWN_IFFUP;
else
#endif
ifp->carrier = LINK_DOWN;
if (!ifp->active || nolink)
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))
{
if (ifp->flags & IFF_UP &&
!(ifp->options->options & DHCPCD_ANONYMOUS))
{
#ifdef ARP
arp_drop(ifp);
arp_drop(ifp);
#endif
#ifdef INET
dhcp_abort(ifp);
dhcp_abort(ifp);
#endif
#ifdef DHCP6
dhcp6_abort(ifp);
dhcp6_abort(ifp);
#endif
} else
} else
#endif
dhcpcd_drop(ifp, 0);
if (ifp->options->options & DHCPCD_ANONYMOUS) {
bool was_up = ifp->flags & IFF_UP;
dhcpcd_drop(ifp, 0);
if (ifp->options->options & DHCPCD_ANONYMOUS) {
bool is_up = ifp->flags & IFF_UP;
if (was_up)
if_down(ifp);
if (if_randomisemac(ifp) == -1 && errno != ENXIO)
logerr(__func__);
if (was_up)
if_up(ifp);
}
if (is_up)
if_down(ifp);
if (if_randomisemac(ifp) == -1 && errno != ENXIO)
logerr(__func__);
if (is_up)
if_up(ifp);
}
} else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
if (ifp->carrier != LINK_UP) {
ifp->carrier = LINK_UP;
if (ifp->active)
loginfox("%s: carrier acquired", ifp->name);
return;
}
/*
* At this point carrier is NOT DOWN and we have IFF_UP.
* We should treat LINK_UNKNOWN as up as the driver may not support
* link state changes.
* The consideration of any other information about carrier should
* be handled in the OS specific if_carrier() function.
*/
if (was_link_up)
return;
if (ifp->active) {
if (carrier == LINK_UNKNOWN)
loginfox("%s: carrier unknown, assuming up", ifp->name);
else
loginfox("%s: carrier acquired", ifp->name);
}
#if !defined(__linux__) && !defined(__NetBSD__)
/* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
* hardware address changes so we have to go
* through the disovery process to work it out. */
dhcpcd_handleinterface(ifp->ctx, 0, ifp->name);
/* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
* hardware address changes so we have to go
* through the disovery process to work it out. */
dhcpcd_handleinterface(ifp->ctx, 0, ifp->name);
#endif
if (ifp->wireless) {
uint8_t ossid[IF_SSIDLEN];
size_t olen;
olen = ifp->ssid_len;
memcpy(ossid, ifp->ssid, ifp->ssid_len);
if_getssid(ifp);
if (ifp->wireless) {
uint8_t ossid[IF_SSIDLEN];
size_t olen;
/* If we changed SSID network, drop leases */
if ((ifp->ssid_len != olen ||
memcmp(ifp->ssid, ossid, ifp->ssid_len)) &&
ifp->active)
{
dhcpcd_reportssid(ifp);
olen = ifp->ssid_len;
memcpy(ossid, ifp->ssid, ifp->ssid_len);
if_getssid(ifp);
/* If we changed SSID network, drop leases */
if ((ifp->ssid_len != olen ||
memcmp(ifp->ssid, ossid, ifp->ssid_len)) && ifp->active)
{
dhcpcd_reportssid(ifp);
#ifdef NOCARRIER_PRESERVE_IP
dhcpcd_drop(ifp, 0);
dhcpcd_drop(ifp, 0);
#endif
#ifdef IPV4LL
ipv4ll_reset(ifp);
ipv4ll_reset(ifp);
#endif
}
}
if (!ifp->active || nolink)
return;
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);
}
}
if (!ifp->active)
return;
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);
}
static void
@ -866,9 +858,7 @@ dhcpcd_startinterface(void *arg)
struct interface *ifp = arg;
struct if_options *ifo = ifp->options;
if (ifo->options & DHCPCD_LINK && (ifp->carrier == LINK_DOWN ||
(ifp->carrier == LINK_UNKNOWN && !IF_UPANDRUNNING(ifp))))
{
if (ifo->options & DHCPCD_LINK && !if_is_link_up(ifp)) {
loginfox("%s: waiting for carrier", ifp->name);
return;
}
@ -959,7 +949,7 @@ dhcpcd_prestartinterface(void *arg)
struct dhcpcd_ctx *ctx = ifp->ctx;
bool anondown;
if (ifp->carrier == LINK_DOWN &&
if (ifp->carrier <= LINK_DOWN &&
ifp->options->options & DHCPCD_ANONYMOUS &&
ifp->flags & IFF_UP)
{
@ -990,7 +980,7 @@ run_preinit(struct interface *ifp)
return;
script_runreason(ifp, "PREINIT");
if (ifp->wireless && ifp->carrier == LINK_UP)
if (ifp->wireless && if_is_link_up(ifp))
dhcpcd_reportssid(ifp);
if (ifp->options->options & DHCPCD_LINK && ifp->carrier != LINK_UNKNOWN)
script_runreason(ifp,
@ -1032,8 +1022,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
}
if (ifp->active) {
logdebugx("%s: interface departed", ifp->name);
ifp->options->options |= DHCPCD_DEPARTED;
stop_interface(ifp);
stop_interface(ifp, "DEPARTED");
}
TAILQ_REMOVE(ctx->ifaces, ifp, next);
if_free(ifp);
@ -1346,7 +1335,7 @@ stop_all_interfaces(struct dhcpcd_ctx *ctx, unsigned long long opts)
if (ifp->options->options & DHCPCD_RELEASE)
ifp->options->options &= ~DHCPCD_PERSISTENT;
ifp->options->options |= DHCPCD_EXITING;
stop_interface(ifp);
stop_interface(ifp, NULL);
}
}
@ -1357,8 +1346,7 @@ dhcpcd_ifrenew(struct interface *ifp)
if (!ifp->active)
return;
if (ifp->options->options & DHCPCD_LINK &&
ifp->carrier == LINK_DOWN)
if (ifp->options->options & DHCPCD_LINK && !if_is_link_up(ifp))
return;
#ifdef INET
@ -1599,7 +1587,7 @@ dumperr:
ifp->options->options |= opts;
if (opts & DHCPCD_RELEASE)
ifp->options->options &= ~DHCPCD_PERSISTENT;
stop_interface(ifp);
stop_interface(ifp, NULL);
}
return 0;
}
@ -1779,7 +1767,7 @@ dhcpcd_stderr_cb(void *arg)
}
int
main(int argc, char **argv)
main(int argc, char **argv, char **envp)
{
struct dhcpcd_ctx ctx;
struct ifaddrs *ifaddrs = NULL;
@ -1799,6 +1787,12 @@ main(int argc, char **argv)
size_t si;
#endif
#ifdef SETPROCTITLE_H
setproctitle_init(argc, argv, envp);
#else
UNUSED(envp);
#endif
/* Test for --help and --version */
if (argc > 1) {
if (strcmp(argv[1], "--help") == 0) {
@ -2258,7 +2252,7 @@ printpidfile:
ctx.fork_fd = fork_fd[1];
close(fork_fd[0]);
#ifdef PRIVSEP_RIGHTS
if (ps_rights_limit_fd(fork_fd[1]) == -1) {
if (ps_rights_limit_fd(ctx.fork_fd) == -1) {
logerr("ps_rights_limit_fdpair");
goto exit_failure;
}
@ -2301,14 +2295,12 @@ printpidfile:
break;
default:
setproctitle("[launcher]");
ctx.options |= DHCPCD_FORKED;
ctx.options |= DHCPCD_FORKED | DHCPCD_LAUNCHER;
ctx.fork_fd = fork_fd[0];
close(fork_fd[1]);
#ifdef PRIVSEP_RIGHTS
if (ps_rights_limit_fd(fork_fd[0]) == -1 ||
ps_rights_limit_fd(stderr_fd[0]) == 1)
{
logerr("ps_rights_limit_fdpair");
if (ps_rights_limit_fd(ctx.fork_fd) == -1) {
logerr("ps_rights_limit_fd");
goto exit_failure;
}
#endif
@ -2318,14 +2310,13 @@ printpidfile:
ctx.stderr_fd = stderr_fd[0];
close(stderr_fd[1]);
#ifdef PRIVSEP_RIGHTS
if (ps_rights_limit_fd(stderr_fd[0]) == 1) {
logerr("ps_rights_limit_fdpair");
if (ps_rights_limit_fd(ctx.stderr_fd) == 1) {
logerr("ps_rights_limit_fd");
goto exit_failure;
}
#endif
if (ctx.stderr_valid)
eloop_event_add(ctx.eloop, ctx.stderr_fd,
dhcpcd_stderr_cb, &ctx);
eloop_event_add(ctx.eloop, ctx.stderr_fd,
dhcpcd_stderr_cb, &ctx);
}
#ifdef PRIVSEP
if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1)
@ -2463,8 +2454,7 @@ printpidfile:
TAILQ_FOREACH(ifp, ctx.ifaces, next) {
if (ifp->active) {
run_preinit(ifp);
if (!(ifp->options->options & DHCPCD_LINK) ||
ifp->carrier != LINK_DOWN)
if (if_is_link_up(ifp))
opt = 1;
}
}
@ -2582,7 +2572,7 @@ exit1:
free(ctx.logfile);
free(ctx.ctl_buf);
#ifdef SETPROCTITLE_H
setproctitle_free();
setproctitle_fini();
#endif
#ifdef USE_SIGNALS
if (ctx.options & DHCPCD_STARTED) {

View File

@ -55,7 +55,6 @@
#define LINK_UP 1
#define LINK_UNKNOWN 0
#define LINK_DOWN -1
#define LINK_DOWN_IFFUP -2
#define IF_DATA_IPV4 0
#define IF_DATA_ARP 1

View File

@ -178,8 +178,9 @@ duid_get(struct dhcpcd_ctx *ctx, const struct interface *ifp)
if (ifp == NULL) {
if (ctx->duid_type != DUID_DEFAULT &&
ctx->duid_type != DUID_UUID)
return 0;
len = duid_make_uuid(data);
len = 0;
else
len = duid_make_uuid(data);
if (len == 0)
free(data);
else

View File

@ -385,7 +385,7 @@ static int if_indirect_ioctl(struct dhcpcd_ctx *ctx,
}
int
if_carrier(__unused struct interface *ifp, const void *ifadata)
if_carrier(struct interface *ifp, const void *ifadata)
{
const struct if_data *ifi = ifadata;
@ -398,8 +398,15 @@ if_carrier(__unused struct interface *ifp, const void *ifadata)
if (ifi->ifi_link_state >= LINK_STATE_UP)
return LINK_UP;
if (ifi->ifi_link_state == LINK_STATE_UNKNOWN)
if (ifi->ifi_link_state == LINK_STATE_UNKNOWN) {
/*
* Work around net80211 issues in some BSDs.
* Wireless MUST support link state change.
*/
if (ifp->wireless)
return LINK_DOWN;
return LINK_UNKNOWN;
}
return LINK_DOWN;
}

View File

@ -99,7 +99,7 @@
#define DHCPCD_NOALIAS (1ULL << 39)
#define DHCPCD_IA_FORCED (1ULL << 40)
#define DHCPCD_STOPPING (1ULL << 41)
#define DHCPCD_DEPARTED (1ULL << 42)
#define DHCPCD_LAUNCHER (1ULL << 42)
#define DHCPCD_HOSTNAME_SHORT (1ULL << 43)
#define DHCPCD_EXITING (1ULL << 44)
#define DHCPCD_WAITIP4 (1ULL << 45)

View File

@ -193,6 +193,17 @@ if_setflag(struct interface *ifp, short setflag, short unsetflag)
return 0;
}
bool
if_is_link_up(const struct interface *ifp)
{
return ifp->flags & IFF_UP &&
(ifp->carrier == LINK_UP ||
(ifp->carrier == LINK_UNKNOWN &&
!(ifp->options == NULL ||
ifp->options->options & DHCPCD_LINK)));
}
int
if_randomisemac(struct interface *ifp)
{
@ -411,11 +422,16 @@ if_check_arphrd(struct interface *ifp, unsigned int active, bool if_noconf)
}
break;
default:
if (if_noconf)
active = IF_INACTIVE;
if (active)
logwarnx("%s: unsupported interface type 0x%.2x",
if (active) {
int i;
if (if_noconf)
active = IF_INACTIVE;
i = active ? LOG_WARNING : LOG_DEBUG;
logmessage(i, "%s: unsupported"
" interface type 0x%.2x",
ifp->name, ifp->hwtype);
}
break;
}
@ -621,12 +637,14 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
#endif
default:
/* Don't allow unless explicit */
if (if_noconf)
active = IF_INACTIVE;
if (active)
logwarnx("%s: unsupported"
if (active) {
if (if_noconf)
active = IF_INACTIVE;
i = active ? LOG_WARNING : LOG_DEBUG;
logmessage(i, "%s: unsupported"
" interface type 0x%.2x",
ifp->name, sdl->sdl_type);
}
/* Pretend it's ethernet */
ifp->hwtype = ARPHRD_ETHER;
break;

View File

@ -146,6 +146,7 @@ int if_getflags(struct interface *);
int if_setflag(struct interface *, short, short);
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
#define if_down(ifp) if_setflag((ifp), 0, IFF_UP);
bool if_is_link_up(const struct interface *);
bool if_valid_hwaddr(const uint8_t *, size_t);
struct if_head *if_discover(struct dhcpcd_ctx *, struct ifaddrs **,
int, char * const *);

View File

@ -105,7 +105,7 @@
defined(IFF_NOLINKLOCAL)
/* Only add the LL address if we have a carrier, so DaD works. */
#define CAN_ADD_LLADDR(ifp) \
(!((ifp)->options->options & DHCPCD_LINK) || (ifp)->carrier != LINK_DOWN)
(!((ifp)->options->options & DHCPCD_LINK) || if_is_link_up((ifp)))
#ifdef __sun
/* Although we can add our own LL address, we cannot drop it
* without unplumbing the if which is a lot of code.

View File

@ -437,7 +437,7 @@ ipv6nd_sendadvertisement(void *arg)
const struct rs_state *state = RS_CSTATE(ifp);
int s;
if (state == NULL || ifp->carrier <= LINK_DOWN)
if (state == NULL || !if_is_link_up(ifp))
goto freeit;
#ifdef SIN6_LEN
@ -505,7 +505,7 @@ ipv6nd_advertise(struct ipv6_addr *ia)
iaf = NULL;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
state = IPV6_STATE(ifp);
if (state == NULL || ifp->carrier <= LINK_DOWN)
if (state == NULL || !if_is_link_up(ifp))
continue;
TAILQ_FOREACH(iap, &state->addrs, next) {

View File

@ -366,20 +366,24 @@ int
logopen(const char *path)
{
struct logctx *ctx = &_logctx;
int opts = 0;
/* Cache timezone */
tzset();
(void)setvbuf(stderr, ctx->log_buf, _IOLBF, sizeof(ctx->log_buf));
if (path == NULL) {
int opts = 0;
if (ctx->log_opts & LOGERR_LOG_PID)
opts |= LOG_PID;
openlog(NULL, opts, LOGERR_SYSLOG_FACILITY);
if (!(ctx->log_opts & LOGERR_LOG))
return 1;
#ifdef LOG_NDELAY
opts |= LOG_NDELAY;
#endif
if (ctx->log_opts & LOGERR_LOG_PID)
opts |= LOG_PID;
openlog(NULL, opts, LOGERR_SYSLOG_FACILITY);
if (path == NULL)
return 1;
}
#ifndef SMALL
if ((ctx->log_file = fopen(path, "ae")) == NULL)

View File

@ -253,6 +253,17 @@ ps_bpf_dispatch(struct dhcpcd_ctx *ctx,
uint8_t *bpf;
size_t bpf_len;
switch (psm->ps_cmd) {
#ifdef ARP
case PS_BPF_ARP:
#endif
case PS_BPF_BOOTP:
break;
default:
errno = ENOTSUP;
return -1;
}
ifp = if_findindex(ctx->ifaces, psm->ps_id.psi_ifindex);
/* interface may have departed .... */
if (ifp == NULL)
@ -270,9 +281,6 @@ ps_bpf_dispatch(struct dhcpcd_ctx *ctx,
case PS_BPF_BOOTP:
dhcp_packet(ifp, bpf, bpf_len, (unsigned int)psm->ps_flags);
break;
default:
errno = ENOTSUP;
return -1;
}
return 1;

View File

@ -89,6 +89,28 @@ ps_inet_recvdhcp6(void *arg)
}
#endif
bool
ps_inet_canstart(const struct dhcpcd_ctx *ctx)
{
#ifdef INET
if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MASTER)) ==
(DHCPCD_IPV4 | DHCPCD_MASTER))
return true;
#endif
#if defined(INET6) && !defined(__sun)
if (ctx->options & DHCPCD_IPV6)
return true;
#endif
#ifdef DHCP6
if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MASTER)) ==
(DHCPCD_IPV6 | DHCPCD_MASTER))
return true;
#endif
return false;
}
static int
ps_inet_startcb(void *arg)
{

View File

@ -29,6 +29,7 @@
#ifndef PRIVSEP_INET_H
#define PRIVSEP_INET_H
bool ps_inet_canstart(const struct dhcpcd_ctx *);
pid_t ps_inet_start(struct dhcpcd_ctx *);
int ps_inet_stop(struct dhcpcd_ctx *);
ssize_t ps_inet_cmd(struct dhcpcd_ctx *, struct ps_msghdr *, struct msghdr *);

View File

@ -116,7 +116,7 @@ ps_dropprivs(struct dhcpcd_ctx *ctx)
{
struct passwd *pw = ctx->ps_user;
if (!(ctx->options & DHCPCD_FORKED))
if (ctx->options & DHCPCD_LAUNCHER)
logdebugx("chrooting as %s to %s", pw->pw_name, pw->pw_dir);
if (chroot(pw->pw_dir) == -1 &&
(errno != EPERM || ctx->options & DHCPCD_FORKED))
@ -166,7 +166,10 @@ ps_dropprivs(struct dhcpcd_ctx *ctx)
/* Prohibit writing to files.
* Obviously this won't work if we are using a logfile
* or redirecting stderr to a file. */
if (ctx->logfile == NULL) {
if (ctx->logfile == NULL &&
(ctx->options & DHCPCD_STARTED ||
!ctx->stderr_valid || isatty(STDERR_FILENO) == 1))
{
if (setrlimit(RLIMIT_FSIZE, &rzero) == -1)
logerr("setrlimit RLIMIT_FSIZE");
}
@ -467,13 +470,11 @@ ps_start(struct dhcpcd_ctx *ctx)
/* No point in spawning the generic network listener if we're
* not going to use it. */
if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_IPV6)))
if (!ps_inet_canstart(ctx))
goto started_net;
switch (pid = ps_inet_start(ctx)) {
case -1:
if (errno == ENXIO)
return 0;
return -1;
case 0:
return 0;
@ -566,7 +567,7 @@ ps_mastersandbox(struct dhcpcd_ctx *ctx, const char *_pledge)
}
logerr("%s: %s", __func__, sandbox);
return -1;
} else if (!forked)
} else if (ctx->options & DHCPCD_LAUNCHER)
logdebugx("sandbox: %s", sandbox);
return 0;
}

View File

@ -589,7 +589,6 @@ send_interface(struct fd_list *fd, const struct interface *ifp, int af)
reason = "CARRIER";
break;
case LINK_DOWN:
case LINK_DOWN_IFFUP:
reason = "NOCARRIER";
break;
default: