From: Roy Marples Date: Sun, 7 Sep 2014 19:03:41 +0000 (+0000) Subject: Add variables if_oneup and if_ipwaited so hook scripts know the overall state of... X-Git-Tag: v6.4.4~37 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f4d126e24bd7aa64bd2e0d57d9de4570b90c472;p=thirdparty%2Fdhcpcd.git Add variables if_oneup and if_ipwaited so hook scripts know the overall state of dhcpcd better. --- diff --git a/dhcpcd.c b/dhcpcd.c index 13ece6a9..85a0db45 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -209,6 +209,41 @@ handle_exit_timeout(void *arg) eloop_timeout_add_sec(ctx->eloop, timeout, handle_exit_timeout, ctx); } +int +dhcpcd_oneup(struct dhcpcd_ctx *ctx) +{ + const struct interface *ifp; + + TAILQ_FOREACH(ifp, ctx->ifaces, next) { + if (D_STATE_RUNNING(ifp) || + RS_STATE_RUNNING(ifp) || + D6_STATE_RUNNING(ifp)) + return 1; + } + return 0; +} + +int +dhcpcd_ipwaited(struct dhcpcd_ctx *ctx) +{ + + if (ctx->options & DHCPCD_WAITIP4 && + !ipv4_addrexists(ctx, NULL)) + return 0; + if (ctx->options & DHCPCD_WAITIP6 && + !ipv6nd_addrexists(ctx, NULL) && + !dhcp6_addrexists(ctx, NULL)) + return 0; + if ((ctx->options & + (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)) == + (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6) && + !ipv4_addrexists(ctx, NULL) && + !ipv6nd_addrexists(ctx, NULL) && + !dhcp6_addrexists(ctx, NULL)) + return 0; + return 1; +} + /* Returns the pid of the child, otherwise 0. */ pid_t dhcpcd_daemonise(struct dhcpcd_ctx *ctx) @@ -225,19 +260,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) if (ctx->options & DHCPCD_DAEMONISE && !(ctx->options & DHCPCD_DAEMONISED)) { - if (ctx->options & DHCPCD_WAITIP4 && - !ipv4_addrexists(ctx, NULL)) - return 0; - if (ctx->options & DHCPCD_WAITIP6 && - !ipv6nd_addrexists(ctx, NULL) && - !dhcp6_addrexists(ctx, NULL)) - return 0; - if ((ctx->options & - (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)) == - (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6) && - !ipv4_addrexists(ctx, NULL) && - !ipv6nd_addrexists(ctx, NULL) && - !dhcp6_addrexists(ctx, NULL)) + if (!dhcpcd_ipwaited(ctx)) return 0; } diff --git a/dhcpcd.h b/dhcpcd.h index f5340d15..a45d9a90 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -140,6 +140,8 @@ struct dhcpcd_ctx { extern const int dhcpcd_handlesigs[]; #endif +int dhcpcd_oneup(struct dhcpcd_ctx *); +int dhcpcd_ipwaited(struct dhcpcd_ctx *); pid_t dhcpcd_daemonise(struct dhcpcd_ctx *); int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **); diff --git a/script.c b/script.c index effa81d7..7e420f2d 100644 --- a/script.c +++ b/script.c @@ -280,7 +280,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) if (ifp->ctx->options & DHCPCD_DUMPLEASE) elen = 2; else - elen = 11; + elen = 13; #define EMALLOC(i, l) if ((env[(i)] = malloc((l))) == NULL) goto eexit; /* Make our env */ @@ -351,6 +351,18 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) } if (env[9] == NULL || env[10] == NULL) goto eexit; + if (dhcpcd_oneup(ifp->ctx)) + env[11] = strdup("if_oneup=true"); + else + env[11] = strdup("if_oneup=false"); + if (env[11] == NULL) + goto eexit; + if (dhcpcd_ipwaited(ifp->ctx)) + env[12] = strdup("if_ipwaited=true"); + else + env[12] = strdup("if_ipwaited=false"); + if (env[12] == NULL) + goto eexit; if (*ifp->profile) { e = strlen("profile=") + strlen(ifp->profile) + 2; EMALLOC(elen, e);