summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-11-28 16:41:15 +0000
committerRoy Marples <roy@marples.name>2019-11-28 16:41:15 +0000
commit6502584888c432a468d8918ce04e202281cb8ef9 (patch)
treeb62b1e3a7ba544c9e842e6f595b25fdaab8059b4 /src/if.c
parenta7613391cbd1f33867446a981c6ec648d3e35278 (diff)
downloaddhcpcd-6502584888c432a468d8918ce04e202281cb8ef9.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.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/if.c b/src/if.c
index c0b67ec9..4b6efecc 100644
--- a/src/if.c
+++ b/src/if.c
@@ -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;