]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If we have to bring an interface up, and we don't have any carriers
authorRoy Marples <roy@marples.name>
Fri, 20 Nov 2009 15:14:27 +0000 (15:14 +0000)
committerRoy Marples <roy@marples.name>
Fri, 20 Nov 2009 15:14:27 +0000 (15:14 +0000)
then we need to wait for a second to allow an interface to settle.

dhcpcd.c
if-options.h
net.c

index 7b1f0921f2ed3bedeb4d19e7f2420cbec7a801e7..3e058e9bc7a9b0bbdc4e3d9cf1190accd6b3387e 100644 (file)
--- 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);
 
index 9f49021aaffc6f8beb29d8670c168cbacd5d6e0b..6b05c164ec9af6cefc108405507d064ddd162c4b 100644 (file)
@@ -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 a45951cce926dd6ea5dad6ff06186d8ef3537e1e..331e5d9b444df1b7e130b2c360d1785220bee75b 100644 (file)
--- 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) {