From: Ben Pfaff Date: Fri, 20 Mar 2009 20:41:44 +0000 (-0700) Subject: packets: New function eth_addr_mark_random(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=344a15d937a4027cb70df497c5b4e36883d4465a;p=openvswitch 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. --- 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])