netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Poirier <benjamin.poirier@gmail.com>
To: Oliver Neukum <oneukum@suse.com>
Cc: bjorn@mork.no, netdev@vger.kernel.org
Subject: Re: [RFC] usbnet: assign unique random MAC
Date: Thu, 16 Nov 2023 15:48:55 -0500	[thread overview]
Message-ID: <ZVaAN28EeKJeMKPJ@d3> (raw)
In-Reply-To: <20231116140616.4848-1-oneukum@suse.com>

On 2023-11-16 15:05 +0100, Oliver Neukum wrote:
> The old method had the bug of issuing the same
> random MAC over and over even to every device.
> This bug is as old as the driver.
> 
> This new method generates each device whose minidriver
> does not provide its own MAC its own unique random
> MAC.
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
>  drivers/net/usb/usbnet.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index 2d14b0d78541..37e3bb2170bc 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -61,9 +61,6 @@
>  
>  /*-------------------------------------------------------------------------*/
>  
> -// randomly generated ethernet address
> -static u8	node_id [ETH_ALEN];
> -
>  /* use ethtool to change the level for any given device */
>  static int msg_level = -1;
>  module_param (msg_level, int, 0);
> @@ -1731,7 +1728,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
>  
>  	dev->net = net;
>  	strscpy(net->name, "usb%d", sizeof(net->name));
> -	eth_hw_addr_set(net, node_id);
>  
>  	/* rx and tx sides can use different message sizes;
>  	 * bind() should set rx_urb_size in that case.
> @@ -1805,9 +1801,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
>  		goto out4;
>  	}
>  
> -	/* let userspace know we have a random address */
> -	if (ether_addr_equal(net->dev_addr, node_id))
> -		net->addr_assign_type = NET_ADDR_RANDOM;
> +	/*
> +	 * if the device does not come with a MAC

The patch's formatting has some problems. Please run checkpatch before
resubmitting.

> +	 * we ask the network core to generate us one
> +	 * and flag the device accordingly
> +	 */
> +	if (!is_valid_ether_addr(net->dev_addr))
> +			eth_hw_addr_random(net);

Before initialization, dev_addr is null (00:00:00:00:00:00). Since this
patch moves the fallback address initialization after the 
	if (info->bind) {
block, if the bind() did not initialize the address, this patch changes
the result of the
		     (net->dev_addr [0] & 0x02) == 0))
test within the block, no? The test now takes place on an uninitialized
address and the result goes from false to true.

  parent reply	other threads:[~2023-11-16 20:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16 14:05 [RFC] usbnet: assign unique random MAC Oliver Neukum
2023-11-16 18:51 ` Stephen Hemminger
2023-11-16 20:48 ` Benjamin Poirier [this message]
2023-11-20 10:44   ` Oliver Neukum
  -- strict thread matches above, loose matches on Subject: below --
2023-11-16 12:30 Oliver Neukum
2023-11-16 12:39 ` Bjørn Mork
2023-11-16 13:02   ` Oliver Neukum
2023-11-16 13:21     ` Bjørn Mork
2023-11-16 13:29       ` Oliver Neukum
2023-11-16 14:49         ` Bjørn Mork
2023-11-16 17:45           ` Oliver Neukum
2023-11-16 21:47   ` Andrew Lunn
2023-11-16 18:49 ` Stephen Hemminger

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=ZVaAN28EeKJeMKPJ@d3 \
    --to=benjamin.poirier@gmail.com \
    --cc=bjorn@mork.no \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.com \
    /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).