Bug 262406

Summary: [re] if_re doesn't generate MAC address if hardware has none
Product: Base System Reporter: Evgeni Golov <evgeni>
Component: kernAssignee: Warner Losh <imp>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, freebsd, zlei
Priority: --- Flags: linimon: mfc-stable13?
Version: 13.0-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
patch to use ether_gen_addr none

Description Evgeni Golov 2022-03-07 19:33:15 UTC
Ohai,

there exists hardware (like [1]) that has no ethernet address burned into the EEPROM. Loading if_re on such a HW brings the device up with '00:00:00:00:00:00' as the address, and that doesn't get you too far in a real network.

Other drivers use ether_gen_addr(9) in such cases, to generate an address, and so should if_re, I think?

Probably something like this (untested yet):

diff --git sys/dev/re/if_re.c sys/dev/re/if_re.c
index 5d1446e51ab..7905740a930 100644
--- sys/dev/re/if_re.c
+++ sys/dev/re/if_re.c
@@ -1676,6 +1676,11 @@ re_attach(device_t dev)
 		goto fail;
 	}
 
+	/* If address was not found, create one based on the hostid and name. */
+	if (ETHER_IS_ZERO(eaddr)) {
+		ether_gen_addr(ifp, eaddr);
+	}
+
 	/*
 	 * Call MI attach routine.
 	 */

Thanks!

[1] https://www.dfrobot.com/product-2242.html
Comment 1 Evgeni Golov 2022-03-07 20:15:15 UTC
ether_gen_addr(ifp, (struct ether_addr *)eaddr);

works much better if you cast properly (eaddr is a plain char array in if_re.c)
Comment 2 Evgeni Golov 2022-03-07 20:15:59 UTC
Created attachment 232309 [details]
patch to use ether_gen_addr
Comment 3 Evgeni Golov 2022-03-08 20:20:55 UTC
https://reviews.freebsd.org/D34485
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2023-02-26 14:18:58 UTC
> [1] https://www.dfrobot.com/product-2242.html

The fix is simple, but still deserves a test on hardware such as mentioned [1].
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-02-27 22:56:23 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=55747938b5c4c913f742fd03189f0c660ced7bef

commit 55747938b5c4c913f742fd03189f0c660ced7bef
Author:     Evgeni Golov <evgeni@debian.org>
AuthorDate: 2023-02-27 22:50:56 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-02-27 22:51:27 +0000

    if_re: Generate an address if there is none in the EEPROM

    There exists hardware that has no ethernet address burned into
    the EEPROM. Loading if_re on such a HW brings the device up
    with '00:00:00:00:00:00' as the address, and that doesn't get
    you too far in a real network.

    PR: 262406
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/670
    Signed-off-by: Evgeni Golov <evgeni@debian.org>
    Differential Revision: https://reviews.freebsd.org/D34485

 sys/dev/re/if_re.c | 5 +++++
 1 file changed, 5 insertions(+)
Comment 6 Mina Galić freebsd_triage 2023-02-28 02:18:58 UTC
this was merged and it's slated for MFC, so i think we can close it
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2024-01-08 04:58:34 UTC
^Triage: assign to committer to see if there is any mfc-stable13 interest.
Comment 8 commit-hook freebsd_committer freebsd_triage 2024-02-19 02:56:05 UTC
A commit in branch stable/13 references this bug:

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

commit fcb6cac22397ecfc3fa9eaa9957a86a2fb639c8f
Author:     Evgeni Golov <evgeni@debian.org>
AuthorDate: 2023-02-27 22:50:56 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-02-19 02:52:41 +0000

    if_re: Generate an address if there is none in the EEPROM

    There exists hardware that has no ethernet address burned into
    the EEPROM. Loading if_re on such a HW brings the device up
    with '00:00:00:00:00:00' as the address, and that doesn't get
    you too far in a real network.

    PR: 262406
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/670
    Signed-off-by: Evgeni Golov <evgeni@debian.org>
    Differential Revision: https://reviews.freebsd.org/D34485
    (cherry picked from commit 55747938b5c4c913f742fd03189f0c660ced7bef)

 sys/dev/re/if_re.c | 5 +++++
 1 file changed, 5 insertions(+)