All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: William Dauchy <w.dauchy@criteo.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net] net, ip_tunnel: fix interface lookup with no key
Date: Fri, 27 Mar 2020 08:30:40 +0100	[thread overview]
Message-ID: <d74c2c22-19e7-8be3-3d21-ea17c1863b13@6wind.com> (raw)
In-Reply-To: <20200326185626.GA22732@dontpanic>

Le 26/03/2020 à 19:56, William Dauchy a écrit :
> Hello Nicolas,
> 
> Thanks for your review.
> 
> On Thu, Mar 26, 2020 at 07:01:20PM +0100, Nicolas Dichtel wrote:
>> Hmm, removing this test may break some existing scenario. This flag is part of
>> the UAPI (for gre). Suppose that a tool configures a gre tunnel, leaves the key
>> uninitialized and set this flag. After this patch, the lookup may return
>> something else.
> 
> Indeed I was not sure about possible other impacts, as it seemed to not
> break iproute2 tooling, but it's true it could break other tools.
> But if we consider to remove the key test in that case, would it be
> acceptable to have something like:
> 
> diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
> index 74e1d964a615..8bdb9856d4c4 100644
> --- a/net/ipv4/ip_tunnel.c
> +++ b/net/ipv4/ip_tunnel.c
> @@ -142,23 +142,32 @@ struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
>     cand = t;
>   }
> 
> - if (flags & TUNNEL_NO_KEY)
> -  goto skip_key_lookup;
> -
> - hlist_for_each_entry_rcu(t, head, hash_node) {
> -  if (t->parms.i_key != key ||
> -      t->parms.iph.saddr != 0 ||
> -      t->parms.iph.daddr != 0 ||
> -      !(t->dev->flags & IFF_UP))
> -   continue;
> + if (flags & TUNNEL_NO_KEY) {
> +  hlist_for_each_entry_rcu(t, head, hash_node) {
> +   if (t->parms.iph.saddr != 0 ||
> +       t->parms.iph.daddr != 0 ||
> +       !(t->dev->flags & IFF_UP))
> +    continue;
> 
>    if (t->parms.link == link)
>     return t;
>    else if (!cand)
>     cand = t;
> - }
> + } else {
> +
> +  hlist_for_each_entry_rcu(t, head, hash_node) {
> +   if (t->parms.i_key != key ||
> +       t->parms.iph.saddr != 0 ||
> +       t->parms.iph.daddr != 0 ||
> +       !(t->dev->flags & IFF_UP))
> +    continue;
> +
> +   if (t->parms.link == link)
> +    return t;
> +   else if (!cand)
> +    cand = t;
> +  }
> 
> -skip_key_lookup:
>   if (cand)
>    return cand;
> 
Maybe less code duplication? Something like:

diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 74e1d964a615..cd4b84310d92 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -142,11 +142,8 @@ struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
 			cand = t;
 	}

-	if (flags & TUNNEL_NO_KEY)
-		goto skip_key_lookup;
-
 	hlist_for_each_entry_rcu(t, head, hash_node) {
-		if (t->parms.i_key != key ||
+		if ((!(flags & TUNNEL_NO_KEY) && t->parms.i_key != key) ||
 		    t->parms.iph.saddr != 0 ||
 		    t->parms.iph.daddr != 0 ||
 		    !(t->dev->flags & IFF_UP))
@@ -158,7 +155,6 @@ struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
 			cand = t;
 	}

-skip_key_lookup:
 	if (cand)
 		return cand;


  reply	other threads:[~2020-03-27  7:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 15:03 [PATCH net] net, ip_tunnel: fix interface lookup with no key William Dauchy
2020-03-25 15:22 ` William Dauchy
2020-03-26  6:00 ` kbuild test robot
2020-03-26 18:01 ` Nicolas Dichtel
2020-03-26 18:56   ` William Dauchy
2020-03-27  7:30     ` Nicolas Dichtel [this message]
2020-03-27 14:54 ` [PATCH v2 " William Dauchy
2020-03-27 18:15   ` Nicolas Dichtel
2020-03-27 18:56   ` [PATCH v3 " William Dauchy
2020-03-27 22:29     ` Nicolas Dichtel
2020-03-30  5:21     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d74c2c22-19e7-8be3-3d21-ea17c1863b13@6wind.com \
    --to=nicolas.dichtel@6wind.com \
    --cc=netdev@vger.kernel.org \
    --cc=w.dauchy@criteo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.