From: Stephen Hemminger <shemminger@osdl.org>
To: linux-kernel@vger.kernel.org
Subject: Re: strange issues with simple net module for 2.4
Date: Wed, 2 Aug 2006 11:00:44 -0700 [thread overview]
Message-ID: <20060802110044.028718fb@dxpl.pdx.osdl.net> (raw)
In-Reply-To: <32831.83.29.18.163.1154472723.squirrel@83.29.18.163>
On Wed, 2 Aug 2006 00:52:03 +0200 (CEST)
gj@pointblue.com.pl 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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Stephen Hemminger <shemminger@osdl.org>
"And in the Packet there writ down that doome"
prev parent reply other threads:[~2006-08-02 18:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-01 22:52 gj
2006-08-02 18:00 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060802110044.028718fb@dxpl.pdx.osdl.net \
--to=shemminger@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®