aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-04-11 07:17:55 -0400
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-04-12 00:43:14 -0400
commitfed85383ac34d82e96f227ce49ce68117cec23a0 (patch)
tree970dacedc8df29cf96511c0fc3e4bc1d103d3055 /include/net
parentcaad295fed8b652c67159911d11c65d476351d2f (diff)
[IPV6]: Use XOR and OR rather than mutiple ands for ipv6 address comparisons.
ipv6_addr_equal(), ipv6_addr_v4mapped(), ipv6_addr_is_ll_all_{nodes,routers}(), ipv6_masked_addr_cmp() Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/addrconf.h14
-rw-r--r--include/net/ipv6.h22
2 files changed, 16 insertions, 20 deletions
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index bdcc863a60a4..1dc9d03372d9 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -240,18 +240,16 @@ static inline int ipv6_addr_is_multicast(const struct in6_addr *addr)
240 240
241static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr) 241static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr)
242{ 242{
243 return (addr->s6_addr32[0] == htonl(0xff020000) && 243 return (((addr->s6_addr32[0] ^ htonl(0xff020000)) |
244 addr->s6_addr32[1] == 0 && 244 addr->s6_addr32[1] | addr->s6_addr32[2] |
245 addr->s6_addr32[2] == 0 && 245 (addr->s6_addr32[3] ^ htonl(0x00000001))) == 0);
246 addr->s6_addr32[3] == htonl(0x00000001));
247} 246}
248 247
249static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr) 248static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr)
250{ 249{
251 return (addr->s6_addr32[0] == htonl(0xff020000) && 250 return (((addr->s6_addr32[0] ^ htonl(0xff020000)) |
252 addr->s6_addr32[1] == 0 && 251 addr->s6_addr32[1] | addr->s6_addr32[2] |
253 addr->s6_addr32[2] == 0 && 252 (addr->s6_addr32[3] ^ htonl(0x00000002))) == 0);
254 addr->s6_addr32[3] == htonl(0x00000002));
255} 253}
256 254
257static inline int ipv6_isatap_eui64(u8 *eui, __be32 addr) 255static inline int ipv6_isatap_eui64(u8 *eui, __be32 addr)
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 5738c1c73ac1..a0c285b6311e 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -280,12 +280,10 @@ static inline int
280ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m, 280ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
281 const struct in6_addr *a2) 281 const struct in6_addr *a2)
282{ 282{
283 unsigned int i; 283 return (!!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
284 284 ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
285 for (i = 0; i < 4; i++) 285 ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
286 if ((a1->s6_addr32[i] ^ a2->s6_addr32[i]) & m->s6_addr32[i]) 286 ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3])));
287 return 1;
288 return 0;
289} 287}
290 288
291static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2) 289static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2)
@@ -320,10 +318,10 @@ static inline void ipv6_addr_set(struct in6_addr *addr,
320static inline int ipv6_addr_equal(const struct in6_addr *a1, 318static inline int ipv6_addr_equal(const struct in6_addr *a1,
321 const struct in6_addr *a2) 319 const struct in6_addr *a2)
322{ 320{
323 return (a1->s6_addr32[0] == a2->s6_addr32[0] && 321 return (((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
324 a1->s6_addr32[1] == a2->s6_addr32[1] && 322 (a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
325 a1->s6_addr32[2] == a2->s6_addr32[2] && 323 (a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
326 a1->s6_addr32[3] == a2->s6_addr32[3]); 324 (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0);
327} 325}
328 326
329static inline int __ipv6_prefix_equal(const __be32 *a1, const __be32 *a2, 327static inline int __ipv6_prefix_equal(const __be32 *a1, const __be32 *a2,
@@ -371,8 +369,8 @@ static inline int ipv6_addr_any(const struct in6_addr *a)
371 369
372static inline int ipv6_addr_v4mapped(const struct in6_addr *a) 370static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
373{ 371{
374 return ((a->s6_addr32[0] | a->s6_addr32[1]) == 0 && 372 return ((a->s6_addr32[0] | a->s6_addr32[1] |
375 a->s6_addr32[2] == htonl(0x0000ffff)); 373 (a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0);
376} 374}
377 375
378/* 376/*