mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Richard Gobert <richardbgobert@gmail.com>,
	davem@davemloft.net, yoshfuji@linux-ipv6.org,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: setsockopt: fix IPV6_UNICAST_IF option for connected sockets
Date: Thu, 24 Nov 2022 20:00:24 -0800	[thread overview]
Message-ID: <ba4d41bc-ec24-f4b4-e4d5-f9db51fed071@kernel.org> (raw)
In-Reply-To: <20221124114713.GA73129@debian>

On 11/24/22 4:48 AM, Richard Gobert wrote:
> Change the behaviour of ip6_datagram_connect to consider the interface
> set by the IPV6_UNICAST_IF socket option, similarly to udpv6_sendmsg.
> 
> This change is the IPv6 counterpart of the fix for IP_UNICAST_IF.
> The tests introduced by that patch showed that the incorrect
> behavior is present in IPv6 as well.
> This patch fixes the broken test.
> 
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Link: https://lore.kernel.org/r/202210062117.c7eef1a3-oliver.sang@intel.com
> 

Fixes tag here.

> Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
> ---
>  net/ipv6/datagram.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
> index 7c7155b48f17..c3999f9e3545 100644
> --- a/net/ipv6/datagram.c
> +++ b/net/ipv6/datagram.c
> @@ -42,24 +42,30 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk)
>  {
>  	struct inet_sock *inet = inet_sk(sk);
>  	struct ipv6_pinfo *np = inet6_sk(sk);
> +	int oif;

	int oif = sk->sk_bound_dev_if;
>  
>  	memset(fl6, 0, sizeof(*fl6));
>  	fl6->flowi6_proto = sk->sk_protocol;
>  	fl6->daddr = sk->sk_v6_daddr;
>  	fl6->saddr = np->saddr;
> -	fl6->flowi6_oif = sk->sk_bound_dev_if;
> +	oif = sk->sk_bound_dev_if;

and then drop this line in the middle of all of the fl6 setup.

>  	fl6->flowi6_mark = sk->sk_mark;
>  	fl6->fl6_dport = inet->inet_dport;
>  	fl6->fl6_sport = inet->inet_sport;
>  	fl6->flowlabel = np->flow_label;
>  	fl6->flowi6_uid = sk->sk_uid;
>  
> -	if (!fl6->flowi6_oif)
> -		fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
> +	if (!oif)
> +		oif = np->sticky_pktinfo.ipi6_ifindex;
>  
> -	if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr))
> -		fl6->flowi6_oif = np->mcast_oif;
> +	if (!oif) {
> +		if (ipv6_addr_is_multicast(&fl6->daddr))
> +			oif = np->mcast_oif;
> +		else
> +			oif = np->ucast_oif;
> +	}
>  
> +	fl6->flowi6_oif = oif;
>  	security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
>  }
>  

thanks for the fix.

Besides the nit,
Reviewed-by: David Ahern <dsahern@kernel.org>

      reply	other threads:[~2022-11-25  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 11:48 Richard Gobert
2022-11-25  4:00 ` David Ahern [this message]

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=ba4d41bc-ec24-f4b4-e4d5-f9db51fed071@kernel.org \
    --to=dsahern@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardbgobert@gmail.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®