netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* question on random MAC in usbnet
@ 2023-11-16 10:14 Oliver Neukum
  2023-11-16 11:31 ` Bjørn Mork
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Neukum @ 2023-11-16 10:14 UTC (permalink / raw)
  To: Bjørn Mork; +Cc: netdev@vger.kernel.org, USB list

Hi,

I am wondering about the MAC address usbnet is handing
out. In particular why that is a singular address.
Frankly that seems plainly wrong. A MAC is supposed
to be unique, which is just fundamentally incompatible
to using the same MAC for multiple devices, as usbnet
currently potentially does.

Do you think that behavior should be changed to using
a separate random MAC for each device that requires it?

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question on random MAC in usbnet
  2023-11-16 10:14 question on random MAC in usbnet Oliver Neukum
@ 2023-11-16 11:31 ` Bjørn Mork
  2023-11-16 12:32   ` Oliver Neukum
  2023-11-19 11:09   ` David Laight
  0 siblings, 2 replies; 7+ messages in thread
From: Bjørn Mork @ 2023-11-16 11:31 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: netdev@vger.kernel.org, USB list

Oliver Neukum <oneukum@suse.com> writes:

> I am wondering about the MAC address usbnet is handing
> out. In particular why that is a singular address.

This has been the case since long long before I ever looked at usbnet.c.
The variable declaration is in fact still attributed to the initial git
commit:

 ^1da177e4c3f4 drivers/usb/net/usbnet.c (Linus Torvalds              2005-04-16 15:20:36 -0700   64) // randomly generated ethernet address
 ^1da177e4c3f4 drivers/usb/net/usbnet.c (Linus Torvalds              2005-04-16 15:20:36 -0700   65) static u8   node_id [ETH_ALEN];

Pretty impressive given the churn we've had since then :)

If I were to guess why it ended up like that, I'd say that it probably
was because it was considered an exceptional fallback only.

If you wrote a driver with the USB-IF communication class spec in mind,
then it was reasonable to expect a functional decriptor pointing to a
string descriptor with a globally unique mac address, assigned by the
device manufacturer.

A host using more than one usbnet device was also unlikely 20 years
ago.  So host unique was good enough in any case.

These factors have change a lot since then, obviously.

> Frankly that seems plainly wrong. A MAC is supposed
> to be unique, which is just fundamentally incompatible
> to using the same MAC for multiple devices, as usbnet
> currently potentially does.

Agreed.

> Do you think that behavior should be changed to using
> a separate random MAC for each device that requires it?

I'm in favour.

I could be wrong, but I don't expect anything to break if we did that.
The current static address comes from eth_random_addr() in any case, so
the end result as seen from the mini drivers should be identical.  The
difference will be seen in userspace and surrounding equipment, And
those should be for the better.


Bjørn

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question on random MAC in usbnet
  2023-11-16 11:31 ` Bjørn Mork
@ 2023-11-16 12:32   ` Oliver Neukum
  2023-11-19 11:09   ` David Laight
  1 sibling, 0 replies; 7+ messages in thread
From: Oliver Neukum @ 2023-11-16 12:32 UTC (permalink / raw)
  To: Bjørn Mork, Oliver Neukum; +Cc: netdev@vger.kernel.org, USB list

On 16.11.23 12:31, Bjørn Mork wrote:
> Oliver Neukum <oneukum@suse.com> writes:

> A host using more than one usbnet device was also unlikely 20 years
> ago.  So host unique was good enough in any case.
> 
> These factors have change a lot since then, obviously.

Yes.
   
> I could be wrong, but I don't expect anything to break if we did that.
> The current static address comes from eth_random_addr() in any case, so
> the end result as seen from the mini drivers should be identical.  The
> difference will be seen in userspace and surrounding equipment, And
> those should be for the better.

In theory somebody might have a setup with multiple devices on the same
bus and using them getting the same MAC for seamless fallover.

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: question on random MAC in usbnet
  2023-11-16 11:31 ` Bjørn Mork
  2023-11-16 12:32   ` Oliver Neukum
@ 2023-11-19 11:09   ` David Laight
  2023-11-19 16:13     ` Andrew Lunn
                       ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: David Laight @ 2023-11-19 11:09 UTC (permalink / raw)
  To: 'Bjørn Mork', Oliver Neukum; +Cc: netdev@vger.kernel.org, USB list

From: Bjørn Mork
> Sent: 16 November 2023 11:32
...
> > Do you think that behavior should be changed to using
> > a separate random MAC for each device that requires it?
> 
> I'm in favour.
> 
> I could be wrong, but I don't expect anything to break if we did that.
> The current static address comes from eth_random_addr() in any case, so
> the end result as seen from the mini drivers should be identical.  The
> difference will be seen in userspace and surrounding equipment, And
> those should be for the better.

It might cause grief when a USB device 'bounces' [1].
At the moment it will pick up the same 'random' MAC address.
But afterwards it will change.

So you might want to save the MAC on device removal and
re-use it on the next insert.

[1] We ended up putting the USB interface inside a 'bond'
in order to stop the interface everything was using
randomly disappearing due to common-mode noise on the
USB data lines causing a disconnect.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question on random MAC in usbnet
  2023-11-19 11:09   ` David Laight
