From: Roy Marples Date: Thu, 27 Feb 2014 10:52:11 +0000 (+0000) Subject: Report interface carrier state to the dhcpcd-run-hooks as ifcarrier. X-Git-Tag: v6.3.1~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e0740acd3788154117d4b02950f97a4cfc6e67f;p=thirdparty%2Fdhcpcd.git Report interface carrier state to the dhcpcd-run-hooks as ifcarrier. If ifcarrier is up, don't start wpa_supplicant. --- diff --git a/dhcpcd-hooks/01-test b/dhcpcd-hooks/01-test index ac71f089..b8500395 100644 --- a/dhcpcd-hooks/01-test +++ b/dhcpcd-hooks/01-test @@ -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 diff --git a/dhcpcd-hooks/10-wpa_supplicant b/dhcpcd-hooks/10-wpa_supplicant index a0dc018e..9ab05163 100644 --- a/dhcpcd-hooks/10-wpa_supplicant +++ b/dhcpcd-hooks/10-wpa_supplicant @@ -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 \ diff --git a/dhcpcd.c b/dhcpcd.c index a16cc9d3..93a52ccc 100644 --- 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 diff --git a/script.c b/script.c index 1fc5538f..a39d25c6 100644 --- 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;