Skip to content

Commit ffa84b5

Browse files
edumazetkuba-moo
authored andcommitted
net: add netns refcount tracker to struct sock
Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9ba74e6 commit ffa84b5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

include/net/sock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ struct bpf_local_storage;
350350
* @sk_txtime_deadline_mode: set deadline mode for SO_TXTIME
351351
* @sk_txtime_report_errors: set report errors mode for SO_TXTIME
352352
* @sk_txtime_unused: unused txtime flags
353+
* @ns_tracker: tracker for netns reference
353354
*/
354355
struct sock {
355356
/*
@@ -538,6 +539,7 @@ struct sock {
538539
struct bpf_local_storage __rcu *sk_bpf_storage;
539540
#endif
540541
struct rcu_head sk_rcu;
542+
netns_tracker ns_tracker;
541543
};
542544

543545
enum sk_pacing {

net/core/sock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
19831983
sock_lock_init(sk);
19841984
sk->sk_net_refcnt = kern ? 0 : 1;
19851985
if (likely(sk->sk_net_refcnt)) {
1986-
get_net(net);
1986+
get_net_track(net, &sk->ns_tracker, priority);
19871987
sock_inuse_add(net, 1);
19881988
}
19891989

@@ -2039,7 +2039,7 @@ static void __sk_destruct(struct rcu_head *head)
20392039
put_pid(sk->sk_peer_pid);
20402040

20412041
if (likely(sk->sk_net_refcnt))
2042-
put_net(sock_net(sk));
2042+
put_net_track(sock_net(sk), &sk->ns_tracker);
20432043
sk_prot_free(sk->sk_prot_creator, sk);
20442044
}
20452045

@@ -2126,7 +2126,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
21262126

21272127
/* SANITY */
21282128
if (likely(newsk->sk_net_refcnt)) {
2129-
get_net(sock_net(newsk));
2129+
get_net_track(sock_net(newsk), &newsk->ns_tracker, priority);
21302130
sock_inuse_add(sock_net(newsk), 1);
21312131
}
21322132
sk_node_init(&newsk->sk_node);

0 commit comments

Comments
 (0)