[Top] [All Lists]

Re: network interface names ethX and renaming interfaces

To: Hein Roehrig <hein@xxxxxxx>
Subject: Re: network interface names ethX and renaming interfaces
From: Neale Banks <neale@xxxxxxxxxxxxxxxx>
Date: Wed, 19 Dec 2001 10:49:16 +1100 (EST)
Cc: Rusty Russell <rusty@xxxxxxxxxxxxxxx>, netdev@xxxxxxxxxxx
In-reply-to: <E16GRHO-0000Es-00@qaip3>
Sender: owner-netdev@xxxxxxxxxxx
On Tue, 18 Dec 2001, Hein Roehrig wrote:

> So is anybody already working on a fix? If not, I would try to 
> produce one over Xmas; your input & advice would be welcome. 

Not exactly "working on a fix", but I did take a closer look since my
earlier email.  I don't claim to be a seasoned hacker (i.e. probably
missed a few things) - this is what I did pick up:

(1) lack of bounds checking on the index of statically-dimensioned
arrays like *ethdev_index[MAX_ETH_CARDS] in net_init.c

(2) init_etherdev() can return a NULL pointer.  I can (so far) find a few
ethernet drivers which specifically contemplate this possibility
(ne2k-pci.c 3c527.c 3c59x.c 8139too.c acenic.c arlan.c).  Conversely, at
least these appear not to contemplate the return of NULL: 3c507.c 3c509.c
3c515.c ac3200.c (others don't appear use the return value).  Note that
this was only a very quick grep of some of the drivers.

(3) (OK, this one's a nitpick) assignment of a value to a variable in it's
declaration (or is that definition?) then immediately assigning it another
value in a "for" loop (yeah, compiler's optimisation should pick this up -
but IMVHO that misses the point - it's very unpretty).

Appended patch starts on (1) and cleans up one instance of (3) (as well as
being incomplete, I have a nagging suspicion of an off-by-one error).

Point (2) initially looked too scary for me but on looking closer at the
drivers which appear to do the Right Thing maybe it's not so bad (but
perhaps the ettiquette of getting such an aggregate patch accepted should
scare me ;-).

BTW, I suspect a different slant on your case would be to bring up say
eth0, rename that to eth1 and try to bring up another ethernet (exact
reaction depends on point (2) above, but could be significantly different
to what you have experienced from renaming dummy<n> to eth<m>).

> PS: what is netdev@xxxxxxxxxxx?

I don't know (but I suspect a polite wave to Keith may be in order).


--- linux-2.2.20-orig/drivers/net/net_init.c    Sun Nov 11 19:14:23 2001
+++ linux-2.2.20-ntb/drivers/net/net_init.c     Wed Dec 19 09:54:23 2001
@@ -104,6 +104,10 @@
                                                goto found;
+               if (i>=MAX_ETH_CARDS) {
+                       printk("init_etherdev: FATAL - too many eth devs.\n");
+                       return NULL;
+               }
                alloc_size &= ~3;               /* Round to dword boundary. */
@@ -127,6 +131,7 @@
                                ethdev_index[i] = dev;
+               /* FIXME??? Need to check (i>=MAX_ETH_CARDS)??? */
        ether_setup(dev);       /* Hmmm, should this be called here? */
@@ -468,8 +473,7 @@
 static int etherdev_get_index(struct device *dev)
-       int i=MAX_ETH_CARDS;
+       int i;
        for (i = 0; i < MAX_ETH_CARDS; ++i)     {
                if (ethdev_index[i] == NULL) {
                        sprintf(dev->name, "eth%d", i);

<Prev in Thread] Current Thread [Next in Thread>