Commit fed85383 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki

[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: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
parent caad295f
......@@ -240,18 +240,16 @@ static inline int ipv6_addr_is_multicast(const struct in6_addr *addr)
static inline int ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr)
{
return (addr->s6_addr32[0] == htonl(0xff020000) &&
addr->s6_addr32[1] == 0 &&
addr->s6_addr32[2] == 0 &&
addr->s6_addr32[3] == htonl(0x00000001));
return (((addr->s6_addr32[0] ^ htonl(0xff020000)) |
addr->s6_addr32[1] | addr->s6_addr32[2] |
(addr->s6_addr32[3] ^ htonl(0x00000001))) == 0);
}
static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr)
{
return (addr->s6_addr32[0] == htonl(0xff020000) &&
addr->s6_addr32[1] == 0 &&
addr->s6_addr32[2] == 0 &&
addr->s6_addr32[3] == htonl(0x00000002));
return (((addr->s6_addr32[0] ^ htonl(0xff020000)) |
addr->s6_addr32[1] | addr->s6_addr32[2] |
(addr->s6_addr32[3] ^ htonl(0x00000002))) == 0);
}
static inline int ipv6_isatap_eui64(u8 *eui, __be32 addr)
......
......@@ -280,12 +280,10 @@ static inline int
ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
const struct in6_addr *a2)
{
unsigned int i;
for (i = 0; i < 4; i++)
if ((a1->s6_addr32[i] ^ a2->s6_addr32[i]) & m->s6_addr32[i])
return 1;
return 0;
return (!!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3])));
}
static 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,
static inline int ipv6_addr_equal(const struct in6_addr *a1,
const struct in6_addr *a2)
{
return (a1->s6_addr32[0] == a2->s6_addr32[0] &&
a1->s6_addr32[1] == a2->s6_addr32[1] &&
a1->s6_addr32[2] == a2->s6_addr32[2] &&
a1->s6_addr32[3] == a2->s6_addr32[3]);
return (((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0);
}
static 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)
static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
{
return ((a->s6_addr32[0] | a->s6_addr32[1]) == 0 &&
a->s6_addr32[2] == htonl(0x0000ffff));
return ((a->s6_addr32[0] | a->s6_addr32[1] |
(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0);
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment