From baa17d44d0e08249fe3a69b9afa72b3de24bdb19 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Tue, 22 Nov 2011 06:46:02 +0000 Subject: [PATCH] --- yaml --- r: 277920 b: refs/heads/master c: 26bff940dd975499c6c47438d4395d7d215911e8 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/net/xfrm.h | 8 ++++++++ trunk/net/xfrm/xfrm_policy.c | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index 675e81d11389..af67e395a38d 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 3ee32fee65ef6a4a8a4188e913be7dd90ba9e058 +refs/heads/master: 26bff940dd975499c6c47438d4395d7d215911e8 diff --git a/trunk/include/net/xfrm.h b/trunk/include/net/xfrm.h index b203e14d26b7..4de7ed9016d9 100644 --- a/trunk/include/net/xfrm.h +++ b/trunk/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) { diff --git a/trunk/net/xfrm/xfrm_policy.c b/trunk/net/xfrm/xfrm_policy.c index 552df27dcf53..593c8a1f1440 100644 --- a/trunk/net/xfrm/xfrm_policy.c +++ b/trunk/net/xfrm/xfrm_policy.c @@ -61,8 +61,8 @@ __xfrm4_selector_match(const struct xfrm_selector *sel, const struct flowi *fl) { const struct flowi4 *fl4 = &fl->u.ip4; - return addr_match(&fl4->daddr, &sel->daddr, sel->prefixlen_d) && - addr_match(&fl4->saddr, &sel->saddr, sel->prefixlen_s) && + return addr4_match(fl4->daddr, sel->daddr.a4, sel->prefixlen_d) && + addr4_match(fl4->saddr, sel->saddr.a4, sel->prefixlen_s) && !((xfrm_flowi_dport(fl, &fl4->uli) ^ sel->dport) & sel->dport_mask) && !((xfrm_flowi_sport(fl, &fl4->uli) ^ sel->sport) & sel->sport_mask) && (fl4->flowi4_proto == sel->proto || !sel->proto) &&