Skip to content

Commit

Permalink
xfrm: optimise to search the inexact policy list
Browse files Browse the repository at this point in the history
The policies are organized into list by priority ascent of policy,
so it is unnecessary to continue to loop the policy if the priority
of current looped police is larger than or equal priority which is
from the policy_bydst list.

This allows to match policy with ~0U priority in inexact list too.

Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Li RongQing authored and Steffen Klassert committed May 18, 2015
1 parent de2ad48 commit 8faf491
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,9 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
}
chain = &net->xfrm.policy_inexact[dir];
hlist_for_each_entry(pol, chain, bydst) {
if ((pol->priority >= priority) && ret)
break;

err = xfrm_policy_match(pol, fl, type, family, dir);
if (err) {
if (err == -ESRCH)
Expand All @@ -1122,7 +1125,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
ret = ERR_PTR(err);
goto fail;
}
} else if (pol->priority < priority) {
} else {
ret = pol;
break;
}
Expand Down Expand Up @@ -3203,9 +3206,11 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
}
chain = &net->xfrm.policy_inexact[dir];
hlist_for_each_entry(pol, chain, bydst) {
if ((pol->priority >= priority) && ret)
break;

if (xfrm_migrate_selector_match(sel, &pol->selector) &&
pol->type == type &&
pol->priority < priority) {
pol->type == type) {
ret = pol;
break;
}
Expand Down

0 comments on commit 8faf491

Please sign in to comment.