aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/etherdevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/etherdevice.h')
-rw-r--r--include/linux/etherdevice.h60
1 files changed, 35 insertions, 25 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index fe5136d81454..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 */
62static inline int is_zero_ether_addr(const u8 *addr) 60static 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 */
74static inline int is_multicast_ether_addr(const u8 *addr) 72static 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 */
85static inline int is_local_ether_addr(const u8 *addr) 83static 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 */
96static inline int is_broadcast_ether_addr(const u8 *addr) 94static 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 */
107static inline int is_unicast_ether_addr(const u8 *addr) 105static 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 */
121static inline int is_valid_ether_addr(const u8 *addr) 119static 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,7 @@ 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, non-zero otherwise. 160 * Compare two Ethernet addresses, returns 0 if equal, non-zero otherwise.
163 * Unlike memcmp(), it doesn't return a value suitable for sorting. 161 * Unlike memcmp(), it doesn't return a value suitable for sorting.
164 */ 162 */
165static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2) 163static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
@@ -171,6 +169,18 @@ static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
171 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;
172} 170}
173 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 */
179static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
180{
181 return !compare_ether_addr(addr1, addr2);
182}
183
174static inline unsigned long zap_last_2bytes(unsigned long value) 184static inline unsigned long zap_last_2bytes(unsigned long value)
175{ 185{
176#ifdef __BIG_ENDIAN 186#ifdef __BIG_ENDIAN
@@ -181,34 +191,34 @@ static inline unsigned long zap_last_2bytes(unsigned long value)
181} 191}
182 192
183/** 193/**
184 * compare_ether_addr_64bits - Compare two Ethernet addresses 194 * ether_addr_equal_64bits - Compare two Ethernet addresses
185 * @addr1: Pointer to an array of 8 bytes 195 * @addr1: Pointer to an array of 8 bytes
186 * @addr2: Pointer to an other array of 8 bytes 196 * @addr2: Pointer to an other array of 8 bytes
187 * 197 *
188 * Compare two ethernet addresses, returns 0 if equal, non-zero otherwise. 198 * Compare two Ethernet addresses, returns true if equal, false otherwise.
189 * Unlike memcmp(), it doesn't return a value suitable for sorting. 199 *
190 * The function doesn't need any conditional branches and possibly uses 200 * The function doesn't need any conditional branches and possibly uses
191 * word memory accesses on CPU allowing cheap unaligned memory reads. 201 * word memory accesses on CPU allowing cheap unaligned memory reads.
192 * arrays = { byte1, byte2, byte3, byte4, byte6, byte7, pad1, pad2} 202 * arrays = { byte1, byte2, byte3, byte4, byte5, byte6, pad1, pad2 }
193 * 203 *
194 * 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.
195 */ 205 */
196 206
197static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], 207static inline bool ether_addr_equal_64bits(const u8 addr1[6+2],
198 const u8 addr2[6+2]) 208 const u8 addr2[6+2])
199{ 209{
200#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 210#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
201 unsigned long fold = ((*(unsigned long *)addr1) ^ 211 unsigned long fold = ((*(unsigned long *)addr1) ^
202 (*(unsigned long *)addr2)); 212 (*(unsigned long *)addr2));
203 213
204 if (sizeof(fold) == 8) 214 if (sizeof(fold) == 8)
205 return zap_last_2bytes(fold) != 0; 215 return zap_last_2bytes(fold) == 0;
206 216
207 fold |= zap_last_2bytes((*(unsigned long *)(addr1 + 4)) ^ 217 fold |= zap_last_2bytes((*(unsigned long *)(addr1 + 4)) ^
208 (*(unsigned long *)(addr2 + 4))); 218 (*(unsigned long *)(addr2 + 4)));
209 return fold != 0; 219 return fold == 0;
210#else 220#else
211 return compare_ether_addr(addr1, addr2); 221 return ether_addr_equal(addr1, addr2);
212#endif 222#endif
213} 223}
214 224
@@ -220,23 +230,23 @@ static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2],
220 * 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
221 * address if one of the device addresses. 231 * address if one of the device addresses.
222 * 232 *
223 * 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
224 * the right padding. 234 * the right padding.
225 */ 235 */
226static inline bool is_etherdev_addr(const struct net_device *dev, 236static inline bool is_etherdev_addr(const struct net_device *dev,
227 const u8 addr[6 + 2]) 237 const u8 addr[6 + 2])
228{ 238{
229 struct netdev_hw_addr *ha; 239 struct netdev_hw_addr *ha;
230 int res = 1; 240 bool res = false;
231 241
232 rcu_read_lock(); 242 rcu_read_lock();
233 for_each_dev_addr(dev, ha) { 243 for_each_dev_addr(dev, ha) {
234 res = compare_ether_addr_64bits(addr, ha->addr); 244 res = ether_addr_equal_64bits(addr, ha->addr);
235 if (!res) 245 if (res)
236 break; 246 break;
237 } 247 }
238 rcu_read_unlock(); 248 rcu_read_unlock();
239 return !res; 249 return res;
240} 250}
241#endif /* __KERNEL__ */ 251#endif /* __KERNEL__ */
242 252
@@ -245,7 +255,7 @@ static inline bool is_etherdev_addr(const struct net_device *dev,
245 * @a: Pointer to Ethernet header 255 * @a: Pointer to Ethernet header
246 * @b: Pointer to Ethernet header 256 * @b: Pointer to Ethernet header
247 * 257 *
248 * Compare two ethernet headers, returns 0 if equal. 258 * Compare two Ethernet headers, returns 0 if equal.
249 * 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
250 * aligned OR the platform can handle unaligned access. This is the 260 * aligned OR the platform can handle unaligned access. This is the
251 * case for all packets coming into netif_receive_skb or similar 261 * case for all packets coming into netif_receive_skb or similar