6 * Author: Eric Biederman <ebiederm@xmission.com>
8 * proc net directory handling functions
11 #include <asm/uaccess.h>
13 #include <linux/errno.h>
14 #include <linux/time.h>
15 #include <linux/proc_fs.h>
16 #include <linux/stat.h>
17 #include <linux/init.h>
18 #include <linux/sched.h>
19 #include <linux/module.h>
20 #include <linux/bitops.h>
21 #include <linux/smp_lock.h>
22 #include <linux/mount.h>
23 #include <linux/nsproxy.h>
24 #include <net/net_namespace.h>
25 #include <linux/seq_file.h>
30 int seq_open_net(struct inode *ino, struct file *f,
31 const struct seq_operations *ops, int size)
34 struct seq_net_private *p;
36 BUG_ON(size < sizeof(*p));
38 net = get_proc_net(ino);
42 p = __seq_open_private(f, ops, size);
50 EXPORT_SYMBOL_GPL(seq_open_net);
52 int seq_release_net(struct inode *ino, struct file *f)
55 struct seq_net_private *p;
57 seq = f->private_data;
61 seq_release_private(ino, f);
64 EXPORT_SYMBOL_GPL(seq_release_net);
67 struct proc_dir_entry *proc_net_fops_create(struct net *net,
68 const char *name, mode_t mode, const struct file_operations *fops)
70 struct proc_dir_entry *res;
72 res = create_proc_entry(name, mode, net->proc_net);
74 res->proc_fops = fops;
77 EXPORT_SYMBOL_GPL(proc_net_fops_create);
79 void proc_net_remove(struct net *net, const char *name)
81 remove_proc_entry(name, net->proc_net);
83 EXPORT_SYMBOL_GPL(proc_net_remove);
85 struct net *get_proc_net(const struct inode *inode)
87 return maybe_get_net(PDE_NET(PDE(inode)));
89 EXPORT_SYMBOL_GPL(get_proc_net);
91 static struct proc_dir_entry *shadow_pde;
93 static struct proc_dir_entry *proc_net_shadow(struct task_struct *task,
94 struct proc_dir_entry *de)
96 return task->nsproxy->net_ns->proc_net;
99 struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
100 struct proc_dir_entry *parent)
102 struct proc_dir_entry *pde;
103 pde = proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
108 EXPORT_SYMBOL_GPL(proc_net_mkdir);
110 static __net_init int proc_net_ns_init(struct net *net)
112 struct proc_dir_entry *root, *netd, *net_statd;
116 root = kzalloc(sizeof(*root), GFP_KERNEL);
121 netd = proc_net_mkdir(net, "net", root);
126 net_statd = proc_net_mkdir(net, "stat", netd);
132 net->proc_net_root = root;
133 net->proc_net = netd;
134 net->proc_net_stat = net_statd;
140 remove_proc_entry("net", root);
146 static __net_exit void proc_net_ns_exit(struct net *net)
148 remove_proc_entry("stat", net->proc_net);
149 remove_proc_entry("net", net->proc_net_root);
150 kfree(net->proc_net_root);
153 static struct pernet_operations __net_initdata proc_net_ns_ops = {
154 .init = proc_net_ns_init,
155 .exit = proc_net_ns_exit,
158 int __init proc_net_init(void)
160 shadow_pde = proc_mkdir("net", NULL);
161 shadow_pde->shadow_proc = proc_net_shadow;
163 return register_pernet_subsys(&proc_net_ns_ops);