diff options
Diffstat (limited to 'include/linux/etherdevice.h')
| -rw-r--r-- | include/linux/etherdevice.h | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 8a1835855faa..3d406e0ede6d 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h | |||
| @@ -18,8 +18,6 @@ | |||
| 18 | * as published by the Free Software Foundation; either version | 18 | * as published by the Free Software Foundation; either version |
| 19 | * 2 of the License, or (at your option) any later version. | 19 | * 2 of the License, or (at your option) any later version. |
| 20 | * | 20 | * |
| 21 | * WARNING: This move may well be temporary. This file will get merged with others RSN. | ||
| 22 | * | ||
| 23 | */ | 21 | */ |
| 24 | #ifndef _LINUX_ETHERDEVICE_H | 22 | #ifndef _LINUX_ETHERDEVICE_H |
| 25 | #define _LINUX_ETHERDEVICE_H | 23 | #define _LINUX_ETHERDEVICE_H |
| @@ -59,7 +57,7 @@ extern struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, | |||
| 59 | * | 57 | * |
| 60 | * Return true if the address is all zeroes. | 58 | * Return true if the address is all zeroes. |
| 61 | */ | 59 | */ |
| 62 | static inline int is_zero_ether_addr(const u8 *addr) | 60 | static inline bool is_zero_ether_addr(const u8 *addr) |
| 63 | { | 61 | { |
| 64 | return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); | 62 | return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); |
| 65 | } | 63 | } |
| @@ -71,7 +69,7 @@ static inline int is_zero_ether_addr(const u8 *addr) | |||
| 71 | * Return true if the address is a multicast address. | 69 | * Return true if the address is a multicast address. |
| 72 | * By definition the broadcast address is also a multicast address. | 70 | * By definition the broadcast address is also a multicast address. |
| 73 | */ | 71 | */ |
| 74 | static inline int is_multicast_ether_addr(const u8 *addr) | 72 | static inline bool is_multicast_ether_addr(const u8 *addr) |
| 75 | { | 73 | { |
| 76 | return 0x01 & addr[0]; | 74 | return 0x01 & addr[0]; |
| 77 | } | 75 | } |
| @@ -82,7 +80,7 @@ static inline int is_multicast_ether_addr(const u8 *addr) | |||
| 82 | * | 80 | * |
| 83 | * Return true if the address is a local address. | 81 | * Return true if the address is a local address. |
| 84 | */ | 82 | */ |
| 85 | static inline int is_local_ether_addr(const u8 *addr) | 83 | static inline bool is_local_ether_addr(const u8 *addr) |
| 86 | { | 84 | { |
| 87 | return 0x02 & addr[0]; | 85 | return 0x02 & addr[0]; |
| 88 | } | 86 | } |
| @@ -93,7 +91,7 @@ static inline int is_local_ether_addr(const u8 *addr) | |||
| 93 | * | 91 | * |
| 94 | * Return true if the address is the broadcast address. | 92 | * Return true if the address is the broadcast address. |
| 95 | */ | 93 | */ |
| 96 | static inline int is_broadcast_ether_addr(const u8 *addr) | 94 | static inline bool is_broadcast_ether_addr(const u8 *addr) |
| 97 | { | 95 | { |
| 98 | return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; | 96 | return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; |
| 99 | } | 97 | } |
| @@ -104,7 +102,7 @@ static inline int is_broadcast_ether_addr(const u8 *addr) | |||
| 104 | * | 102 | * |
| 105 | * Return true if the address is a unicast address. | 103 | * Return true if the address is a unicast address. |
| 106 | */ | 104 | */ |
| 107 | static inline int is_unicast_ether_addr(const u8 *addr) | 105 | static inline bool is_unicast_ether_addr(const u8 *addr) |
| 108 | { | 106 | { |
| 109 | return !is_multicast_ether_addr(addr); | 107 | return !is_multicast_ether_addr(addr); |
| 110 | } | 108 | } |
| @@ -118,7 +116,7 @@ static inline int is_unicast_ether_addr(const u8 *addr) | |||
| 118 | * | 116 | * |
| 119 | * Return true if the address is valid. | 117 | * Return true if the address is valid. |
| 120 | */ | 118 | */ |
| 121 | static inline int is_valid_ether_addr(const u8 *addr) | 119 | static inline bool is_valid_ether_addr(const u8 *addr) |
| 122 | { | 120 | { |
| 123 | /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to | 121 | /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to |
| 124 | * explicitly check for it here. */ | 122 | * explicitly check for it here. */ |
| @@ -159,7 +157,8 @@ static inline void eth_hw_addr_random(struct net_device *dev) | |||
| 159 | * @addr1: Pointer to a six-byte array containing the Ethernet address | 157 | * @addr1: Pointer to a six-byte array containing the Ethernet address |
| 160 | * @addr2: Pointer other six-byte array containing the Ethernet address | 158 | * @addr2: Pointer other six-byte array containing the Ethernet address |
| 161 | * | 159 | * |
| 162 | * Compare two ethernet addresses, returns 0 if equal | 160 | * Compare two Ethernet addresses, returns 0 if equal, non-zero otherwise. |
| 161 | * Unlike memcmp(), it doesn't return a value suitable for sorting. | ||
| 163 | */ | 162 | */ |
| 164 | static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) | 163 | static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) |
| 165 | { | 164 | { |
| @@ -170,6 +169,18 @@ static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) | |||
| 170 | return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0; | 169 | return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0; |
| 171 | } | 170 | } |
| 172 | 171 | ||
| 172 | /** | ||
| 173 | * ether_addr_equal - Compare two Ethernet addresses | ||
| 174 | * @addr1: Pointer to a six-byte array containing the Ethernet address | ||
| 175 | * @addr2: Pointer other six-byte array containing the Ethernet address | ||
| 176 | * | ||
| 177 | * Compare two Ethernet addresses, returns true if equal | ||
| 178 | */ | ||
| 179 | static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) | ||
| 180 | { | ||
| 181 | return !compare_ether_addr(addr1, addr2); | ||
| 182 | } | ||
| 183 | |||
| 173 | static inline unsigned long zap_last_2bytes(unsigned long value) | 184 | static inline unsigned long zap_last_2bytes(unsigned long value) |
| 174 | { | 185 | { |
| 175 | #ifdef __BIG_ENDIAN | 186 | #ifdef __BIG_ENDIAN |
| @@ -180,34 +191,34 @@ static inline unsigned long zap_last_2bytes(unsigned long value) | |||
| 180 | } | 191 | } |
| 181 | 192 | ||
| 182 | /** | 193 | /** |
| 183 | * compare_ether_addr_64bits - Compare two Ethernet addresses | 194 | * ether_addr_equal_64bits - Compare two Ethernet addresses |
| 184 | * @addr1: Pointer to an array of 8 bytes | 195 | * @addr1: Pointer to an array of 8 bytes |
| 185 | * @addr2: Pointer to an other array of 8 bytes | 196 | * @addr2: Pointer to an other array of 8 bytes |
| 186 | * | 197 | * |
| 187 | * Compare two ethernet addresses, returns 0 if equal. | 198 | * Compare two Ethernet addresses, returns true if equal, false otherwise. |
| 188 | * Same result than "memcmp(addr1, addr2, ETH_ALEN)" but without conditional | 199 | * |
| 189 | * branches, and possibly long word memory accesses on CPU allowing cheap | 200 | * The function doesn't need any conditional branches and possibly uses |
| 190 | * unaligned memory reads. | 201 | * word memory accesses on CPU allowing cheap unaligned memory reads. |
| 191 | * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} | 202 | * arrays = { byte1, byte2, byte3, byte4, byte5, byte6, pad1, pad2 } |
| 192 | * | 203 | * |
| 193 | * Please note that alignment of addr1 & addr2 is only guaranted to be 16 bits. | 204 | * Please note that alignment of addr1 & addr2 are only guaranteed to be 16 bits. |
| 194 | */ | 205 | */ |
| 195 | 206 | ||
| 196 | static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], | 207 | static inline bool ether_addr_equal_64bits(const u8 addr1[6+2], |
| 197 | const u8 addr2[6+2]) | 208 | const u8 addr2[6+2]) |
| 198 | { | 209 | { |
| 199 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | 210 | #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 200 | unsigned long fold = ((*(unsigned long *)addr1) ^ | 211 | unsigned long fold = ((*(unsigned long *)addr1) ^ |
| 201 | (*(unsigned long *)addr2)); | 212 | (*(unsigned long *)addr2)); |
| 202 | 213 | ||
| 203 | if (sizeof(fold) == 8) | 214 | if (sizeof(fold) == 8) |
| 204 | return zap_last_2bytes(fold) != 0; | 215 | return zap_last_2bytes(fold) == 0; |
| 205 | 216 | ||
| 206 | fold |= zap_last_2bytes((*(unsigned long *)(addr1 + 4)) ^ | 217 | fold |= zap_last_2bytes((*(unsigned long *)(addr1 + 4)) ^ |
| 207 | (*(unsigned long *)(addr2 + 4))); | 218 | (*(unsigned long *)(addr2 + 4))); |
| 208 | return fold != 0; | 219 | return fold == 0; |
| 209 | #else | 220 | #else |
| 210 | return compare_ether_addr(addr1, addr2); | 221 | return ether_addr_equal(addr1, addr2); |
| 211 | #endif | 222 | #endif |
| 212 | } | 223 | } |
| 213 | 224 | ||
| @@ -219,23 +230,23 @@ static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], | |||
| 219 | * Compare passed address with all addresses of the device. Return true if the | 230 | * Compare passed address with all addresses of the device. Return true if the |
| 220 | * address if one of the device addresses. | 231 | * address if one of the device addresses. |
| 221 | * | 232 | * |
| 222 | * Note that this function calls compare_ether_addr_64bits() so take care of | 233 | * Note that this function calls ether_addr_equal_64bits() so take care of |
| 223 | * the right padding. | 234 | * the right padding. |
| 224 | */ | 235 | */ |
| 225 | static inline bool is_etherdev_addr(const struct net_device *dev, | 236 | static inline bool is_etherdev_addr(const struct net_device *dev, |
| 226 | const u8 addr[6 + 2]) | 237 | const u8 addr[6 + 2]) |
| 227 | { | 238 | { |
| 228 | struct netdev_hw_addr *ha; | 239 | struct netdev_hw_addr *ha; |
| 229 | int res = 1; | 240 | bool res = false; |
| 230 | 241 | ||
| 231 | rcu_read_lock(); | 242 | rcu_read_lock(); |
| 232 | for_each_dev_addr(dev, ha) { | 243 | for_each_dev_addr(dev, ha) { |
| 233 | res = compare_ether_addr_64bits(addr, ha->addr); | 244 | res = ether_addr_equal_64bits(addr, ha->addr); |
| 234 | if (!res) | 245 | if (res) |
| 235 | break; | 246 | break; |
| 236 | } | 247 | } |
| 237 | rcu_read_unlock(); | 248 | rcu_read_unlock(); |
| 238 | return !res; | 249 | return res; |
| 239 | } | 250 | } |
| 240 | #endif /* __KERNEL__ */ | 251 | #endif /* __KERNEL__ */ |
| 241 | 252 | ||
| @@ -244,7 +255,7 @@ static inline bool is_etherdev_addr(const struct net_device *dev, | |||
| 244 | * @a: Pointer to Ethernet header | 255 | * @a: Pointer to Ethernet header |
| 245 | * @b: Pointer to Ethernet header | 256 | * @b: Pointer to Ethernet header |
| 246 | * | 257 | * |
| 247 | * Compare two ethernet headers, returns 0 if equal. | 258 | * Compare two Ethernet headers, returns 0 if equal. |
| 248 | * This assumes that the network header (i.e., IP header) is 4-byte | 259 | * This assumes that the network header (i.e., IP header) is 4-byte |
| 249 | * aligned OR the platform can handle unaligned access. This is the | 260 | * aligned OR the platform can handle unaligned access. This is the |
| 250 | * case for all packets coming into netif_receive_skb or similar | 261 | * case for all packets coming into netif_receive_skb or similar |
