Roy Marples [Fri, 23 Aug 2019 17:01:24 +0000 (18:01 +0100)]
BSD: Fix router reachability tests
dhcpcd likes to indicate an on-link route as a NULL gateway.
However, we were testing this for an AF_LINK address to ensure
reachability. As such, it was possible to log a false positive.
Instead, record the existance of a valid AF_LINK address via
RTDF_GATELINK.
While here, ensure that we only treat RTM_DELETE as unreachable
and only other messages with RTDF_GATELINK as reachable, ignoring
other states so that a new incomplete address won't make us
unreachable if we're just discovering it.
Roy Marples [Tue, 20 Aug 2019 21:59:47 +0000 (22:59 +0100)]
Linux: Add support for ARPHRD_NONE
So apprently I've been doing this wrong for years - on glibc at
least, getifaddrs(3) never reported a hardware address for
AF_PACKET addresses. Infact, it reported nothing but useless
stats in ifa_data.
I view this as a bug because SIOCGIFHWADDR will get a sockaddr
with a sa_family set correctly. getifaddrs should do the same.
Anyway, if we have the ioctl and no address for the AF_PACKET
"address", call upon the above ioctl to get the correct family
for the interface.
While here, replace if_nametoindex with an ioctl to save libc
from doing it for us.
Roy Marples [Tue, 20 Aug 2019 18:11:01 +0000 (19:11 +0100)]
DHCP: Remove check for requiring a clientid when hwlen == 0
We forced DUID anyway for this, so the check is now invalid
and allows (mostly) default config to work.
This does rely on one interface being found with a valid
hardware address to seed the DUID file initally, which
should always be the case.
Roy Marples [Fri, 16 Aug 2019 21:29:58 +0000 (22:29 +0100)]
script: Rework assert to pass coverity.
It does work differently for non debug builds, but we don't care
because we reset the value anyway.
This way maybe more descriptive and does avoid a write.
Roy Marples [Wed, 31 Jul 2019 08:39:58 +0000 (09:39 +0100)]
DHCP: Rework checksuming so that the packet isn't touched.
Other than setting udp->uh_sum to zero which we need to do to
calculate the checksum.
Also, the UDP checksum needs to include a pseudo IP header
without options and mostly blank. Instead of changing the packet,
just checksum a blank object we've filled in with the needed
data from the given IP object and use this to start the UDP
checksum calculation with.
While here, improve the checksum function so it more matches the
in_cksum function as noted in RFC 1071 4.1 using 16 byte words.
Roy Marples [Mon, 29 Jul 2019 12:31:23 +0000 (13:31 +0100)]
ND6: Disable advertising on OS other than NetBSD and Linux
It's only used for IP6 address sharing to prefer an interface,
but this only works on NetBSD. It might work on Linux too.
For all other OS advertising either fails to work (OpenBSD)
or erroneously logs duplicate address messages (all other BSD's).
Roy Marples [Sun, 28 Jul 2019 10:49:17 +0000 (11:49 +0100)]
script: ensure that tmp files are removed
fopen creates a new stream which will use a new fd.
Why using fdopen, the new stream will use the same fd, so when
it's closed the tmp file will really unlink.
Roy Marples [Thu, 25 Jul 2019 15:27:09 +0000 (16:27 +0100)]
NetBSD: Allow dhcpcd to be built without ARP support
Because NetBSD has RFC 5227 support in the kernel, we only need
ARP to announce addresses and we only need to do that when
address sharing which shouldn't be a concern for small
installations where size is paramount.
Roy Marples [Tue, 23 Jul 2019 14:27:48 +0000 (15:27 +0100)]
Linux: Work around a coverity issue
sa points to a struct sockaddr inside a union where the
biggest member os sockaddr_in6.
We cast sa to char *, and then write to the address offset
directly which will go beyond a sockaddr if we're writing
a sockaddr_in6 - but this is fine, the union caters for it.
Roy Marples [Mon, 22 Jul 2019 09:37:13 +0000 (10:37 +0100)]
DHCP: Set address vltime and pltime to the length of the lease
The only OS which supports this is Linux, but more importantly it
will report the address as "dynamic" so that users can distinguish
it from statically added addresses.
Roy Marples [Tue, 16 Jul 2019 09:53:35 +0000 (10:53 +0100)]
arp: Fix a crash when dhcpcd forks or an interface removed
Because we try and free the ARP state when dhcpcd forks or an
interface is removed, the loop to work out the next state to free
could return invalid memory.
So test we have an ARP state each time we iterate and free.