Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Dec 2019 06:56:21 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356145 - head/sys/mips/atheros
Message-ID:  <201912280656.xBS6uL6X012337@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Sat Dec 28 06:56:21 2019
New Revision: 356145
URL: https://svnweb.freebsd.org/changeset/base/356145

Log:
  [ar71xx] generate a random mac address using eth_gen_addr()
  
  This removes a hard-coded random mac address generator and
  uses the (not so) new system routine.
  
  Tested:
  
  * TP-Link WDR-4300 (AR934x + AR9580)

Modified:
  head/sys/mips/atheros/ar71xx_macaddr.c
  head/sys/mips/atheros/ar71xx_macaddr.h
  head/sys/mips/atheros/if_arge.c

Modified: head/sys/mips/atheros/ar71xx_macaddr.c
==============================================================================
--- head/sys/mips/atheros/ar71xx_macaddr.c	Sat Dec 28 05:28:29 2019	(r356144)
+++ head/sys/mips/atheros/ar71xx_macaddr.c	Sat Dec 28 06:56:21 2019	(r356145)
@@ -93,18 +93,9 @@ ar71xx_mac_addr_init(unsigned char *dst, const unsigne
  * Returns 0 on success, -1 on error.
  */
 int
-ar71xx_mac_addr_random_init(unsigned char *dst)
+ar71xx_mac_addr_random_init(struct ifnet *ifp, struct ether_addr *dst)
 {
-	uint32_t rnd;
 
-	rnd = arc4random();
-
-	dst[0] = 'b';
-	dst[1] = 's';
-	dst[2] = 'd';
-	dst[3] = (rnd >> 24) & 0xff;
-	dst[4] = (rnd >> 16) & 0xff;
-	dst[5] = (rnd >> 8) & 0xff;
-
+	ether_gen_addr(ifp, dst);
 	return (0);
 }

Modified: head/sys/mips/atheros/ar71xx_macaddr.h
==============================================================================
--- head/sys/mips/atheros/ar71xx_macaddr.h	Sat Dec 28 05:28:29 2019	(r356144)
+++ head/sys/mips/atheros/ar71xx_macaddr.h	Sat Dec 28 06:56:21 2019	(r356145)
@@ -34,6 +34,6 @@ extern	uint8_t ar71xx_board_mac_addr[ETHER_ADDR_LEN];
 
 extern	int ar71xx_mac_addr_init(unsigned char *dst, const unsigned char *src,
 	    int offset, int is_local);
-extern	int ar71xx_mac_addr_random_init(unsigned char *dst);
+extern	int ar71xx_mac_addr_random_init(struct ifnet *ifp, struct ether_addr *dst);
 
 #endif /* __ATHEROS_AR71XX_MACADDR_H__ */

Modified: head/sys/mips/atheros/if_arge.c
==============================================================================
--- head/sys/mips/atheros/if_arge.c	Sat Dec 28 05:28:29 2019	(r356144)
+++ head/sys/mips/atheros/if_arge.c	Sat Dec 28 06:56:21 2019	(r356145)
@@ -876,7 +876,11 @@ arge_attach(device_t dev)
 		if  (bootverbose)
 			device_printf(dev,
 			    "Generating random ethernet address.\n");
-		(void) ar71xx_mac_addr_random_init(sc->arge_eaddr);
+		if (ar71xx_mac_addr_random_init(ifp, (void *) sc->arge_eaddr) < 0) {
+			device_printf(dev, "Failed to choose random MAC address\n");
+			error = EINVAL;
+			goto fail;
+		}
 	}
 
 	if (arge_dma_alloc(sc) != 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912280656.xBS6uL6X012337>