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.
While here, clarify the BPF instruction space needed for ARP as it
could overflow in the very unlikely event we ARP for three
addresses at the same time.
Roy Marples [Fri, 3 May 2019 13:44:06 +0000 (14:44 +0100)]
DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
dhcpcd only checks that the prefix length of the exclusion
matches the prefix length of the ia and equals the length of the
data in the option.
This could potentially overrun the in6_addr structure.
This is fixed by enforcing RFC 6603 section 4.2 option limits
more clearly.
Thanks to Maxime Villard <max@m00nbsd.net> for finding this.
Roy Marples [Thu, 2 May 2019 20:25:57 +0000 (21:25 +0100)]
BSD: Simplify carrier detection once more.
RTM_IFINFO messages now send the un-molested link status to
the main carrier handler which no longer polls on LINK_UNKNOWN.
Instead, we check carrier status directly, which if unsupported
we instead interface flags.
This is 2019, all interface drivers should report link status
correctly via RTM_IFINFO messages and trying to constantly work
around this is error prone and time consuming.