Skip to content

Commit

Permalink
net: make /proc/net/protocols namespace aware
Browse files Browse the repository at this point in the history
Converting /proc/net/protocols to be namespace aware is quite easy
and permits us to use sock_prot_inuse_get().

This provides seperate counters for each protocol. For example
we can really count TCPv6 sockets and TCPv4 sockets, while previously,
we had the same value, and this value was not namespace aware.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 19, 2008
1 parent 3680453 commit 14e943d
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ static void proto_seq_printf(struct seq_file *seq, struct proto *proto)
"%2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c %2c\n",
proto->name,
proto->obj_size,
proto->sockets_allocated != NULL ? atomic_read(proto->sockets_allocated) : -1,
sock_prot_inuse_get(seq_file_net(seq), proto),
proto->memory_allocated != NULL ? atomic_read(proto->memory_allocated) : -1,
proto->memory_pressure != NULL ? *proto->memory_pressure ? "yes" : "no" : "NI",
proto->max_header,
Expand Down Expand Up @@ -2228,21 +2228,40 @@ static const struct seq_operations proto_seq_ops = {

static int proto_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &proto_seq_ops);
return seq_open_net(inode, file, &proto_seq_ops,
sizeof(struct seq_net_private));
}

static const struct file_operations proto_seq_fops = {
.owner = THIS_MODULE,
.open = proto_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
.release = seq_release_net,
};

static __net_init int proto_init_net(struct net *net)
{
if (!proc_net_fops_create(net, "protocols", S_IRUGO, &proto_seq_fops))
return -ENOMEM;

return 0;
}

static __net_exit void proto_exit_net(struct net *net)
{
proc_net_remove(net, "protocols");
}


static __net_initdata struct pernet_operations proto_net_ops = {
.init = proto_init_net,
.exit = proto_exit_net,
};

static int __init proto_init(void)
{
/* register /proc/net/protocols */
return proc_net_fops_create(&init_net, "protocols", S_IRUGO, &proto_seq_fops) == NULL ? -ENOBUFS : 0;
return register_pernet_subsys(&proto_net_ops);
}

subsys_initcall(proto_init);
Expand Down

0 comments on commit 14e943d

Please sign in to comment.