Commit 01902f8c authored by Li RongQing's avatar Li RongQing Committed by Pablo Neira Ayuso

netfilter: optimize nf_inet_addr_cmp

optimize nf_inet_addr_cmp by 64bit xor computation
similar to ipv6_addr_equal()
Signed-off-by: default avatarYuan Linsi <yuanlinsi01@baidu.com>
Signed-off-by: default avatarLi RongQing <lirongqing@baidu.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 84c0d5e9
...@@ -24,10 +24,17 @@ static inline int NF_DROP_GETERR(int verdict) ...@@ -24,10 +24,17 @@ static inline int NF_DROP_GETERR(int verdict)
static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1, static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1,
const union nf_inet_addr *a2) const union nf_inet_addr *a2)
{ {
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
const unsigned long *ul1 = (const unsigned long *)a1;
const unsigned long *ul2 = (const unsigned long *)a2;
return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
#else
return a1->all[0] == a2->all[0] && return a1->all[0] == a2->all[0] &&
a1->all[1] == a2->all[1] && a1->all[1] == a2->all[1] &&
a1->all[2] == a2->all[2] && a1->all[2] == a2->all[2] &&
a1->all[3] == a2->all[3]; a1->all[3] == a2->all[3];
#endif
} }
static inline void nf_inet_addr_mask(const union nf_inet_addr *a1, static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,
......
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