Re: strange issues with simple net module for 2.4

From: Stephen Hemminger
Date: Wed Aug 02 2006 - 13:59:57 EST


On Wed, 2 Aug 2006 00:52:03 +0200 (CEST)
gj@xxxxxxxxxxxxxxxx wrote:

> /* Please do CC me on replies, I am not subscribed to the list. */
>
> hi devs
>
> I have spend some time, and wrote very simple NET device module for 2.4
> kernels. It does allocate certain number of paired net interfaces named
> tola%d , where for instance:
> tola(N*2)<->tola(N*2)+1
>
> anything you send to tola0, appears on tola1, and the other way around,
> same for all Ns.
>
> http://podgorze.pl/~gj/tola.tar.bz2
> (~2kb)
>
> there are few issues however.
> First of all, I am not able to allocate more than 50 pairs (the param is
> at the top of the source - int nrofi; ). Secondly, every once in a while
> it crashes badly on unload, and frankly - I have no idea why.

Since you want a specific device name, ask for it rather than letting
register_netdev assign it. The code to do automagic device names (like eth%d)
is very slow and limited in 2.4.

So change:
strcpy(tola_dev[i]->name, "tola%d");

To:
snprintf(tola_dev[i]->name, "tola%d", i);

And rather than putting ascii values in the ethernet address, put
a valid software random address.
Replace this bad code:
snprintf( mak+1, ETH_ALEN-1, "%dtola", i );
mak[0] = '\0';
memcpy(tola_dev[i]->dev_addr, mak, ETH_ALEN );

with:
get_random_bytes(tola_dev[i]->dev_addr, ETH_ALEN);
dev->dev_addr[0] &= 0xfe;
dev->dev_addr[0] |= 0x02;

This is code from random_ether_adddr() in 2.6.

Don't lose the error return from register_netdev and leak memory:

Not:
r = register_netdev (tola_dev[i]);
if ( r ) {
return -ENOMEM;
}

Use:
r = register_netdev(tola_dev[i]);
if (r) {
int j;
free_netdev(tola_dev[i]);
for (j = 0; j < i; j++) {
unregister_netdev(tola_dev[j]);
free_netdev(tola_dev[j]);
}
return r;
}

You don't need tola_open, tola_close stubs, since the core network
code does the right thing if the pointers are NULL.

Lastly, you need to free the netdevice in the cleanup code.


> Once again, this is 2.4.X module! The reason being, we are using here only
> 2.4 series for networking for various reasons that I don't want to get
> into now.
> I do appriciate any help or hints regarding this module please.
>
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/


--
Stephen Hemminger <shemminger@xxxxxxxx>
"And in the Packet there writ down that doome"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/