Skip to content

Commit 5a22bba

Browse files
q2vendavem330
authored andcommitted
tcp: Save address type in inet_bind2_bucket.
inet_bind2_bucket_addr_match() and inet_bind2_bucket_match_addr_any() are called for each bhash2 bucket to check conflicts. Thus, we call ipv6_addr_any() and ipv6_addr_v4mapped() over and over during bind(). Let's avoid calling them by saving the address type in inet_bind2_bucket. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 06a8c04 commit 5a22bba

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

include/net/inet_hashtables.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct inet_bind2_bucket {
9696
int l3mdev;
9797
unsigned short port;
9898
#if IS_ENABLED(CONFIG_IPV6)
99+
unsigned short addr_type;
99100
struct in6_addr v6_rcv_saddr;
100101
#define rcv_saddr v6_rcv_saddr.s6_addr32[3]
101102
#else

net/ipv4/inet_hashtables.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ static void inet_bind2_bucket_init(struct inet_bind2_bucket *tb,
110110
tb->l3mdev = l3mdev;
111111
tb->port = port;
112112
#if IS_ENABLED(CONFIG_IPV6)
113-
if (sk->sk_family == AF_INET6)
113+
BUILD_BUG_ON(USHRT_MAX < (IPV6_ADDR_ANY | IPV6_ADDR_MAPPED));
114+
if (sk->sk_family == AF_INET6) {
115+
tb->addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
114116
tb->v6_rcv_saddr = sk->sk_v6_rcv_saddr;
115-
else
117+
} else {
118+
tb->addr_type = IPV6_ADDR_MAPPED;
116119
ipv6_addr_set_v4mapped(sk->sk_rcv_saddr, &tb->v6_rcv_saddr);
120+
}
117121
#else
118122
tb->rcv_saddr = sk->sk_rcv_saddr;
119123
#endif
@@ -153,7 +157,7 @@ static bool inet_bind2_bucket_addr_match(const struct inet_bind2_bucket *tb2,
153157
if (sk->sk_family == AF_INET6)
154158
return ipv6_addr_equal(&tb2->v6_rcv_saddr, &sk->sk_v6_rcv_saddr);
155159

156-
if (!ipv6_addr_v4mapped(&tb2->v6_rcv_saddr))
160+
if (tb2->addr_type != IPV6_ADDR_MAPPED)
157161
return false;
158162
#endif
159163
return tb2->rcv_saddr == sk->sk_rcv_saddr;
@@ -830,21 +834,14 @@ bool inet_bind2_bucket_match_addr_any(const struct inet_bind2_bucket *tb, const
830834
return false;
831835

832836
#if IS_ENABLED(CONFIG_IPV6)
833-
if (sk->sk_family == AF_INET6) {
834-
if (ipv6_addr_any(&tb->v6_rcv_saddr))
835-
return true;
836-
837-
if (!ipv6_addr_v4mapped(&tb->v6_rcv_saddr))
838-
return false;
839-
840-
return ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr) &&
841-
tb->rcv_saddr == 0;
842-
}
843-
844-
if (ipv6_addr_any(&tb->v6_rcv_saddr))
837+
if (tb->addr_type == IPV6_ADDR_ANY)
845838
return true;
846839

847-
if (!ipv6_addr_v4mapped(&tb->v6_rcv_saddr))
840+
if (tb->addr_type != IPV6_ADDR_MAPPED)
841+
return false;
842+
843+
if (sk->sk_family == AF_INET6 &&
844+
!ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
848845
return false;
849846
#endif
850847
return tb->rcv_saddr == 0;

0 commit comments

Comments
 (0)