From 344a15d937a4027cb70df497c5b4e36883d4465a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 20 Mar 2009 13:41:44 -0700 Subject: [PATCH] packets: New function eth_addr_mark_random(). This function is useful for turning a sequence of random bits into a valid MAC address, which we need for generating DPIDs under Xen. --- lib/packets.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/packets.h b/lib/packets.h index 0a0da381..9c7ee9ce 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -91,12 +91,16 @@ static inline void eth_addr_from_uint64(uint64_t x, uint8_t ea[ETH_ADDR_LEN]) ea[4] = x >> 8; ea[5] = x; } -static inline void eth_addr_random(uint8_t ea[ETH_ADDR_LEN]) +static inline void eth_addr_mark_random(uint8_t ea[ETH_ADDR_LEN]) { - random_bytes(ea, ETH_ADDR_LEN); ea[0] &= ~1; /* Unicast. */ ea[0] |= 2; /* Private. */ } +static inline void eth_addr_random(uint8_t ea[ETH_ADDR_LEN]) +{ + random_bytes(ea, ETH_ADDR_LEN); + eth_addr_mark_random(ea); +} /* Returns true if 'ea' is a reserved multicast address, that a bridge must * never forward, false otherwise. */ static inline bool eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN]) -- 2.30.2