From: Roy Marples Date: Fri, 20 Nov 2009 15:14:27 +0000 (+0000) Subject: If we have to bring an interface up, and we don't have any carriers X-Git-Tag: v5.1.4~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68510bef057857947e44320e4d67ec2a54fcf204;p=thirdparty%2Fdhcpcd.git If we have to bring an interface up, and we don't have any carriers then we need to wait for a second to allow an interface to settle. --- diff --git a/dhcpcd.c b/dhcpcd.c index 7b1f0921..3e058e9b 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1806,16 +1806,38 @@ main(int argc, char **argv) if (iface->carrier != LINK_DOWN) opt = 1; } - if (opt == 0 && - options & DHCPCD_LINK && - !(options & DHCPCD_WAITIP)) - { - syslog(LOG_WARNING, "no interfaces have a carrier"); - daemonise(); - } else if (options & DHCPCD_DAEMONISE && ifo->timeout > 0) { - if (options & DHCPCD_IPV4LL) - options |= DHCPCD_TIMEOUT_IPV4LL; - add_timeout_sec(ifo->timeout, handle_exit_timeout, NULL); + + if (!(options & DHCPCD_BACKGROUND)) { + /* If we don't have a carrier, we may have to wait for a second + * before one becomes available if we brought an interface up. */ + if (opt == 0 && + options & DHCPCD_LINK && + options & DHCPCD_WAITUP && + !(options & DHCPCD_WAITIP)) + { + ts.tv_sec = 1; + ts.tv_nsec = 0; + nanosleep(&ts, NULL); + for (iface = ifaces; iface; iface = iface->next) { + handle_carrier(iface->name); + if (iface->carrier != LINK_DOWN) { + opt = 1; + break; + } + } + } + if (opt == 0 && + options & DHCPCD_LINK && + !(options & DHCPCD_WAITIP)) + { + syslog(LOG_WARNING, "no interfaces have a carrier"); + daemonise(); + } else if (options & DHCPCD_DAEMONISE && ifo->timeout > 0) { + if (options & DHCPCD_IPV4LL) + options |= DHCPCD_TIMEOUT_IPV4LL; + add_timeout_sec(ifo->timeout, handle_exit_timeout, NULL); + } + } free_options(ifo); diff --git a/if-options.h b/if-options.h index 9f49021a..6b05c164 100644 --- a/if-options.h +++ b/if-options.h @@ -72,6 +72,7 @@ #define DHCPCD_VENDORRAW (1 << 23) #define DHCPCD_TIMEOUT_IPV4LL (1 << 24) #define DHCPCD_WAITIP (1 << 25) +#define DHCPCD_WAITUP (1 << 26) extern const struct option cf_options[]; diff --git a/net.c b/net.c index a45951cc..331e5d9b 100644 --- a/net.c +++ b/net.c @@ -389,12 +389,17 @@ discover_interfaces(int argc, char * const *argv) continue; /* Bring the interface up if not already */ - if (!(ifp->flags & IFF_UP) && + if (!(ifp->flags & IFF_UP) #ifdef SIOCGIFMEDIA - carrier_status(ifp) != -1 && + && carrier_status(ifp) != -1 #endif - up_interface(ifp) != 0) - syslog(LOG_ERR, "%s: up_interface: %m", ifp->name); + ) + { + if (up_interface(ifp) == 0) + options |= DHCPCD_WAITUP; + else + syslog(LOG_ERR, "%s: up_interface: %m", ifp->name); + } /* Don't allow loopback unless explicit */ if (ifp->flags & IFF_LOOPBACK) {