Skip to content

Commit affbc21

Browse files
Paolo Abeniopsiff
authored andcommitted
udp: fix l4 hash after reconnect
[ Upstream commit 51a00be ] After the blamed commit below, udp_rehash() is supposed to be called with both local and remote addresses set. Currently that is already the case for IPv6 sockets, but for IPv4 the destination address is updated after rehashing. Address the issue moving the destination address and port initialization before rehashing. Fixes: 1b29a73 ("ipv6/udp: Add 4-tuple hash for connected socket") Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/4761e466ab9f7542c68cdc95f248987d127044d2.1733499715.git.pabeni@redhat.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> [ Backport from v6.13-rc3 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
1 parent b5ad0aa commit affbc21

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

net/ipv4/datagram.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
6161
err = -EACCES;
6262
goto out;
6363
}
64+
65+
/* Update addresses before rehashing */
66+
inet->inet_daddr = fl4->daddr;
67+
inet->inet_dport = usin->sin_port;
6468
if (!inet->inet_saddr)
65-
inet->inet_saddr = fl4->saddr; /* Update source address */
69+
inet->inet_saddr = fl4->saddr;
6670
if (!inet->inet_rcv_saddr) {
6771
inet->inet_rcv_saddr = fl4->saddr;
6872
if (sk->sk_prot->rehash)
6973
sk->sk_prot->rehash(sk);
7074
}
71-
inet->inet_daddr = fl4->daddr;
72-
inet->inet_dport = usin->sin_port;
7375
reuseport_has_conns_set(sk);
7476
sk->sk_state = TCP_ESTABLISHED;
7577
sk_set_txhash(sk);

0 commit comments

Comments
 (0)