Skip to content

Commit b9c6c96

Browse files
Richard Gobertgregkh
authored andcommitted
net: setsockopt: fix IPV6_UNICAST_IF option for connected sockets
[ Upstream commit 526682b ] 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: 0e4d354 ("net-next: Fix IP_UNICAST_IF option behavior for connected sockets") Signed-off-by: Richard Gobert <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 105aa2e commit b9c6c96

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎net/ipv6/datagram.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,29 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk)
4242
{
4343
struct inet_sock *inet = inet_sk(sk);
4444
struct ipv6_pinfo *np = inet6_sk(sk);
45+
int oif = sk->sk_bound_dev_if;
4546

4647
memset(fl6, 0, sizeof(*fl6));
4748
fl6->flowi6_proto = sk->sk_protocol;
4849
fl6->daddr = sk->sk_v6_daddr;
4950
fl6->saddr = np->saddr;
50-
fl6->flowi6_oif = sk->sk_bound_dev_if;
5151
fl6->flowi6_mark = sk->sk_mark;
5252
fl6->fl6_dport = inet->inet_dport;
5353
fl6->fl6_sport = inet->inet_sport;
5454
fl6->flowlabel = np->flow_label;
5555
fl6->flowi6_uid = sk->sk_uid;
5656

57-
if (!fl6->flowi6_oif)
58-
fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
57+
if (!oif)
58+
oif = np->sticky_pktinfo.ipi6_ifindex;
5959

60-
if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr))
61-
fl6->flowi6_oif = np->mcast_oif;
60+
if (!oif) {
61+
if (ipv6_addr_is_multicast(&fl6->daddr))
62+
oif = np->mcast_oif;
63+
else
64+
oif = np->ucast_oif;
65+
}
6266

67+
fl6->flowi6_oif = oif;
6368
security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
6469
}
6570

0 commit comments

Comments
 (0)