diff options
| author | Roy Marples <roy@marples.name> | 2019-11-28 16:41:15 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-11-28 16:41:15 +0000 |
| commit | d5786118da1bad4c247631cae86344f1b249a8cb (patch) | |
| tree | b62b1e3a7ba544c9e842e6f595b25fdaab8059b4 /src/if.c | |
| parent | f90486b1657f0331ae5e7d817b9ba3de90856d52 (diff) | |
| download | dhcpcd-d5786118da1bad4c247631cae86344f1b249a8cb.tar.xz | |
privsep: Add support for priviledge separation
Not enabled by default - enable with ./configure --enable-privsep
Requires a user added to the system - default _dhcpcd
Several processes will be spawned off the main state engine:
a privileged actioneer and a generic network proxy.
Only the privileged actioneer process will retain root permissions.
When required, the privileged actioneer will also spawn
BPF listeners for BOOTP (DHCP) and ARP.
The BOOTP BPF listener should be a short lived process.
On kernels with RFC 5227 support, the ARP BPF listener will only
be used for ARPing and announcing a preferred address and will
also be a short lived process.
When not running in master mode, an address listener will be
spawned for each address (with the exception of RA dervived addresses)
dhcpcd cares about.
TODO:
* Solaris support.
* ARP BPF address filtering.
Diffstat (limited to 'src/if.c')
| -rw-r--r-- | src/if.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -71,6 +71,7 @@ #include "ipv4ll.h" #include "ipv6nd.h" #include "logerr.h" +#include "privsep.h" #ifdef __sun /* It has the ioctl, but the member is missing from the struct? @@ -132,6 +133,17 @@ if_closesockets(struct dhcpcd_ctx *ctx) } int +if_ioctl(struct dhcpcd_ctx *ctx, unsigned long req, void *data, size_t len) +{ + +#ifdef PRIVSEP + if (ctx->options & DHCPCD_PRIVSEP) + return (int)ps_root_ioctl(ctx, req, data, len); +#endif + return ioctl(ctx->pf_inet_fd, req, data, len); +} + +int if_getflags(struct interface *ifp) { struct ifreq ifr = { .ifr_flags = 0 }; @@ -158,7 +170,7 @@ if_setflag(struct interface *ifp, short flag) strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); ifr.ifr_flags = f | flag; - if (ioctl(ifp->ctx->pf_inet_fd, SIOCSIFFLAGS, &ifr) == -1) + if (if_ioctl(ifp->ctx, SIOCSIFFLAGS, &ifr, sizeof(ifr)) == -1) return -1; ifp->flags = (unsigned int)ifr.ifr_flags; @@ -717,7 +729,10 @@ if_domtu(const struct interface *ifp, short int mtu) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); ifr.ifr_mtu = mtu; - r = ioctl(ifp->ctx->pf_inet_fd, mtu ? SIOCSIFMTU : SIOCGIFMTU, &ifr); + if (mtu != 0) + r = if_ioctl(ifp->ctx, SIOCSIFMTU, &ifr, sizeof(ifr)); + else + r = ioctl(ifp->ctx->pf_inet_fd, SIOCGIFMTU, &ifr); if (r == -1) return -1; return ifr.ifr_mtu; |
