From 26bff940dd975499c6c47438d4395d7d215911e8 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Tue, 22 Nov 2011 06:46:02 +0000 Subject: xfrm: optimize ipv4 selector matching Current addr_match() is errh, under-optimized. Compiler doesn't know that memcmp() branch doesn't trigger for IPv4. Also, pass addresses by value -- they fit into register. Signed-off-by: Alexey Dobriyan Signed-off-by: David S. Miller --- include/net/xfrm.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/net/xfrm.h') diff --git a/include/net/xfrm.h b/include/net/xfrm.h index b203e14d26b7..4de7ed9016d9 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -827,6 +827,14 @@ static inline bool addr_match(const void *token1, const void *token2, return true; } +static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen) +{ + /* C99 6.5.7 (3): u32 << 32 is undefined behaviour */ + if (prefixlen == 0) + return true; + return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen))); +} + static __inline__ __be16 xfrm_flowi_sport(const struct flowi *fl, const union flowi_uli *uli) { -- cgit v1.2.3