Skip to content

Commit

Permalink
[XFRM]: Respect priority in policy lookups.
Browse files Browse the repository at this point in the history
Even if we find an exact match in the hash table,
we must inspect the inexact list to look for a match
with a better priority.

Noticed by Masahide NAKAMURA <[email protected]>.

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
David S. Miller committed Sep 22, 2006
1 parent 65e3d72 commit acba48e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(u8 type, struct flowi *fl,
xfrm_address_t *daddr, *saddr;
struct hlist_node *entry;
struct hlist_head *chain;
u32 priority = ~0U;

daddr = xfrm_flowi_daddr(fl, family);
saddr = xfrm_flowi_saddr(fl, family);
Expand All @@ -919,21 +920,21 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(u8 type, struct flowi *fl,
ret = NULL;
hlist_for_each_entry(pol, entry, chain, bydst) {
if (xfrm_policy_match(pol, fl, type, family, dir)) {
xfrm_pol_hold(pol);
ret = pol;
priority = ret->priority;
break;
}
}
if (!ret) {
chain = &xfrm_policy_inexact[dir];
hlist_for_each_entry(pol, entry, chain, bydst) {
if (xfrm_policy_match(pol, fl, type, family, dir)) {
xfrm_pol_hold(pol);
ret = pol;
break;
}
chain = &xfrm_policy_inexact[dir];
hlist_for_each_entry(pol, entry, chain, bydst) {
if (xfrm_policy_match(pol, fl, type, family, dir) &&
pol->priority < priority) {
ret = pol;
break;
}
}
if (ret)
xfrm_pol_hold(ret);
read_unlock_bh(&xfrm_policy_lock);

return ret;
Expand Down

0 comments on commit acba48e

Please sign in to comment.