netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wu Fengguang <wfg@linux.intel.com>
To: Peter Korsgaard <jacmet@sunsite.dk>
Cc: dbrownell@users.sourceforge.net, netdev@vger.kernel.org
Subject: Re: [PATCH] dm9601: handle corrupt mac address
Date: Tue, 6 Jan 2009 17:50:08 +0800	[thread overview]
Message-ID: <20090106095008.GA19365@localhost> (raw)
In-Reply-To: <874p0cvnae.fsf@macbook.be.48ers.dk>

On Tue, Jan 06, 2009 at 09:42:01AM +0100, Peter Korsgaard wrote:
> >>>>> "Wu" == Wu Fengguang <wfg@linux.intel.com> writes:
> 
> Hi,
> 
>  >> Do we automatically get a random address in netdev nowadays without
>  >> calling random_ether_addr? I didn't know that.
> 
>  Wu> I confirmed based on both code review and tests.
>  Wu> The logic goes like this in usbnet.c:
> 
>  Wu>   80 // randomly generated ethernet address
>  Wu>   81 static u8       node_id [ETH_ALEN];
>  Wu> ...
>  Wu> 1118 int
>  Wu> 1119 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
>  Wu> 1120 {
>  Wu> ...
>  Wu> 1168         dev->net = net;
>  Wu> 1169         strcpy (net->name, "usb%d");
>  Wu> 1170         memcpy (net->dev_addr, node_id, sizeof node_id);
>  Wu> ...
> 
> So what happens if you plug in 2 devices without an EEPROM? Do they
> get the same MAC address? That seems broken.

Good catch. The following patch for this case was tested OK.

But this simple fix will make the mac address change between
ifup/ifdowns, is this acceptable?

Thanks,
Fengguang
---
usbnet: use different random mac addresses for multiple usbnet devices

It is a bug to use the same mac address for possibly 2+ connected
usbnet devices.  Fix this concern raised by Peter Korsgaard.

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 drivers/net/usb/usbnet.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

--- linux-2.6.orig/drivers/net/usb/usbnet.c
+++ linux-2.6/drivers/net/usb/usbnet.c
@@ -77,9 +77,6 @@
 
 /*-------------------------------------------------------------------------*/
 
-// randomly generated ethernet address
-static u8	node_id [ETH_ALEN];
-
 static const char driver_name [] = "usbnet";
 
 /* use ethtool to change the level for any given device */
@@ -1167,7 +1164,7 @@ usbnet_probe (struct usb_interface *udev
 
 	dev->net = net;
 	strcpy (net->name, "usb%d");
-	memcpy (net->dev_addr, node_id, sizeof node_id);
+	random_ether_addr(net->dev_addr);
 
 	/* rx and tx sides can use different message sizes;
 	 * bind() should set rx_urb_size in that case.
@@ -1310,7 +1307,6 @@ static int __init usbnet_init(void)
 	BUILD_BUG_ON (sizeof (((struct sk_buff *)0)->cb)
 			< sizeof (struct skb_data));
 
-	random_ether_addr(node_id);
 	return 0;
 }
 module_init(usbnet_init);

  reply	other threads:[~2009-01-06  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06  6:14 [PATCH] dm9601: handle corrupt mac address Wu Fengguang
2009-01-06  8:04 ` Peter Korsgaard
2009-01-06  8:29   ` Wu Fengguang
2009-01-06  8:42     ` Peter Korsgaard
2009-01-06  9:50       ` Wu Fengguang [this message]
2009-01-06 10:28       ` David Brownell
2009-01-06 10:56         ` Peter Korsgaard
2009-01-06 18:55   ` David Miller

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=20090106095008.GA19365@localhost \
    --to=wfg@linux.intel.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=jacmet@sunsite.dk \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).