@ 2023-11-19 16:13     ` Andrew Lunn
  2023-11-20 11:06     ` Oliver Neukum
  2023-11-20 16:48     ` Dan Williams
  2 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2023-11-19 16:13 UTC (permalink / raw)
  To: David Laight
  Cc: 'Bjørn Mork', Oliver Neukum, netdev@vger.kernel.org,
	USB list

> So you might want to save the MAC on device removal and
> re-use it on the next insert.

That gets interesting when you have multiple USB-Ethernet dongles.

I have a machine with 20 of them, which i use for functional testing
of Ethernet switches. Luckily for me, they all have a vendor assigned
MAC address.

> 
> [1] We ended up putting the USB interface inside a 'bond'
> in order to stop the interface everything was using
> randomly disappearing due to common-mode noise on the
> USB data lines causing a disconnect.

Maybe you should of just thrown the hardware away since it seems
broken.

	Andrew

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question on random MAC in usbnet
  2023-11-19 11:09   ` David Laight
  2023-11-19 16:13     ` Andrew Lunn
@ 2023-11-20 11:06     ` Oliver Neukum
  2023-11-20 16:48     ` Dan Williams
  2 siblings, 0 replies; 7+ messages in thread
From: Oliver Neukum @ 2023-11-20 11:06 UTC (permalink / raw)
  To: David Laight, 'Bjørn Mork', Oliver Neukum
  Cc: netdev@vger.kernel.org, USB list

On 19.11.23 12:09, David Laight wrote:

> It might cause grief when a USB device 'bounces' [1].
> At the moment it will pick up the same 'random' MAC address.
> But afterwards it will change.
> 
> So you might want to save the MAC on device removal and
> re-use it on the next insert.

That means that the MAC a device would get depends on the
sequence of plugs and unplugs. That seems ... interesting.

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: question on random MAC in usbnet
  2023-11-19 11:09   ` David Laight
  2023-11-19 16:13     ` Andrew Lunn
  2023-11-20 11:06     ` Oliver Neukum
@ 2023-11-20 16:48     ` Dan Williams
  2 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2023-11-20 16:48 UTC (permalink / raw)
  To: David Laight, 'Bjørn Mork', Oliver Neukum
  Cc: netdev@vger.kernel.org, USB list

On Sun, 2023-11-19 at 11:09 +0000, David Laight wrote:
> From: Bjørn Mork
> > Sent: 16 November 2023 11:32
> ...
> > > Do you think that behavior should be changed to using
> > > a separate random MAC for each device that requires it?
> > 
> > I'm in favour.
> > 
> > I could be wrong, but I don't expect anything to break if we did
> > that.
> > The current static address comes from eth_random_addr() in any
> > case, so
> > the end result as seen from the mini drivers should be identical. 
> > The
> > difference will be seen in userspace and surrounding equipment, And
> > those should be for the better.
> 
> It might cause grief when a USB device 'bounces' [1].
> At the moment it will pick up the same 'random' MAC address.
> But afterwards it will change.

Can that be achieved with userspace helpers too? They can match against
USB device details (or just use a static MAC for everything like the
driver does today) and set that on the device before anything else in
userspace starts using it.

Dan

> 
> So you might want to save the MAC on device removal and
> re-use it on the next insert.
> 
> [1] We ended up putting the USB interface inside a 'bond'
> in order to stop the interface everything was using
> randomly disappearing due to common-mode noise on the
> USB data lines causing a disconnect.
> 
>         David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
> MK1 1PT, UK
> Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-11-20 16:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 10:14 question on random MAC in usbnet Oliver Neukum
2023-11-16 11:31 ` Bjørn Mork
2023-11-16 12:32   ` Oliver Neukum
2023-11-19 11:09   ` David Laight
2023-11-19 16:13     ` Andrew Lunn
2023-11-20 11:06     ` Oliver Neukum
2023-11-20 16:48     ` Dan Williams

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).