netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype
@ 2015-05-09 11:17 roy.qing.li
  2015-05-11 12:06 ` Steffen Klassert
  0 siblings, 1 reply; 4+ messages in thread
From: roy.qing.li @ 2015-05-09 11:17 UTC (permalink / raw)
  To: netdev; +Cc: steffen.klassert

From: Li RongQing <roy.qing.li@gmail.com>

It is unnecessary to continue to loop the policy if the priority
of current looped police is larger than priority which is from
the policy_bydst list.

Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
 net/xfrm/xfrm_policy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 66450c3..4adee12 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1116,6 +1116,8 @@ 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)
+			break;
 		err = xfrm_policy_match(pol, fl, type, family, dir);
 		if (err) {
 			if (err == -ESRCH)
@@ -1124,7 +1126,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;
 		}
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype
  2015-05-09 11:17 [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype roy.qing.li
@ 2015-05-11 12:06 ` Steffen Klassert
  2015-05-12  8:25   ` Li RongQing
  0 siblings, 1 reply; 4+ messages in thread
From: Steffen Klassert @ 2015-05-11 12:06 UTC (permalink / raw)
  To: roy.qing.li; +Cc: netdev

On Sat, May 09, 2015 at 07:17:37PM +0800, roy.qing.li@gmail.com wrote:
> From: Li RongQing <roy.qing.li@gmail.com>
> 
> It is unnecessary to continue to loop the policy if the priority
> of current looped police is larger than priority which is from
> the policy_bydst list.

Please explain why it is unnecessary to continue with the
loop here. In general a commit message should explain why
this code is changed.

> 
> Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
> ---
>  net/xfrm/xfrm_policy.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index 66450c3..4adee12 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -1116,6 +1116,8 @@ 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)
> +			break;

priority is initialized with ~0U at the beginning of this function.
What if someone has an inexact policy with priority ~0U configured?
With your change, this policy will never match because we don't even
try to search for it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype
  2015-05-11 12:06 ` Steffen Klassert
@ 2015-05-12  8:25   ` Li RongQing
  2015-05-12 11:37     ` Steffen Klassert
  0 siblings, 1 reply; 4+ messages in thread
From: Li RongQing @ 2015-05-12  8:25 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: netdev

On Mon, May 11, 2015 at 8:06 PM, Steffen Klassert
<steffen.klassert@secunet.com> wrote:
> Please explain why it is unnecessary to continue with the
> loop here. In general a commit message should explain why
> this code is changed.
>
Ok, I will add


>> +                     break;
>
> priority is initialized with ~0U at the beginning of this function.
> What if someone has an inexact policy with priority ~0U configured?
> With your change, this policy will never match because we don't even
> try to search for it.

The original code can not handle this kind of policy whose priority is ~0U,
I will fix it when resubmit this patch.

1121         chain = &net->xfrm.policy_inexact[dir];
1122         hlist_for_each_entry(pol, chain, bydst) {
1123                 err = xfrm_policy_match(pol, fl, type, family, dir);
1124                 if (err) {
1125                         if (err == -ESRCH)
1126                                 continue;
1127                         else {
1128                                 ret = ERR_PTR(err);
1129                                 goto fail;
1130                         }
1131                 } else if (pol->priority < priority) {
1132                         ret = pol;
1133                         break;
1134                 }
1135         }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype
  2015-05-12  8:25   ` Li RongQing
@ 2015-05-12 11:37     ` Steffen Klassert
  0 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2015-05-12 11:37 UTC (permalink / raw)
  To: Li RongQing; +Cc: netdev

On Tue, May 12, 2015 at 04:25:07PM +0800, Li RongQing wrote:
> On Mon, May 11, 2015 at 8:06 PM, Steffen Klassert
> <steffen.klassert@secunet.com> wrote:
> >
> > priority is initialized with ~0U at the beginning of this function.
> > What if someone has an inexact policy with priority ~0U configured?
> > With your change, this policy will never match because we don't even
> > try to search for it.
> 
> The original code can not handle this kind of policy whose priority is ~0U,

Right, these kind of policies are currently not enforced.

> I will fix it when resubmit this patch.

OK, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-05-12 11:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-09 11:17 [PATCH][next] xfrm: optimise xfrm_policy_lookup_bytype roy.qing.li
2015-05-11 12:06 ` Steffen Klassert
2015-05-12  8:25   ` Li RongQing
2015-05-12 11:37     ` Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).