]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add variables if_oneup and if_ipwaited so hook scripts know the overall state of...
authorRoy Marples <roy@marples.name>
Sun, 7 Sep 2014 19:03:41 +0000 (19:03 +0000)
committerRoy Marples <roy@marples.name>
Sun, 7 Sep 2014 19:03:41 +0000 (19:03 +0000)
dhcpcd.c
dhcpcd.h
script.c

index 13ece6a96533f1fa49116fb443fa4e86836d3249..85a0db450fa4df0c86428f4ef0eb3a569a2e7f92 100644 (file)
--- 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;
        }
 
index f5340d152f06ef8dea9a4637e6f8759eee9473ce..a45d9a9027e5a6d64402fa90211ba3c2cf1b52f8 100644 (file)
--- 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 **);
index effa81d7c8356919ec7b453a615899fdc26155d4..7e420f2d5bcb2777fad28ac037cfde2a68e2ff29 100644 (file)
--- 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);