changeset 1387:30fc2f427245 draft

Some drivers report ENODEV when bring the interface up if their kill switch is on. This stops dhcpcd from using the interface, so we now just blunder on and await a carrier up event. IMO, ENODEV is the wrong error code as the device IS present, it's just disabled. But the patch here still makes sense.
author Roy Marples <roy@marples.name>
date Wed, 05 Aug 2009 21:16:09 +0000
parents 90ffa9d2be95
children be4facdc8e5f
files net.c
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/net.c	Wed Aug 05 21:15:50 2009 +0000
+++ b/net.c	Wed Aug 05 21:16:09 2009 +0000
@@ -218,21 +218,20 @@
 			goto eexit;
 	}
 
-	if (up_interface(ifname) != 0)
-		goto eexit;
 	snprintf(iface->leasefile, sizeof(iface->leasefile),
 	    LEASEFILE, ifname);
 	/* 0 is a valid fd, so init to -1 */
 	iface->raw_fd = -1;
 	iface->udp_fd = -1;
 	iface->arp_fd = -1;
-	close(s);
-	return iface;
+	goto exit;
 
 eexit:
 	free(iface);
+	iface = NULL;
+exit:
 	close(s);
-	return NULL;
+	return iface;
 }
 
 void
@@ -322,6 +321,15 @@
 		}
 		if ((ifp = init_interface(p)) == NULL)
 			continue;
+
+		/* Bring the interface up */
+		if (!(ifp->flags & IFF_UP) && up_interface(p) != 0)
+			/* Some drivers return ENODEV here when they are disabled by a switch.
+			 * We just blunder on as the carrier will be down anyway.
+			 * When the switch is enabled, it should bring the interface up.
+			 * Then we'll spot the carrier and start working. */
+			syslog(LOG_ERR, "%s: up_interface: %m", p);
+
 		/* Don't allow loopback unless explicit */
 		if (ifp->flags & IFF_LOOPBACK) {
 			if (argc == 0 && ifac == 0) {
@@ -364,6 +372,7 @@
 				syslog(LOG_WARNING, "%s: unknown hardware family", p);
 			}
 		}
+
 		if (ifl)
 			ifl->next = ifp; 
 		else