22 #ifndef _LINUX_ETHERDEVICE_H
23 #define _LINUX_ETHERDEVICE_H
25 #include <linux/if_ether.h>
26 #include <linux/netdevice.h>
27 #include <linux/random.h>
28 #include <asm/unaligned.h>
36 const void *
daddr,
const void *
saddr,
unsigned len);
42 const unsigned char *haddr);
51 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
52 #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count)
60 static inline bool is_zero_ether_addr(
const u8 *
addr)
62 return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
72 static inline bool is_multicast_ether_addr(
const u8 *
addr)
74 return 0x01 & addr[0];
83 static inline bool is_local_ether_addr(
const u8 *
addr)
85 return 0x02 & addr[0];
94 static inline bool is_broadcast_ether_addr(
const u8 *
addr)
96 return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
105 static inline bool is_unicast_ether_addr(
const u8 *addr)
107 return !is_multicast_ether_addr(addr);
119 static inline bool is_valid_ether_addr(
const u8 *addr)
123 return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
133 static inline void eth_random_addr(
u8 *addr)
140 #define random_ether_addr(addr) eth_random_addr(addr)
148 static inline void eth_broadcast_addr(
u8 *addr)
159 static inline void eth_zero_addr(
u8 *addr)
173 static inline void eth_hw_addr_random(
struct net_device *
dev)
187 static inline unsigned compare_ether_addr(
const u8 *
addr1,
const u8 *
addr2)
189 const u16 *
a = (
const u16 *) addr1;
190 const u16 *
b = (
const u16 *) addr2;
193 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
203 static inline bool ether_addr_equal(
const u8 *addr1,
const u8 *addr2)
205 return !compare_ether_addr(addr1, addr2);
208 static inline unsigned long zap_last_2bytes(
unsigned long value)
231 static inline bool ether_addr_equal_64bits(
const u8 addr1[6+2],
234 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
235 unsigned long fold = ((*(
unsigned long *)addr1) ^
236 (*(
unsigned long *)addr2));
238 if (
sizeof(fold) == 8)
239 return zap_last_2bytes(fold) == 0;
241 fold |= zap_last_2bytes((*(
unsigned long *)(addr1 + 4)) ^
242 (*(
unsigned long *)(addr2 + 4)));
245 return ether_addr_equal(addr1, addr2);
260 static inline bool is_etherdev_addr(
const struct net_device *
dev,
261 const u8 addr[6 + 2])
268 res = ether_addr_equal_64bits(addr, ha->
addr);
289 static inline unsigned long compare_ether_header(
const void *a,
const void *b)
291 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
302 fold = *(
unsigned long *)a ^ *(
unsigned long *)
b;
303 fold |= *(
unsigned long *)(a + 6) ^ *(
unsigned long *)(b + 6);
309 return (*(
u16 *)a ^ *(
u16 *)b) | (a32[0] ^ b32[0]) |
310 (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);