summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-10-07 15:28:33 +0100
committerRoy Marples <roy@marples.name>2020-10-07 15:28:33 +0100
commit5699c07d535fbe8cdc513b1c380519cb861009b3 (patch)
tree51497bd058038663df30e92e4e9d22cdb0cda420
parentd047f2dd0d9cee881d1d3e56da8ba67664f7726d (diff)
downloaddhcpcd-5699c07d535fbe8cdc513b1c380519cb861009b3.tar.xz
privsep: Only start network proxy if we need to
Do this before starting it rather than it shutting down.
-rw-r--r--src/privsep-inet.c22
-rw-r--r--src/privsep-inet.h1
-rw-r--r--src/privsep.c4
3 files changed, 24 insertions, 3 deletions
diff --git a/src/privsep-inet.c b/src/privsep-inet.c
index 81487f63..2770569f 100644
--- a/src/privsep-inet.c
+++ b/src/privsep-inet.c
@@ -89,6 +89,28 @@ ps_inet_recvdhcp6(void *arg)
}
#endif
+bool
+ps_inet_canstart(const struct dhcpcd_ctx *ctx)
+{
+
+#ifdef INET
+ if ((ctx->options & (DHCPCD_IPV4 | DHCPCD_MASTER)) ==
+ (DHCPCD_IPV4 | DHCPCD_MASTER))
+ return true;
+#endif
+#if defined(INET6) && !defined(__sun)
+ if (ctx->options & DHCPCD_IPV6)
+ return true;
+#endif
+#ifdef DHCP6
+ if ((ctx->options & (DHCPCD_IPV6 | DHCPCD_MASTER)) ==
+ (DHCPCD_IPV6 | DHCPCD_MASTER))
+ return true;
+#endif
+
+ return false;
+}
+
static int
ps_inet_startcb(void *arg)
{
diff --git a/src/privsep-inet.h b/src/privsep-inet.h
index 7aa0b3cb..d6b70402 100644
--- a/src/privsep-inet.h
+++ b/src/privsep-inet.h
@@ -29,6 +29,7 @@
#ifndef PRIVSEP_INET_H
#define PRIVSEP_INET_H
+bool ps_inet_canstart(const struct dhcpcd_ctx *);
pid_t ps_inet_start(struct dhcpcd_ctx *);
int ps_inet_stop(struct dhcpcd_ctx *);
ssize_t ps_inet_cmd(struct dhcpcd_ctx *, struct ps_msghdr *, struct msghdr *);
diff --git a/src/privsep.c b/src/privsep.c
index 771e7317..aa87cd0c 100644
--- a/src/privsep.c
+++ b/src/privsep.c
@@ -467,13 +467,11 @@ ps_start(struct dhcpcd_ctx *ctx)
/* No point in spawning the generic network listener if we're
* not going to use it. */
- if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_IPV6)))
+ if (!ps_inet_canstart(ctx))
goto started_net;
switch (pid = ps_inet_start(ctx)) {
case -1:
- if (errno == ENXIO)
- return 0;
return -1;
case 0:
return 0;