[NET] sysctl: make the sys.net.core sysctls per-namespace
[cascardo/linux.git] / include / net / net_namespace.h
1 /*
2  * Operations on the network namespace
3  */
4 #ifndef __NET_NET_NAMESPACE_H
5 #define __NET_NET_NAMESPACE_H
6
7 #include <asm/atomic.h>
8 #include <linux/workqueue.h>
9 #include <linux/list.h>
10
11 struct proc_dir_entry;
12 struct net_device;
13 struct sock;
14 struct ctl_table_header;
15
16 struct net {
17         atomic_t                count;          /* To decided when the network
18                                                  *  namespace should be freed.
19                                                  */
20         atomic_t                use_count;      /* To track references we
21                                                  * destroy on demand
22                                                  */
23         struct list_head        list;           /* list of network namespaces */
24         struct work_struct      work;           /* work struct for freeing */
25
26         struct proc_dir_entry   *proc_net;
27         struct proc_dir_entry   *proc_net_stat;
28         struct proc_dir_entry   *proc_net_root;
29
30         struct list_head        sysctl_table_headers;
31
32         struct net_device       *loopback_dev;          /* The loopback */
33
34         struct list_head        dev_base_head;
35         struct hlist_head       *dev_name_head;
36         struct hlist_head       *dev_index_head;
37
38         struct sock             *rtnl;                  /* rtnetlink socket */
39
40         /* core sysctls */
41         struct ctl_table_header *sysctl_core_hdr;
42
43         /* List of all packet sockets. */
44         rwlock_t                packet_sklist_lock;
45         struct hlist_head       packet_sklist;
46
47         /* unix sockets */
48         int                     sysctl_unix_max_dgram_qlen;
49         struct ctl_table_header *unix_ctl;
50 };
51
52 #ifdef CONFIG_NET
53 /* Init's network namespace */
54 extern struct net init_net;
55 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
56 #else
57 #define INIT_NET_NS(net_ns)
58 #endif
59
60 extern struct list_head net_namespace_list;
61
62 #ifdef CONFIG_NET
63 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
64 #else
65 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
66 {
67         /* There is nothing to copy so this is a noop */
68         return net_ns;
69 }
70 #endif
71
72 #ifdef CONFIG_NET_NS
73 extern void __put_net(struct net *net);
74
75 static inline struct net *get_net(struct net *net)
76 {
77         atomic_inc(&net->count);
78         return net;
79 }
80
81 static inline struct net *maybe_get_net(struct net *net)
82 {
83         /* Used when we know struct net exists but we
84          * aren't guaranteed a previous reference count
85          * exists.  If the reference count is zero this
86          * function fails and returns NULL.
87          */
88         if (!atomic_inc_not_zero(&net->count))
89                 net = NULL;
90         return net;
91 }
92
93 static inline void put_net(struct net *net)
94 {
95         if (atomic_dec_and_test(&net->count))
96                 __put_net(net);
97 }
98
99 static inline struct net *hold_net(struct net *net)
100 {
101         atomic_inc(&net->use_count);
102         return net;
103 }
104
105 static inline void release_net(struct net *net)
106 {
107         atomic_dec(&net->use_count);
108 }
109 #else
110 static inline struct net *get_net(struct net *net)
111 {
112         return net;
113 }
114
115 static inline void put_net(struct net *net)
116 {
117 }
118
119 static inline struct net *hold_net(struct net *net)
120 {
121         return net;
122 }
123
124 static inline void release_net(struct net *net)
125 {
126 }
127
128 static inline struct net *maybe_get_net(struct net *net)
129 {
130         return net;
131 }
132 #endif
133
134 #define for_each_net(VAR)                               \
135         list_for_each_entry(VAR, &net_namespace_list, list)
136
137 #ifdef CONFIG_NET_NS
138 #define __net_init
139 #define __net_exit
140 #define __net_initdata
141 #else
142 #define __net_init      __init
143 #define __net_exit      __exit_refok
144 #define __net_initdata  __initdata
145 #endif
146
147 struct pernet_operations {
148         struct list_head list;
149         int (*init)(struct net *net);
150         void (*exit)(struct net *net);
151 };
152
153 extern int register_pernet_subsys(struct pernet_operations *);
154 extern void unregister_pernet_subsys(struct pernet_operations *);
155 extern int register_pernet_device(struct pernet_operations *);
156 extern void unregister_pernet_device(struct pernet_operations *);
157
158 struct ctl_path;
159 struct ctl_table;
160 struct ctl_table_header;
161 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
162         const struct ctl_path *path, struct ctl_table *table);
163 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
164
165 #endif /* __NET_NET_NAMESPACE_H */