Skip to content

Commit 1eeb504

Browse files
edumazetkuba-moo
authored andcommitted
tcp/dccp: do not care about families in inet_twsk_purge()
We lost ability to unload ipv6 module a long time ago. Instead of calling expensive inet_twsk_purge() twice, we can handle all families in one round. Also remove an extra line added in my prior patch, per Kuniyuki Iwashima feedback. Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/netdev/[email protected]/ Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 58169ec commit 1eeb504

File tree

8 files changed

+10
-25
lines changed

8 files changed

+10
-25
lines changed

include/net/inet_timewait_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo
111111

112112
void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
113113

114-
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family);
114+
void inet_twsk_purge(struct inet_hashinfo *hashinfo);
115115

116116
static inline
117117
struct net *twsk_net(const struct inet_timewait_sock *twsk)

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb);
353353
void tcp_rcv_space_adjust(struct sock *sk);
354354
int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp);
355355
void tcp_twsk_destructor(struct sock *sk);
356-
void tcp_twsk_purge(struct list_head *net_exit_list, int family);
356+
void tcp_twsk_purge(struct list_head *net_exit_list);
357357
ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos,
358358
struct pipe_inode_info *pipe, size_t len,
359359
unsigned int flags);

net/dccp/ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ static void __net_exit dccp_v4_exit_net(struct net *net)
10391039

10401040
static void __net_exit dccp_v4_exit_batch(struct list_head *net_exit_list)
10411041
{
1042-
inet_twsk_purge(&dccp_hashinfo, AF_INET);
1042+
inet_twsk_purge(&dccp_hashinfo);
10431043
}
10441044

10451045
static struct pernet_operations dccp_v4_ops = {

net/dccp/ipv6.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,15 +1119,9 @@ static void __net_exit dccp_v6_exit_net(struct net *net)
11191119
inet_ctl_sock_destroy(pn->v6_ctl_sk);
11201120
}
11211121

1122-
static void __net_exit dccp_v6_exit_batch(struct list_head *net_exit_list)
1123-
{
1124-
inet_twsk_purge(&dccp_hashinfo, AF_INET6);
1125-
}
1126-
11271122
static struct pernet_operations dccp_v6_ops = {
11281123
.init = dccp_v6_init_net,
11291124
.exit = dccp_v6_exit_net,
1130-
.exit_batch = dccp_v6_exit_batch,
11311125
.id = &dccp_v6_pernet_id,
11321126
.size = sizeof(struct dccp_v6_pernet),
11331127
};

net/ipv4/inet_timewait_sock.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, bool rearm)
264264
EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
265265

266266
/* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
267-
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
267+
void inet_twsk_purge(struct inet_hashinfo *hashinfo)
268268
{
269269
struct inet_ehash_bucket *head = &hashinfo->ehash[0];
270270
unsigned int ehash_mask = hashinfo->ehash_mask;
@@ -273,7 +273,6 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
273273
struct sock *sk;
274274

275275
for (slot = 0; slot <= ehash_mask; slot++, head++) {
276-
277276
if (hlist_nulls_empty(&head->chain))
278277
continue;
279278

@@ -288,15 +287,13 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
288287
TCPF_NEW_SYN_RECV))
289288
continue;
290289

291-
if (sk->sk_family != family ||
292-
refcount_read(&sock_net(sk)->ns.count))
290+
if (refcount_read(&sock_net(sk)->ns.count))
293291
continue;
294292

295293
if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
296294
continue;
297295

298-
if (unlikely(sk->sk_family != family ||
299-
refcount_read(&sock_net(sk)->ns.count))) {
296+
if (refcount_read(&sock_net(sk)->ns.count)) {
300297
sock_gen_put(sk);
301298
goto restart;
302299
}

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3501,7 +3501,7 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)
35013501
{
35023502
struct net *net;
35033503

3504-
tcp_twsk_purge(net_exit_list, AF_INET);
3504+
tcp_twsk_purge(net_exit_list);
35053505

35063506
list_for_each_entry(net, net_exit_list, exit_list) {
35073507
inet_pernet_hashinfo_free(net->ipv4.tcp_death_row.hashinfo);

net/ipv4/tcp_minisocks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,17 @@ void tcp_twsk_destructor(struct sock *sk)
388388
}
389389
EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
390390

391-
void tcp_twsk_purge(struct list_head *net_exit_list, int family)
391+
void tcp_twsk_purge(struct list_head *net_exit_list)
392392
{
393393
bool purged_once = false;
394394
struct net *net;
395395

396396
list_for_each_entry(net, net_exit_list, exit_list) {
397397
if (net->ipv4.tcp_death_row.hashinfo->pernet) {
398398
/* Even if tw_refcount == 1, we must clean up kernel reqsk */
399-
inet_twsk_purge(net->ipv4.tcp_death_row.hashinfo, family);
399+
inet_twsk_purge(net->ipv4.tcp_death_row.hashinfo);
400400
} else if (!purged_once) {
401-
inet_twsk_purge(&tcp_hashinfo, family);
401+
inet_twsk_purge(&tcp_hashinfo);
402402
purged_once = true;
403403
}
404404
}

net/ipv6/tcp_ipv6.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,15 +2389,9 @@ static void __net_exit tcpv6_net_exit(struct net *net)
23892389
inet_ctl_sock_destroy(net->ipv6.tcp_sk);
23902390
}
23912391

2392-
static void __net_exit tcpv6_net_exit_batch(struct list_head *net_exit_list)
2393-
{
2394-
tcp_twsk_purge(net_exit_list, AF_INET6);
2395-
}
2396-
23972392
static struct pernet_operations tcpv6_net_ops = {
23982393
.init = tcpv6_net_init,
23992394
.exit = tcpv6_net_exit,
2400-
.exit_batch = tcpv6_net_exit_batch,
24012395
};
24022396

24032397
int __init tcpv6_init(void)

0 commit comments

Comments
 (0)