[PATCH 05/11] net: implement random_ether_addr
Sascha Hauer
s.hauer at pengutronix.de
Mon Jun 14 05:48:35 EDT 2010
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
include/net.h | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/include/net.h b/include/net.h
index 8db83d8..2e17e39 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,8 @@
#include <linux/types.h>
#include <param.h>
#include <malloc.h>
+#include <clock.h>
+#include <random.h>
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
@@ -331,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
*
--
1.7.1
More information about the barebox
mailing list