Commit 5983a3df authored by Benjamin Thery's avatar Benjamin Thery Committed by David S. Miller

[NETNS][IPV6] flowlabels - make proc per namespace

Make /proc/net/ip6_flowlabel show only flow labels belonging to the
current network namespace.
Signed-off-by: default avatarBenjamin Thery <benjamin.thery@bull.net>
Signed-off-by: default avatarDaniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 60e8fbc4
...@@ -611,6 +611,7 @@ int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen) ...@@ -611,6 +611,7 @@ int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
struct ip6fl_iter_state { struct ip6fl_iter_state {
struct seq_net_private p;
int bucket; int bucket;
}; };
...@@ -620,12 +621,15 @@ static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq) ...@@ -620,12 +621,15 @@ static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq)
{ {
struct ip6_flowlabel *fl = NULL; struct ip6_flowlabel *fl = NULL;
struct ip6fl_iter_state *state = ip6fl_seq_private(seq); struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
struct net *net = seq_file_net(seq);
for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) { for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) {
if (fl_ht[state->bucket]) { fl = fl_ht[state->bucket];
fl = fl_ht[state->bucket];
while (fl && fl->fl_net != net)
fl = fl->next;
if (fl)
break; break;
}
} }
return fl; return fl;
} }
...@@ -633,12 +637,18 @@ static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq) ...@@ -633,12 +637,18 @@ static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq)
static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flowlabel *fl) static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flowlabel *fl)
{ {
struct ip6fl_iter_state *state = ip6fl_seq_private(seq); struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
struct net *net = seq_file_net(seq);
fl = fl->next; fl = fl->next;
try_again:
while (fl && fl->fl_net != net)
fl = fl->next;
while (!fl) { while (!fl) {
if (++state->bucket <= FL_HASH_MASK) if (++state->bucket <= FL_HASH_MASK) {
fl = fl_ht[state->bucket]; fl = fl_ht[state->bucket];
else goto try_again;
} else
break; break;
} }
return fl; return fl;
...@@ -708,8 +718,8 @@ static const struct seq_operations ip6fl_seq_ops = { ...@@ -708,8 +718,8 @@ static const struct seq_operations ip6fl_seq_ops = {
static int ip6fl_seq_open(struct inode *inode, struct file *file) static int ip6fl_seq_open(struct inode *inode, struct file *file)
{ {
return seq_open_private(file, &ip6fl_seq_ops, return seq_open_net(inode, file, &ip6fl_seq_ops,
sizeof(struct ip6fl_iter_state)); sizeof(struct ip6fl_iter_state));
} }
static const struct file_operations ip6fl_seq_fops = { static const struct file_operations ip6fl_seq_fops = {
...@@ -717,12 +727,13 @@ static const struct file_operations ip6fl_seq_fops = { ...@@ -717,12 +727,13 @@ static const struct file_operations ip6fl_seq_fops = {
.open = ip6fl_seq_open, .open = ip6fl_seq_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
.release = seq_release_private, .release = seq_release_net,
}; };
static int ip6_flowlabel_proc_init(struct net *net) static int ip6_flowlabel_proc_init(struct net *net)
{ {
if (!proc_net_fops_create(net, "ip6_flowlabel", S_IRUGO, &ip6fl_seq_fops)) if (!proc_net_fops_create(net, "ip6_flowlabel",
S_IRUGO, &ip6fl_seq_fops))
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
...@@ -745,25 +756,21 @@ static inline void ip6_flowlabel_proc_fini(struct net *net) ...@@ -745,25 +756,21 @@ static inline void ip6_flowlabel_proc_fini(struct net *net)
static inline void ip6_flowlabel_net_exit(struct net *net) static inline void ip6_flowlabel_net_exit(struct net *net)
{ {
ip6_fl_purge(net); ip6_fl_purge(net);
ip6_flowlabel_proc_fini(net);
} }
static struct pernet_operations ip6_flowlabel_net_ops = { static struct pernet_operations ip6_flowlabel_net_ops = {
.init = ip6_flowlabel_proc_init,
.exit = ip6_flowlabel_net_exit, .exit = ip6_flowlabel_net_exit,
}; };
int ip6_flowlabel_init(void) int ip6_flowlabel_init(void)
{ {
int err; return register_pernet_subsys(&ip6_flowlabel_net_ops);
err = register_pernet_subsys(&ip6_flowlabel_net_ops);
if (err)
return err;
return ip6_flowlabel_proc_init(&init_net);
} }
void ip6_flowlabel_cleanup(void) void ip6_flowlabel_cleanup(void)
{ {
del_timer(&ip6_fl_gc_timer); del_timer(&ip6_fl_gc_timer);
unregister_pernet_subsys(&ip6_flowlabel_net_ops); unregister_pernet_subsys(&ip6_flowlabel_net_ops);
ip6_flowlabel_proc_fini(&init_net);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment