Mercurial > hg > dhcpcd
changeset 5502:7100066d2c7e draft
privsep: Only start network proxy if we need to
Do this before starting it rather than it shutting down.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 07 Oct 2020 15:28:33 +0100 |
| parents | 5b2272a0f3c3 |
| children | 18a7063f70c1 |
| files | src/privsep-inet.c src/privsep-inet.h src/privsep.c |
| diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/privsep-inet.c Wed Oct 07 14:37:35 2020 +0100 +++ b/src/privsep-inet.c Wed Oct 07 15:28:33 2020 +0100 @@ -89,6 +89,28 @@ } #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) {
--- a/src/privsep-inet.h Wed Oct 07 14:37:35 2020 +0100 +++ b/src/privsep-inet.h Wed Oct 07 15:28:33 2020 +0100 @@ -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 *);
--- a/src/privsep.c Wed Oct 07 14:37:35 2020 +0100 +++ b/src/privsep.c Wed Oct 07 15:28:33 2020 +0100 @@ -467,13 +467,11 @@ /* 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;
