mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 20:51:44 +00:00
net: setsockopt: fix IPV6_UNICAST_IF option for connected sockets
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: 0e4d354762
("net-next: Fix IP_UNICAST_IF option behavior for connected sockets")
Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
1b1661f68b
commit
526682b458
@ -42,24 +42,29 @@ 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 = 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;
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user