Skip to content

Commit 4461568

Browse files
q2venkuba-moo
authored andcommitted
tcp: Access &tcp_hashinfo via net.
We will soon introduce an optional per-netns ehash. This means we cannot use tcp_hashinfo directly in most places. Instead, access it via net->ipv4.tcp_death_row.hashinfo. The access will be valid only while initialising tcp_hashinfo itself and creating/destroying each netns. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 429e42c commit 4461568

File tree

17 files changed

+108
-78
lines changed

17 files changed

+108
-78
lines changed

drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,7 @@ static void chtls_pass_accept_rpl(struct sk_buff *skb,
10691069
cxgb4_l2t_send(csk->egress_dev, skb, csk->l2t_entry);
10701070
}
10711071

1072-
static void inet_inherit_port(struct inet_hashinfo *hash_info,
1073-
struct sock *lsk, struct sock *newsk)
1072+
static void inet_inherit_port(struct sock *lsk, struct sock *newsk)
10741073
{
10751074
local_bh_disable();
10761075
__inet_inherit_port(lsk, newsk);
@@ -1240,7 +1239,7 @@ static struct sock *chtls_recv_sock(struct sock *lsk,
12401239
ipv4.sysctl_tcp_window_scaling),
12411240
tp->window_clamp);
12421241
neigh_release(n);
1243-
inet_inherit_port(&tcp_hashinfo, lsk, newsk);
1242+
inet_inherit_port(lsk, newsk);
12441243
csk_set_flag(csk, CSK_CONN_INLINE);
12451244
bh_unlock_sock(newsk); /* tcp_create_openreq_child ->sk_clone_lock */
12461245

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static void resync_update_sn(struct mlx5e_rq *rq, struct sk_buff *skb)
461461
{
462462
struct ethhdr *eth = (struct ethhdr *)(skb->data);
463463
struct net_device *netdev = rq->netdev;
464+
struct net *net = dev_net(netdev);
464465
struct sock *sk = NULL;
465466
unsigned int datalen;
466467
struct iphdr *iph;
@@ -475,7 +476,7 @@ static void resync_update_sn(struct mlx5e_rq *rq, struct sk_buff *skb)
475476
depth += sizeof(struct iphdr);
476477
th = (void *)iph + sizeof(struct iphdr);
477478

478-
sk = inet_lookup_established(dev_net(netdev), &tcp_hashinfo,
479+
sk = inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
479480
iph->saddr, th->source, iph->daddr,
480481
th->dest, netdev->ifindex);
481482
#if IS_ENABLED(CONFIG_IPV6)
@@ -485,7 +486,7 @@ static void resync_update_sn(struct mlx5e_rq *rq, struct sk_buff *skb)
485486
depth += sizeof(struct ipv6hdr);
486487
th = (void *)ipv6h + sizeof(struct ipv6hdr);
487488

488-
sk = __inet6_lookup_established(dev_net(netdev), &tcp_hashinfo,
489+
sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
489490
&ipv6h->saddr, th->source,
490491
&ipv6h->daddr, ntohs(th->dest),
491492
netdev->ifindex, 0);

drivers/net/ethernet/netronome/nfp/crypto/tls.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ int nfp_net_tls_rx_resync_req(struct net_device *netdev,
474474
{
475475
struct nfp_net *nn = netdev_priv(netdev);
476476
struct nfp_net_tls_offload_ctx *ntls;
477+
struct net *net = dev_net(netdev);
477478
struct ipv6hdr *ipv6h;
478479
struct tcphdr *th;
479480
struct iphdr *iph;
@@ -494,13 +495,13 @@ int nfp_net_tls_rx_resync_req(struct net_device *netdev,
494495

495496
switch (ipv6h->version) {
496497
case 4:
497-
sk = inet_lookup_established(dev_net(netdev), &tcp_hashinfo,
498+
sk = inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
498499
iph->saddr, th->source, iph->daddr,
499500
th->dest, netdev->ifindex);
500501
break;
501502
#if IS_ENABLED(CONFIG_IPV6)
502503
case 6:
503-
sk = __inet6_lookup_established(dev_net(netdev), &tcp_hashinfo,
504+
sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
504505
&ipv6h->saddr, th->source,
505506
&ipv6h->daddr, ntohs(th->dest),
506507
netdev->ifindex, 0);

net/core/filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6373,6 +6373,7 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = {
63736373
static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
63746374
int dif, int sdif, u8 family, u8 proto)
63756375
{
6376+
struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
63766377
bool refcounted = false;
63776378
struct sock *sk = NULL;
63786379

@@ -6381,7 +6382,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
63816382
__be32 dst4 = tuple->ipv4.daddr;
63826383

63836384
if (proto == IPPROTO_TCP)
6384-
sk = __inet_lookup(net, &tcp_hashinfo, NULL, 0,
6385+
sk = __inet_lookup(net, hinfo, NULL, 0,
63856386
src4, tuple->ipv4.sport,
63866387
dst4, tuple->ipv4.dport,
63876388
dif, sdif, &refcounted);
@@ -6395,7 +6396,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
63956396
struct in6_addr *dst6 = (struct in6_addr *)&tuple->ipv6.daddr;
63966397

63976398
if (proto == IPPROTO_TCP)
6398-
sk = __inet6_lookup(net, &tcp_hashinfo, NULL, 0,
6399+
sk = __inet6_lookup(net, hinfo, NULL, 0,
63996400
src6, tuple->ipv6.sport,
64006401
dst6, ntohs(tuple->ipv6.dport),
64016402
dif, sdif, &refcounted);

net/ipv4/esp4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static void esp_free_tcp_sk(struct rcu_head *head)
134134
static struct sock *esp_find_tcp_sk(struct xfrm_state *x)
135135
{
136136
struct xfrm_encap_tmpl *encap = x->encap;
137+
struct net *net = xs_net(x);
137138
struct esp_tcp_sk *esk;
138139
__be16 sport, dport;
139140
struct sock *nsk;
@@ -160,7 +161,7 @@ static struct sock *esp_find_tcp_sk(struct xfrm_state *x)
160161
}
161162
spin_unlock_bh(&x->lock);
162163

163-
sk = inet_lookup_established(xs_net(x), &tcp_hashinfo, x->id.daddr.a4,
164+
sk = inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo, x->id.daddr.a4,
164165
dport, x->props.saddr.a4, sport, 0);
165166
if (!sk)
166167
return ERR_PTR(-ENOENT);

net/ipv4/inet_hashtables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static inline struct sock *inet_lookup_run_bpf(struct net *net,
386386
struct sock *sk, *reuse_sk;
387387
bool no_reuseport;
388388

389-
if (hashinfo != &tcp_hashinfo)
389+
if (hashinfo != net->ipv4.tcp_death_row.hashinfo)
390390
return NULL; /* only TCP is supported */
391391

392392
no_reuseport = bpf_sk_lookup_run_v4(net, IPPROTO_TCP, saddr, sport,

net/ipv4/netfilter/nf_socket_ipv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ nf_socket_get_sock_v4(struct net *net, struct sk_buff *skb, const int doff,
7171
{
7272
switch (protocol) {
7373
case IPPROTO_TCP:
74-
return inet_lookup(net, &tcp_hashinfo, skb, doff,
75-
saddr, sport, daddr, dport,
74+
return inet_lookup(net, net->ipv4.tcp_death_row.hashinfo,
75+
skb, doff, saddr, sport, daddr, dport,
7676
in->ifindex);
7777
case IPPROTO_UDP:
7878
return udp4_lib_lookup(net, saddr, sport, daddr, dport,

net/ipv4/netfilter/nf_tproxy_ipv4.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb,
7979
const struct net_device *in,
8080
const enum nf_tproxy_lookup_t lookup_type)
8181
{
82+
struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
8283
struct sock *sk;
8384

8485
switch (protocol) {
@@ -92,12 +93,10 @@ nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb,
9293

9394
switch (lookup_type) {
9495
case NF_TPROXY_LOOKUP_LISTENER:
95-
sk = inet_lookup_listener(net, &tcp_hashinfo, skb,
96-
ip_hdrlen(skb) +
97-
__tcp_hdrlen(hp),
98-
saddr, sport,
99-
daddr, dport,
100-
in->ifindex, 0);
96+
sk = inet_lookup_listener(net, hinfo, skb,
97+
ip_hdrlen(skb) + __tcp_hdrlen(hp),
98+
saddr, sport, daddr, dport,
99+
in->ifindex, 0);
101100

102101
if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
103102
sk = NULL;
@@ -108,9 +107,8 @@ nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb,
108107
*/
109108
break;
110109
case NF_TPROXY_LOOKUP_ESTABLISHED:
111-
sk = inet_lookup_established(net, &tcp_hashinfo,
112-
saddr, sport, daddr, dport,
113-
in->ifindex);
110+
sk = inet_lookup_established(net, hinfo, saddr, sport,
111+
daddr, dport, in->ifindex);
114112
break;
115113
default:
116114
BUG();

net/ipv4/tcp_diag.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,35 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin)
181181
static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
182182
const struct inet_diag_req_v2 *r)
183183
{
184-
inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r);
184+
struct inet_hashinfo *hinfo;
185+
186+
hinfo = sock_net(cb->skb->sk)->ipv4.tcp_death_row.hashinfo;
187+
188+
inet_diag_dump_icsk(hinfo, skb, cb, r);
185189
}
186190

187191
static int tcp_diag_dump_one(struct netlink_callback *cb,
188192
const struct inet_diag_req_v2 *req)
189193
{
190-
return inet_diag_dump_one_icsk(&tcp_hashinfo, cb, req);
194+
struct inet_hashinfo *hinfo;
195+
196+
hinfo = sock_net(cb->skb->sk)->ipv4.tcp_death_row.hashinfo;
197+
198+
return inet_diag_dump_one_icsk(hinfo, cb, req);
191199
}
192200

193201
#ifdef CONFIG_INET_DIAG_DESTROY
194202
static int tcp_diag_destroy(struct sk_buff *in_skb,
195203
const struct inet_diag_req_v2 *req)
196204
{
197205
struct net *net = sock_net(in_skb->sk);
198-
struct sock *sk = inet_diag_find_one_icsk(net, &tcp_hashinfo, req);
206+
struct inet_hashinfo *hinfo;
207+
struct sock *sk;
199208
int err;
200209

210+
hinfo = net->ipv4.tcp_death_row.hashinfo;
211+
sk = inet_diag_find_one_icsk(net, hinfo, req);
212+
201213
if (IS_ERR(sk))
202214
return PTR_ERR(sk);
203215

0 commit comments

Comments
 (0)