@@ -65,7 +65,7 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
inet->inet_saddr = fl4->saddr; /* Update source address */
if (!inet->inet_rcv_saddr) {
inet->inet_rcv_saddr = fl4->saddr;
- if (sk->sk_prot->rehash)
+ if (sk->sk_prot->rehash && sk->sk_family == AF_INET)
sk->sk_prot->rehash(sk);
}
inet->inet_daddr = fl4->daddr;
@@ -211,7 +211,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,
ipv6_mapped_addr_any(&sk->sk_v6_rcv_saddr)) {
ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
&sk->sk_v6_rcv_saddr);
- if (sk->sk_prot->rehash)
+ if (sk->sk_prot->rehash && sk->sk_family == AF_INET6)
sk->sk_prot->rehash(sk);
}
It makes no sense to rehash an IPv4 socket when we change sk_v6_rcv_saddr, or to rehash an IPv6 socket as inet_rcv_saddr is set: the secondary hash (including the local address) won't change, because ipv4_portaddr_hash() and ipv6_portaddr_hash() only take the address matching the socket family. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> --- net/ipv4/datagram.c | 2 +- net/ipv6/datagram.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)