From: Roy Marples Date: Mon, 30 Jun 2014 15:43:58 +0000 (+0000) Subject: Improve startup with regards to carrier checking and adding a link-local X-Git-Tag: v6.4.1~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bce64b152474984f49749a47454e0e5c55f7ddc8;p=thirdparty%2Fdhcpcd.git Improve startup with regards to carrier checking and adding a link-local IPv6 address. --- diff --git a/dhcpcd.c b/dhcpcd.c index 11b07b8c..b0c66f5c 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -339,7 +339,7 @@ configure_interface1(struct interface *ifp) ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL); if (!(ifp->flags & (IFF_POINTOPOINT | IFF_LOOPBACK | IFF_MULTICAST))) ifo->options &= ~DHCPCD_IPV6RS; - if (ifo->options & DHCPCD_LINK && if_carrier(ifp) == LINK_UNKNOWN) + if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_UNKNOWN) ifo->options &= ~DHCPCD_LINK; if (ifo->metric != -1) @@ -561,32 +561,35 @@ warn_iaid_conflict(struct interface *ifp, uint8_t *iaid) ifp->name, ifn->name); } -void -dhcpcd_startinterface(void *arg) +static void +pre_start(struct interface *ifp) { - struct interface *ifp = arg; - struct if_options *ifo = ifp->options; - size_t i; - char buf[DUID_LEN * 3]; /* Add our link-local address before upping the interface * so our RFC7217 address beats the hwaddr based one. * This is also a safety check incase it was ripped out * from under us. */ - if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { + if (ifp->options->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name); - ifo->options &= DHCPCD_IPV6; + ifp->options->options &= DHCPCD_IPV6; } - if (!(ifp->flags & IFF_UP) && if_carrier(ifp) != LINK_UNKNOWN) { - if (if_up(ifp) == -1) - syslog(LOG_ERR, "%s: if_up: %m", - ifp->name); - } + if (!(ifp->flags & IFF_UP) && if_up(ifp) == -1) + syslog(LOG_ERR, "%s: if_up: %m", ifp->name); +} + + +void +dhcpcd_startinterface(void *arg) +{ + struct interface *ifp = arg; + struct if_options *ifo = ifp->options; + size_t i; + char buf[DUID_LEN * 3]; + + pre_start(ifp); - if (ifp->carrier == LINK_UNKNOWN) - dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, 0, ifp->name); - if (ifp->carrier == LINK_DOWN) { + if (ifp->carrier == LINK_DOWN && ifo->options & DHCPCD_LINK) { syslog(LOG_INFO, "%s: waiting for carrier", ifp->name); return; } @@ -700,31 +703,17 @@ init_state(struct interface *ifp, int argc, char **argv) static void run_preinit(struct interface *ifp) { - const char *reason; - reason = NULL; /* appease gcc */ - if (ifp->options->options & DHCPCD_LINK) { - switch (if_carrier(ifp)) { - case LINK_DOWN: - ifp->carrier = LINK_DOWN; - reason = "NOCARRIER"; - break; - case LINK_UP: - ifp->carrier = LINK_UP; - reason = "CARRIER"; - break; - default: - ifp->carrier = LINK_UNKNOWN; - return; - } - } else - ifp->carrier = LINK_UNKNOWN; + pre_start(ifp); + if (ifp->ctx->options & DHCPCD_TEST) + return; - if (!(ifp->ctx->options & DHCPCD_TEST)) - script_runreason(ifp, "PREINIT"); + script_runreason(ifp, "PREINIT"); - if (ifp->carrier != LINK_UNKNOWN && !(ifp->ctx->options & DHCPCD_TEST)) - script_runreason(ifp, reason); + if (ifp->carrier != LINK_UNKNOWN && + ifp->options->options & DHCPCD_LINK) + script_runreason(ifp, + ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER"); } int diff --git a/if.c b/if.c index 7d5f3896..1155c215 100644 --- a/if.c +++ b/if.c @@ -295,6 +295,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) ifp->ctx = ctx; strlcpy(ifp->name, p, sizeof(ifp->name)); ifp->flags = ifa->ifa_flags; + ifp->carrier = if_carrier(ifp); sdl_type = 0; /* Don't allow loopback unless explicit */