From dcbc5d7cca1c1fb43d6753a691c304e25c983e3c Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Tue, 28 Feb 2012 14:49:12 -0800 Subject: [PATCH] compat: backport eth_hw_addr_random() 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 --- include/linux/compat-2.6.h | 1 + include/linux/compat-3.4.h | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 include/linux/compat-3.4.h diff --git a/include/linux/compat-2.6.h b/include/linux/compat-2.6.h index 3ccd051..c14aeb8 100644 --- a/include/linux/compat-2.6.h +++ b/include/linux/compat-2.6.h @@ -38,5 +38,6 @@ #include #include #include +#include #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 index 0000000..378371f --- /dev/null +++ b/include/linux/compat-3.4.h @@ -0,0 +1,51 @@ +#ifndef LINUX_3_4_COMPAT_H +#define LINUX_3_4_COMPAT_H + +#include + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) + +#include + +#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 */ -- 2.41.0