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.
Roy Marples [Fri, 24 Mar 2017 09:13:02 +0000 (09:13 +0000)]
Remove custom logger and output all diagnostics via syslog(3).
Remove the --logfile option.
Support LOG_PTRIM and LOG_NLOG if available.
This reduces the binary size by almost 5k.
If you don't like how the diagnostics look on your screen, speak
with your libc vendor about implementing the above NetBSD extensions.
Roy Marples [Wed, 8 Mar 2017 12:05:57 +0000 (12:05 +0000)]
Reading BPF works fine on SunOS as well.
However, sending BPF appears to go nowhere even though the man page
indicates it should work.
So remove the if_*raw functions from if-sun.c and add a small bpf_send
function which uses DLPI.
Roy Marples [Wed, 8 Mar 2017 08:41:07 +0000 (08:41 +0000)]
Rename if_*raw functions to bpf_* so it's more descriptive and move
them from if-bsd.c to bpf.c so they can be re-used on SunOS in the future.
Linux is a special snowflake, so the BPF functions for opening, reading and
attaching remain in if-linux.c.
On Linux, open PF_PACKET as SOCK_RAW so we see the datalink frame header
just as BPF elsewhere so we don't have to mess around with offsets.
The BPF filters themselves have been improved to filter out more gunk such
as ensuring BOOTP messages are in an IPv4 packet and from the BOOTPS port.
ARP messages now check protocol family as well.
Roy Marples [Sun, 5 Mar 2017 21:05:24 +0000 (21:05 +0000)]
bpf: ARP and BOOTP filter improvements
The ARP filter now checks hardware and protocol length matches
the interface, it's not from the interface itself and either the
source ip or target ip is one of our addresses of interest.
The BOOTP filter now checks for BOOTREPLY and matching xid.
If the interface hardware address fits inside chaddr then
that is checked as well.