Skip to content

Commit

Permalink
net: add netns refcount tracker to struct seq_net_private
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Eric Dumazet authored and kuba-moo committed Dec 10, 2021
1 parent ffa84b5 commit 04a931e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions fs/proc/proc_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,27 @@ static int seq_open_net(struct inode *inode, struct file *file)
}
#ifdef CONFIG_NET_NS
p->net = net;
netns_tracker_alloc(net, &p->ns_tracker, GFP_KERNEL);
#endif
return 0;
}

static void seq_file_net_put_net(struct seq_file *seq)
{
#ifdef CONFIG_NET_NS
struct seq_net_private *priv = seq->private;

put_net_track(priv->net, &priv->ns_tracker);
#else
put_net(&init_net);
#endif
}

static int seq_release_net(struct inode *ino, struct file *f)
{
struct seq_file *seq = f->private_data;

put_net(seq_file_net(seq));
seq_file_net_put_net(seq);
seq_release_private(ino, f);
return 0;
}
Expand All @@ -87,7 +99,8 @@ int bpf_iter_init_seq_net(void *priv_data, struct bpf_iter_aux_info *aux)
#ifdef CONFIG_NET_NS
struct seq_net_private *p = priv_data;

p->net = get_net(current->nsproxy->net_ns);
p->net = get_net_track(current->nsproxy->net_ns, &p->ns_tracker,
GFP_KERNEL);
#endif
return 0;
}
Expand All @@ -97,7 +110,7 @@ void bpf_iter_fini_seq_net(void *priv_data)
#ifdef CONFIG_NET_NS
struct seq_net_private *p = priv_data;

put_net(p->net);
put_net_track(p->net, &p->ns_tracker);
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion include/linux/seq_file_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ extern struct net init_net;

struct seq_net_private {
#ifdef CONFIG_NET_NS
struct net *net;
struct net *net;
netns_tracker ns_tracker;
#endif
};

Expand Down

0 comments on commit 04a931e

Please sign in to comment.