Skip to content

Commit 3fb72f1

Browse files
Micha Nelissendavem330
authored andcommitted
ipconfig wait for carrier
v3 -> v4: fix return boolean false instead of 0 for ic_is_init_dev Currently the ip auto configuration has a hardcoded delay of 1 second. When (ethernet) link takes longer to come up (e.g. more than 3 seconds), nfs root may not be found. Remove the hardcoded delay, and wait for carrier on at least one network device. Signed-off-by: Micha Nelissen <micha@neli.hopto.org> Cc: David Miller <davem@davemloft.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c182f90 commit 3fb72f1

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

net/ipv4/ipconfig.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#endif
8888

8989
/* Define the friendly delay before and after opening net devices */
90-
#define CONF_PRE_OPEN 500 /* Before opening: 1/2 second */
91-
#define CONF_POST_OPEN 1 /* After opening: 1 second */
90+
#define CONF_POST_OPEN 10 /* After opening: 10 msecs */
91+
#define CONF_CARRIER_TIMEOUT 120000 /* Wait for carrier timeout */
9292

9393
/* Define the timeout for waiting for a DHCP/BOOTP/RARP reply */
9494
#define CONF_OPEN_RETRIES 2 /* (Re)open devices twice */
@@ -188,21 +188,22 @@ struct ic_device {
188188
static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */
189189
static struct net_device *ic_dev __initdata = NULL; /* Selected device */
190190

191-
static bool __init ic_device_match(struct net_device *dev)
191+
static bool __init ic_is_init_dev(struct net_device *dev)
192192
{
193-
if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
193+
if (dev->flags & IFF_LOOPBACK)
194+
return false;
195+
return user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
194196
(!(dev->flags & IFF_LOOPBACK) &&
195197
(dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) &&
196-
strncmp(dev->name, "dummy", 5)))
197-
return true;
198-
return false;
198+
strncmp(dev->name, "dummy", 5));
199199
}
200200

201201
static int __init ic_open_devs(void)
202202
{
203203
struct ic_device *d, **last;
204204
struct net_device *dev;
205205
unsigned short oflags;
206+
unsigned long start;
206207

207208
last = &ic_first_dev;
208209
rtnl_lock();
@@ -216,9 +217,7 @@ static int __init ic_open_devs(void)
216217
}
217218

218219
for_each_netdev(&init_net, dev) {
219-
if (dev->flags & IFF_LOOPBACK)
220-
continue;
221-
if (ic_device_match(dev)) {
220+
if (ic_is_init_dev(dev)) {
222221
int able = 0;
223222
if (dev->mtu >= 364)
224223
able |= IC_BOOTP;
@@ -252,6 +251,17 @@ static int __init ic_open_devs(void)
252251
dev->name, able, d->xid));
253252
}
254253
}
254+
255+
/* wait for a carrier on at least one device */
256+
start = jiffies;
257+
while (jiffies - start < msecs_to_jiffies(CONF_CARRIER_TIMEOUT)) {
258+
for_each_netdev(&init_net, dev)
259+
if (ic_is_init_dev(dev) && netif_carrier_ok(dev))
260+
goto have_carrier;
261+
262+
msleep(1);
263+
}
264+
have_carrier:
255265
rtnl_unlock();
256266

257267
*last = NULL;
@@ -1324,14 +1334,13 @@ static int __init wait_for_devices(void)
13241334
{
13251335
int i;
13261336

1327-
msleep(CONF_PRE_OPEN);
13281337
for (i = 0; i < DEVICE_WAIT_MAX; i++) {
13291338
struct net_device *dev;
13301339
int found = 0;
13311340

13321341
rtnl_lock();
13331342
for_each_netdev(&init_net, dev) {
1334-
if (ic_device_match(dev)) {
1343+
if (ic_is_init_dev(dev)) {
13351344
found = 1;
13361345
break;
13371346
}
@@ -1378,7 +1387,7 @@ static int __init ip_auto_config(void)
13781387
return err;
13791388

13801389
/* Give drivers a chance to settle */
1381-
ssleep(CONF_POST_OPEN);
1390+
msleep(CONF_POST_OPEN);
13821391

13831392
/*
13841393
* If the config information is insufficient (e.g., our IP address or

0 commit comments

Comments
 (0)