compat: backport eth_hw_addr_random()
authorLuis R. Rodriguez <mcgrof@frijolero.org>
Tue, 28 Feb 2012 22:49:12 +0000 (14:49 -0800)
committerLuis R. Rodriguez <mcgrof@frijolero.org>
Tue, 28 Feb 2012 22:49:12 +0000 (14:49 -0800)
This backports eth_hw_addr_random(). Tested with
ckmake on v2.6.24..v3.3 :

Trying kernel                  3.3.0-030300rc2-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-13-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-22-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]

Signed-off-by: Luis R. Rodriguez <mcgrof@frijolero.org>
include/linux/compat-2.6.h
include/linux/compat-3.4.h [new file with mode: 0644]

index 3ccd05166863245805fae3965d30e51568cb1204..c14aeb8641b615303199e8ddd2bfc6c60c87b889 100644 (file)
@@ -38,5 +38,6 @@
 #include <linux/compat-3.1.h>
 #include <linux/compat-3.2.h>
 #include <linux/compat-3.3.h>
+#include <linux/compat-3.4.h>
 
 #endif /* LINUX_26_COMPAT_H */
diff --git a/include/linux/compat-3.4.h b/include/linux/compat-3.4.h
new file mode 100644 (file)
index 0000000..378371f
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef LINUX_3_4_COMPAT_H
+#define LINUX_3_4_COMPAT_H
+
+#include <linux/version.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
+
+#include <linux/etherdevice.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12))
+static inline void eth_hw_addr_random(struct net_device *dev)
+{
+#error eth_hw_addr_random() needs to be implemented for < 2.6.12
+}
+#else  /* kernels >= 2.6.12 */
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31))
+static inline void eth_hw_addr_random(struct net_device *dev)
+{
+       get_random_bytes(dev->dev_addr, ETH_ALEN);
+       dev->dev_addr[0] &= 0xfe;       /* clear multicast bit */
+       dev->dev_addr[0] |= 0x02;       /* set local assignment bit (IEEE802) */
+}
+#else /* kernels >= 2.6.31 */
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36))
+/* So this is 2.6.31..2.6.35 */
+
+/* Just have the flags present, they won't really mean anything though */
+#define NET_ADDR_PERM          0       /* address is permanent (default) */
+#define NET_ADDR_RANDOM                1       /* address is generated randomly */
+#define NET_ADDR_STOLEN                2       /* address is stolen from other device */
+
+static inline void eth_hw_addr_random(struct net_device *dev)
+{
+       random_ether_addr(dev->dev_addr);
+}
+
+#else /* 2.6.36 and on */
+static inline void eth_hw_addr_random(struct net_device *dev)
+{
+       dev_hw_addr_random(dev, dev->dev_addr);
+}
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
+
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)) */
+
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) */
+
+#endif /* LINUX_5_4_COMPAT_H */