Skip to content

Commit 822fb91

Browse files
q2vendavem330
authored andcommitted
tcp: Link bhash2 to bhash.
bhash2 added a new member sk_bind2_node in struct sock to link sockets to bhash2 in addition to bhash. bhash is still needed to search conflicting sockets efficiently from a port for the wildcard address. However, bhash itself need not have sockets. If we link each bhash2 bucket to the corresponding bhash bucket, we can iterate the same set of the sockets from bhash2 via bhash. This patch links bhash2 to bhash only, and the actual use will be in the later patches. Finally, we will remove sk_bind2_node. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4dd7108 commit 822fb91

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

include/net/inet_hashtables.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct inet_bind_bucket {
8989
bool fast_ipv6_only;
9090
struct hlist_node node;
9191
struct hlist_head owners;
92+
struct hlist_head bhash2;
9293
};
9394

9495
struct inet_bind2_bucket {
@@ -104,6 +105,7 @@ struct inet_bind2_bucket {
104105
#endif
105106
/* Node in the bhash2 inet_bind_hashbucket chain */
106107
struct hlist_node node;
108+
struct hlist_node bhash_node;
107109
/* List of sockets hashed to this bucket */
108110
struct hlist_head owners;
109111
/* bhash has twsk in owners, but bhash2 has twsk in
@@ -239,7 +241,7 @@ bool inet_bind_bucket_match(const struct inet_bind_bucket *tb,
239241
struct inet_bind2_bucket *
240242
inet_bind2_bucket_create(struct kmem_cache *cachep, struct net *net,
241243
struct inet_bind_hashbucket *head,
242-
unsigned short port, int l3mdev,
244+
struct inet_bind_bucket *tb,
243245
const struct sock *sk);
244246

245247
void inet_bind2_bucket_destroy(struct kmem_cache *cachep,

net/ipv4/inet_connection_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
572572

573573
if (!tb2) {
574574
tb2 = inet_bind2_bucket_create(hinfo->bind2_bucket_cachep,
575-
net, head2, port, l3mdev, sk);
575+
net, head2, tb, sk);
576576
if (!tb2)
577577
goto fail_unlock;
578578
bhash2_created = true;

net/ipv4/inet_hashtables.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct inet_bind_bucket *inet_bind_bucket_create(struct kmem_cache *cachep,
7777
tb->fastreuse = 0;
7878
tb->fastreuseport = 0;
7979
INIT_HLIST_HEAD(&tb->owners);
80+
INIT_HLIST_HEAD(&tb->bhash2);
8081
hlist_add_head(&tb->node, &head->chain);
8182
}
8283
return tb;
@@ -103,12 +104,12 @@ bool inet_bind_bucket_match(const struct inet_bind_bucket *tb, const struct net
103104
static void inet_bind2_bucket_init(struct inet_bind2_bucket *tb2,
104105
struct net *net,
105106
struct inet_bind_hashbucket *head,
106-
unsigned short port, int l3mdev,
107+
struct inet_bind_bucket *tb,
107108
const struct sock *sk)
108109
{
109110
write_pnet(&tb2->ib_net, net);
110-
tb2->l3mdev = l3mdev;
111-
tb2->port = port;
111+
tb2->l3mdev = tb->l3mdev;
112+
tb2->port = tb->port;
112113
#if IS_ENABLED(CONFIG_IPV6)
113114
BUILD_BUG_ON(USHRT_MAX < (IPV6_ADDR_ANY | IPV6_ADDR_MAPPED));
114115
if (sk->sk_family == AF_INET6) {
@@ -124,19 +125,19 @@ static void inet_bind2_bucket_init(struct inet_bind2_bucket *tb2,
124125
INIT_HLIST_HEAD(&tb2->owners);
125126
INIT_HLIST_HEAD(&tb2->deathrow);
126127
hlist_add_head(&tb2->node, &head->chain);
128+
hlist_add_head(&tb2->bhash_node, &tb->bhash2);
127129
}
128130

129131
struct inet_bind2_bucket *inet_bind2_bucket_create(struct kmem_cache *cachep,
130132
struct net *net,
131133
struct inet_bind_hashbucket *head,
132-
unsigned short port,
133-
int l3mdev,
134+
struct inet_bind_bucket *tb,
134135
const struct sock *sk)
135136
{
136137
struct inet_bind2_bucket *tb2 = kmem_cache_alloc(cachep, GFP_ATOMIC);
137138

138139
if (tb2)
139-
inet_bind2_bucket_init(tb2, net, head, port, l3mdev, sk);
140+
inet_bind2_bucket_init(tb2, net, head, tb, sk);
140141

141142
return tb2;
142143
}
@@ -146,6 +147,7 @@ void inet_bind2_bucket_destroy(struct kmem_cache *cachep, struct inet_bind2_buck
146147
{
147148
if (hlist_empty(&tb->owners) && hlist_empty(&tb->deathrow)) {
148149
__hlist_del(&tb->node);
150+
__hlist_del(&tb->bhash_node);
149151
kmem_cache_free(cachep, tb);
150152
}
151153
}
@@ -273,8 +275,7 @@ int __inet_inherit_port(const struct sock *sk, struct sock *child)
273275
tb2 = inet_bind2_bucket_find(head2, net, port, l3mdev, child);
274276
if (!tb2) {
275277
tb2 = inet_bind2_bucket_create(table->bind2_bucket_cachep,
276-
net, head2, port,
277-
l3mdev, child);
278+
net, head2, tb, child);
278279
if (!tb2)
279280
goto error;
280281
}
@@ -954,7 +955,7 @@ static int __inet_bhash2_update_saddr(struct sock *sk, void *saddr, int family,
954955
tb2 = inet_bind2_bucket_find(head2, net, port, l3mdev, sk);
955956
if (!tb2) {
956957
tb2 = new_tb2;
957-
inet_bind2_bucket_init(tb2, net, head2, port, l3mdev, sk);
958+
inet_bind2_bucket_init(tb2, net, head2, inet_csk(sk)->icsk_bind_hash, sk);
958959
}
959960
sk_add_bind2_node(sk, &tb2->owners);
960961
inet_csk(sk)->icsk_bind2_hash = tb2;
@@ -1101,7 +1102,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
11011102
tb2 = inet_bind2_bucket_find(head2, net, port, l3mdev, sk);
11021103
if (!tb2) {
11031104
tb2 = inet_bind2_bucket_create(hinfo->bind2_bucket_cachep, net,
1104-
head2, port, l3mdev, sk);
1105+
head2, tb, sk);
11051106
if (!tb2)
11061107
goto error;
11071108
}

0 commit comments

Comments
 (0)