diff mbox series

of: net: Add option for random mac address

Message ID 20241010215417.332801-1-igilca1980@gmail.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series of: net: Add option for random mac address | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0
netdev/contest warning net-next-2024-10-11--00-00 (tests: 777)

Commit Message

Iulian Gilca Oct. 10, 2024, 9:54 p.m. UTC
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(+)

Comments

Russell King (Oracle) Oct. 10, 2024, 10:54 p.m. UTC | #1
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.
Andrew Lunn Oct. 10, 2024, 11 p.m. UTC | #2
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
diff mbox series

Patch

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