1 #ifndef __LINUX_ETHERDEVICE_WRAPPER_H
2 #define __LINUX_ETHERDEVICE_WRAPPER_H 1
4 #include_next <linux/etherdevice.h>
5 #include <linux/random.h>
8 * is_multicast_ether_addr - Determine if the Ethernet address is a multicast.
9 * @addr: Pointer to a six-byte array containing the Ethernet address
11 * Return true if the address is a multicast address.
12 * By definition the broadcast address is also a multicast address.
14 static inline int is_multicast_ether_addr(const u8 *addr)
16 return (0x01 & addr[0]);
20 * is_local_ether_addr - Determine if the Ethernet address is locally-assigned
22 * @addr: Pointer to a six-byte array containing the Ethernet address
24 * Return true if the address is a local address.
26 static inline int is_local_ether_addr(const u8 *addr)
28 return (0x02 & addr[0]);
32 * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast
33 * @addr: Pointer to a six-byte array containing the Ethernet address
35 * Return true if the address is the broadcast address.
37 static inline int is_broadcast_ether_addr(const u8 *addr)
39 return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
43 * random_ether_addr - Generate software assigned random Ethernet address
44 * @addr: Pointer to a six-byte array containing the Ethernet address
46 * Generate a random Ethernet address (MAC) that is not multicast
47 * and has the local assigned bit set.
49 static inline void random_ether_addr(u8 *addr)
51 get_random_bytes (addr, ETH_ALEN);
52 addr [0] &= 0xfe; /* clear multicast bit */
53 addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
57 * compare_ether_addr - Compare two Ethernet addresses
58 * @addr1: Pointer to a six-byte array containing the Ethernet address
59 * @addr2: Pointer other six-byte array containing the Ethernet address
61 * Compare two ethernet addresses, returns 0 if equal
63 static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
65 const u16 *a = (const u16 *) addr1;
66 const u16 *b = (const u16 *) addr2;
68 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;