]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Report interface carrier state to the dhcpcd-run-hooks as ifcarrier.
authorRoy Marples <roy@marples.name>
Thu, 27 Feb 2014 10:52:11 +0000 (10:52 +0000)
committerRoy Marples <roy@marples.name>
Thu, 27 Feb 2014 10:52:11 +0000 (10:52 +0000)
If ifcarrier is up, don't start wpa_supplicant.

dhcpcd-hooks/01-test
dhcpcd-hooks/10-wpa_supplicant
dhcpcd.c
script.c

index ac71f089583dd729f6da0d7fe4565986c9821426..b850039592fffb5c82d49796adf81850599efc90 100644 (file)
@@ -1,6 +1,7 @@
 # Just echo our DHCP options we have
 
 if [ "$reason" = "TEST" ]; then
-       set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort
+       set | grep "^\(interface\|pid\|reason\|skip_hooks\)=" | sort
+       set | grep "^if\(carrier\|flags\|mtu\|wireless\)=" | sort
        set | grep "^\(new_\|old_\|ra_count=\|ra[0-9]*_\)" | sort
 fi
index a0dc018e1751d4c06f96f7e3613153be7b3ac1f1..9ab05163881d1d366090b4d71eec47dbe56e827e 100644 (file)
@@ -38,6 +38,9 @@ wpa_supplicant_start()
 {
        local dir err errn
 
+       # If the carrier is up, don't bother checking anything
+       [ "$ifcarrier" = "up" ] && return 0
+
        # Pre flight checks
        if [ ! -s "$wpa_supplicant_conf" ]; then
                syslog warn \
index a16cc9d3bac97a6954b0dc55d98875218a37c348..93a52ccc69bb2e220c06d6a58998116f91076f03 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -657,7 +657,7 @@ static void
 init_state(struct interface *ifp, int argc, char **argv)
 {
        struct if_options *ifo;
-       const char *reason = NULL;
+       const char *reason;
 
        configure_interface(ifp, argc, argv);
        ifo = ifp->options;
@@ -671,9 +671,7 @@ init_state(struct interface *ifp, int argc, char **argv)
                ifo->options &= ~DHCPCD_IPV6RS;
        }
 
-       if (!(ifp->ctx->options & DHCPCD_TEST))
-               script_runreason(ifp, "PREINIT");
-
+       reason = NULL; /* appease gcc */
        if (ifo->options & DHCPCD_LINK) {
                switch (carrier_status(ifp)) {
                case LINK_DOWN:
@@ -688,10 +686,14 @@ init_state(struct interface *ifp, int argc, char **argv)
                        ifp->carrier = LINK_UNKNOWN;
                        return;
                }
-               if (reason && !(ifp->ctx->options & DHCPCD_TEST))
-                       script_runreason(ifp, reason);
        } else
                ifp->carrier = LINK_UNKNOWN;
+
+       if (!(ifp->ctx->options & DHCPCD_TEST))
+               script_runreason(ifp, "PREINIT");
+
+       if (ifp->carrier != LINK_UNKNOWN && !(ifp->ctx->options & DHCPCD_TEST))
+               script_runreason(ifp, reason);
 }
 
 void
index 1fc5538f10dd108528a66b2a1adb53f4fcff86de..a39d25c63bfb9b0c2c92e007b02267bc5beaf53e 100644 (file)
--- a/script.c
+++ b/script.c
@@ -58,6 +58,7 @@ static const char * const if_params[] = {
        "interface",
        "reason",
        "pid",
+       "ifcarrier",
        "ifmetric",
        "ifwireless",
        "ifflags",
@@ -241,7 +242,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        if (ifp->ctx->options & DHCPCD_DUMPLEASE)
                elen = 2;
        else
-               elen = 10;
+               elen = 11;
 
 #define EMALLOC(i, l) if ((env[(i)] = malloc(l)) == NULL) goto eexit;
        /* Make our env */
@@ -260,19 +261,23 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        EMALLOC(2, e);
        snprintf(env[2], e, "pid=%d", getpid());
        EMALLOC(3, e);
-       snprintf(env[3], e, "ifmetric=%d", ifp->metric);
+       snprintf(env[3], e, "ifcarrier=%s",
+           ifp->carrier == LINK_UNKNOWN ? "unknown" :
+           ifp->carrier == LINK_UP ? "up" : "down");
        EMALLOC(4, e);
-       snprintf(env[4], e, "ifwireless=%d", ifp->wireless);
+       snprintf(env[4], e, "ifmetric=%d", ifp->metric);
        EMALLOC(5, e);
-       snprintf(env[5], e, "ifflags=%u", ifp->flags);
+       snprintf(env[5], e, "ifwireless=%d", ifp->wireless);
        EMALLOC(6, e);
-       snprintf(env[6], e, "ifmtu=%d", get_mtu(ifp->name));
+       snprintf(env[6], e, "ifflags=%u", ifp->flags);
+       EMALLOC(7, e);
+       snprintf(env[7], e, "ifmtu=%d", get_mtu(ifp->name));
        l = e = strlen("interface_order=");
        TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
                e += strlen(ifp2->name) + 1;
        }
-       EMALLOC(7, e);
-       p = env[7];
+       EMALLOC(8, e);
+       p = env[8];
        strlcpy(p, "interface_order=", e);
        e -= l;
        p += l;
@@ -285,8 +290,8 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
        }
        *--p = '\0';
        if (strcmp(reason, "TEST") == 0) {
-               env[8] = strdup("if_up=false");
-               env[9] = strdup("if_down=false");
+               env[9] = strdup("if_up=false");
+               env[10] = strdup("if_down=false");
        } else if ((dhcp && state && state->new)
 #ifdef INET6
            || (dhcp6 && d6_state && d6_state->new)
@@ -294,13 +299,13 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
 #endif
            )
        {
-               env[8] = strdup("if_up=true");
-               env[9] = strdup("if_down=false");
+               env[9] = strdup("if_up=true");
+               env[10] = strdup("if_down=false");
        } else {
-               env[8] = strdup("if_up=false");
-               env[9] = strdup("if_down=true");
+               env[9] = strdup("if_up=false");
+               env[10] = strdup("if_down=true");
        }
-       if (env[8] == NULL || env[9] == NULL)
+       if (env[9] == NULL || env[10] == NULL)
                goto eexit;
        if (*ifp->profile) {
                e = strlen("profile=") + strlen(ifp->profile) + 2;
@@ -316,8 +321,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
                        env = nenv;
                        EMALLOC(elen, e);
                        snprintf(env[elen++], e, "new_ssid=%s", ifp->ssid);
-               }
-               else if (strcmp(reason, "NOCARRIER") == 0) {
+               } else if (strcmp(reason, "NOCARRIER") == 0) {
                        nenv = realloc(env, sizeof(char *) * (elen + 2));
                        if (nenv == NULL)
                                goto eexit;