Roy Marples [Fri, 6 Mar 2026 23:02:36 +0000 (23:02 +0000)]
BSD: don't send uninitialised memory using ps_root_indirectioctl
This will affect FreeBSD and OpenBSD.
Use sendmsg to send the length of the interface name, then the
interface name and then the data rather than just sending
IFNAMSIZ which may have uninitialised bytes at the end.
Opimise ps_sendcmdmsg while here.
Hopefully helps #565 but I'm not hopeful.
Daniel Gröber [Fri, 6 Mar 2026 22:47:42 +0000 (22:47 +0000)]
manager: Fix loosing iface options on CARRIER
When an interface (re-)gains carrier dhcpcd_handlecarrier() runs
dhcpcd_initstate() to kick off profile re-selection. Previously this used
args originally passed when starting the manager (ctx->argv).
However interfaces started via the manager control
interface (dhcpcd_initstate1() in dhcpcd_handleargs()) may be started with
different args.
For example if we start a manager with
dhcpcd -M --inactive
and then start only IPv4 on an interface with
dhcpcd -4 iface0
a subsequent CARRIER event will reset the interface to what amounts to
"default config + `-M --inactive`" which in this case will enable ipv6
also!
To fix this we keep a copy of the arguments used to start an interface in
the manager (dhcpcd_handleargs()) code path around around (ifp->argv).
In the current implementation args passed for renew following the initial
interface start will not be persisted. This causes the interface to reset
to a state of "defaults + config + profile + start-cmdline".
For example (continuing the scenario above) after enabling ipv6 with -n:
$ dhcpcd -6 -n iface0
A subsequent CARRIER event will disable ipv6 again as the effective
arguments remain `-4 iface0` as passed during interface start.
Note the per-interface daemon code path wasn't affected as ctx->args
already contains the interface start args.
acst1223 [Thu, 26 Feb 2026 08:35:12 +0000 (17:35 +0900)]
DHCP: Add parentheses to macro definitions
Missing parentheses in IP_UDP_SIZE caused wrong computation of MSZ
(option57). When mtu is 1500, current MSZ value is 1488=1500-20+8, while
the correct value should be 1472=1500-(20+8).
Roy Marples [Tue, 17 Feb 2026 12:48:55 +0000 (12:48 +0000)]
privsep: Ensure we recv for real after a successful recv MSG_PEEK
* privsep: Ensure we recv for real after a successful recv MSG_PEEK
Adjust the code flow so that the same errors would be caught
after the final recv.
This ensures we read what is really meant for us and not
something silly.
Jessica Clarke [Fri, 9 Jan 2026 21:56:25 +0000 (21:56 +0000)]
common: Cast via uintptr_t rather than unsigned long in UNCONST (#581)
On ILP32 and LP64 systems, unsigned long is sufficient to round-trip
pointers, but on LLP64 systems it is too small, and on systems like
CHERI where pointers are capabilities, it does not propagate capability
metadata, and casting back to a pointer to yield a pointer that cannot
be dereferenced.
Instead, cast via uintptr_t to ensure we always use an integral type
that can losslessly round-trip pointers.
Roy Marples [Thu, 13 Nov 2025 14:40:02 +0000 (14:40 +0000)]
BSD: Reject routes are not cloned/connected routes
Likewise, if we change from a reject to a non reject route
we need to remove it rather than changing it as some BSD
kernels preserve the RTF_GATEWAY flag.
Roy Marples [Tue, 11 Nov 2025 13:13:03 +0000 (13:13 +0000)]
Protocols will notify when dhcpcd can exit (#536)
* Protocols will notify when dhcpcd can exit
DHCPv6 RELEASE requires the addresses to be dropped before
a RELEASE message is sent.
We now wait for an acknowledgement or a timeout before notifying
that DHCPv6 has stopped for the interface.
DHCPv4 RELEASE is the other way around, there is no acknowledgement.
So we wait for 1 second after sending the message before removing
the address and notifying DHCP has stopped for the interface.
If we are not releasing then we notify dhcpcd that the protocol has
stopped right away when we drop the lease.
dhcpcd will exit once there are no running protocols for the
interfaces.
Fixes #513.
Hopefully #535, #519 and #509 as well.
Roy Marples [Thu, 30 Oct 2025 14:07:54 +0000 (14:07 +0000)]
eloop: Import latest from dhcpsd
Finally have kqueue and epoll working for a multi-process
setup.
The secret sauce was that after forking the fd for polling
is invalid and as such should not be closed blindly.
Roy Marples [Tue, 30 Sep 2025 08:41:18 +0000 (09:41 +0100)]
route: Don't change them when exiting with persistence.
If an interface stops, it might affect the routing priority.
When dhcpcd is exiting we want to avoid this behaviour to keep
the system running as best as.
To guarantee that a reader will never read two messages in one read
operation, the writer shall put end of record markers.
The problem exposed itself in FreeBSD 15.0 that started to follow the
specification better than before.
Other SOCK_SEQPACKET usage considerations: a) as long as our reader
provides a receive buffer that would fit the largest message our writer
would ever send, we are good with regards to not a reading a partial
message b) as long as our writer always write full messages with one
write, we don't need use of MSG_WAITALL in reader.
Roy Marples [Thu, 19 Jun 2025 09:15:20 +0000 (10:15 +0100)]
DHCP: Put the message type option first
There is no ordering requirement from any RFC other than the
recommendations in RFC 7844.
But it seems some DHCP servers really want the message type as
the first option.
Roy Marples [Sun, 1 Jun 2025 15:52:28 +0000 (16:52 +0100)]
compat: use timingsafe_bcmp if available
Its return value is the opposite of consttime_memequal.
This function is available all modern BSD's except for NetBSD where
we have consttime_memequal.
Doug Nazar [Fri, 25 Apr 2025 19:37:54 +0000 (15:37 -0400)]
Restore logic on when to open an address specific socket (#502)
850f93b changed the logic while moving things around. Restore
the original logic so we open a socket even if the address is the
same, so long as it's the first time.
Roy Marples [Tue, 15 Apr 2025 09:29:11 +0000 (10:29 +0100)]
privsep: Fix valgrind and hardened-malloc on Linux with SECCOMP
Valgrind will still error by default at exit as the syscall to
unlink the pipe files is denied.
This can be avoided by compiling with -DVALGRIND.
The pipe files still won't be removed as dhcpcd has
already dropped to the non root user.
This is a Vagrind issue really.
hardened-malloc should now run as well as their documented syscalls
are now allowed by default.
Roy Marples [Sun, 9 Mar 2025 19:56:40 +0000 (19:56 +0000)]
BPF: Start with the EOF marker set
This will allow us to abort any BPF read loop if it's reset.
While here, delay restarting DHCP slightly to allow privsep builds
to recover the same error.