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>
29 struct proc_dir_entry *proc_net_fops_create(struct net *net,
30 const char *name, mode_t mode, const struct file_operations *fops)
32 struct proc_dir_entry *res;
34 res = create_proc_entry(name, mode, net->proc_net);
36 res->proc_fops = fops;
39 EXPORT_SYMBOL_GPL(proc_net_fops_create);
41 void proc_net_remove(struct net *net, const char *name)
43 remove_proc_entry(name, net->proc_net);
45 EXPORT_SYMBOL_GPL(proc_net_remove);
47 struct net *get_proc_net(const struct inode *inode)
49 return maybe_get_net(PDE_NET(PDE(inode)));
51 EXPORT_SYMBOL_GPL(get_proc_net);
53 static struct proc_dir_entry *shadow_pde;
55 static struct proc_dir_entry *proc_net_shadow(struct task_struct *task,
56 struct proc_dir_entry *de)
58 return task->nsproxy->net_ns->proc_net;
61 static __net_init int proc_net_ns_init(struct net *net)
63 struct proc_dir_entry *root, *netd, *net_statd;
67 root = kzalloc(sizeof(*root), GFP_KERNEL);
72 netd = proc_mkdir("net", root);
77 net_statd = proc_mkdir("stat", netd);
83 net_statd->data = net;
85 net->proc_net_root = root;
87 net->proc_net_stat = net_statd;
93 remove_proc_entry("net", root);
99 static __net_exit void proc_net_ns_exit(struct net *net)
101 remove_proc_entry("stat", net->proc_net);
102 remove_proc_entry("net", net->proc_net_root);
103 kfree(net->proc_net_root);
106 static struct pernet_operations __net_initdata proc_net_ns_ops = {
107 .init = proc_net_ns_init,
108 .exit = proc_net_ns_exit,
111 int __init proc_net_init(void)
113 shadow_pde = proc_mkdir("net", NULL);
114 shadow_pde->shadow_proc = proc_net_shadow;
116 return register_pernet_subsys(&proc_net_ns_ops);