[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)
This commit is contained in:
adrian 2019-12-28 06:56:21 +00:00
parent de3a5fc160
commit 48a5564f98
3 changed files with 8 additions and 13 deletions

View File

@ -93,18 +93,9 @@ ar71xx_mac_addr_init(unsigned char *dst, const unsigned char *src,
* 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);
}

View File

@ -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__ */

View File

@ -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) {