2 * Operations on the network namespace
4 #ifndef __NET_NET_NAMESPACE_H
5 #define __NET_NET_NAMESPACE_H
7 #include <asm/atomic.h>
8 #include <linux/workqueue.h>
9 #include <linux/list.h>
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>
23 struct proc_dir_entry
;
26 struct ctl_table_header
;
30 atomic_t count
; /* To decided when the network
31 * namespace should be freed.
33 #ifdef NETNS_REFCNT_DEBUG
34 atomic_t use_count
; /* To track references we
38 struct list_head list
; /* list of network namespaces */
39 struct work_struct work
; /* work struct for freeing */
41 struct proc_dir_entry
*proc_net
;
42 struct proc_dir_entry
*proc_net_stat
;
45 struct ctl_table_set sysctls
;
48 struct net_device
*loopback_dev
; /* The loopback */
50 struct list_head dev_base_head
;
51 struct hlist_head
*dev_name_head
;
52 struct hlist_head
*dev_index_head
;
55 struct list_head rules_ops
;
56 spinlock_t rules_mod_lock
;
58 struct sock
*rtnl
; /* rtnetlink socket */
60 struct netns_core core
;
62 struct netns_packet packet
;
63 struct netns_unix unx
;
64 struct netns_ipv4 ipv4
;
65 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66 struct netns_ipv6 ipv6
;
68 #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
69 struct netns_dccp dccp
;
71 #ifdef CONFIG_NETFILTER
73 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
77 struct net_generic
*gen
;
81 #include <linux/seq_file_net.h>
83 /* Init's network namespace */
84 extern struct net init_net
;
87 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
89 extern struct net
*copy_net_ns(unsigned long flags
, struct net
*net_ns
);
91 #else /* CONFIG_NET */
93 #define INIT_NET_NS(net_ns)
95 static inline struct net
*copy_net_ns(unsigned long flags
, struct net
*net_ns
)
97 /* There is nothing to copy so this is a noop */
100 #endif /* CONFIG_NET */
103 extern struct list_head net_namespace_list
;
106 extern void __put_net(struct net
*net
);
108 static inline int net_alive(struct net
*net
)
110 return net
&& atomic_read(&net
->count
);
113 static inline struct net
*get_net(struct net
*net
)
115 atomic_inc(&net
->count
);
119 static inline struct net
*maybe_get_net(struct net
*net
)
121 /* Used when we know struct net exists but we
122 * aren't guaranteed a previous reference count
123 * exists. If the reference count is zero this
124 * function fails and returns NULL.
126 if (!atomic_inc_not_zero(&net
->count
))
131 static inline void put_net(struct net
*net
)
133 if (atomic_dec_and_test(&net
->count
))
138 int net_eq(const struct net
*net1
, const struct net
*net2
)
144 static inline int net_alive(struct net
*net
)
149 static inline struct net
*get_net(struct net
*net
)
154 static inline void put_net(struct net
*net
)
158 static inline struct net
*maybe_get_net(struct net
*net
)
164 int net_eq(const struct net
*net1
, const struct net
*net2
)
171 #ifdef NETNS_REFCNT_DEBUG
172 static inline struct net
*hold_net(struct net
*net
)
175 atomic_inc(&net
->use_count
);
179 static inline void release_net(struct net
*net
)
182 atomic_dec(&net
->use_count
);
185 static inline struct net
*hold_net(struct net
*net
)
190 static inline void release_net(struct net
*net
)
196 #define for_each_net(VAR) \
197 list_for_each_entry(VAR, &net_namespace_list, list)
202 #define __net_initdata
204 #define __net_init __init
205 #define __net_exit __exit_refok
206 #define __net_initdata __initdata
209 struct pernet_operations
{
210 struct list_head list
;
211 int (*init
)(struct net
*net
);
212 void (*exit
)(struct net
*net
);
215 extern int register_pernet_subsys(struct pernet_operations
*);
216 extern void unregister_pernet_subsys(struct pernet_operations
*);
217 extern int register_pernet_gen_subsys(int *id
, struct pernet_operations
*);
218 extern void unregister_pernet_gen_subsys(int id
, struct pernet_operations
*);
219 extern int register_pernet_device(struct pernet_operations
*);
220 extern void unregister_pernet_device(struct pernet_operations
*);
221 extern int register_pernet_gen_device(int *id
, struct pernet_operations
*);
222 extern void unregister_pernet_gen_device(int id
, struct pernet_operations
*);
226 struct ctl_table_header
;
228 extern struct ctl_table_header
*register_net_sysctl_table(struct net
*net
,
229 const struct ctl_path
*path
, struct ctl_table
*table
);
230 extern struct ctl_table_header
*register_net_sysctl_rotable(
231 const struct ctl_path
*path
, struct ctl_table
*table
);
232 extern void unregister_net_sysctl_table(struct ctl_table_header
*header
);
234 #endif /* __NET_NET_NAMESPACE_H */