netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: net: Add option for random mac address
@ 2024-10-10 19:05 Iulian Gilca
  2024-10-10 19:53 ` Andrew Lunn
  0 siblings, 1 reply; 7+ messages in thread
From: Iulian Gilca @ 2024-10-10 19:05 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: igilca, Iulian Gilca, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel

Embedded devices that may not have fixed mac address
may want to use a randomly generated one.
DSA switch ports are some of these.

Signed-off-by: Iulian Gilca <igilca1980@gmail.com>
---
 net/core/of_net.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248..aa4acdffc710 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -142,6 +142,10 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
 	if (!ret)
 		return 0;
 
+	ret = of_get_mac_addr(np, "random-address", addr);
+	if (!ret)
+		return 0;
+
 	return of_get_mac_address_nvmem(np, addr);
 }
 EXPORT_SYMBOL(of_get_mac_address);
-- 
2.43.0


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

* Re: [PATCH] of: net: Add option for random mac address
  2024-10-10 19:05 [PATCH] of: net: Add option for random mac address Iulian Gilca
@ 2024-10-10 19:53 ` Andrew Lunn
  2024-10-10 20:29   ` [PATCH v2] User random address if dt sets so Iulian Gilca
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2024-10-10 19:53 UTC (permalink / raw)
  To: Iulian Gilca
  Cc: igilca, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Thu, Oct 10, 2024 at 03:05:03PM -0400, Iulian Gilca wrote:
> Embedded devices that may not have fixed mac address
> may want to use a randomly generated one.
> DSA switch ports are some of these.

Sorry, i don't follow what this patch is doing. You are looking in DT
for a property "random-address". DT is static, so how is it going to
be random?

I also don't understand you use case. Generally, a MAC driver will try
to find a fixed MAC address. If one cannot be found, it generates a
random one.

For DSA, it takes the MAC address from the conduit interface for the
user interfaces. If userspace whats to use come other MAC address on
user ports, it can change the MAC address in the usual way.

	Andrew

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

* [PATCH v2] User random address if dt sets so
  2024-10-10 19:53 ` Andrew Lunn
@ 2024-10-10 20:29   ` Iulian Gilca
  2024-10-10 20:59     ` Andrew Lunn
  0 siblings, 1 reply; 7+ messages in thread
From: Iulian Gilca @ 2024-10-10 20:29 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: igilca, Iulian Gilca, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel

---
 net/core/of_net.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/core/of_net.c b/net/core/of_net.c
index aa4acdffc710..a11f1c12c395 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -142,7 +142,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
 	if (!ret)
 		return 0;
 
-	ret = of_get_mac_addr(np, "random-address", addr);
+	if (of_find_property(np, "random-address", NULL)) {
+		eth_random_addr(addr);
+		return 0;
+	}
+
 	if (!ret)
 		return 0;
 
-- 
2.43.0


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

* Re: [PATCH v2] User random address if dt sets so
  2024-10-10 20:29   ` [PATCH v2] User random address if dt sets so Iulian Gilca
@ 2024-10-10 20:59     ` Andrew Lunn
  2024-10-10 21:54       ` [PATCH] of: net: Add option for random mac address Iulian Gilca
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2024-10-10 20:59 UTC (permalink / raw)
  To: Iulian Gilca
  Cc: igilca, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Thu, Oct 10, 2024 at 04:29:37PM -0400, Iulian Gilca wrote:

The commit message cannot be empty like this.

Please explain in detail your use case. We need to understand the
'Why?' to decide if this is the correct solution to the problem.  To
me, it seems like you have a broken MAC driver, and fixing that MAC
driver is the correct fix.

    Andrew

---
pw-bot: cr
       

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

* [PATCH] of: net: Add option for random mac address
  2024-10-10 20:59     ` Andrew Lunn
