compat: backport eth_random_addr()
authorLuis R. Rodriguez <mcgrof@frijolero.org>
Fri, 20 Jul 2012 01:22:55 +0000 (18:22 -0700)
committerLuis R. Rodriguez <mcgrof@frijolero.org>
Fri, 20 Jul 2012 02:08:14 +0000 (19:08 -0700)
This really was a rename but to make code simpler just
reimplement this for all kernels.

commit 0a4dd594982a321699000218715e28664ec49169
Author: Joe Perches <joe@perches.com>
Date:   Thu Jul 12 19:33:05 2012 +0000

    etherdevice: Rename random_ether_addr to eth_random_addr

    Add some API symmetry to eth_broadcast_addr and
    add a #define to the old name for backward compatibility.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
mcgrof@tux ~/compat (git::master)$ ckmake -t
Trying kernel 3.4.0-030400rc1-generic [OK]
Trying kernel 3.3.7-030307-generic [OK]
Trying kernel 3.2.2-030202-generic [OK]
Trying kernel 3.1.10-030110-generic [OK]
Trying kernel 3.0.18-030018-generic [OK]
Trying kernel 2.6.39-02063904-generic [OK]
Trying kernel 2.6.38-02063808-generic [OK]
Trying kernel 2.6.37-02063706-generic [OK]
Trying kernel 2.6.36-02063604-generic [OK]
Trying kernel 2.6.35-02063512-generic [OK]
Trying kernel 2.6.34-02063410-generic [OK]
Trying kernel 2.6.33-02063305-generic [OK]
Trying kernel 2.6.32-02063255-generic [OK]
Trying kernel 2.6.31-02063113-generic [OK]
Trying kernel 2.6.30-02063010-generic [OK]
Trying kernel 2.6.29-02062906-generic [OK]
Trying kernel 2.6.28-02062810-generic [OK]
Trying kernel 2.6.27-020627-generic [OK]
Trying kernel 2.6.26-020626-generic [OK]
Trying kernel 2.6.25-020625-generic [OK]
Trying kernel 2.6.24-020624-generic [OK]

real    4m25.765s
user    9m56.460s
sys     1m24.650s

real    2m7.808s
user    3m20.640s
sys     0m40.520s

Signed-off-by: Luis R. Rodriguez <mcgrof@frijolero.org>
include/linux/compat-3.6.h

index 9da8ec5009197c2dc79df36a47cef62a0b55c015..0b36ca0090cbeacaeb379a38a33f3c49938ab4a9 100644 (file)
@@ -6,6 +6,21 @@
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
 
 #include <net/genetlink.h>
+#include <linux/etherdevice.h>
+
+/**
+ * eth_random_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 eth_random_addr(u8 *addr)
+{
+       get_random_bytes(addr, ETH_ALEN);
+       addr[0] &= 0xfe;        /* clear multicast bit */
+       addr[0] |= 0x02;        /* set local assignment bit (IEEE802) */
+}
 
 #define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN)