Roy Marples [Tue, 7 Jan 2020 22:15:09 +0000 (22:15 +0000)]
DHCP6: Calulate ReTransmission using milliseconds
This is the exact formula in RFC8415 Section 15, the prior one
was not so exact.
This makes the code a lot simpler and removes the need for
complicated timespec handling.
Roy Marples [Tue, 7 Jan 2020 14:15:14 +0000 (14:15 +0000)]
eloop: reduce timers rather than calculating expiry
This saves the need to store a created date per timer, we just need
to know when the timers were last changed which we can store in the
eloop.
This makes it easier to make the actual timeout for polling.
While here, add the eloop_timespec_diff function to workout the
elapsed time from usp to tsp even when time has wrapped on one or
both times.
This works if time wraps on the maximal size time_t allows AND
we know that tsp is always newer than usp.
Roy Marples [Wed, 1 Jan 2020 11:18:49 +0000 (11:18 +0000)]
eloop: Allow for for timeouts greater than time_t and time wrapping
On some systems time_t is int32_t.
However, on wire timeouts are generally uint32_t.
As such, we need to avoid using timespec internally except to
record when the timeout was created. Instead, record the timeout
as unsigned int seconds and long nanoseconds.
On long running systems using time_t as int32_t, monotonic time
would wrap after approximately 68 years. It's highly unlikely dhcpcd
would be running for so long, but just incase it does, the code
should now cope.
Roy Marples [Wed, 1 Jan 2020 22:35:56 +0000 (22:35 +0000)]
Merge pull request #12 from andersk/ra-time-units
The RA times are provided in milliseconds, but commit 569051c8aa8fc297eb8edb7bd228e0fd353d30c1 (dhcpcd-8.1.3~18) “Linux:
prefer ms RA times” incorrectly scaled them by an extra factor of 1000
before writing them to retrans_time_ms and base_reachable_time_ms.
Instead, write the values in milliseconds directly to the *_ms files,
and correctly convert to jiffies or seconds for the other files if
necessary.
Anders Kaseorg [Wed, 1 Jan 2020 19:42:47 +0000 (11:42 -0800)]
Linux: fix RA time unit confusion
The RA times are provided in milliseconds, but commit 569051c8aa8fc297eb8edb7bd228e0fd353d30c1 (dhcpcd-8.1.3~18) “Linux:
prefer ms RA times” incorrectly scaled them by an extra factor of 1000
before writing them to retrans_time_ms and base_reachable_time_ms.
Instead, write the values in milliseconds directly to the *_ms files,
and correctly convert to jiffies or seconds for the other files if
necessary.
Roy Marples [Tue, 17 Dec 2019 22:16:26 +0000 (22:16 +0000)]
DHCP6: Rework delegation deprecation
Split ipv6_addaddrs out so ipv6_doaddr can operate on a single address.
Call this when deprecating delegated addresses to avoid calling
ipv6_addaddrs.
This allows a more simple ipv6_addaddrs that doesn't need to test
which address collection we are deleting from and removes DHCPv6
specific code from the generic IPv6 module.
Roy Marples [Fri, 29 Nov 2019 22:11:46 +0000 (22:11 +0000)]
dhcpcd: Rework daemonisation
Now that we spawn helper processes for priviledge separation,
we need to fork() and setssid() much earlier. Infact, pretty much
from the get go of starting up.
dhcpcd_daemonise now writes to the launcher signal pipe about the
result of "daemonisation", even though it's already deamonised at
this point.
This allows dhcpcd to keep the helper processes running when
started by the system init at boot.
Roy Marples [Fri, 29 Nov 2019 13:55:46 +0000 (13:55 +0000)]
privsep: Use another eloop instead of a blocking read.
We need to read the error status from making a privileged request.
This happens in an eloop already, but the read itself needs to block.
So that we can still be interupted, use an inner eloop whose sole
purpose is to monitor the root fd for message back. Then we can
make the fd non blocking.
Roy Marples [Thu, 28 Nov 2019 16:41:15 +0000 (16:41 +0000)]
privsep: Add support for priviledge separation
Not enabled by default - enable with ./configure --enable-privsep
Requires a user added to the system - default _dhcpcd
Several processes will be spawned off the main state engine:
a privileged actioneer and a generic network proxy.
Only the privileged actioneer process will retain root permissions.
When required, the privileged actioneer will also spawn
BPF listeners for BOOTP (DHCP) and ARP.
The BOOTP BPF listener should be a short lived process.
On kernels with RFC 5227 support, the ARP BPF listener will only
be used for ARPing and announcing a preferred address and will
also be a short lived process.
When not running in master mode, an address listener will be
spawned for each address (with the exception of RA dervived addresses)
dhcpcd cares about.
TODO:
* Solaris support.
* ARP BPF address filtering.
Roy Marples [Thu, 28 Nov 2019 11:17:23 +0000 (11:17 +0000)]
DHCP: Require unspecificed BOOTP port for master mode
This mirrors DHCP6 behaviour and will make privsep easier.
This is also a change in behaviour from prior versions and is the
first real change for dhcpcd-9.