Skip to content

Commit 5e07e67

Browse files
q2vendavem330
authored andcommitted
tcp: Use bhash2 for v4-mapped-v6 non-wildcard address.
While checking port availability in bind() or listen(), we used only bhash for all v4-mapped-v6 addresses. But there is no good reason not to use bhash2 for v4-mapped-v6 non-wildcard addresses. Let's do it by returning true in inet_use_bhash2_on_bind(). Then, we also need to add a test in inet_bind2_bucket_match_addr_any() so that ::ffff:X.X.X.X will match with 0.0.0.0. Note that sk->sk_rcv_saddr is initialised for v4-mapped-v6 sk in __inet6_bind(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 67f440c commit 5e07e67

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

net/ipv4/inet_connection_sock.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ static bool inet_use_bhash2_on_bind(const struct sock *sk)
159159
if (sk->sk_family == AF_INET6) {
160160
int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
161161

162-
return addr_type != IPV6_ADDR_ANY &&
163-
addr_type != IPV6_ADDR_MAPPED;
162+
if (addr_type == IPV6_ADDR_ANY)
163+
return false;
164+
165+
if (addr_type != IPV6_ADDR_MAPPED)
166+
return true;
164167
}
165168
#endif
166169
return sk->sk_rcv_saddr != htonl(INADDR_ANY);

net/ipv4/inet_hashtables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const
841841
return ipv6_addr_any(&tb->v6_rcv_saddr) ||
842842
ipv6_addr_v4mapped_any(&tb->v6_rcv_saddr);
843843

844-
return false;
844+
return ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr) &&
845+
tb->rcv_saddr == 0;
845846
}
846847

847848
if (sk->sk_family == AF_INET6)

0 commit comments

Comments
 (0)