From nobody Mon Jul 13 09:36:16 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gzHPj4JNsz6kx6Q; Mon, 13 Jul 2026 09:36:25 +0000 (UTC) (envelope-from ronald-lists@klop.ws) Received: from smtp-relay-int-backup.realworks.nl (smtp-relay-int-backup.realworks.nl [87.255.56.188]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4gzHPj0TgMz4B17; Mon, 13 Jul 2026 09:36:25 +0000 (UTC) (envelope-from ronald-lists@klop.ws) Authentication-Results: mx1.freebsd.org; none Received: from smtp-relay-int.realworks.nl (rwvirtual84.colo.realworks.nl [10.0.10.103]) by mailrelayint2.colo2.realworks.nl (Postfix) with ESMTP id 4gzHPX5FwYz1B7; Mon, 13 Jul 2026 11:36:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=klop.ws; s=rw2; t=1783935376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YFg6EzftE610RzX827ANfajYNXrRXyZ8n6SxjDSpy/c=; b=YcxiUpz44tang9j0fzomydcdRwGR+H+k5x/0N07yud8v834qJrhYB41BIP0SroL27ZAtw1 bMxDfjSa2Lap2zbIIQO82ARNq+ZT1q3/KMfE/z1uDAODks5dakgMFaTbdr2SAXOSZ98gSk gQ+Mob37godbeE6BbsWSTjHGCfRntMFSaEcLVpU2j9APsJaLRQkchOHnjEPy9hESy72kU1 N9EkSmgBPWI5YEc+w2AQnYW2mMtIpuMRImWGNdlVDlqCP58ec+vwT9FmEqGQaAuMBRORuJ +2QWNFOqg9sT08TBU7BlnoPlELmNd33dKttgOvCX8+C8+lWHIrEbY4m0XSOzRg== Received: from rwvirtual84.colo.realworks.nl (localhost [127.0.0.1]) by rwvirtual84.colo.realworks.nl (Postfix) with ESMTP id 7EDC4C01DA; Mon, 13 Jul 2026 11:36:16 +0200 (CEST) Date: Mon, 13 Jul 2026 11:36:16 +0200 (CEST) From: Ronald Klop To: Michal Meloun Cc: dev-commits-src-all@FreeBSD.org, src-committers@FreeBSD.org, dev-commits-src-main@FreeBSD.org Message-ID: <286652666.1198.1783935376299@localhost> In-Reply-To: <6a54a3a6.3466a.6cbf6a26@gitrepo.freebsd.org> References: <6a54a3a6.3466a.6cbf6a26@gitrepo.freebsd.org> Subject: Re: git: 920518cf2e75 - main - FDT: implement fdt_ether_get_addr() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1197_406320084.1783935376295" X-Mailer: Realworks (803.136) X-Originating-Host: from (89-20-164-210.static.ef-service.nl [89.20.164.210]) by rwvirtual84 [10.0.10.103] with HTTP; Mon, 13 Jul 2026 11:36:16 +0200 Importance: Normal X-Priority: 3 (Normal) X-Originating-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:152.0) Gecko/20100101 Firefox/152.0 X-Rspamd-Queue-Id: 4gzHPj0TgMz4B17 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:38930, ipnet:87.255.32.0/19, country:NL] X-Spamd-Bar: ---- ------=_Part_1197_406320084.1783935376295 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi, Nice work! I like the usage of ether_gen_addr for user friendliness when no MAC is known. I did some work on ether_gen_addr in the past and back then I had a situation that an ifp was not (yet) available so I added ether_gen_addr_byname. Somebody (I can look it up if needed) agreed on this and said that ether_gen_addr using ifp is actually a layering violation. So you might take a look if it is easy to pass in the interface name and call ether_gen_addr_byname instead of using the ifp. Regards, Ronald. Van: Michal Meloun Datum: maandag, 13 juli 2026 10:36 Aan: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Onderwerp: git: 920518cf2e75 - main - FDT: implement fdt_ether_get_addr() > > The branch main has been updated by mmel: > > URL: https://cgit.FreeBSD.org/src/commit/?id=920518cf2e75012135104886d92814c048baa2fb > > commit 920518cf2e75012135104886d92814c048baa2fb > Author: Michal Meloun > AuthorDate: 2026-07-13 08:34:22 +0000 > Commit: Michal Meloun > CommitDate: 2026-07-13 08:35:47 +0000 > > FDT: implement fdt_ether_get_addr() > > Introduce fdt_ether_get_addr() in fdt_common.c/h that tries standard > DT properties in the correct order and falls back to a random address > when needed. This should be used by ethernet drivers instead of open-coding > the same logic. > > MFC after: 2 weeks > > Reviewed by: mhorne, adrian, bz, jrtc27 > Differential Revision: https://reviews.freebsd.org/D58104 > --- > sys/dev/fdt/fdt_common.c | 40 ++++++++++++++++++++++++++++++++++++++++ > sys/dev/fdt/fdt_common.h | 4 ++++ > 2 files changed, 44 insertions(+) > > diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c > index f43551c6310e..93897b598b30 100644 > --- a/sys/dev/fdt/fdt_common.c > +++ b/sys/dev/fdt/fdt_common.c > @@ -553,3 +553,43 @@ fdt_get_chosen_bootargs(char *bootargs, size_t max_size) > return (ENXIO); > return (0); > } > + > +/* > + * fdt_ether_get_addr - Get ethernet MAC address using FDT properties. > + * Order: > + * 1. "mac-address" > + * 2. "local-mac-address" > + * 3. Keep pre-initialized value (if valid) > + * 4. random ether_gen_addr() as last resort > + */ > +void > +fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr) > +{ > + uint8_t tmp[ETHER_ADDR_LEN]; > + int len; > + > + /* Firstly try "mac-address" */ > + len = OF_getprop(node, "mac-address", tmp, sizeof(tmp)); > + if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) && > + !ETHER_IS_MULTICAST(tmp)) { > + bcopy(tmp, eaddr, ETHER_ADDR_LEN); > + return; > + } > + > + /* Next use "local-mac-address" */ > + len = OF_getprop(node, "local-mac-address", tmp, sizeof(tmp)); > + if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) && > + !ETHER_IS_MULTICAST(tmp)) { > + bcopy(tmp, eaddr, ETHER_ADDR_LEN); > + return; > + } > + > + /* Next use existing one if set */ > + if (!ETHER_IS_ZERO(eaddr) && !ETHER_IS_MULTICAST(eaddr)) > + return; > + > + /* Last resort - generate random one */ > + ether_gen_addr(ifp, (struct ether_addr *)eaddr); > + > + return; > +} > diff --git a/sys/dev/fdt/fdt_common.h b/sys/dev/fdt/fdt_common.h > index f597233f9771..3eee6913ad72 100644 > --- a/sys/dev/fdt/fdt_common.h > +++ b/sys/dev/fdt/fdt_common.h > @@ -33,8 +33,11 @@ > > #include > #include > +#include > #include > #include > +#include > +#include > > #define FDT_MEM_REGIONS 64 > > @@ -70,6 +73,7 @@ typedef void (*fdt_mem_region_cb)(const struct mem_region *, void *); > int fdt_addrsize_cells(phandle_t, int *, int *); > u_long fdt_data_get(const void *, int); > int fdt_data_to_res(const pcell_t *, int, int, u_long *, u_long *); > +void fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr); > phandle_t fdt_find_compatible(phandle_t, const char *, int); > phandle_t fdt_depth_search_compatible(phandle_t, const char *, int); > int fdt_foreach_mem_region(fdt_mem_region_cb, void *); > > > > ------=_Part_1197_406320084.1783935376295 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hi,

Nice work! I like the usage of ether_gen_addr for user friendliness when no MAC is known.

I did some work on ether_gen_addr in the past and back then I had a situation that an ifp was not (yet) available so I added ether_gen_addr_byname. Somebody (I can look it up if needed) agreed on this and said that ether_gen_addr using ifp is actually a layering violation.
So you might take a look if it is easy to pass in the interface name and call ether_gen_addr_byname instead of using the ifp.

Regards,
Ronald.

 

Van: Michal Meloun <mmel@FreeBSD.org>
Datum: maandag, 13 juli 2026 10:36
Aan: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Onderwerp: git: 920518cf2e75 - main - FDT: implement fdt_ether_get_addr()

The branch main has been updated by mmel:

URL: https://cgit.FreeBSD.org/src/commit/?id=920518cf2e75012135104886d92814c048baa2fb

commit 920518cf2e75012135104886d92814c048baa2fb
Author:     Michal Meloun <mmel@FreeBSD.org>
AuthorDate: 2026-07-13 08:34:22 +0000
Commit:     Michal Meloun <mmel@FreeBSD.org>
CommitDate: 2026-07-13 08:35:47 +0000

    FDT: implement fdt_ether_get_addr()
    
    Introduce fdt_ether_get_addr() in fdt_common.c/h that tries standard
    DT properties in the correct order and falls back to a random address
    when needed. This should be used by ethernet drivers instead of open-coding
    the same logic.
    
    MFC after:      2 weeks
    
    Reviewed by:    mhorne, adrian, bz, jrtc27
    Differential Revision:  https://reviews.freebsd.org/D58104
---
 sys/dev/fdt/fdt_common.c | 40 ++++++++++++++++++++++++++++++++++++++++
 sys/dev/fdt/fdt_common.h |  4 ++++
 2 files changed, 44 insertions(+)

diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c
index f43551c6310e..93897b598b30 100644
--- a/sys/dev/fdt/fdt_common.c
+++ b/sys/dev/fdt/fdt_common.c
@@ -553,3 +553,43 @@ fdt_get_chosen_bootargs(char *bootargs, size_t max_size)
        return (ENXIO);
    return (0);
 }
