Commit | Line | Data |
---|---|---|
3c12afe7 DM |
1 | /* |
2 | * linux/fs/proc/net.c | |
3 | * | |
4 | * Copyright (C) 2007 | |
5 | * | |
6 | * Author: Eric Biederman <ebiederm@xmission.com> | |
7 | * | |
8 | * proc net directory handling functions | |
9 | */ | |
10 | ||
11 | #include <asm/uaccess.h> | |
12 | ||
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 | ||
26 | #include "internal.h" | |
27 | ||
28 | ||
3c12afe7 DM |
29 | struct proc_dir_entry *proc_net_fops_create(struct net *net, |
30 | const char *name, mode_t mode, const struct file_operations *fops) | |
31 | { | |
32 | struct proc_dir_entry *res; | |
33 | ||
34 | res = create_proc_entry(name, mode, net->proc_net); | |
35 | if (res) | |
36 | res->proc_fops = fops; | |
37 | return res; | |
38 | } | |
36ac3135 | 39 | EXPORT_SYMBOL_GPL(proc_net_fops_create); |
3c12afe7 DM |
40 | |
41 | void proc_net_remove(struct net *net, const char *name) | |
42 | { | |
43 | remove_proc_entry(name, net->proc_net); | |
44 | } | |
36ac3135 | 45 | EXPORT_SYMBOL_GPL(proc_net_remove); |
3c12afe7 | 46 | |
077130c0 EB |
47 | struct net *get_proc_net(const struct inode *inode) |
48 | { | |
49 | return maybe_get_net(PDE_NET(PDE(inode))); | |
50 | } | |
51 | EXPORT_SYMBOL_GPL(get_proc_net); | |
52 | ||
2b1e300a | 53 | static struct proc_dir_entry *shadow_pde; |
3c12afe7 | 54 | |
2b1e300a | 55 | static struct proc_dir_entry *proc_net_shadow(struct task_struct *task, |
3c12afe7 DM |
56 | struct proc_dir_entry *de) |
57 | { | |
2b1e300a | 58 | return task->nsproxy->net_ns->proc_net; |
3c12afe7 DM |
59 | } |
60 | ||
4665079c | 61 | static __net_init int proc_net_ns_init(struct net *net) |
3c12afe7 DM |
62 | { |
63 | struct proc_dir_entry *root, *netd, *net_statd; | |
64 | int err; | |
65 | ||
66 | err = -ENOMEM; | |
67 | root = kzalloc(sizeof(*root), GFP_KERNEL); | |
68 | if (!root) | |
69 | goto out; | |
70 | ||
71 | err = -EEXIST; | |
72 | netd = proc_mkdir("net", root); | |
73 | if (!netd) | |
74 | goto free_root; | |
75 | ||
76 | err = -EEXIST; | |
77 | net_statd = proc_mkdir("stat", netd); | |
78 | if (!net_statd) | |
79 | goto free_net; | |
80 | ||
81 | root->data = net; | |
82 | netd->data = net; | |
83 | net_statd->data = net; | |
84 | ||
85 | net->proc_net_root = root; | |
86 | net->proc_net = netd; | |
87 | net->proc_net_stat = net_statd; | |
88 | err = 0; | |
89 | ||
90 | out: | |
91 | return err; | |
92 | free_net: | |
93 | remove_proc_entry("net", root); | |
94 | free_root: | |
95 | kfree(root); | |
96 | goto out; | |
97 | } | |
98 | ||
4665079c | 99 | static __net_exit void proc_net_ns_exit(struct net *net) |
3c12afe7 DM |
100 | { |
101 | remove_proc_entry("stat", net->proc_net); | |
102 | remove_proc_entry("net", net->proc_net_root); | |
103 | kfree(net->proc_net_root); | |
104 | } | |
105 | ||
022cbae6 | 106 | static struct pernet_operations __net_initdata proc_net_ns_ops = { |
3c12afe7 DM |
107 | .init = proc_net_ns_init, |
108 | .exit = proc_net_ns_exit, | |
109 | }; | |
110 | ||
4665079c | 111 | int __init proc_net_init(void) |
3c12afe7 | 112 | { |
2b1e300a EB |
113 | shadow_pde = proc_mkdir("net", NULL); |
114 | shadow_pde->shadow_proc = proc_net_shadow; | |
3c12afe7 DM |
115 | |
116 | return register_pernet_subsys(&proc_net_ns_ops); | |
117 | } |