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.
Roy Marples [Fri, 4 Oct 2024 15:36:01 +0000 (15:36 +0000)]
dhcpcd: remove advertisement of addresses
Address advertisemnt was used to allow IP address sharing to work.
It also required the DHCP server to allow the same IP for many
hosts, which modern DHCP servers deny you from doing.
Lastly, there are niggles with the implementation that are
impossible to fully fix due to how the various protocols work,
especially ARP.
All platforms dhcpcd supports allow better ways of doing this,
such as bonding (Linux), trunk(4) (OpenBSD), lagg(4) (Other BSDs).
ARP advertisements will only be made when addresses are added
OR defended against for kernels without RFC 5227 support.
Roy Marples [Wed, 11 Sep 2024 09:28:58 +0000 (10:28 +0100)]
IPv6: Only advertise addresses when needed
Remember when we have advertised an address.
If we want to advertise it again, check this first.
If we still want to advertise it, clear this flag for all other
matching addresses.
Clear advertised flags from all addresses on carrier up.
This reduces needless NA spam from dhcpcd when the IPv6 Router
is needlessly chatty with RA.
Roy Marples [Tue, 3 Sep 2024 08:37:47 +0000 (09:37 +0100)]
privsep: Capsicum needs root to access ipv6 forwarding sysctl
Optimise the flow so that if we do have a global address on the
source interface we avoid the sysctl via the privileged process.
Generally the only time we don't is when we de-configure an
interface or we are configuring an interface where there is
no autoconf prefix from the RA and the only globals come
from a DHCPv6 Prefix Delegation to other interfaces which
requires us to be a router.
Roy Marples [Wed, 28 Aug 2024 18:04:53 +0000 (19:04 +0100)]
IPv6: Add the added address to state
We used to rely on route(4) adding it to state based on RTM_NEWADDR
but the message could get lost if the socket overflows.
Work around this by always adding the address to the state.
Roy Marples [Mon, 29 Jul 2024 15:17:08 +0000 (16:17 +0100)]
DHCP: No longer set interface mtu (#346)
We've been enforcing an interface MTU that is slightly larger
than the minimum for some time.
Instead, log an error than the MTU is smaller than the minimum
to send a BOOTP message.
The DHCP MTU is only used when adding routes as setting the
interface MTU can cause a PHY reset which is bad.