+
+/*
+ * fdt_ether_get_addr - Get ethernet MAC address using FDT properties.
+ * Order:
+ *   1. "mac-address"
+ *   2. "local-mac-address"
+ *   3. Keep pre-initialized value (if valid)
+ *   4. random ether_gen_addr() as last resort
+ */
+void
+fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr)
+{
+   uint8_t tmp[ETHER_ADDR_LEN];
+   int len;
+
+   /* Firstly try "mac-address" */
+   len = OF_getprop(node, "mac-address", tmp, sizeof(tmp));
+   if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) &&
+       !ETHER_IS_MULTICAST(tmp)) {
+       bcopy(tmp, eaddr, ETHER_ADDR_LEN);
+       return;
+   }
+
+   /* Next use  "local-mac-address" */
+   len = OF_getprop(node, "local-mac-address", tmp, sizeof(tmp));
+   if (len == ETHER_ADDR_LEN && !ETHER_IS_ZERO(tmp) &&
+       !ETHER_IS_MULTICAST(tmp)) {
+       bcopy(tmp, eaddr, ETHER_ADDR_LEN);
+       return;
+   }
+
+   /* Next use existing one if set */
+   if (!ETHER_IS_ZERO(eaddr) && !ETHER_IS_MULTICAST(eaddr))
+       return;
+
+   /* Last resort - generate random one */
+   ether_gen_addr(ifp, (struct ether_addr *)eaddr);
+
+   return;
+}
diff --git a/sys/dev/fdt/fdt_common.h b/sys/dev/fdt/fdt_common.h
index f597233f9771..3eee6913ad72 100644
--- a/sys/dev/fdt/fdt_common.h
+++ b/sys/dev/fdt/fdt_common.h
@@ -33,8 +33,11 @@
 
 #include <sys/sysctl.h>
 #include <sys/slicer.h>
+#include <sys/socket.h>
 #include <contrib/libfdt/libfdt_env.h>
 #include <dev/ofw/ofw_bus.h>
+#include <net/ethernet.h>
+#include <net/if.h>
 
 #define FDT_MEM_REGIONS    64
 
@@ -70,6 +73,7 @@ typedef void (*fdt_mem_region_cb)(const struct mem_region *, void *);
 int fdt_addrsize_cells(phandle_t, int *, int *);
 u_long fdt_data_get(const void *, int);
 int fdt_data_to_res(const pcell_t *, int, int, u_long *, u_long *);
+void fdt_ether_get_addr(phandle_t node, struct ifnet *ifp, uint8_t *eaddr);
 phandle_t fdt_find_compatible(phandle_t, const char *, int);
 phandle_t fdt_depth_search_compatible(phandle_t, const char *, int);
 int fdt_foreach_mem_region(fdt_mem_region_cb, void *);
 


  ------=_Part_1197_406320084.1783935376295--