Roy Marples [Mon, 15 May 2017 12:10:17 +0000 (13:10 +0100)]
Prefix Delegation: build routes after all addresses delegated
Summary:
When addresses are delegated the routing for them needs to be
managed. But this can be done after all addresses have been
added because DaD will cause the scripts to be run shortly
after adding all of them.
The only problem with this approach is when dhcpcd is restarted
and adds a delegation which already exists. In this case,
dhcpcd will log it added the route after it ran the hook script.
This is of course incorrect because the route should already be
there and working - assuming dhcpcd is the sole changer of the route.
Fixes T117 because rebuilding the routes inside the enumeration
of interfaces may change the order of interfaces and thus break
the enumeration.
Test Plan:
Setup dhcpcd to request delegation to many interfaces.
Once delegation is assigned, drop and restore carrier on the upstream interface.
Observe dhcpcd assigns delegations to all interfaces with carriers.
Roy Marples [Mon, 24 Apr 2017 19:50:45 +0000 (20:50 +0100)]
DHCPv6: deprecate addresses on stale leases.
Summary:
When a DHCPv6 Address or Prefix Delegation is leased, it may not be renewed as a
different one could be assigned. In this situation, we should
prompt the kernel to prefer this new one by deprecating the old
one. This is achieved by setting it's pltime to zero.
Related to T114.
Test Plan:
Configure your DHCPv6 server to assign a delegation from Pool A.
Configure dhcpcd to lease a Prefix delegation and assign it
to a downstream interface.
Start dhcpcd.
Configure your DHCPv6 server to asssign a delegation from Pool B.
Down/Up the link dhcpcd is using.
dhcpcd should assign the new delegation and depreate the old
by marking it's pltime as zero.
Roy Marples [Wed, 26 Apr 2017 08:57:16 +0000 (09:57 +0100)]
IPv6: show actual address lifetimes being applied
Summary:
For IPv6, the acquisition time of the address is stored.
When adding the address during a refresh, the valid and preferred
times are decreased by the difference between the acquisition time
and the current time. This is not shown in the logs, but it should
be otherwise you could be confused by a prefix adding an address,
but it really came from a stale lease.
While here, if vltime overflows then log an error and zero it.
This effectively removes the address when it's added.
Related to T114.
Test Plan:
Configure your DHCPv6 server to lease a Prefix from Pool A.
Configure dhcpcd to request a Prefix Delegation and assign to
a downstream interface.
Start dhcpcd.
Configure your DHCPv6 server to lease a Prefix from Pool B.
Observe dhcpcd debug logs - it should note that addresses
previously assigned from group A have decreasing valid times.
Roy Marples [Tue, 2 May 2017 18:58:19 +0000 (19:58 +0100)]
DHCPv6: drop Prefix Delegations when dropping the lease.
Summary:
When dropping the lease, we should drop any Delegated Prefixes
as well, because they are from the lease.
Add a note to say if this needs to be changed, at least mark
the Delegated Prefixes as deprecated.
Fixes T114.
Test Plan:
Configure dhcpcd to request a Prefix Delegation and assign it to a downstream
interface.
Bring the interface down which dhcpcd requests the delegation from.
dhcpcd should remove the assigned delegation from the other interface.
Roy Marples [Mon, 24 Apr 2017 20:08:31 +0000 (21:08 +0100)]
prefix delegation: Remove deleted addresses from consideration
Summary:
Currently dhcpcd does not free addresses generated from stale
Prefix Delegation leases which then expire. As the address
isn't likely to come back anytime soon it should be freed.
Related to T114.
Test Plan:
Configure your DHCPv6 server to lease a Prefix from Pool A.
Configure dhcpcd to request a Prefix Delegation and assign to
a downstream interface.
Start dhcpcd.
Configure your DHCPv6 server to lease a Prefix from Pool B.
Observe dhcpcd debug logs - it should detect the kernel
removing the deleted address and not re-add it when the prefix
changes.
Roy Marples [Tue, 25 Apr 2017 19:47:53 +0000 (20:47 +0100)]
Because dhcpcd now binds to the interfaces LL address when not
running in master mode, the socket options SO_REUSEADDR and
SO_REUSEPORT can be dropped.
If there is a problem binding the socket, log an error.
Roy Marples [Tue, 11 Apr 2017 17:04:03 +0000 (18:04 +0100)]
Write syslog entries in logfile:
date tag[pid]: message
This does add a few more bytes, but it allows for the same log
analysis tools to be used.
When building SMALL, this code is removed and you just get the
message in the logfile.
Roy Marples [Sun, 9 Apr 2017 07:44:16 +0000 (08:44 +0100)]
logerr: errx with logging
Had a few complaints that the lastlog option was dropped.
It's now been restored, but with a new way of logging which is
the same as errx(3) as found on the BSD platforms but the output
also goes to the logging option of choice.
This allows the function to define the log priority for syslog
and there is no more need to specify %m.
In turn, this makes the code needed to write error messages
a lot shorter than before.
loginfo and logdebug have no optional x suffix because they are not
meant to record errors, unlike logerr and logwarn.
Roy Marples [Tue, 4 Apr 2017 10:49:24 +0000 (11:49 +0100)]
bpf: rewind the buffer on close
BPF reads the whole BPF buffer in for processing.
We might close the BPF socket during processing and because the
buffer is shared between ARP and DHCP we need to re-wind it
when closing.
Roy Marples [Tue, 4 Apr 2017 08:55:33 +0000 (09:55 +0100)]
bpf: trim ARP payload in the BPF filter.
ARP is a fixed sized packet, the size varies only on the type of
datalink. As such, instruct the BPF filter to trim the payload
to this size so any extra data such as FCS or even junk, is discarded.
Roy Marples [Tue, 4 Apr 2017 08:45:27 +0000 (09:45 +0100)]
bpf: don't check caplen == datalen
Some drivers return FCS at the end of the payload to BPF.
AFAIK, we have no way of knowing this in userland.
We can guess that FCS is there because the BPF filter trims the
DHCP payload to the Frame and IP lengths, but equally the data
could be anything.
As such removing the check that caplen == datalen makes sense.
Roy Marples [Thu, 30 Mar 2017 10:57:49 +0000 (11:57 +0100)]
dhcpcd: fix crash forcing lease renewals on inactive interfaces.
Summary:
Forcing a lease renewal on an interface assumes all interfaces
will have options. This is no longer the case because dhcpcd now
lists every interface on the system and the active flag indicates
whether dhcpcd is controlling it or not, so we need to check this
before blindly renewing.
While here, add a syslog entry to note the forced renew and make
the code a little more readable by returning early rather than
enclosing in if blocks.
Fixes T111.
Test Plan:
Start dhcpcd and send it SIGUSR1.
Check it does not crash and review renewal notice in syslog.