From 0a68f8d2f3ef09a749f1642df0491f8f92f54ec3 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 22 Oct 2021 14:48:37 +0100 Subject: [PATCH] Update to dhcpcd-9.4.1 with the following changes: * BSD: Find the correct interface for tunnelled routes * OpenBSD: Fix uniqueness of routes for matching priorities * Linux: Support more platforms for seccomp (thanks to Fabrice Fontaine) * eloop: Process all waiting fd's as they come in * control: Unlink sockets when not in privsep * privsep: Renamed Master to Manager * privsep: Renamed Privilged Actioneer to Privileged Proxy * privsep: Fix getting interface VLANID on BSD * privsep: Enforce proper alignment of serialized struct cmsghdr * IPv4LL: Don't remove statically assigned addresses * routes: Fix route comparision for network prefixes with different masks * DHCP6: Only send FQDN for SOLICIT, REQUEST, RENEW, or REBIND messages * DHCP6: Don't spam the log when a RA repeatedly triggers an INFORM * DHCP: Fix infinite INFORM messages --- contrib/dhcpcd/LICENSE | 2 +- contrib/dhcpcd/README.md | 12 +- .../hooks/{30-hostname.in => 30-hostname} | 2 +- .../dhcpcd/hooks/{50-ypbind.in => 50-ypbind} | 5 +- .../{dhcpcd-run-hooks.in => dhcpcd-run-hooks} | 16 +-- ...cpcd-run-hooks.8.in => dhcpcd-run-hooks.8} | 16 +-- contrib/dhcpcd/src/arp.c | 2 +- contrib/dhcpcd/src/arp.h | 2 +- contrib/dhcpcd/src/auth.c | 2 +- contrib/dhcpcd/src/auth.h | 2 +- contrib/dhcpcd/src/bpf.c | 2 +- contrib/dhcpcd/src/bpf.h | 2 +- contrib/dhcpcd/src/common.c | 2 +- contrib/dhcpcd/src/common.h | 2 +- contrib/dhcpcd/src/control.c | 21 +-- contrib/dhcpcd/src/control.h | 2 +- contrib/dhcpcd/src/defs.h | 4 +- contrib/dhcpcd/src/dev.h | 2 +- contrib/dhcpcd/src/dhcp-common.c | 2 +- contrib/dhcpcd/src/dhcp-common.h | 2 +- contrib/dhcpcd/src/dhcp.c | 44 +++--- contrib/dhcpcd/src/dhcp.h | 2 +- contrib/dhcpcd/src/dhcp6.c | 125 +++++++++++------- contrib/dhcpcd/src/dhcp6.h | 3 +- contrib/dhcpcd/src/dhcpcd-embedded.c | 2 +- contrib/dhcpcd/src/dhcpcd-embedded.h | 2 +- contrib/dhcpcd/src/{dhcpcd.8.in => dhcpcd.8} | 89 +++++++------ contrib/dhcpcd/src/dhcpcd.c | 54 ++++---- .../src/{dhcpcd.conf.5.in => dhcpcd.conf.5} | 21 +-- contrib/dhcpcd/src/dhcpcd.h | 4 +- contrib/dhcpcd/src/duid.c | 2 +- contrib/dhcpcd/src/duid.h | 2 +- contrib/dhcpcd/src/eloop.c | 58 +++++--- contrib/dhcpcd/src/eloop.h | 2 +- contrib/dhcpcd/src/if-bsd.c | 5 +- contrib/dhcpcd/src/if-options.c | 22 +-- contrib/dhcpcd/src/if-options.h | 4 +- contrib/dhcpcd/src/if.c | 2 +- contrib/dhcpcd/src/if.h | 2 +- contrib/dhcpcd/src/ipv4.c | 33 ++++- contrib/dhcpcd/src/ipv4.h | 4 +- contrib/dhcpcd/src/ipv4ll.c | 2 +- contrib/dhcpcd/src/ipv4ll.h | 2 +- contrib/dhcpcd/src/ipv6.c | 4 +- contrib/dhcpcd/src/ipv6.h | 2 +- contrib/dhcpcd/src/ipv6nd.c | 2 +- contrib/dhcpcd/src/ipv6nd.h | 2 +- contrib/dhcpcd/src/logerr.c | 9 +- contrib/dhcpcd/src/logerr.h | 2 +- contrib/dhcpcd/src/privsep-bpf.c | 4 +- contrib/dhcpcd/src/privsep-bpf.h | 2 +- contrib/dhcpcd/src/privsep-bsd.c | 12 +- contrib/dhcpcd/src/privsep-control.c | 6 +- contrib/dhcpcd/src/privsep-control.h | 2 +- contrib/dhcpcd/src/privsep-inet.c | 20 +-- contrib/dhcpcd/src/privsep-inet.h | 2 +- contrib/dhcpcd/src/privsep-root.c | 16 +-- contrib/dhcpcd/src/privsep-root.h | 2 +- contrib/dhcpcd/src/privsep.c | 71 +++++++--- contrib/dhcpcd/src/privsep.h | 6 +- contrib/dhcpcd/src/route.c | 30 +++-- contrib/dhcpcd/src/route.h | 2 +- contrib/dhcpcd/src/sa.c | 2 +- contrib/dhcpcd/src/sa.h | 2 +- contrib/dhcpcd/src/script.c | 5 +- contrib/dhcpcd/src/script.h | 2 +- 66 files changed, 465 insertions(+), 330 deletions(-) rename contrib/dhcpcd/hooks/{30-hostname.in => 30-hostname} (98%) rename contrib/dhcpcd/hooks/{50-ypbind.in => 50-ypbind} (95%) rename contrib/dhcpcd/hooks/{dhcpcd-run-hooks.in => dhcpcd-run-hooks} (97%) rename contrib/dhcpcd/hooks/{dhcpcd-run-hooks.8.in => dhcpcd-run-hooks.8} (96%) rename contrib/dhcpcd/src/{dhcpcd.8.in => dhcpcd.8} (92%) rename contrib/dhcpcd/src/{dhcpcd.conf.5.in => dhcpcd.conf.5} (98%) diff --git a/contrib/dhcpcd/LICENSE b/contrib/dhcpcd/LICENSE index b4396ea4b0..aba8b6aa6b 100644 --- a/contrib/dhcpcd/LICENSE +++ b/contrib/dhcpcd/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2006-2020 Roy Marples +Copyright (c) 2006-2021 Roy Marples All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/README.md b/contrib/dhcpcd/README.md index 7d760e3676..751ea3d440 100644 --- a/contrib/dhcpcd/README.md +++ b/contrib/dhcpcd/README.md @@ -22,14 +22,9 @@ to ensure they can co-exist. See [BUILDING.md](BUILDING.md) for how to build dhcpcd. -If you wish to file a support ticket or help out with development, please -[visit the Development Area](https://dev.marples.name/project/profile/101/) -or join the mailing list below. - ## Configuration -You should read the -[dhcpcd.conf man page](http://roy.marples.name/man/html5/dhcpcd.conf.html) +You should read the dhcpcd.conf man page and put your options into `/etc/dhcpcd.conf`. The default configuration file should work for most people just fine. Here it is, in case you lose it. @@ -78,7 +73,8 @@ require dhcp_server_identifier slaac private ``` -The [dhcpcd man page](/man/html8/dhcpcd.html) has a lot of the same options and more, which only apply to calling dhcpcd from the command line. +The dhcpcd man page has a lot of the same options and more, +which only apply to calling dhcpcd from the command line. ## Compatibility @@ -96,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](http://roy.marples.name/git/dhcpcd.git/log/) and +[commit log](https://roy.marples.name/git/dhcpcd/log) and [archived release announcements](http://roy.marples.name/archives/dhcpcd-discuss/). diff --git a/contrib/dhcpcd/hooks/30-hostname.in b/contrib/dhcpcd/hooks/30-hostname similarity index 98% rename from contrib/dhcpcd/hooks/30-hostname.in rename to contrib/dhcpcd/hooks/30-hostname index abeb369672..eda367e6c1 100644 --- a/contrib/dhcpcd/hooks/30-hostname.in +++ b/contrib/dhcpcd/hooks/30-hostname @@ -17,7 +17,7 @@ # If we used to set the hostname, but relinquish control of it, we should # reset to the default value. -: ${hostname_default=@DEFAULT_HOSTNAME@} +: ${hostname_default=} # Some systems don't have hostname(1) _hostname() diff --git a/contrib/dhcpcd/hooks/50-ypbind.in b/contrib/dhcpcd/hooks/50-ypbind similarity index 95% rename from contrib/dhcpcd/hooks/50-ypbind.in rename to contrib/dhcpcd/hooks/50-ypbind index 09a12b97dc..5bdb7b76fc 100644 --- a/contrib/dhcpcd/hooks/50-ypbind.in +++ b/contrib/dhcpcd/hooks/50-ypbind @@ -4,9 +4,8 @@ : ${ypbind_restart_cmd:=service_command ypbind restart} : ${ypbind_stop_cmd:=service_condcommand ypbind stop} ypbind_dir="$state_dir/ypbind" -: ${ypdomain_dir:=@YPDOMAIN_DIR@} -: ${ypdomain_suffix:=@YPDOMAIN_SUFFIX@} - +: ${ypdomain_dir:=} +: ${ypdomain_suffix:=} best_domain() { diff --git a/contrib/dhcpcd/hooks/dhcpcd-run-hooks.in b/contrib/dhcpcd/hooks/dhcpcd-run-hooks similarity index 97% rename from contrib/dhcpcd/hooks/dhcpcd-run-hooks.in rename to contrib/dhcpcd/hooks/dhcpcd-run-hooks index a237f6af53..c1c717603b 100644 --- a/contrib/dhcpcd/hooks/dhcpcd-run-hooks.in +++ b/contrib/dhcpcd/hooks/dhcpcd-run-hooks @@ -8,7 +8,7 @@ signature_base="# Generated by dhcpcd" signature="$signature_base $from $ifname" signature_base_end="# End of dhcpcd" signature_end="$signature_base_end $from $ifname" -state_dir=@RUNDIR@/hook-state +state_dir=/var/run/dhcpcd/hook-state _detected_init=false : ${if_up:=false} @@ -215,9 +215,9 @@ valid_domainname_list() # using unless overridden by configure. detect_init() { - _service_exists="@SERVICEEXISTS@" - _service_cmd="@SERVICECMD@" - _service_status="@SERVICESTATUS@" + _service_exists="" + _service_cmd="" + _service_status="" [ -n "$_service_cmd" ] && return 0 @@ -229,7 +229,7 @@ detect_init() # Detect the running init system. # As systemd and OpenRC can be installed on top of legacy init # systems we try to detect them first. - status="@STATUSARG@" + status="onestatus" : ${status:=status} if [ -x /bin/systemctl ] && [ -S /run/systemd/private ]; then _service_exists="/bin/systemctl --quiet is-enabled \$1.service" @@ -334,9 +334,9 @@ service_condcommand() # Thus, the user can create their dhcpcd.enter/exit-hook script to configure # /etc/resolv.conf how they want and stop the system scripts ever updating it. for hook in \ - @SYSCONFDIR@/dhcpcd.enter-hook \ - @HOOKDIR@/* \ - @SYSCONFDIR@/dhcpcd.exit-hook + /etc/dhcpcd.enter-hook \ + /usr/libexec/dhcpcd-hooks/* \ + /etc/dhcpcd.exit-hook do for skip in $skip_hooks; do case "$hook" in diff --git a/contrib/dhcpcd/hooks/dhcpcd-run-hooks.8.in b/contrib/dhcpcd/hooks/dhcpcd-run-hooks.8 similarity index 96% rename from contrib/dhcpcd/hooks/dhcpcd-run-hooks.8.in rename to contrib/dhcpcd/hooks/dhcpcd-run-hooks.8 index 9b5483a420..137db84d7f 100644 --- a/contrib/dhcpcd/hooks/dhcpcd-run-hooks.8.in +++ b/contrib/dhcpcd/hooks/dhcpcd-run-hooks.8 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2006-2020 Roy Marples +.\" Copyright (c) 2006-2021 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -34,11 +34,11 @@ is used by .Xr dhcpcd 8 to run any system and user defined hook scripts. System hook scripts are found in -.Pa @HOOKDIR@ +.Pa /usr/libexec/dhcpcd-hooks and the user defined hooks are -.Pa @SYSCONFDIR@/dhcpcd.enter-hook . +.Pa /etc/dhcpcd.enter-hook . and -.Pa @SYSCONFDIR@/dhcpcd.exit-hook . +.Pa /etc/dhcpcd.exit-hook . The default install supplies hook scripts for configuring .Pa /etc/resolv.conf and the hostname. @@ -50,7 +50,7 @@ console from DISCOVER message. The hooks scripts are loaded into the current shell rather than executed in their own process. This allows each hook script, such as -.Pa @SYSCONFDIR@/dhcpcd.enter-hook +.Pa /etc/dhcpcd.enter-hook to customise environment variables or provide alternative functions to hooks further down the chain. As such, using the shell builtins @@ -213,11 +213,11 @@ space separated list of delegated prefixes. When .Nm runs, it loads -.Pa @SYSCONFDIR@/dhcpcd.enter-hook +.Pa /etc/dhcpcd.enter-hook and any scripts found in -.Pa @HOOKDIR@ +.Pa /usr/libexec/dhcpcd-hooks in a lexical order and then finally -.Pa @SYSCONFDIR@/dhcpcd.exit-hook +.Pa /etc/dhcpcd.exit-hook .Sh SEE ALSO .Xr dhcpcd 8 .Sh AUTHORS diff --git a/contrib/dhcpcd/src/arp.c b/contrib/dhcpcd/src/arp.c index 6f24ebf73f..e8a27f4225 100644 --- a/contrib/dhcpcd/src/arp.c +++ b/contrib/dhcpcd/src/arp.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - ARP handler - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/arp.h b/contrib/dhcpcd/src/arp.h index e8da0fb866..0ac8ef7116 100644 --- a/contrib/dhcpcd/src/arp.h +++ b/contrib/dhcpcd/src/arp.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/auth.c b/contrib/dhcpcd/src/auth.c index b7891b6877..bfb2b5dda5 100644 --- a/contrib/dhcpcd/src/auth.c +++ b/contrib/dhcpcd/src/auth.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/auth.h b/contrib/dhcpcd/src/auth.h index 30cc38b33a..c6eb428512 100644 --- a/contrib/dhcpcd/src/auth.h +++ b/contrib/dhcpcd/src/auth.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/bpf.c b/contrib/dhcpcd/src/bpf.c index 9e85dbe24e..21b73af207 100644 --- a/contrib/dhcpcd/src/bpf.c +++ b/contrib/dhcpcd/src/bpf.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd: BPF arp and bootp filtering - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/bpf.h b/contrib/dhcpcd/src/bpf.h index 866ae23c0d..40da95e61e 100644 --- a/contrib/dhcpcd/src/bpf.h +++ b/contrib/dhcpcd/src/bpf.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd: BPF arp and bootp filtering - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/common.c b/contrib/dhcpcd/src/common.c index c60d98463a..bb89100ef2 100644 --- a/contrib/dhcpcd/src/common.c +++ b/contrib/dhcpcd/src/common.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/common.h b/contrib/dhcpcd/src/common.h index 77efb7ae4e..ff8f3f8b94 100644 --- a/contrib/dhcpcd/src/common.h +++ b/contrib/dhcpcd/src/common.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/control.c b/contrib/dhcpcd/src/control.c index 71405ed167..4d768d887b 100644 --- a/contrib/dhcpcd/src/control.c +++ b/contrib/dhcpcd/src/control.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -50,7 +50,7 @@ #ifndef SUN_LEN #define SUN_LEN(su) \ - (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) #endif static void @@ -84,7 +84,8 @@ control_free(struct fd_list *fd) fd->ctx->ps_control_client = NULL; #endif - eloop_event_remove_writecb(fd->ctx->eloop, fd->fd); + if (eloop_event_remove_writecb(fd->ctx->eloop, fd->fd) == -1) + logerr(__func__); TAILQ_REMOVE(&fd->ctx->control_fds, fd, next); control_queue_free(fd); free(fd); @@ -350,12 +351,12 @@ control_start1(struct dhcpcd_ctx *ctx, const char *ifname, sa_family_t family, } #endif - if ((fmode & S_PRIV) == S_PRIV) - strlcpy(ctx->control_sock, sa.sun_path, - sizeof(ctx->control_sock)); - else + if ((fmode & S_UNPRIV) == S_UNPRIV) strlcpy(ctx->control_sock_unpriv, sa.sun_path, sizeof(ctx->control_sock_unpriv)); + else + strlcpy(ctx->control_sock, sa.sun_path, + sizeof(ctx->control_sock)); return fd; } @@ -368,7 +369,8 @@ control_start(struct dhcpcd_ctx *ctx, const char *ifname, sa_family_t family) if (IN_PRIVSEP_SE(ctx)) { make_path(ctx->control_sock, sizeof(ctx->control_sock), ifname, family, false); - make_path(ctx->control_sock_unpriv, sizeof(ctx->control_sock), + make_path(ctx->control_sock_unpriv, + sizeof(ctx->control_sock_unpriv), ifname, family, true); return 0; } @@ -528,7 +530,8 @@ control_writeone(void *arg) if (TAILQ_FIRST(&fd->queue) != NULL) return; - eloop_event_remove_writecb(fd->ctx->eloop, fd->fd); + if (eloop_event_remove_writecb(fd->ctx->eloop, fd->fd) == -1) + logerr(__func__); #ifdef PRIVSEP if (IN_PRIVSEP_SE(fd->ctx) && !(fd->flags & FD_LISTEN)) { if (ps_ctl_sendeof(fd) == -1) diff --git a/contrib/dhcpcd/src/control.h b/contrib/dhcpcd/src/control.h index 606f94b69d..110b0a7b2f 100644 --- a/contrib/dhcpcd/src/control.h +++ b/contrib/dhcpcd/src/control.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/defs.h b/contrib/dhcpcd/src/defs.h index 39f14a87d7..cde76f8857 100644 --- a/contrib/dhcpcd/src/defs.h +++ b/contrib/dhcpcd/src/defs.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,7 +29,7 @@ #define CONFIG_H #define PACKAGE "dhcpcd" -#define VERSION "9.4.0" +#define VERSION "9.4.1" #ifndef PRIVSEP_USER # define PRIVSEP_USER "_" PACKAGE diff --git a/contrib/dhcpcd/src/dev.h b/contrib/dhcpcd/src/dev.h index 3bfb57291d..e7263c5b87 100644 --- a/contrib/dhcpcd/src/dev.h +++ b/contrib/dhcpcd/src/dev.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/contrib/dhcpcd/src/dhcp-common.c b/contrib/dhcpcd/src/dhcp-common.c index 4f0dbd6381..dbcfcc564d 100644 --- a/contrib/dhcpcd/src/dhcp-common.c +++ b/contrib/dhcpcd/src/dhcp-common.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/dhcp-common.h b/contrib/dhcpcd/src/dhcp-common.h index 7be821f0ba..a82fcd4cec 100644 --- a/contrib/dhcpcd/src/dhcp-common.h +++ b/contrib/dhcpcd/src/dhcp-common.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/dhcp.c b/contrib/dhcpcd/src/dhcp.c index e13c63e52b..fbed2f3ca2 100644 --- a/contrib/dhcpcd/src/dhcp.c +++ b/contrib/dhcpcd/src/dhcp.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -2031,14 +2031,14 @@ dhcp_finish_dad(struct interface *ifp, struct in_addr *ia) #ifdef IPV4LL /* Stop IPv4LL now we have a working DHCP address */ - ipv4ll_drop(ifp); + if (!IN_LINKLOCAL(ntohl(ia->s_addr))) + ipv4ll_drop(ifp); #endif if (ifp->options->options & DHCPCD_INFORM) dhcp_inform(ifp); } - static bool dhcp_addr_duplicated(struct interface *ifp, struct in_addr *ia) { @@ -2069,7 +2069,7 @@ dhcp_addr_duplicated(struct interface *ifp, struct in_addr *ia) if (opts & (DHCPCD_STATIC | DHCPCD_INFORM)) { state->reason = "EXPIRE"; script_runreason(ifp, state->reason); -#define NOT_ONLY_SELF (DHCPCD_MASTER | DHCPCD_IPV6RS | DHCPCD_DHCP6) +#define NOT_ONLY_SELF (DHCPCD_MANAGER | DHCPCD_IPV6RS | DHCPCD_DHCP6) if (!(ctx->options & NOT_ONLY_SELF)) eloop_exit(ifp->ctx->eloop, EXIT_FAILURE); return deleted; @@ -2380,8 +2380,9 @@ dhcp_bind(struct interface *ifp) dhcp_closebpf(ifp); openudp: - /* If not in master mode, open an address specific socket. */ - if (ctx->options & DHCPCD_MASTER || + /* If not in manager mode, open an address specific socket. */ + if (ctx->options & DHCPCD_MANAGER || + ifo->options & DHCPCD_STATIC || (state->old != NULL && state->old->yiaddr == state->new->yiaddr && old_state & STATE_ADDED && !(old_state & STATE_FAKE))) @@ -2399,7 +2400,7 @@ openudp: state->udp_rfd = dhcp_openudp(&state->addr->addr); if (state->udp_rfd == -1) { logerr(__func__); - /* Address sharing without master mode is not supported. + /* Address sharing without manager mode is not supported. * It's also possible another DHCP client could be running, * which is even worse. * We still need to work, so re-open BPF. */ @@ -2569,7 +2570,6 @@ dhcp_inform(struct interface *ifp) state = D_STATE(ifp); ifo = ifp->options; - state->state = DHS_INFORM; free(state->offer); state->offer = NULL; state->offer_len = 0; @@ -2610,6 +2610,7 @@ dhcp_inform(struct interface *ifp) } } + state->state = DHS_INFORM; state->addr = ia; state->offer_len = dhcp_message_new(&state->offer, &ia->addr, &ia->mask); @@ -3952,9 +3953,9 @@ dhcp_start1(void *arg) /* Listen on *.*.*.*:bootpc so that the kernel never sends an * ICMP port unreachable message back to the DHCP server. - * Only do this in master mode so we don't swallow messages + * Only do this in manager mode so we don't swallow messages * for dhcpcd running on another interface. */ - if ((ctx->options & (DHCPCD_MASTER|DHCPCD_PRIVSEP)) == DHCPCD_MASTER + if ((ctx->options & (DHCPCD_MANAGER|DHCPCD_PRIVSEP)) == DHCPCD_MANAGER && ctx->udp_rfd == -1) { ctx->udp_rfd = dhcp_openudp(NULL); @@ -4244,7 +4245,7 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) #ifdef PRIVSEP if (IN_PRIVSEP_SE(ifp->ctx) && - !(ifp->ctx->options & (DHCPCD_MASTER | DHCPCD_CONFIGURE)) && + !(ifp->ctx->options & (DHCPCD_MANAGER | DHCPCD_CONFIGURE)) && IN_ARE_ADDR_EQUAL(&state->lease.addr, &ia->addr)) { state->addr = ia; @@ -4255,37 +4256,38 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) } #endif + /* If we have requested a specific address, return now. + * The below code is only for when inform or static has been + * requested without a specific address. */ + if (ifo->req_addr.s_addr != INADDR_ANY) + return ia; + + /* Only inform if we are NOT in the inform state or bound. */ if (ifo->options & DHCPCD_INFORM) { - if (state->state != DHS_INFORM) + if (state->state != DHS_INFORM && state->state != DHS_BOUND) dhcp_inform(ifp); return ia; } + /* Static and inform are mutually exclusive. If not static, return. */ if (!(ifo->options & DHCPCD_STATIC)) return ia; - if (ifo->req_addr.s_addr != INADDR_ANY) - return ia; free(state->old); state->old = state->new; state->new_len = dhcp_message_new(&state->new, &ia->addr, &ia->mask); if (state->new == NULL) return ia; + if (ifp->flags & IFF_POINTOPOINT) { for (i = 1; i < 255; i++) if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i)) dhcp_message_add_addr(state->new, i, ia->brd); } + state->reason = "STATIC"; rt_build(ifp->ctx, AF_INET); script_runreason(ifp, state->reason); - if (ifo->options & DHCPCD_INFORM) { - state->state = DHS_INFORM; - dhcp_new_xid(ifp); - state->lease.server.s_addr = INADDR_ANY; - state->addr = ia; - dhcp_inform(ifp); - } return ia; } diff --git a/contrib/dhcpcd/src/dhcp.h b/contrib/dhcpcd/src/dhcp.h index d0f569d59e..9359d564da 100644 --- a/contrib/dhcpcd/src/dhcp.h +++ b/contrib/dhcpcd/src/dhcp.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/dhcp6.c b/contrib/dhcpcd/src/dhcp6.c index 176a12e4df..21198c42c0 100644 --- a/contrib/dhcpcd/src/dhcp6.c +++ b/contrib/dhcpcd/src/dhcp6.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -637,7 +637,7 @@ dhcp6_makemessage(struct interface *ifp) uint8_t type; uint16_t si_len, uni_len, n_options; uint8_t *o_lenp; - struct if_options *ifo; + struct if_options *ifo = ifp->options; const struct dhcp_opt *opt, *opt2; const struct ipv6_addr *ap; char hbuf[HOSTNAME_MAX_LEN + 1]; @@ -658,8 +658,50 @@ dhcp6_makemessage(struct interface *ifp) state->send = NULL; } - ifo = ifp->options; - fqdn = ifo->fqdn; + switch(state->state) { + case DH6S_INIT: /* FALLTHROUGH */ + case DH6S_DISCOVER: + type = DHCP6_SOLICIT; + break; + case DH6S_REQUEST: + type = DHCP6_REQUEST; + break; + case DH6S_CONFIRM: + type = DHCP6_CONFIRM; + break; + case DH6S_REBIND: + type = DHCP6_REBIND; + break; + case DH6S_RENEW: + type = DHCP6_RENEW; + break; + case DH6S_INFORM: + type = DHCP6_INFORMATION_REQ; + break; + case DH6S_RELEASE: + type = DHCP6_RELEASE; + break; + case DH6S_DECLINE: + type = DHCP6_DECLINE; + break; + default: + errno = EINVAL; + return -1; + } + + /* RFC 4704 Section 5 says we can only send FQDN for these + * message types. */ + switch(type) { + case DHCP6_SOLICIT: + case DHCP6_REQUEST: + case DHCP6_RENEW: + case DHCP6_REBIND: + fqdn = ifo->fqdn; + break; + default: + fqdn = FQDN_DISABLE; + break; + } if (fqdn == FQDN_DISABLE && ifo->options & DHCPCD_HOSTNAME) { /* We're sending the DHCPv4 hostname option, so send FQDN as @@ -822,37 +864,6 @@ dhcp6_makemessage(struct interface *ifp) ml = state->new_len; } - switch(state->state) { - case DH6S_INIT: /* FALLTHROUGH */ - case DH6S_DISCOVER: - type = DHCP6_SOLICIT; - break; - case DH6S_REQUEST: - type = DHCP6_REQUEST; - break; - case DH6S_CONFIRM: - type = DHCP6_CONFIRM; - break; - case DH6S_REBIND: - type = DHCP6_REBIND; - break; - case DH6S_RENEW: - type = DHCP6_RENEW; - break; - case DH6S_INFORM: - type = DHCP6_INFORMATION_REQ; - break; - case DH6S_RELEASE: - type = DHCP6_RELEASE; - break; - case DH6S_DECLINE: - type = DHCP6_DECLINE; - break; - default: - errno = EINVAL; - return -1; - } - switch(state->state) { case DH6S_REQUEST: /* FALLTHROUGH */ case DH6S_RENEW: /* FALLTHROUGH */ @@ -868,11 +879,11 @@ dhcp6_makemessage(struct interface *ifp) break; } - /* In non master mode we listen and send from fixed addresses. + /* In non manager mode we listen and send from fixed addresses. * We should try and match an address we have to unicast to, * but for now this is the safest policy. */ - if (unicast != NULL && !(ifp->ctx->options & DHCPCD_MASTER)) { - logdebugx("%s: ignoring unicast option as not master", + if (unicast != NULL && !(ifp->ctx->options & DHCPCD_MANAGER)) { + logdebugx("%s: ignoring unicast option as not manager", ifp->name); unicast = NULL; } @@ -1638,7 +1649,7 @@ dhcp6_startinform(void *arg) ifp = arg; state = D6_STATE(ifp); - if (state->new == NULL && !state->failed) + if (state->new_start || (state->new == NULL && !state->failed)) llevel = LOG_INFO; else llevel = LOG_DEBUG; @@ -3035,18 +3046,25 @@ static void dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom) { struct dhcp6_state *state = D6_STATE(ifp); - bool timedout = (op == NULL), has_new = false, confirmed; + bool timedout = (op == NULL), confirmed; struct ipv6_addr *ia; int loglevel; struct timespec now; - TAILQ_FOREACH(ia, &state->addrs, next) { - if (ia->flags & IPV6_AF_NEW) { - has_new = true; - break; + if (state->state == DH6S_RENEW && !state->new_start) { + loglevel = LOG_DEBUG; + TAILQ_FOREACH(ia, &state->addrs, next) { + if (ia->flags & IPV6_AF_NEW) { + loglevel = LOG_INFO; + break; + } } - } - loglevel = has_new || state->state != DH6S_RENEW ? LOG_INFO : LOG_DEBUG; + } else if (state->state == DH6S_INFORM) + loglevel = state->new_start ? LOG_INFO : LOG_DEBUG; + else + loglevel = LOG_INFO; + state->new_start = false; + if (!timedout) { logmessage(loglevel, "%s: %s received from %s", ifp->name, op, sfrom); @@ -3245,7 +3263,7 @@ dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom) if (ifp->ctx->options & DHCPCD_TEST || (ifp->options->options & DHCPCD_INFORM && - !(ifp->ctx->options & DHCPCD_MASTER))) + !(ifp->ctx->options & DHCPCD_MANAGER))) { eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS); } @@ -3852,7 +3870,7 @@ dhcp6_start1(void *arg) size_t i; const struct dhcp_compat *dhc; - if ((ctx->options & (DHCPCD_MASTER|DHCPCD_PRIVSEP)) == DHCPCD_MASTER && + if ((ctx->options & (DHCPCD_MANAGER|DHCPCD_PRIVSEP)) == DHCPCD_MANAGER && ctx->dhcp6_rfd == -1) { ctx->dhcp6_rfd = dhcp6_openudp(0, NULL); @@ -3923,7 +3941,13 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) (state->state == DH6S_DISCOVER && !(ifp->options->options & DHCPCD_IA_FORCED) && !ipv6nd_hasradhcp(ifp, true))) + { + /* We don't want log spam when the RA + * has just adjusted it's prefix times. */ + if (state->state != DH6S_INFORMED) + state->new_start = true; dhcp6_startinform(ifp); + } break; case DH6S_REQUEST: if (ifp->options->options & DHCPCD_DHCP6 && @@ -3972,6 +3996,7 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) TAILQ_INIT(&state->addrs); gogogo: + state->new_start = true; state->state = init_state; state->lerror = 0; state->failed = false; @@ -4155,11 +4180,11 @@ dhcp6_handleifa(int cmd, struct ipv6_addr *ia, pid_t pid) struct dhcp6_state *state; struct interface *ifp = ia->iface; - /* If not running in master mode, listen to this address */ + /* If not running in manager mode, listen to this address */ if (cmd == RTM_NEWADDR && !(ia->addr_flags & IN6_IFF_NOTUSEABLE) && ifp->active == IF_ACTIVE_USER && - !(ifp->ctx->options & DHCPCD_MASTER) && + !(ifp->ctx->options & DHCPCD_MANAGER) && ifp->options->options & DHCPCD_DHCP6) { #ifdef PRIVSEP diff --git a/contrib/dhcpcd/src/dhcp6.h b/contrib/dhcpcd/src/dhcp6.h index 31e8045248..0b257fab6c 100644 --- a/contrib/dhcpcd/src/dhcp6.h +++ b/contrib/dhcpcd/src/dhcp6.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -213,6 +213,7 @@ struct dhcp6_state { uint16_t lerror; /* Last error received from DHCPv6 reply. */ bool has_no_binding; bool failed; /* Entered the failed state - used to rate limit log. */ + bool new_start; /* New external start, to determine log type. */ #ifdef AUTH struct authstate auth; #endif diff --git a/contrib/dhcpcd/src/dhcpcd-embedded.c b/contrib/dhcpcd/src/dhcpcd-embedded.c index d039a08871..73a8c68f5a 100644 --- a/contrib/dhcpcd/src/dhcpcd-embedded.c +++ b/contrib/dhcpcd/src/dhcpcd-embedded.c @@ -6,7 +6,7 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/dhcpcd-embedded.h b/contrib/dhcpcd/src/dhcpcd-embedded.h index a0a448f9f6..532cd4e355 100644 --- a/contrib/dhcpcd/src/dhcpcd-embedded.h +++ b/contrib/dhcpcd/src/dhcpcd-embedded.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/dhcpcd.8.in b/contrib/dhcpcd/src/dhcpcd.8 similarity index 92% rename from contrib/dhcpcd/src/dhcpcd.8.in rename to contrib/dhcpcd/src/dhcpcd.8 index 7533f30baa..9fa447e8bf 100644 --- a/contrib/dhcpcd/src/dhcpcd.8.in +++ b/contrib/dhcpcd/src/dhcpcd.8 @@ -1,6 +1,6 @@ .\" SPDX-License-Identifier: BSD-2-Clause .\" -.\" Copyright (c) 2006-2020 Roy Marples +.\" Copyright (c) 2006-2021 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd November 25, 2020 +.Dd August 23, 2021 .Dt DHCPCD 8 .Os .Sh NAME @@ -172,7 +172,7 @@ discovers available Ethernet interfaces that can be configured. When .Nm not limited to one interface on the command line, -it is running in Master mode. +it is running in Manager mode. The .Nm dhcpcd-ui project expects dhcpcd to be running this way. @@ -192,9 +192,9 @@ Using a single interface also affects the and .Fl x options, where the same interface will need to be specified, as a lack of an -interface will imply Master mode which this is not. -To force starting in Master mode with only one interface, the -.Fl M , Fl Fl master +interface will imply Manager mode which this is not. +To force starting in Manager mode with only one interface, the +.Fl M , Fl Fl manager option can be used. .Pp Interfaces are preferred by carrier, DHCP lease/IPv4LL and then lowest metric. @@ -213,16 +213,16 @@ To work with these devices they either need to be specified on the command line, be listed in .Fl Fl allowinterfaces or have an interface directive in -.Pa @SYSCONFDIR@/dhcpcd.conf . +.Pa /etc/dhcpcd.conf . .Ss Hooking into events .Nm runs -.Pa @SCRIPT@ , +.Pa /usr/libexec/dhcpcd-run-hooks , or the script specified by the .Fl c , Fl Fl script option. This script runs each script found in -.Pa @HOOKDIR@ +.Pa /usr/libexec/dhcpcd-hooks in a lexical order. The default installation supplies the scripts .Pa 01-test , @@ -240,9 +240,9 @@ for details on how these scripts work. currently ignores the exit code of the script. .Pp More scripts are supplied in -.Pa @DATADIR@/dhcpcd/hooks +.Pa /usr/share/dhcpcd/hooks and need to be copied to -.Pa @HOOKDIR@ +.Pa /usr/libexec/dhcpcd-hooks if you intend to use them. For example, you could install .Pa 29-lookup-hostname @@ -263,7 +263,7 @@ carrier status. Use this .Ar script instead of the default -.Pa @SCRIPT@ . +.Pa /usr/libexec/dhcpcd-run-hooks . .It Fl D , Fl Fl duid Op Ar ll | lt | uuid | value Use a DHCP Unique Identifier. If a system UUID is available, that will be used to create a DUID-UUID, @@ -271,7 +271,7 @@ otheriwse if persistent storage is available then a DUID-LLT (link local address + time) is generated, otherwise DUID-LL is generated (link local address). The DUID type can be hinted as an optional parameter if the file -.Pa @DBDIR@/duid +.Pa /var/db/dhcpcd/duid does not exist. If not .Va ll , @@ -284,7 +284,7 @@ will be converted from 00:11:22:33 format. This, plus the IAID will be used as the .Fl I , Fl Fl clientid . The DUID generated will be held in -.Pa @DBDIR@/duid +.Pa /var/db/dhcpcd/duid and should not be copied to other hosts. This file also takes precedence over the above rules except for setting a value. .It Fl d , Fl Fl debug @@ -333,7 +333,7 @@ encodes the FQDN hostname as specified in .Li RFC 1035 . .It Fl f , Fl Fl config Ar file Specify a config to load instead of -.Pa @SYSCONFDIR@/dhcpcd.conf . +.Pa /etc/dhcpcd.conf . .Nm always processes the config file before any command line options. .It Fl h , Fl Fl hostname Ar hostname @@ -393,7 +393,7 @@ regardless of the option. If no .Ar interface -is specified then this applies to all interfaces in Master mode. +is specified then this applies to all interfaces in Manager mode. If no interfaces are left running, .Nm will exit. @@ -406,17 +406,18 @@ By default .Nm does not request any lease time and leaves it in the hands of the DHCP server. -.It Fl M , Fl Fl master +.It Fl M , Fl Fl manager Start .Nm -in Master mode even if only one interface specified on the command line. +in Manager mode even if only one interface specified on the command line. See the Multiple Interfaces section above. .It Fl m , Fl Fl metric Ar metric Metrics are used to prefer an interface over another one, lowest wins. .Nm -will supply a default metic of 200 + +will supply a default metric of 1000 + .Xr if_nametoindex 3 . -An extra 100 will be added for wireless interfaces. +This will be offset by 2000 for wireless interfaces, with additional offsets +of 1000000 for IPv4LL and 2000000 for roaming interfaces. .It Fl n , Fl Fl rebind Op Ar interface Notifies .Nm @@ -424,7 +425,7 @@ to reload its configuration and rebind the specified .Ar interface . If no .Ar interface -is specified then this applies to all interfaces in Master mode. +is specified then this applies to all interfaces in Manager mode. If .Nm is not running, then it starts up as normal. @@ -435,7 +436,7 @@ to renew existing addresses on the specified .Ar interface . If no .Ar interface -is specified then this applies to all interfaces in Master mode. +is specified then this applies to all interfaces in Manager mode. If .Nm is not running, then it starts up as normal. @@ -448,7 +449,7 @@ is not reloaded. Request the DHCP .Ar option variable for use in -.Pa @SCRIPT@ . +.Pa /usr/libexec/dhcpcd-run-hooks . .It Fl p , Fl Fl persistent .Nm normally de-configures the @@ -578,7 +579,7 @@ process running on the to exit. If no .Ar interface -is specified, then the above is applied to all interfaces in Master mode. +is specified, then the above is applied to all interfaces in Manager mode. See the .Fl p , Fl Fl persistent option to control configuration persistence on exit, @@ -689,7 +690,7 @@ These messages are still logged via .Xr syslog 3 . .It Fl T , Fl Fl test On receipt of DHCP messages just call -.Pa @SCRIPT@ +.Pa /usr/libexec/dhcpcd-run-hooks with the reason of TEST which echos the DHCP variables found in the message to the console. The interface configuration isn't touched and neither are any configuration @@ -747,7 +748,7 @@ then it is still denied. Don't start any interfaces other than those specified on the command line. This allows .Nm -to be started in Master mode and then wait for subsequent +to be started in Manager mode and then wait for subsequent .Nm commands to start each interface as required. .It Fl Fl configure @@ -811,55 +812,57 @@ option .Nm sends to match. If using a DUID in place of the ClientID, edit -.Pa @DBDIR@/duid +.Pa /var/db/dhcpcd/duid accordingly. .Sh FILES .Bl -ohang -.It Pa @SYSCONFDIR@/dhcpcd.conf +.It Pa /etc/dhcpcd.conf Configuration file for dhcpcd. If you always use the same options, put them here. -.It Pa @SCRIPT@ +.It Pa /usr/libexec/dhcpcd-run-hooks Bourne shell script that is run to configure or de-configure an interface. -.It Pa @LIBDIR@/dhcpcd/dev +.It Pa /lib/dhcpcd/dev Linux .Pa /dev management modules. -.It Pa @HOOKDIR@ +.It Pa /usr/libexec/dhcpcd-hooks A directory containing bourne shell scripts that are run by the above script. Each script can be disabled by using the .Fl C , Fl Fl nohook option described above. -.It Pa @DBDIR@/duid +.It Pa /var/db/dhcpcd/duid Text file that holds the DUID used to identify the host. -.It Pa @DBDIR@/secret +.It Pa /var/db/dhcpcd/secret Text file that holds a secret key known only to the host. -.It Pa @DBDIR@/ Ns Ar interface Ns Ar -ssid Ns .lease +.It Pa /var/db/dhcpcd/ Ns Ar interface Ns Ar -ssid Ns .lease The actual DHCP message sent by the server. We use this when reading the last lease and use the file's mtime as when it was issued. -.It Pa @DBDIR@/ Ns Ar interface Ns Ar -ssid Ns .lease6 +.It Pa /var/db/dhcpcd/ Ns Ar interface Ns Ar -ssid Ns .lease6 The actual DHCPv6 message sent by the server. We use this when reading the last lease and use the file's mtime as when it was issued. -.It Pa @DBDIR@/rdm_monotonic +.It Pa /var/db/dhcpcd/rdm_monotonic Stores the monotonic counter used in the .Ar replay field in Authentication Options. -.It Pa @RUNDIR@/pid +.It Pa /var/run/dhcpcd/pid Stores the PID of .Nm running on all interfaces. -.It Pa @RUNDIR@/ Ns Ar interface Ns .pid +.It Pa /var/run/dhcpcd/ Ns Ar interface Ns .pid Stores the PID of .Nm running on the .Ar interface . -.It Pa @RUNDIR@/sock -Control socket to the master daemon. -.It Pa @RUNDIR@/unpriv.sock -Unprivileged socket to the master daemon, only allows state retrieval. -.It Pa @RUNDIR@/ Ns Ar interface Ns .sock +.It Pa /var/run/dhcpcd/sock +Control socket to the manager daemon. +.It Pa /var/run/dhcpcd/unpriv.sock +Unprivileged socket to the manager daemon, only allows state retrieval. +.It Pa /var/run/dhcpcd/ Ns Ar interface Ns .sock Control socket to per interface daemon. +.It Pa /var/run/dhcpcd/ Ns Ar interface Ns .unpriv.sock +Unprivileged socket to per interface daemon, only allows state retrieval. .El .Sh SEE ALSO .Xr fnmatch 3 , diff --git a/contrib/dhcpcd/src/dhcpcd.c b/contrib/dhcpcd/src/dhcpcd.c index 97417e2557..6a4c972374 100644 --- a/contrib/dhcpcd/src/dhcpcd.c +++ b/contrib/dhcpcd/src/dhcpcd.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ -static const char dhcpcd_copyright[] = "Copyright (c) 2006-2020 Roy Marples"; +static const char dhcpcd_copyright[] = "Copyright (c) 2006-2021 Roy Marples"; #include #include @@ -107,7 +107,7 @@ printf("usage: "PACKAGE"\t[-146ABbDdEGgHJKLMNPpqTV]\n" "\t\t[-C, --nohook hook] [-c, --script script]\n" "\t\t[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]\n" "\t\t[-h, --hostname hostname] [-I, --clientid clientid]\n" - "\t\t[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]\n" + "\t\t[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]\n" "\t\t[-l, --leasetime seconds] [-m, --metric metric]\n" "\t\t[-O, --nooption option] [-o, --option option]\n" "\t\t[-Q, --require option] [-r, --request address]\n" @@ -196,7 +196,7 @@ handle_exit_timeout(void *arg) ctx = arg; logerrx("timed out"); - if (!(ctx->options & DHCPCD_MASTER)) { + if (!(ctx->options & DHCPCD_MANAGER)) { struct interface *ifp; TAILQ_FOREACH(ifp, ctx->ifaces, next) { @@ -370,12 +370,12 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) /* * Stop writing to stderr. - * On the happy path, only the master process writes to stderr, + * On the happy path, only the manager process writes to stderr, * so this just stops wasting fprintf calls to nowhere. * All other calls - ie errors in privsep processes or script output, * will error when printing. * If we *really* want to fix that, then we need to suck - * stderr/stdout in the master process and either disacrd it or pass + * stderr/stdout in the manager process and either disacrd it or pass * it to the launcher process and then to stderr. */ logopts &= ~LOGERR_ERR; @@ -427,7 +427,7 @@ stop_interface(struct interface *ifp, const char *reason) ifp->active = IF_INACTIVE; ifp->options->options &= ~DHCPCD_STOPPING; - if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST))) + if (!(ctx->options & (DHCPCD_MANAGER | DHCPCD_TEST))) eloop_exit(ctx->eloop, EXIT_FAILURE); } @@ -980,7 +980,7 @@ dhcpcd_prestartinterface(void *arg) } else randmac_down = false; - if ((!(ctx->options & DHCPCD_MASTER) || + if ((!(ctx->options & DHCPCD_MANAGER) || ifp->options->options & DHCPCD_IF_UP || randmac_down) && !(ifp->flags & IFF_UP)) { @@ -1311,8 +1311,8 @@ reload_config(struct dhcpcd_ctx *ctx) /* 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_MANAGER) + ifo->options |= DHCPCD_MANAGER; if (ctx->options & DHCPCD_DAEMONISED) ifo->options |= DHCPCD_DAEMONISED; if (ctx->options & DHCPCD_PRIVSEP) @@ -1988,7 +1988,7 @@ main(int argc, char **argv, char **envp) } if (optind != argc - 1) - ctx.options |= DHCPCD_MASTER; + ctx.options |= DHCPCD_MANAGER; logsetopts(logopts); logopen(ctx.logfile); @@ -2068,7 +2068,7 @@ main(int argc, char **argv, char **envp) printpidfile: /* If we have any other args, we should run as a single dhcpcd * instance for that interface. */ - if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) { + if (optind == argc - 1 && !(ctx.options & DHCPCD_MANAGER)) { const char *per; const char *ifname; @@ -2094,7 +2094,7 @@ printpidfile: } else { snprintf(ctx.pidfile, sizeof(ctx.pidfile), PIDFILE, "", "", ""); - ctx.options |= DHCPCD_MASTER; + ctx.options |= DHCPCD_MANAGER; } if (ctx.options & DHCPCD_PRINT_PIDFILE) { printf("%s\n", ctx.pidfile); @@ -2170,7 +2170,7 @@ printpidfile: { ctx.options |= DHCPCD_FORKED; /* pretend child process */ #ifdef PRIVSEP - if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1) + if (IN_PRIVSEP(&ctx) && ps_managersandbox(&ctx, NULL) == -1) goto exit_failure; #endif ifp = calloc(1, sizeof(*ifp)); @@ -2214,10 +2214,10 @@ printpidfile: !(ctx.options & DHCPCD_TEST)) { ctx.options |= DHCPCD_FORKED; /* avoid socket unlink */ - if (!(ctx.options & DHCPCD_MASTER)) + if (!(ctx.options & DHCPCD_MANAGER)) ctx.control_fd = control_open(argv[optind], family, ctx.options & DHCPCD_DUMPLEASE); - if (!(ctx.options & DHCPCD_MASTER) && ctx.control_fd == -1) + if (!(ctx.options & DHCPCD_MANAGER) && ctx.control_fd == -1) ctx.control_fd = control_open(argv[optind], AF_UNSPEC, ctx.options & DHCPCD_DUMPLEASE); if (ctx.control_fd == -1) @@ -2226,7 +2226,7 @@ printpidfile: if (ctx.control_fd != -1) { #ifdef PRIVSEP if (IN_PRIVSEP(&ctx) && - ps_mastersandbox(&ctx, NULL) == -1) + ps_managersandbox(&ctx, NULL) == -1) goto exit_failure; #endif if (!(ctx.options & DHCPCD_DUMPLEASE)) @@ -2284,7 +2284,7 @@ printpidfile: #if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK) if (!(ctx.options & DHCPCD_DAEMONISE)) - goto start_master; + goto start_manager; if (xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, fork_fd) == -1 || (ctx.stderr_valid && @@ -2368,7 +2368,7 @@ printpidfile: dhcpcd_stderr_cb, &ctx); } #ifdef PRIVSEP - if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1) + if (IN_PRIVSEP(&ctx) && ps_managersandbox(&ctx, NULL) == -1) goto exit_failure; #endif goto run_loop; @@ -2376,8 +2376,8 @@ printpidfile: /* We have now forked, setsid, forked once more. * From this point on, we are the controlling daemon. */ - logdebugx("spawned master process on PID %d", getpid()); -start_master: + logdebugx("spawned manager process on PID %d", getpid()); +start_manager: ctx.options |= DHCPCD_STARTED; if ((pid = pidfile_lock(ctx.pidfile)) != 0) { logerr("%s: pidfile_lock %d", __func__, pid); @@ -2408,7 +2408,7 @@ start_master: if (!(ctx.options & DHCPCD_TEST)) { if (control_start(&ctx, - ctx.options & DHCPCD_MASTER ? + ctx.options & DHCPCD_MANAGER ? NULL : argv[optind], family) == -1) { logerr("%s: control_start", __func__); @@ -2420,13 +2420,13 @@ start_master: /* Start any dev listening plugin which may want to * change the interface name provided by the kernel */ if (!IN_PRIVSEP(&ctx) && - (ctx.options & (DHCPCD_MASTER | DHCPCD_DEV)) == - (DHCPCD_MASTER | DHCPCD_DEV)) + (ctx.options & (DHCPCD_MANAGER | DHCPCD_DEV)) == + (DHCPCD_MANAGER | DHCPCD_DEV)) dev_start(&ctx, dhcpcd_handleinterface); #endif setproctitle("%s%s%s", - ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind], + ctx.options & DHCPCD_MANAGER ? "[manager]" : argv[optind], ctx.options & DHCPCD_IPV4 ? " [ip4]" : "", ctx.options & DHCPCD_IPV6 ? " [ip6]" : ""); @@ -2450,7 +2450,7 @@ start_master: eloop_event_add(ctx.eloop, ctx.link_fd, dhcpcd_handlelink, &ctx); #ifdef PRIVSEP - if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, "stdio route") == -1) + if (IN_PRIVSEP(&ctx) && ps_managersandbox(&ctx, "stdio route") == -1) goto exit_failure; #endif @@ -2511,7 +2511,7 @@ start_master: } if (!(ctx.options & DHCPCD_BACKGROUND)) { - if (ctx.options & DHCPCD_MASTER) + if (ctx.options & DHCPCD_MANAGER) t = ifo->timeout; else { t = 0; diff --git a/contrib/dhcpcd/src/dhcpcd.conf.5.in b/contrib/dhcpcd/src/dhcpcd.conf.5 similarity index 98% rename from contrib/dhcpcd/src/dhcpcd.conf.5.in rename to contrib/dhcpcd/src/dhcpcd.conf.5 index fb89580dad..eb228fe61f 100644 --- a/contrib/dhcpcd/src/dhcpcd.conf.5.in +++ b/contrib/dhcpcd/src/dhcpcd.conf.5 @@ -1,6 +1,6 @@ .\" SPDX-License-Identifier: BSD-2-Clause .\" -.\" Copyright (c) 2006-2020 Roy Marples +.\" Copyright (c) 2006-2021 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 27, 2020 +.Dd August 23, 2021 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -161,7 +161,7 @@ In most cases, will set this automatically. .It Ic controlgroup Ar group Sets the group ownership of -.Pa @RUNDIR@/sock +.Pa /var/run/dhcpcd/sock so that users other than root can connect to .Nm dhcpcd . .It Ic debug @@ -220,7 +220,7 @@ otheriwse if persistent storage is available then a DUID-LLT (link local address + time) is generated, otherwise DUID-LL is generated (link local address). The DUID type can be hinted as an optional parameter if the file -.Pa @DBDIR@/duid +.Pa /var/db/dhcpcd/duid does not exist. If not .Va ll , @@ -233,7 +233,7 @@ will be converted from 00:11:22:33 format. This, plus the IAID will be used as the .Ic clientid . The DUID generated will be held in -.Pa @DBDIR@/duid +.Pa /var/db/dhcpcd/duid and should not be copied to other hosts. This file also takes precedence over the above rules except for setting a value. .It Ic iaid Ar iaid @@ -491,9 +491,10 @@ signal. .It Ic metric Ar metric Metrics are used to prefer an interface over another one, lowest wins. .Nm dhcpcd -will supply a default metric of 200 + +will supply a default metric of 1000 + .Xr if_nametoindex 3 . -An extra 100 will be added for wireless interfaces. +This will be offset by 2000 for wireless interfaces, with additional offsets +of 1000000 for IPv4LL and 2000000 for roaming interfaces. .It Ic mudurl Ar url Specifies the URL for a Manufacturer Usage Description (MUD). The description is used by upstream network devices to instantiate any @@ -550,7 +551,7 @@ Don't solicit or accept IPv6 Router Advertisements. Don't receive link messages about carrier status. You should only set this for buggy interface drivers. .It Ic noup -Don't bring the interface up when in master mode. +Don't bring the interface up when in manager mode. .It Ic option Ar option Requests the .Ar option @@ -641,7 +642,7 @@ will release the lease prior to stopping the interface. Use .Ar script instead of the default -.Pa @SCRIPT@ . +.Pa /usr/libexec/dhcpcd-run-hooks . .It Ic ssid Ar ssid Subsequent options are only parsed for this wireless .Ar ssid . @@ -983,7 +984,7 @@ reset. .Bl -tag -width -indent .It Ic monocounter Read the number in the file -.Pa @DBDIR@/dhcpcd-rdm.monotonic +.Pa /var/db/dhcpcd/dhcpcd-rdm.monotonic and add one to it. .It Ic monotime Create an NTP timestamp from the system time. diff --git a/contrib/dhcpcd/src/dhcpcd.h b/contrib/dhcpcd/src/dhcpcd.h index e18919de57..d7fb816457 100644 --- a/contrib/dhcpcd/src/dhcpcd.h +++ b/contrib/dhcpcd/src/dhcpcd.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -199,7 +199,7 @@ struct dhcpcd_ctx { #ifdef PRIVSEP struct passwd *ps_user; /* struct passwd for privsep user */ pid_t ps_root_pid; - int ps_root_fd; /* Privileged Actioneer commands */ + int ps_root_fd; /* Privileged Proxy commands */ int ps_log_fd; /* chroot logging */ int ps_data_fd; /* Data from root spawned processes */ struct eloop *ps_eloop; /* eloop for polling root data */ diff --git a/contrib/dhcpcd/src/duid.c b/contrib/dhcpcd/src/duid.c index 764c74a92e..be626f5100 100644 --- a/contrib/dhcpcd/src/duid.c +++ b/contrib/dhcpcd/src/duid.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/duid.h b/contrib/dhcpcd/src/duid.h index 1d25f2b66a..da3811d941 100644 --- a/contrib/dhcpcd/src/duid.h +++ b/contrib/dhcpcd/src/duid.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/eloop.c b/contrib/dhcpcd/src/eloop.c index 16bb9b2a9d..a6ab43fbae 100644 --- a/contrib/dhcpcd/src/eloop.c +++ b/contrib/dhcpcd/src/eloop.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * eloop - portable event based main loop. - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -136,6 +137,7 @@ struct eloop { TAILQ_HEAD (event_head, eloop_event) events; size_t nevents; struct event_head free_events; + bool events_need_setup; struct timespec now; TAILQ_HEAD (timeout_head, eloop_timeout) timeouts; @@ -282,11 +284,16 @@ eloop_reduce_timers(struct eloop *eloop) static void eloop_event_setup_fds(struct eloop *eloop) { - struct eloop_event *e; + struct eloop_event *e, *ne; struct pollfd *pfd; pfd = eloop->fds; - TAILQ_FOREACH(e, &eloop->events, next) { + TAILQ_FOREACH_SAFE(e, &eloop->events, next, ne) { + if (e->fd == -1) { + TAILQ_REMOVE(&eloop->events, e, next); + TAILQ_INSERT_TAIL(&eloop->free_events, e, next); + continue; + } #ifdef ELOOP_DEBUG fprintf(stderr, "%s(%d) fd=%d, rcb=%p, wcb=%p\n", __func__, getpid(), e->fd, e->read_cb, e->write_cb); @@ -301,6 +308,7 @@ eloop_event_setup_fds(struct eloop *eloop) pfd->revents = 0; pfd++; } + eloop->events_need_setup = false; } size_t @@ -368,7 +376,8 @@ eloop_event_add_rw(struct eloop *eloop, int fd, } setup: - eloop_event_setup_fds(eloop); + e->pollfd = NULL; + eloop->events_need_setup = true; return 0; } @@ -394,6 +403,10 @@ eloop_event_delete_write(struct eloop *eloop, int fd, int write_only) struct eloop_event *e; assert(eloop != NULL); + if (fd == -1) { + errno = EINVAL; + return -1; + } TAILQ_FOREACH(e, &eloop->events, next) { if (e->fd == fd) @@ -409,16 +422,17 @@ eloop_event_delete_write(struct eloop *eloop, int fd, int write_only) goto remove; e->write_cb = NULL; e->write_cb_arg = NULL; - goto done; + if (e->pollfd != NULL) { + e->pollfd->events &= ~POLLOUT; + e->pollfd->revents &= ~POLLOUT; + } + return 1; } remove: - TAILQ_REMOVE(&eloop->events, e, next); - TAILQ_INSERT_TAIL(&eloop->free_events, e, next); + e->fd = -1; eloop->nevents--; - -done: - eloop_event_setup_fds(eloop); + eloop->events_need_setup = true; return 1; } @@ -736,6 +750,9 @@ eloop_start(struct eloop *eloop, sigset_t *signals) } else tsp = NULL; + if (eloop->events_need_setup) + eloop_event_setup_fds(eloop); + n = ppoll(eloop->fds, (nfds_t)eloop->nevents, tsp, signals); if (n == -1) { if (errno == EINTR) @@ -746,18 +763,23 @@ eloop_start(struct eloop *eloop, sigset_t *signals) continue; TAILQ_FOREACH(e, &eloop->events, next) { - if (e->pollfd->revents & POLLOUT) { - if (e->write_cb != NULL) { + /* Skip freshly added events */ + if (e->pollfd == NULL) + continue; + if (e->pollfd->revents) + n--; + if (e->fd != -1 && e->pollfd->revents & POLLOUT) { + if (e->write_cb != NULL) e->write_cb(e->write_cb_arg); - break; - } } - if (e->pollfd->revents) { - if (e->read_cb != NULL) { + if (e->fd != -1 && + e->pollfd != NULL && e->pollfd->revents) + { + if (e->read_cb != NULL) e->read_cb(e->read_cb_arg); - break; - } } + if (n == 0) + break; } } diff --git a/contrib/dhcpcd/src/eloop.h b/contrib/dhcpcd/src/eloop.h index c7d81e348d..1813eaa64d 100644 --- a/contrib/dhcpcd/src/eloop.h +++ b/contrib/dhcpcd/src/eloop.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/if-bsd.c b/contrib/dhcpcd/src/if-bsd.c index 8fe7d2644c..e5ffe50065 100644 --- a/contrib/dhcpcd/src/if-bsd.c +++ b/contrib/dhcpcd/src/if-bsd.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * BSD interface driver for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -235,6 +235,7 @@ if_closesockets_os(struct dhcpcd_ctx *ctx) close(priv->pf_inet6_fd); free(priv); ctx->priv = NULL; + free(ctx->rt_missfilter); } #if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE) /*NetBSD */ @@ -626,6 +627,8 @@ if_findsa(struct dhcpcd_ctx *ctx, const struct sockaddr *sa) sin = (const void *)sa; if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr))) return ia->iface; + if ((ia = ipv4_findmaskbrd(ctx, &sin->sin_addr))) + return ia->iface; break; } #endif diff --git a/contrib/dhcpcd/src/if-options.c b/contrib/dhcpcd/src/if-options.c index 881591a67e..dd70c80656 100644 --- a/contrib/dhcpcd/src/if-options.c +++ b/contrib/dhcpcd/src/if-options.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -104,7 +104,7 @@ const struct option cf_options[] = { {"broadcast", no_argument, NULL, 'J'}, {"nolink", no_argument, NULL, 'K'}, {"noipv4ll", no_argument, NULL, 'L'}, - {"master", no_argument, NULL, 'M'}, + {"manager", no_argument, NULL, 'M'}, {"renew", no_argument, NULL, 'N'}, {"nooption", required_argument, NULL, 'O'}, {"printpidfile", no_argument, NULL, 'P'}, @@ -321,9 +321,10 @@ parse_str(char *sbuf, size_t slen, const char *str, int flags) break; c[i] = *str++; } - if (c[1] != '\0' && sbuf) { + if (c[1] != '\0') { c[2] = '\0'; - *sbuf++ = (char)strtol(c, NULL, 16); + if (sbuf) + *sbuf++ = (char)strtol(c, NULL, 16); } else l--; break; @@ -335,11 +336,12 @@ parse_str(char *sbuf, size_t slen, const char *str, int flags) break; c[i] = *str++; } - if (c[2] != '\0' && sbuf) { + if (c[2] != '\0') { i = (int)strtol(c, NULL, 8); if (i > 255) i = 255; - *sbuf ++= (char)i; + if (sbuf) + *sbuf++ = (char)i; } else l--; break; @@ -1068,7 +1070,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, ifo->options &= ~DHCPCD_IPV4LL; break; case 'M': - ifo->options |= DHCPCD_MASTER; + ifo->options |= DHCPCD_MANAGER; break; case 'O': ARG_REQUIRED; @@ -1356,7 +1358,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, #endif case O_IAID: ARG_REQUIRED; - if (ctx->options & DHCPCD_MASTER && !IN_CONFIG_BLOCK(ifo)) { + if (ctx->options & DHCPCD_MANAGER && !IN_CONFIG_BLOCK(ifo)) { logerrx("IAID must belong in an interface block"); return -1; } @@ -1398,7 +1400,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, logwarnx("%s: IA_PD not compiled in", ifname); return -1; #else - if (ctx->options & DHCPCD_MASTER && + if (ctx->options & DHCPCD_MANAGER && !IN_CONFIG_BLOCK(ifo)) { logerrx("IA PD must belong in an " @@ -1408,7 +1410,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, i = D6_OPTION_IA_PD; #endif } - if (ctx->options & DHCPCD_MASTER && + if (ctx->options & DHCPCD_MANAGER && !IN_CONFIG_BLOCK(ifo) && arg) { logerrx("IA with IAID must belong in an " diff --git a/contrib/dhcpcd/src/if-options.h b/contrib/dhcpcd/src/if-options.h index e4e39e2820..f80119d6c1 100644 --- a/contrib/dhcpcd/src/if-options.h +++ b/contrib/dhcpcd/src/if-options.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -74,7 +74,7 @@ #define DHCPCD_DAEMONISE (1ULL << 14) #define DHCPCD_DAEMONISED (1ULL << 15) #define DHCPCD_TEST (1ULL << 16) -#define DHCPCD_MASTER (1ULL << 17) +#define DHCPCD_MANAGER (1ULL << 17) #define DHCPCD_HOSTNAME (1ULL << 18) #define DHCPCD_CLIENTID (1ULL << 19) #define DHCPCD_LINK (1ULL << 20) diff --git a/contrib/dhcpcd/src/if.c b/contrib/dhcpcd/src/if.c index d3852f3dc6..b00f5e6f38 100644 --- a/contrib/dhcpcd/src/if.c +++ b/contrib/dhcpcd/src/if.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/if.h b/contrib/dhcpcd/src/if.h index 43d133075d..d24fbc92cf 100644 --- a/contrib/dhcpcd/src/if.h +++ b/contrib/dhcpcd/src/if.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/ipv4.c b/contrib/dhcpcd/src/ipv4.c index 220b33300e..7bf7db3827 100644 --- a/contrib/dhcpcd/src/ipv4.c +++ b/contrib/dhcpcd/src/ipv4.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -170,6 +170,23 @@ ipv4_iffindmaskaddr(struct interface *ifp, const struct in_addr *addr) return NULL; } +static struct ipv4_addr * +ipv4_iffindmaskbrd(struct interface *ifp, const struct in_addr *addr) +{ + struct ipv4_state *state; + struct ipv4_addr *ap; + + state = IPV4_STATE(ifp); + if (state) { + TAILQ_FOREACH (ap, &state->addrs, next) { + if ((ap->brd.s_addr & ap->mask.s_addr) == + (addr->s_addr & ap->mask.s_addr)) + return ap; + } + } + return NULL; +} + struct ipv4_addr * ipv4_findaddr(struct dhcpcd_ctx *ctx, const struct in_addr *addr) { @@ -198,6 +215,20 @@ ipv4_findmaskaddr(struct dhcpcd_ctx *ctx, const struct in_addr *addr) return NULL; } +struct ipv4_addr * +ipv4_findmaskbrd(struct dhcpcd_ctx *ctx, const struct in_addr *addr) +{ + struct interface *ifp; + struct ipv4_addr *ap; + + TAILQ_FOREACH(ifp, ctx->ifaces, next) { + ap = ipv4_iffindmaskbrd(ifp, addr); + if (ap) + return ap; + } + return NULL; +} + int ipv4_hasaddr(const struct interface *ifp) { diff --git a/contrib/dhcpcd/src/ipv4.h b/contrib/dhcpcd/src/ipv4.h index c72418e381..6c0ac8e889 100644 --- a/contrib/dhcpcd/src/ipv4.h +++ b/contrib/dhcpcd/src/ipv4.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -143,6 +143,8 @@ struct ipv4_addr *ipv4_iffindlladdr(struct interface *); struct ipv4_addr *ipv4_findaddr(struct dhcpcd_ctx *, const struct in_addr *); struct ipv4_addr *ipv4_findmaskaddr(struct dhcpcd_ctx *, const struct in_addr *); +struct ipv4_addr *ipv4_findmaskbrd(struct dhcpcd_ctx *, + const struct in_addr *); void ipv4_markaddrsstale(struct interface *); void ipv4_deletestaleaddrs(struct interface *); void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *, diff --git a/contrib/dhcpcd/src/ipv4ll.c b/contrib/dhcpcd/src/ipv4ll.c index 6f9cd73d5c..faaad70f67 100644 --- a/contrib/dhcpcd/src/ipv4ll.c +++ b/contrib/dhcpcd/src/ipv4ll.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/ipv4ll.h b/contrib/dhcpcd/src/ipv4ll.h index bdf4c67da5..0dcf857230 100644 --- a/contrib/dhcpcd/src/ipv4ll.h +++ b/contrib/dhcpcd/src/ipv4ll.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/ipv6.c b/contrib/dhcpcd/src/ipv6.c index c9150c07cb..04bf7746e0 100644 --- a/contrib/dhcpcd/src/ipv6.c +++ b/contrib/dhcpcd/src/ipv6.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -596,7 +596,7 @@ ipv6_deletedaddr(struct ipv6_addr *ia) #ifdef DHCP6 #ifdef PRIVSEP - if (!(ia->iface->ctx->options & DHCPCD_MASTER)) + if (!(ia->iface->ctx->options & DHCPCD_MANAGER)) ps_inet_closedhcp6(ia); #elif defined(SMALL) UNUSED(ia); diff --git a/contrib/dhcpcd/src/ipv6.h b/contrib/dhcpcd/src/ipv6.h index 8eb4fd0050..1fe1d5c224 100644 --- a/contrib/dhcpcd/src/ipv6.h +++ b/contrib/dhcpcd/src/ipv6.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/ipv6nd.c b/contrib/dhcpcd/src/ipv6nd.c index b9ba57f476..b0174a775d 100644 --- a/contrib/dhcpcd/src/ipv6nd.c +++ b/contrib/dhcpcd/src/ipv6nd.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - IPv6 ND handling - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/ipv6nd.h b/contrib/dhcpcd/src/ipv6nd.h index baa59404ff..fd5990cfea 100644 --- a/contrib/dhcpcd/src/ipv6nd.h +++ b/contrib/dhcpcd/src/ipv6nd.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - IPv6 ND handling - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/logerr.c b/contrib/dhcpcd/src/logerr.c index 21e933b898..7a650e87f2 100644 --- a/contrib/dhcpcd/src/logerr.c +++ b/contrib/dhcpcd/src/logerr.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * logerr: errx with logging - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -484,13 +484,14 @@ logclose(void) #endif closelog(); +#if defined(__linux__) + free(_logprog); + _logprog = NULL; +#endif #ifndef SMALL if (ctx->log_file == NULL) return; fclose(ctx->log_file); ctx->log_file = NULL; #endif -#if defined(__linux__) - free(_logprog); -#endif } diff --git a/contrib/dhcpcd/src/logerr.h b/contrib/dhcpcd/src/logerr.h index db1c18b9b3..ba7e4f6a6a 100644 --- a/contrib/dhcpcd/src/logerr.h +++ b/contrib/dhcpcd/src/logerr.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * logerr: errx with logging - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/privsep-bpf.c b/contrib/dhcpcd/src/privsep-bpf.c index 79c4696d38..f402ea1830 100644 --- a/contrib/dhcpcd/src/privsep-bpf.c +++ b/contrib/dhcpcd/src/privsep-bpf.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation BPF Initiator - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -254,10 +254,8 @@ ps_bpf_cmd(struct dhcpcd_ctx *ctx, struct ps_msghdr *psm, struct msghdr *msg) ps_entersandbox("stdio", NULL); break; default: -#ifdef PRIVSEP_DEBUG logdebugx("%s: spawned BPF %s on PID %d", psp->psp_ifname, psp->psp_protostr, start); -#endif break; } return start; diff --git a/contrib/dhcpcd/src/privsep-bpf.h b/contrib/dhcpcd/src/privsep-bpf.h index a9960490ac..50c132379d 100644 --- a/contrib/dhcpcd/src/privsep-bpf.h +++ b/contrib/dhcpcd/src/privsep-bpf.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/privsep-bsd.c b/contrib/dhcpcd/src/privsep-bsd.c index c9e316102b..22472625af 100644 --- a/contrib/dhcpcd/src/privsep-bsd.c +++ b/contrib/dhcpcd/src/privsep-bsd.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd, BSD driver - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -29,10 +29,20 @@ #include /* Need these for filtering the ioctls */ +#include #include +#include #include #include #include +#ifdef __NetBSD__ +#include +#include /* Needs netinet/if_ether.h */ +#elif defined(__DragonFly__) +#include +#else +#include +#endif #ifdef __DragonFly__ # include #else diff --git a/contrib/dhcpcd/src/privsep-control.c b/contrib/dhcpcd/src/privsep-control.c index 52b3342e49..fe9bbbf227 100644 --- a/contrib/dhcpcd/src/privsep-control.c +++ b/contrib/dhcpcd/src/privsep-control.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd, control proxy - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ ps_ctl_startcb(void *arg) struct dhcpcd_ctx *ctx = arg; sa_family_t af; - if (ctx->options & DHCPCD_MASTER) { + if (ctx->options & DHCPCD_MANAGER) { setproctitle("[control proxy]"); af = AF_UNSPEC; } else { @@ -63,7 +63,7 @@ ps_ctl_startcb(void *arg) ctx->ps_control_pid = getpid(); return control_start(ctx, - ctx->options & DHCPCD_MASTER ? NULL : *ctx->ifv, af); + ctx->options & DHCPCD_MANAGER ? NULL : *ctx->ifv, af); } static ssize_t diff --git a/contrib/dhcpcd/src/privsep-control.h b/contrib/dhcpcd/src/privsep-control.h index 3d9522adf0..8f01b536cf 100644 --- a/contrib/dhcpcd/src/privsep-control.h +++ b/contrib/dhcpcd/src/privsep-control.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/privsep-inet.c b/contrib/dhcpcd/src/privsep-inet.c index 2770569f63..3a192ee0c4 100644 --- a/contrib/dhcpcd/src/privsep-inet.c +++ b/contrib/dhcpcd/src/privsep-inet.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd, network proxy - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -94,8 +94,8 @@ ps_inet_canstart(const struct dhcpcd_ctx *ctx) { #ifdef INET - if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MASTER)) == - (DHCPCD_IPV4 | DHCPCD_MASTER)) + if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MANAGER)) == + (DHCPCD_IPV4 | DHCPCD_MANAGER)) return true; #endif #if defined(INET6) && !defined(__sun) @@ -103,8 +103,8 @@ ps_inet_canstart(const struct dhcpcd_ctx *ctx) return true; #endif #ifdef DHCP6 - if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MASTER)) == - (DHCPCD_IPV6 | DHCPCD_MASTER)) + if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MANAGER)) == + (DHCPCD_IPV6 | DHCPCD_MANAGER)) return true; #endif @@ -117,7 +117,7 @@ ps_inet_startcb(void *arg) struct dhcpcd_ctx *ctx = arg; int ret = 0; - if (ctx->options & DHCPCD_MASTER) + if (ctx->options & DHCPCD_MANAGER) setproctitle("[network proxy]"); else setproctitle("[network proxy] %s%s%s", @@ -132,8 +132,8 @@ ps_inet_startcb(void *arg) errno = 0; #ifdef INET - if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MASTER)) == - (DHCPCD_IPV4 | DHCPCD_MASTER)) + if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MANAGER)) == + (DHCPCD_IPV4 | DHCPCD_MANAGER)) { ctx->udp_rfd = dhcp_openudp(NULL); if (ctx->udp_rfd == -1) @@ -178,8 +178,8 @@ ps_inet_startcb(void *arg) } #endif #ifdef DHCP6 - if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MASTER)) == - (DHCPCD_IPV6 | DHCPCD_MASTER)) + if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MANAGER)) == + (DHCPCD_IPV6 | DHCPCD_MANAGER)) { ctx->dhcp6_rfd = dhcp6_openudp(0, NULL); if (ctx->dhcp6_rfd == -1) diff --git a/contrib/dhcpcd/src/privsep-inet.h b/contrib/dhcpcd/src/privsep-inet.h index d6b704026c..dc4a072d8d 100644 --- a/contrib/dhcpcd/src/privsep-inet.h +++ b/contrib/dhcpcd/src/privsep-inet.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/privsep-root.c b/contrib/dhcpcd/src/privsep-root.c index 70c6cf22a1..45af3910fe 100644 --- a/contrib/dhcpcd/src/privsep-root.c +++ b/contrib/dhcpcd/src/privsep-root.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Privilege Separation for dhcpcd, privileged actioneer - * Copyright (c) 2006-2020 Roy Marples + * Privilege Separation for dhcpcd, privileged proxy + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -641,10 +641,10 @@ ps_root_startcb(void *arg) { struct dhcpcd_ctx *ctx = arg; - if (ctx->options & DHCPCD_MASTER) - setproctitle("[privileged actioneer]"); + if (ctx->options & DHCPCD_MANAGER) + setproctitle("[privileged proxy]"); else - setproctitle("[privileged actioneer] %s%s%s", + setproctitle("[privileged proxy] %s%s%s", ctx->ifv[0], ctx->options & DHCPCD_IPV4 ? " [ip4]" : "", ctx->options & DHCPCD_IPV6 ? " [ip6]" : ""); @@ -653,7 +653,7 @@ ps_root_startcb(void *arg) /* Open network sockets for sending. * This is a small bit wasteful for non sandboxed OS's - * but makes life very easy for unicasting DHCPv6 in non master + * but makes life very easy for unicasting DHCPv6 in non manager * mode as we no longer care about address selection. * We can't call shutdown SHUT_RD on the socket because it's * not connectd. All we can do is try and set a zero sized @@ -700,8 +700,8 @@ ps_root_startcb(void *arg) #ifdef PLUGIN_DEV /* Start any dev listening plugin which may want to * change the interface name provided by the kernel */ - if ((ctx->options & (DHCPCD_MASTER | DHCPCD_DEV)) == - (DHCPCD_MASTER | DHCPCD_DEV)) + if ((ctx->options & (DHCPCD_MANAGER | DHCPCD_DEV)) == + (DHCPCD_MANAGER | DHCPCD_DEV)) dev_start(ctx, ps_root_handleinterface); #endif diff --git a/contrib/dhcpcd/src/privsep-root.h b/contrib/dhcpcd/src/privsep-root.h index 9d8a1597cb..7fdd9f69f2 100644 --- a/contrib/dhcpcd/src/privsep-root.h +++ b/contrib/dhcpcd/src/privsep-root.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/privsep.c b/contrib/dhcpcd/src/privsep.c index d5c7c5627c..d574a2bcae 100644 --- a/contrib/dhcpcd/src/privsep.c +++ b/contrib/dhcpcd/src/privsep.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -33,8 +33,8 @@ * or address specific listener. * Spawn an unpriv process to send/receive common network data. * Then drop all privs and start running. - * Every process aside from the privileged actioneer is chrooted. - * All privsep processes ignore signals - only the master process accepts them. + * Every process aside from the privileged proxy is chrooted. + * All privsep processes ignore signals - only the manager process accepts them. * * dhcpcd will maintain the config file in the chroot, no need to handle * this in a script or something. @@ -81,6 +81,15 @@ #include #endif +/* CMSG_ALIGN is a Linux extension */ +#ifndef CMSG_ALIGN +#define CMSG_ALIGN(n) (CMSG_SPACE((n)) - CMSG_SPACE(0)) +#endif + +/* Calculate number of padding bytes to achieve 'struct cmsghdr' alignment */ +#define CALC_CMSG_PADLEN(has_cmsg, pos) \ + ((has_cmsg) ? (socklen_t)(CMSG_ALIGN((pos)) - (pos)) : 0) + int ps_init(struct dhcpcd_ctx *ctx) { @@ -369,7 +378,15 @@ ps_dostart(struct dhcpcd_ctx *ctx, ctx->fork_fd = -1; } pidfile_clean(); + eloop_clear(ctx->eloop); + eloop_signal_set_cb(ctx->eloop, + dhcpcd_signals, dhcpcd_signals_len, signal_cb, ctx); + /* ctx->sigset aready has the initial sigmask set in main() */ + if (eloop_signal_mask(ctx->eloop, NULL) == -1) { + logerr("%s: eloop_signal_mask", __func__); + goto errexit; + } /* We are not root */ if (priv_fd != &ctx->ps_root_fd) { @@ -393,15 +410,6 @@ ps_dostart(struct dhcpcd_ctx *ctx, ctx->ps_inet_fd = -1; } - eloop_signal_set_cb(ctx->eloop, - dhcpcd_signals, dhcpcd_signals_len, signal_cb, ctx); - - /* ctx->sigset aready has the initial sigmask set in main() */ - if (eloop_signal_mask(ctx->eloop, NULL) == -1) { - logerr("%s: eloop_signal_mask", __func__); - goto errexit; - } - if (eloop_event_add(ctx->eloop, *priv_fd, recv_msg, recv_ctx) == -1) { logerr("%s: eloop_event_add", __func__); @@ -466,7 +474,7 @@ ps_start(struct dhcpcd_ctx *ctx) case 0: return 0; default: - logdebugx("spawned privileged actioneer on PID %d", pid); + logdebugx("spawned privileged proxy on PID %d", pid); } /* No point in spawning the generic network listener if we're @@ -532,7 +540,7 @@ ps_entersandbox(const char *_pledge, const char **sandbox) } int -ps_mastersandbox(struct dhcpcd_ctx *ctx, const char *_pledge) +ps_managersandbox(struct dhcpcd_ctx *ctx, const char *_pledge) { const char *sandbox = NULL; bool forked; @@ -583,7 +591,7 @@ ps_mastersandbox(struct dhcpcd_ctx *ctx, const char *_pledge) return -1; } else if (ctx->options & DHCPCD_LAUNCHER || ((!(ctx->options & DHCPCD_DAEMONISE)) && - ctx->options & DHCPCD_MASTER)) + ctx->options & DHCPCD_MANAGER)) logdebugx("sandbox: %s", sandbox); return 0; } @@ -607,7 +615,7 @@ ps_stop(struct dhcpcd_ctx *ctx) ret = r; /* We've been chrooted, so we need to tell the - * privileged actioneer to remove the pidfile. */ + * privileged proxy to remove the pidfile. */ ps_root_unlink(ctx, ctx->pidfile); r = ps_root_stop(ctx); @@ -656,9 +664,11 @@ ps_unrollmsg(struct msghdr *msg, struct ps_msghdr *psm, const void *data, size_t len) { uint8_t *datap, *namep, *controlp; + socklen_t cmsg_padlen = + CALC_CMSG_PADLEN(psm->ps_controllen, psm->ps_namelen); namep = UNCONST(data); - controlp = namep + psm->ps_namelen; + controlp = namep + psm->ps_namelen + cmsg_padlen; datap = controlp + psm->ps_controllen; if (psm->ps_namelen != 0) { @@ -678,7 +688,7 @@ ps_unrollmsg(struct msghdr *msg, struct ps_msghdr *psm, return -1; } msg->msg_control = controlp; - len -= psm->ps_controllen; + len -= psm->ps_controllen + cmsg_padlen; } else msg->msg_control = NULL; msg->msg_controllen = psm->ps_controllen; @@ -699,9 +709,11 @@ ssize_t ps_sendpsmmsg(struct dhcpcd_ctx *ctx, int fd, struct ps_msghdr *psm, const struct msghdr *msg) { + long padding[1] = { 0 }; struct iovec iov[] = { { .iov_base = UNCONST(psm), .iov_len = sizeof(*psm) }, { .iov_base = NULL, }, /* name */ + { .iov_base = NULL, }, /* control padding */ { .iov_base = NULL, }, /* control */ { .iov_base = NULL, }, /* payload 1 */ { .iov_base = NULL, }, /* payload 2 */ @@ -713,6 +725,7 @@ ps_sendpsmmsg(struct dhcpcd_ctx *ctx, int fd, if (msg != NULL) { struct iovec *iovp = &iov[1]; int i; + socklen_t cmsg_padlen; psm->ps_namelen = msg->msg_namelen; psm->ps_controllen = (socklen_t)msg->msg_controllen; @@ -720,9 +733,17 @@ ps_sendpsmmsg(struct dhcpcd_ctx *ctx, int fd, iovp->iov_base = msg->msg_name; iovp->iov_len = msg->msg_namelen; iovp++; + + cmsg_padlen = + CALC_CMSG_PADLEN(msg->msg_controllen, msg->msg_namelen); + assert(cmsg_padlen <= sizeof(padding)); + iovp->iov_len = cmsg_padlen; + iovp->iov_base = cmsg_padlen != 0 ? padding : NULL; + iovp++; + iovp->iov_base = msg->msg_control; iovp->iov_len = msg->msg_controllen; - iovlen = 3; + iovlen = 4; for (i = 0; i < (int)msg->msg_iovlen; i++) { if ((size_t)(iovlen + i) > __arraycount(iov)) { @@ -833,6 +854,8 @@ ps_sendcmdmsg(int fd, uint16_t cmd, const struct msghdr *msg) { .iov_base = data, .iov_len = 0 }, }; size_t dl = sizeof(data); + socklen_t cmsg_padlen = + CALC_CMSG_PADLEN(msg->msg_controllen, msg->msg_namelen); if (msg->msg_namelen != 0) { if (msg->msg_namelen > dl) @@ -844,8 +867,13 @@ ps_sendcmdmsg(int fd, uint16_t cmd, const struct msghdr *msg) } if (msg->msg_controllen != 0) { - if (msg->msg_controllen > dl) + if (msg->msg_controllen + cmsg_padlen > dl) goto nobufs; + if (cmsg_padlen != 0) { + memset(p, 0, cmsg_padlen); + p += cmsg_padlen; + dl -= cmsg_padlen; + } psm.ps_controllen = (socklen_t)msg->msg_controllen; memcpy(p, msg->msg_control, msg->msg_controllen); p += msg->msg_controllen; @@ -856,7 +884,8 @@ ps_sendcmdmsg(int fd, uint16_t cmd, const struct msghdr *msg) if (psm.ps_datalen > dl) goto nobufs; - iov[1].iov_len = psm.ps_namelen + psm.ps_controllen + psm.ps_datalen; + iov[1].iov_len = + psm.ps_namelen + psm.ps_controllen + psm.ps_datalen + cmsg_padlen; if (psm.ps_datalen != 0) memcpy(p, msg->msg_iov[0].iov_base, psm.ps_datalen); return writev(fd, iov, __arraycount(iov)); diff --git a/contrib/dhcpcd/src/privsep.h b/contrib/dhcpcd/src/privsep.h index 87c84eb955..d843dda8fd 100644 --- a/contrib/dhcpcd/src/privsep.h +++ b/contrib/dhcpcd/src/privsep.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Privilege Separation for dhcpcd - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -85,7 +85,7 @@ sizeof(struct ps_msghdr) + \ sizeof(struct msghdr) + \ CMSG_SPACE(sizeof(struct in6_pktinfo) + \ - sizeof(int))) + sizeof(int))) /* Handy macro to work out if in the privsep engine or not. */ #define IN_PRIVSEP(ctx) \ @@ -176,7 +176,7 @@ int ps_init(struct dhcpcd_ctx *); int ps_start(struct dhcpcd_ctx *); int ps_stop(struct dhcpcd_ctx *); int ps_entersandbox(const char *, const char **); -int ps_mastersandbox(struct dhcpcd_ctx *, const char *); +int ps_managersandbox(struct dhcpcd_ctx *, const char *); int ps_unrollmsg(struct msghdr *, struct ps_msghdr *, const void *, size_t); ssize_t ps_sendpsmmsg(struct dhcpcd_ctx *, int, diff --git a/contrib/dhcpcd/src/route.c b/contrib/dhcpcd/src/route.c index 71523c146a..ef9c412580 100644 --- a/contrib/dhcpcd/src/route.c +++ b/contrib/dhcpcd/src/route.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - route management - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -96,17 +96,6 @@ rt_maskedaddr(struct sockaddr *dst, memset(dstp, 0, (size_t)(addre - dstp)); } -int -rt_cmp_dest(const struct rt *rt1, const struct rt *rt2) -{ - union sa_ss ma1 = { .sa.sa_family = AF_UNSPEC }; - union sa_ss ma2 = { .sa.sa_family = AF_UNSPEC }; - - rt_maskedaddr(&ma1.sa, &rt1->rt_dest, &rt1->rt_netmask); - rt_maskedaddr(&ma2.sa, &rt2->rt_dest, &rt2->rt_netmask); - return sa_cmp(&ma1.sa, &ma2.sa); -} - /* * On some systems, host routes have no need for a netmask. * However DHCP specifies host routes using an all-ones netmask. @@ -122,6 +111,22 @@ rt_cmp_netmask(const struct rt *rt1, const struct rt *rt2) return sa_cmp(&rt1->rt_netmask, &rt2->rt_netmask); } +int +rt_cmp_dest(const struct rt *rt1, const struct rt *rt2) +{ + union sa_ss ma1 = { .sa.sa_family = AF_UNSPEC }; + union sa_ss ma2 = { .sa.sa_family = AF_UNSPEC }; + int c; + + rt_maskedaddr(&ma1.sa, &rt1->rt_dest, &rt1->rt_netmask); + rt_maskedaddr(&ma2.sa, &rt2->rt_dest, &rt2->rt_netmask); + c = sa_cmp(&ma1.sa, &ma2.sa); + if (c != 0) + return c; + + return rt_cmp_netmask(rt1, rt2); +} + static int rt_compare_os(__unused void *context, const void *node1, const void *node2) { @@ -409,6 +414,7 @@ rt_proto_add_ctx(rb_tree_t *tree, struct rt *rt, struct dhcpcd_ctx *ctx) return rt; rt_free(rt); + errno = EEXIST; return NULL; } diff --git a/contrib/dhcpcd/src/route.h b/contrib/dhcpcd/src/route.h index cb935c83bd..45f0e1a7dc 100644 --- a/contrib/dhcpcd/src/route.h +++ b/contrib/dhcpcd/src/route.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - route management - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * rEDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS, WITH OR WITHOUT diff --git a/contrib/dhcpcd/src/sa.c b/contrib/dhcpcd/src/sa.c index 4d898b4ecd..c6a19d1bef 100644 --- a/contrib/dhcpcd/src/sa.c +++ b/contrib/dhcpcd/src/sa.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Socket Address handling for dhcpcd - * Copyright (c) 2015-2020 Roy Marples + * Copyright (c) 2015-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/sa.h b/contrib/dhcpcd/src/sa.h index fb10088da8..69724cd857 100644 --- a/contrib/dhcpcd/src/sa.h +++ b/contrib/dhcpcd/src/sa.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * Socket Address handling for dhcpcd - * Copyright (c) 2015-2020 Roy Marples + * Copyright (c) 2015-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/contrib/dhcpcd/src/script.c b/contrib/dhcpcd/src/script.c index 5f404eac45..6173b4020f 100644 --- a/contrib/dhcpcd/src/script.c +++ b/contrib/dhcpcd/src/script.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -390,6 +390,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, if (ifp->ctx->options & DHCPCD_DUMPLEASE) goto dumplease; + ifp->ctx->rt_order = 0; rb_tree_init(&ifaces, &rt_compare_proto_ops); TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) { if (!ifp2->active) @@ -397,7 +398,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, rt = rt_new(UNCONST(ifp2)); if (rt == NULL) goto eexit; - if (rb_tree_insert_node(&ifaces, rt) != rt) + if (rt_proto_add(&ifaces, rt) != rt) goto eexit; } if (fprintf(fp, "interface_order=") == -1) diff --git a/contrib/dhcpcd/src/script.h b/contrib/dhcpcd/src/script.h index 9bcd3350d4..feb8574d59 100644 --- a/contrib/dhcpcd/src/script.h +++ b/contrib/dhcpcd/src/script.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2020 Roy Marples + * Copyright (c) 2006-2021 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without -- 2.41.0