Roy Marples [Sat, 19 Sep 2020 13:40:50 +0000 (14:40 +0100)]
Linux: detect network namespace and deny udev in one
udev says whether an interface name is stable or not.
In a network namespace, udev claims the interface does not exist.
This makes sense because udev only operates in the root namespace.
Roy Marples [Sat, 12 Sep 2020 19:14:47 +0000 (20:14 +0100)]
dhcpcd: Only manipulate stdin, stdout and stderr when valid
UNIX application expect these to exist even if pointed at /dev/null.
We cannot change which fd they use, it's always 0, 1 and 2.
But if these fd's are not open when dhcpcd is called, they could
be assigned to dhcpcd internals.
In this instance we should not use the streams in anyway or form.
Roy Marples [Sun, 6 Sep 2020 01:41:08 +0000 (02:41 +0100)]
dhcpcd: Redirect stdout/stderr to the launcher stderr descriptor
This actually make life really simple!
We no longer need to redirect stdout/stderr to /dev/null for privsep
and any script output is now captured again - and it all goes to stderr
as it should even if a script wants it to go to stdout.
On the happy path, only the master process will actually log anything
to stderr so we turn that off after we "fork".
On the unhappy path, logging to stderr/stdout *may* fail because
the launcher process *may* have exited.
We *could* have the master process as an intermediary but that's
just excess code to avoid errors which *should* not happen.
Regardless, any errror should still hit syslog.
Roy Marples [Sat, 5 Sep 2020 15:16:22 +0000 (16:16 +0100)]
dhcpcd: Setup a socketpair in the launcher to write to stderr
Rather than duping stderr down to the processes.
This allows us to reopen stdout and stderr onto /dev/null right
away and means only the launcher process writes to stderr.
The downside is that any stdout from the script is now lost.
If that's needed, we could setup a stdout socketpair as well.
Roy Marples [Tue, 1 Sep 2020 10:56:53 +0000 (11:56 +0100)]
DHCP: Don't set address lifetimes when extending leases
Otherwise the kernel WILL remove them.
dhcpcd already manages address removal when needed because
some OS's do not support address lifetimes even for IPv6.
Roy Marples [Sun, 16 Aug 2020 17:52:17 +0000 (18:52 +0100)]
privsep: Set a zero length receive buffer for write only sockets
We cannot use shutdown(2) because they are not connected.
Constantly draining would be a waste of CPU time, so just let
the buffer overflow. To ease the kernel as much as we can, set
a zero length buffer.
The kernel may still allocate a small buffer, but this is kernel
dependant and we're just trying to be helpful.
Roy Marples [Sat, 25 Jul 2020 13:22:18 +0000 (14:22 +0100)]
options: open an address socket to detect if inet6 is available
This should silence dhcpcd warnings if IPv6 is compiled out.
Do the same for IPv4, although that's highly unlikely as
it's kind of required for some interface ioctls.
Roy Marples [Tue, 30 Jun 2020 20:33:24 +0000 (21:33 +0100)]
dhcpcd: Turn off stderr logging rather than closing stderr
And only turn it off when stderr is a tty.
A better approach might to open an fd just to log to and
redirect stdout/stderr to /dev/null alongside stdin at program
start, but that's more code.
Roy Marples [Mon, 29 Jun 2020 10:54:29 +0000 (11:54 +0100)]
options: rework prior to use macros
Can't use DHCPCD_MASTER because a config option sets it - duh.
This allows us to use a different config option which makes little
sense in options but makes sense in the code.
Roy Marples [Tue, 23 Jun 2020 10:31:25 +0000 (11:31 +0100)]
Linux: redefine NLA_ALIGNTO as 4U
This removes the last of the alignment issues reported by clang
in the linux driver for dhcpcd.
Upstream has no interest in fixing this and local testing
shows it works fine on all platforms I have.
Roy Marples [Mon, 22 Jun 2020 20:56:16 +0000 (21:56 +0100)]
Linux: keep the generic netlink socket around to get ssid with privsep
While here, improve our reading of netlink(7) and terminate on either
ERROR or DONE. If neither are in the message, read again unless it's
the link receiving socket.
Also, only callback if this is the sequence number expected.
Ismael Luceno [Sun, 21 Jun 2020 14:06:14 +0000 (15:06 +0100)]
Libc implementations are allowed to require the explicit inclusion of
either <sys/types.h> (where it should be defined) or <sys/stat.h>
(prototypes requiring it) to expose mode_t.
Without that it fails to be exposed in musl libc, and potentially other
implementations.