1
2
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#include <net/netns/core.h>
12#include <net/netns/mib.h>
13#include <net/netns/unix.h>
14#include <net/netns/packet.h>
15#include <net/netns/ipv4.h>
16#include <net/netns/ipv6.h>
17#include <net/netns/dccp.h>
18#include <net/netns/x_tables.h>
19#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
20#include <net/netns/conntrack.h>
21#endif
22#include <net/netns/xfrm.h>
23
24struct proc_dir_entry;
25struct net_device;
26struct sock;
27struct ctl_table_header;
28struct net_generic;
29struct sock;
30
31
32#define NETDEV_HASHBITS 8
33#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
34
35struct net {
36 atomic_t count;
37
38
39#ifdef NETNS_REFCNT_DEBUG
40 atomic_t use_count;
41
42
43#endif
44 spinlock_t rules_mod_lock;
45
46 struct list_head list;
47 struct list_head cleanup_list;
48 struct list_head exit_list;
49
50 struct proc_dir_entry *proc_net;
51 struct proc_dir_entry *proc_net_stat;
52
53#ifdef CONFIG_SYSCTL
54 struct ctl_table_set sysctls;
55#endif
56
57 struct sock *rtnl;
58 struct sock *genl_sock;
59
60 struct list_head dev_base_head;
61 struct hlist_head *dev_name_head;
62 struct hlist_head *dev_index_head;
63
64
65 struct list_head rules_ops;
66
67
68 struct net_device *loopback_dev;
69 struct netns_core core;
70 struct netns_mib mib;
71 struct netns_packet packet;
72 struct netns_unix unx;
73 struct netns_ipv4 ipv4;
74#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
75 struct netns_ipv6 ipv6;
76#endif
77#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
78 struct netns_dccp dccp;
79#endif
80#ifdef CONFIG_NETFILTER
81 struct netns_xt xt;
82#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
83 struct netns_ct ct;
84#endif
85 struct sock *nfnl;
86 struct sock *nfnl_stash;
87#endif
88#ifdef CONFIG_WEXT_CORE
89 struct sk_buff_head wext_nlevents;
90#endif
91 struct net_generic __rcu *gen;
92
93
94#ifdef CONFIG_XFRM
95 struct netns_xfrm xfrm;
96#endif
97};
98
99
100#include <linux/seq_file_net.h>
101
102
103extern struct net init_net;
104
105#ifdef CONFIG_NET
106extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
107
108#else
109static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
110{
111
112 return net_ns;
113}
114#endif
115
116
117extern struct list_head net_namespace_list;
118
119extern struct net *get_net_ns_by_pid(pid_t pid);
120
121#ifdef CONFIG_NET_NS
122extern void __put_net(struct net *net);
123
124static inline struct net *get_net(struct net *net)
125{
126 atomic_inc(&net->count);
127 return net;
128}
129
130static inline struct net *maybe_get_net(struct net *net)
131{
132
133
134
135
136
137 if (!atomic_inc_not_zero(&net->count))
138 net = NULL;
139 return net;
140}
141
142static inline void put_net(struct net *net)
143{
144 if (atomic_dec_and_test(&net->count))
145 __put_net(net);
146}
147
148static inline
149int net_eq(const struct net *net1, const struct net *net2)
150{
151 return net1 == net2;
152}
153#else
154
155static inline struct net *get_net(struct net *net)
156{
157 return net;
158}
159
160static inline void put_net(struct net *net)
161{
162}
163
164static inline struct net *maybe_get_net(struct net *net)
165{
166 return net;
167}
168
169static inline
170int net_eq(const struct net *net1, const struct net *net2)
171{
172 return 1;
173}
174#endif
175
176
177#ifdef NETNS_REFCNT_DEBUG
178static inline struct net *hold_net(struct net *net)
179{
180 if (net)
181 atomic_inc(&net->use_count);
182 return net;
183}
184
185static inline void release_net(struct net *net)
186{
187 if (net)
188 atomic_dec(&net->use_count);
189}
190#else
191static inline struct net *hold_net(struct net *net)
192{
193 return net;
194}
195
196static inline void release_net(struct net *net)
197{
198}
199#endif
200
201#ifdef CONFIG_NET_NS
202
203static inline void write_pnet(struct net **pnet, struct net *net)
204{
205 *pnet = net;
206}
207
208static inline struct net *read_pnet(struct net * const *pnet)
209{
210 return *pnet;
211}
212
213#else
214
215#define write_pnet(pnet, net) do { (void)(net);} while (0)
216#define read_pnet(pnet) (&init_net)
217
218#endif
219
220#define for_each_net(VAR) \
221 list_for_each_entry(VAR, &net_namespace_list, list)
222
223#define for_each_net_rcu(VAR) \
224 list_for_each_entry_rcu(VAR, &net_namespace_list, list)
225
226#ifdef CONFIG_NET_NS
227#define __net_init
228#define __net_exit
229#define __net_initdata
230#else
231#define __net_init __init
232#define __net_exit __exit_refok
233#define __net_initdata __initdata
234#endif
235
236struct pernet_operations {
237 struct list_head list;
238 int (*init)(struct net *net);
239 void (*exit)(struct net *net);
240 void (*exit_batch)(struct list_head *net_exit_list);
241 int *id;
242 size_t size;
243};
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264extern int register_pernet_subsys(struct pernet_operations *);
265extern void unregister_pernet_subsys(struct pernet_operations *);
266extern int register_pernet_device(struct pernet_operations *);
267extern void unregister_pernet_device(struct pernet_operations *);
268
269struct ctl_path;
270struct ctl_table;
271struct ctl_table_header;
272
273extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
274 const struct ctl_path *path, struct ctl_table *table);
275extern struct ctl_table_header *register_net_sysctl_rotable(
276 const struct ctl_path *path, struct ctl_table *table);
277extern void unregister_net_sysctl_table(struct ctl_table_header *header);
278
279#endif
280