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.
Roy Marples [Sat, 22 Feb 2025 13:21:17 +0000 (13:21 +0000)]
route lifetime behaviour should mirror other lifetimes
Each lifetime has a an aquistion time so we can compare to
now to know how much of the lifetime is left.
Apply the difference when adding/changing the route just as we
do for addresses.
This allow us to work out better when we need to update the
route lifetime from a newer aquisition.
Roy Marples [Thu, 20 Feb 2025 13:41:34 +0000 (13:41 +0000)]
BSD: Loop when pulling routes into our buffer if no memory
We need to make two sysctls to pull the route table from the kernel.
The first one works out the size of the buffer required and the
second one populates it.
It's possible for more routes to be added between these two calls
causing the second call to fail with ENOMEM.
If this happens, just re-query the size needed and try again.
Roy Marples [Tue, 18 Feb 2025 09:48:19 +0000 (09:48 +0000)]
BSD: Fix netmask family and length for incoming route msgs
Netmask family and length are ignored by traditional
userland tools such as route and netstat and are assumed
to match the destination sockaddr.
This is fortunate because BSD kernels use a radix tree
to store routes which adjusts the netmask at the point
of insertion where this information is lost.
We can just sub in the values from the destination address.
Roy Marples [Thu, 13 Feb 2025 11:05:10 +0000 (11:05 +0000)]
Fix building with different options
Fixes #458.
Add many build options to the NetBSD target
Set any warnings to be errors as NetBSD should build without
any warnings. DragonFly as well, but we don't have a target for that.
Roy Marples [Fri, 7 Feb 2025 11:47:01 +0000 (11:47 +0000)]
BSD: Improve NEWADDR == IFF_UP handling
On BSD when an address is added, the interface is automatically
brought up.
We can detect this by RTM_NEWADDR, but that lacks the IFF_UP flag.
We really want to stay in sync with RTM messages for flags, but
here we need to check the interface for IFF_UP if we think it's
not there. Only set that.
This fixes NEWADDR announcements for state transitions when
the interface is currently down.
Colin McInnes [Wed, 5 Feb 2025 19:38:55 +0000 (13:38 -0600)]
Always send req for InfoRefreshTime option on Inform-Req (#446)
RFC8415 says client must always request Information Request refresh time
option 32.
Client has other logic for handling if server does not include this in
the reply.
Colin McInnes [Wed, 5 Feb 2025 14:06:10 +0000 (08:06 -0600)]
Update route if lifetime needs changing (#441)
Everything about IPv6 is lifetime, not expiry.
Only linux routes have an expiry.
OK, this is not consistent at all!
In the kernel RTA_EXPIRES is only set for IPv4 multicast routes
when emitting route changes and only read for IPv6 routes when
userland makes route changes.
We cannot set this for non IPv6 routes currently.
To make it worse, we set a UINT32 for IPv6 routes but read a
UINT64 for IPv4 multicast routes.
To make this even more totally bonkers, the expiry we set for
the IPv6 route can be read back via RTA_CACHEINE rta_expires
but we need to convert to divide it by hz.
Now we can read kernel route lifetime correctly, we can compare this to what we think it should be when building the routing table (allowing for some deviation due to processing time) and update if needed.
Roy Marples [Thu, 31 Oct 2024 10:40:46 +0000 (10:40 +0000)]
logerr: use LOG_NDELAY for openlog
This ensures openlog gets a fd so logging of errors can occur
within privsep where no log was written before entering privsep.
Also ensures that closelog does not close -1 on some platforms
where no logging took place.
Ken Simon [Tue, 29 Oct 2024 23:11:54 +0000 (19:11 -0400)]
IPv6: Avoid uninitialized ifp state when adding address (#395)
In certain instances, `ifp->if_data[IF_DATA_IPV6]` was not yet
initialized when ipv6_addaddr adds the address to the state, and a
segfault would ensue. Mitigate this by ensuring the state is initialized
when adding the addresses.
Jon Franklin [Tue, 29 Oct 2024 07:53:51 +0000 (02:53 -0500)]
DHCP6: lastlease behavior after Confirm non-response (#387)
If lastlease is enabled, and dhcpcd is unable to confirm its prior
lease, after timeout, bind the lease and move to the REBIND state.
Confine lastlease behavior to the CONFIRM and REBIND states.
Co-authored-by: Jon Franklin <jon_franklin@dell.com>
Roy Marples [Mon, 14 Oct 2024 09:48:23 +0000 (10:48 +0100)]
IPv6: allow any global address for default route
Regardless if we are a router or not.
BSD IPv6 source address selection does really matter for this.
This fixes FreeBSD systes where the forwarding sysctl is set
by the routing script which starts late in the day where
dhcpcd is already running and won't get the default route applied
until another RA comes in which could be a while.
Roy Marples [Thu, 10 Oct 2024 13:19:46 +0000 (14:19 +0100)]
linux: Support old kernels by not including linux/if.h
I wish the linux team used #defines rather than enums, but heh ho.
Ensure we can test IFF_LOWER_UP, IFF_DORMANT and IFA_FLAGS
based on nearest matching #defines available when the respective
feature was comitted.
Diego Santa cruz [Thu, 10 Oct 2024 10:45:34 +0000 (12:45 +0200)]
dhcpcd: stdout output sometimes empty when redirected to a file (#364)
Running dhpcd --dumplease with input from stdin and redirecting stdout
to a file outputs nothing to the output. The reason is that printf /
fprintf is used to write the output but it is not explicitly flushed
when done, or before exiting, and stdout to files is fully buffered by
default while stdout to terminals is line buffered by default.
This adds calls to fflush() at the end of dhcp_print_option_encoding()
and script_dump(), plus one just before exiting dhcpcd.
Signed-off-by: Diego Santa Cruz <diego.santacruz@spinetix.com>
dhcp6: start request when advertise received after IRT (#376)
After the initial solicit timeout, any received advertisements trigger
a request. However, after the timeout, any advertisements will
never result in a request, and the client sends solicits forever.
This patch adds sends a request in response to an advertise if the
initial timeout has expired.