diff options
Diffstat (limited to 'include/net.h')
-rw-r--r-- | include/net.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/net.h b/include/net.h index 709e76c895..c695e5f72a 100644 --- a/include/net.h +++ b/include/net.h @@ -17,6 +17,7 @@ #include <param.h> #include <malloc.h> #include <stdlib.h> +#include <clock.h> #include <asm/byteorder.h> /* for nton* / ntoh* stuff */ @@ -332,6 +333,21 @@ static inline int is_broadcast_ether_addr(const u8 *addr) } /** + * random_ether_addr - Generate software assigned random Ethernet address + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Generate a random Ethernet address (MAC) that is not multicast + * and has the local assigned bit set. + */ +static inline void random_ether_addr(u8 *addr) +{ + srand(get_time_ns()); + get_random_bytes(addr, 6); + addr [0] &= 0xfe; /* clear multicast bit */ + addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ +} + +/** * is_valid_ether_addr - Determine if the given Ethernet address is valid * @addr: Pointer to a six-byte array containing the Ethernet address * |