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.
Roy Marples [Tue, 18 Jun 2019 10:33:53 +0000 (11:33 +0100)]
script: Write variables to a FILE
Each variable is NULL terminated inside the file just like the
control stream which saves us from having to flatten it when
writing to the control stream.
Once written, create env pointers to the start of each string
just after the NULL terminator.
This also means that we just need to free two buffers when
dhcpcd exits (FILE buffer and env buffer) rather than each variable
individually.
If open_memstream(3) is not supported by libc then dhcpcd will
write to a file in /tmp instead.
Roy Marples [Fri, 14 Jun 2019 16:05:24 +0000 (17:05 +0100)]
RA: expire whole RA on carrier up
If preserving IP, we need to expire the whole RA now that we care
about RDNSS and DNSSL lifetimes. Cheat by setting the aquired time
to something very low so it all expires.
Roy Marples [Fri, 14 Jun 2019 12:53:51 +0000 (13:53 +0100)]
RA: expire RDNSS and DNSSL entries
This allows us to remember N fully expired RA's which works around
an obscure issue where a received RA has no lifetime or any
prefixes with lifetimes but does have an instruction to start DHCP6.
It was harmless but filled the log with spam and now there is no
log spam!
Roy Marples [Wed, 12 Jun 2019 12:43:27 +0000 (13:43 +0100)]
DHCP6: Keep running regardless of RA state
We should keep DHCP6 running even if routers expire or link changes.
This is noted in RFC3315 18.1.2:
If the client receives no responses before the message transmission
process terminates, as described in section 14, the client SHOULD
continue to use any IP addresses, using the last known
lifetimes for those addresses, and SHOULD continue to use any other
previously obtained configuration parameters.