]> git.ipfire.org Git - people/ms/dhcpcd.git/commitdiff
privsep: Only start network proxy if we need to
authorRoy Marples <roy@marples.name>
Wed, 7 Oct 2020 14:28:33 +0000 (15:28 +0100)
committerRoy Marples <roy@marples.name>
Wed, 7 Oct 2020 14:28:33 +0000 (15:28 +0100)
Do this before starting it rather than it shutting down.

src/privsep-inet.c
src/privsep-inet.h
src/privsep.c

index 81487f6319ce3897060501e6c814f1e22f1c115a..2770569f631bb9105cacaa10d42a9adb5ad69f57 100644 (file)
@@ -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)
 {
index 7aa0b3cb65f30c6977a31a8830b58022b6997e35..d6b704026c2f689948e7ca074da82e181bc6d77a 100644 (file)
@@ -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 *);
index 771e7317c2ea1c794cdf4049e0880115ab0f8faf..aa87cd0cdff4a5ef6537b7933cebe824d4d42036 100644 (file)
@@ -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;