[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1252701862.15292.73.camel@Joe-Laptop.home>
Date: Fri, 11 Sep 2009 13:44:22 -0700
From: Joe Perches <joe@...ches.com>
To: David Miller <davem@...emloft.net>
Cc: shemminger@...tta.com, jeffrey.t.kirsher@...el.com,
netdev@...r.kernel.org, gospo@...hat.com, gregory.v.rose@...el.com,
donald.c.skidmore@...el.com
Subject: Re: [net-next PATCH V2] etherdevice.h: random_ether_addr update
Perhaps this is slightly better, it doesn't call
random32 for each octet and makes sure the leading
octet is >= 0x04.
random_ether_address should assign a leading octet >= "0x04"
Does not use get_random_bytes to avoid drawing down entropy pool.
Signed-off-by: Joe Perches <joe@...ches.com>
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 3d7a668..fddcabf 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -121,9 +121,26 @@ static inline int is_valid_ether_addr(const u8 *addr)
*/
static inline void random_ether_addr(u8 *addr)
{
- get_random_bytes (addr, ETH_ALEN);
- addr [0] &= 0xfe; /* clear multicast bit */
- addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
+ u32 val;
+
+ /* not calling get_random_bytes to avoid using entropy */
+ do {
+ val = random32();
+ addr[0] = val;
+ } while (addr[0] < 4);
+ addr[0] &= 0xfe; /* clear multicast bit */
+ addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
+
+ val >>= 8;
+ addr[1] = val;
+ val >>= 8;
+ addr[2] = val;
+ val >>= 8;
+ addr[3] = val;
+ val = random32();
+ addr[4] = val;
+ val >>= 8;
+ addr[5] = val;
}
/**
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists