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/unix.h>
12 #include <net/netns/packet.h>
13 #include <net/netns/ipv4.h>
14 #include <net/netns/ipv6.h>
16 struct proc_dir_entry;
19 struct ctl_table_header;
22 atomic_t count; /* To decided when the network
23 * namespace should be freed.
25 atomic_t use_count; /* To track references we
28 struct list_head list; /* list of network namespaces */
29 struct work_struct work; /* work struct for freeing */
31 struct proc_dir_entry *proc_net;
32 struct proc_dir_entry *proc_net_stat;
33 struct proc_dir_entry *proc_net_root;
35 struct list_head sysctl_table_headers;
37 struct net_device *loopback_dev; /* The loopback */
39 struct list_head dev_base_head;
40 struct hlist_head *dev_name_head;
41 struct hlist_head *dev_index_head;
43 struct sock *rtnl; /* rtnetlink socket */
46 struct ctl_table_header *sysctl_core_hdr;
49 struct netns_packet packet;
50 struct netns_unix unx;
51 struct netns_ipv4 ipv4;
52 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
53 struct netns_ipv6 ipv6;
58 /* Init's network namespace */
59 extern struct net init_net;
60 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
62 #define INIT_NET_NS(net_ns)
65 extern struct list_head net_namespace_list;
68 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
70 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
72 /* There is nothing to copy so this is a noop */
78 extern void __put_net(struct net *net);
80 static inline struct net *get_net(struct net *net)
82 atomic_inc(&net->count);
86 static inline struct net *maybe_get_net(struct net *net)
88 /* Used when we know struct net exists but we
89 * aren't guaranteed a previous reference count
90 * exists. If the reference count is zero this
91 * function fails and returns NULL.
93 if (!atomic_inc_not_zero(&net->count))
98 static inline void put_net(struct net *net)
100 if (atomic_dec_and_test(&net->count))
104 static inline struct net *hold_net(struct net *net)
106 atomic_inc(&net->use_count);
110 static inline void release_net(struct net *net)
112 atomic_dec(&net->use_count);
115 static inline struct net *get_net(struct net *net)
120 static inline void put_net(struct net *net)
124 static inline struct net *hold_net(struct net *net)
129 static inline void release_net(struct net *net)
133 static inline struct net *maybe_get_net(struct net *net)
139 #define for_each_net(VAR) \
140 list_for_each_entry(VAR, &net_namespace_list, list)
145 #define __net_initdata
147 #define __net_init __init
148 #define __net_exit __exit_refok
149 #define __net_initdata __initdata
152 struct pernet_operations {
153 struct list_head list;
154 int (*init)(struct net *net);
155 void (*exit)(struct net *net);
158 extern int register_pernet_subsys(struct pernet_operations *);
159 extern void unregister_pernet_subsys(struct pernet_operations *);
160 extern int register_pernet_device(struct pernet_operations *);
161 extern void unregister_pernet_device(struct pernet_operations *);
165 struct ctl_table_header;
166 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
167 const struct ctl_path *path, struct ctl_table *table);
168 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
170 #endif /* __NET_NET_NAMESPACE_H */