diff options
-rw-r--r-- | src/include/ipxe/ethernet.h | 1 | ||||
-rw-r--r-- | src/net/ethernet.c | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/include/ipxe/ethernet.h b/src/include/ipxe/ethernet.h index 5ffc45b..b28a6b8 100644 --- a/src/include/ipxe/ethernet.h +++ b/src/include/ipxe/ethernet.h @@ -87,6 +87,7 @@ extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags ); extern void eth_init_addr ( const void *hw_addr, void *ll_addr ); +extern void eth_random_addr ( void *hw_addr ); extern const char * eth_ntoa ( const void *ll_addr ); extern int eth_mc_hash ( unsigned int af, const void *net_addr, void *ll_addr ); diff --git a/src/net/ethernet.c b/src/net/ethernet.c index a2e5658..03978c2 100644 --- a/src/net/ethernet.c +++ b/src/net/ethernet.c @@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> +#include <stdlib.h> #include <stdio.h> #include <string.h> #include <byteswap.h> @@ -113,6 +114,21 @@ void eth_init_addr ( const void *hw_addr, void *ll_addr ) { } /** + * Generate random Ethernet address + * + * @v hw_addr Generated hardware address + */ +void eth_random_addr ( void *hw_addr ) { + uint8_t *addr = hw_addr; + unsigned int i; + + for ( i = 0 ; i < ETH_ALEN ; i++ ) + addr[i] = random(); + addr[0] &= ~0x01; /* Clear multicast bit */ + addr[0] |= 0x02; /* Set locally-assigned bit */ +} + +/** * Transcribe Ethernet address * * @v ll_addr Link-layer address |