@ 2024-10-10 21:54       ` Iulian Gilca
  2024-10-10 22:54         ` Russell King (Oracle)
  2024-10-10 23:00         ` Andrew Lunn
  0 siblings, 2 replies; 7+ messages in thread
From: Iulian Gilca @ 2024-10-10 21:54 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: igilca, Iulian Gilca, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel

Embedded devices that don't have a fixed mac address may want
to use this property. For example dsa switch ports may use this property in
order avoid setting this from user space. Sometimes, in case of DSA switch
ports is desirable to use a random mac address rather than using the 
conduit interface mac address.

example device tree config :

	....
	netswitch: swdev@5f {
		compatible = "microchip,ksz9897";
		...
		ports {
			port@0 {
				reg = <0>;
				label = "eth0";
				random-address;
			}
			...
		}
	}

	...

This way the switch ports that have the "random-address" property 
will use a random mac address rather than the conduit mac address.

PS. Sorry for the previous malformed patch

Signed-off-by: Iulian Gilca <igilca1980@gmail.com>
---
 net/core/of_net.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248..8a1fc8a4e87f 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -142,6 +142,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
 	if (!ret)
 		return 0;
 
+	if (of_find_property(np, "random-address", NULL)) {
+		eth_random_addr(addr);
+		return 0;
+	}
+
 	return of_get_mac_address_nvmem(np, addr);
 }
 EXPORT_SYMBOL(of_get_mac_address);
-- 
2.43.0


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

* Re: [PATCH] of: net: Add option for random mac address
  2024-10-10 21:54       ` [PATCH] of: net: Add option for random mac address Iulian Gilca
@ 2024-10-10 22:54         ` Russell King (Oracle)
  2024-10-10 23:00         ` Andrew Lunn
  1 sibling, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2024-10-10 22:54 UTC (permalink / raw)
  To: Iulian Gilca
  Cc: Andrew Lunn, igilca, Heiner Kallweit, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Thu, Oct 10, 2024 at 05:54:17PM -0400, Iulian Gilca wrote:
> Embedded devices that don't have a fixed mac address may want
> to use this property. For example dsa switch ports may use this property in
> order avoid setting this from user space.

As Andrew has already explained, DSA switch ports derive their ethernet
address from the ethernet address of the host MAC they are connected to,
and each port does not have its own ethernet address.

Please explain why you want to have DSA switch ports having their own
randomised ethernet addresses, and why this is advantageous over having
a stable ethernet address for the switch ports.

> Sometimes, in case of DSA switch
> ports is desirable to use a random mac address rather than using the 
> conduit interface mac address.

This is just a statement but gives no insight into _why_ you want this.

We want to know the reason behind this change.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH] of: net: Add option for random mac address
  2024-10-10 21:54       ` [PATCH] of: net: Add option for random mac address Iulian Gilca
  2024-10-10 22:54         ` Russell King (Oracle)
@ 2024-10-10 23:00         ` Andrew Lunn
  1 sibling, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2024-10-10 23:00 UTC (permalink / raw)
  To: Iulian Gilca
  Cc: igilca, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

On Thu, Oct 10, 2024 at 05:54:17PM -0400, Iulian Gilca wrote:
> Embedded devices that don't have a fixed mac address may want
> to use this property. For example dsa switch ports may use this property in
> order avoid setting this from user space. Sometimes, in case of DSA switch
> ports is desirable to use a random mac address rather than using the 
> conduit interface mac address.
> 
> example device tree config :
> 
> 	....
> 	netswitch: swdev@5f {
> 		compatible = "microchip,ksz9897";
> 		...
> 		ports {
> 			port@0 {
> 				reg = <0>;
> 				label = "eth0";
> 				random-address;
> 			}
> 			...
> 		}
> 	}
> 
> 	...
> 
> This way the switch ports that have the "random-address" property 
> will use a random mac address rather than the conduit mac address.
> 
> PS. Sorry for the previous malformed patch

In addition to Russells emai:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

and it is much better to answer questions asked than post yet another
patch. Yes, the commit message is better, but it still does not fully
explain 'Why?' and convince us this is the correct solution to your
problem. What _is_ the problem you are trying to solve?

    Andrew

---
pw-bot: cr

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

end of thread, other threads:[~2024-10-10 23:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 19:05 [PATCH] of: net: Add option for random mac address Iulian Gilca
2024-10-10 19:53 ` Andrew Lunn
2024-10-10 20:29   ` [PATCH v2] User random address if dt sets so Iulian Gilca
2024-10-10 20:59     ` Andrew Lunn
2024-10-10 21:54       ` [PATCH] of: net: Add option for random mac address Iulian Gilca
2024-10-10 22:54         ` Russell King (Oracle)
2024-10-10 23:00         ` Andrew Lunn

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