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>
14 struct proc_dir_entry;
17 struct ctl_table_header;
20 atomic_t count; /* To decided when the network
21 * namespace should be freed.
23 atomic_t use_count; /* To track references we
26 struct list_head list; /* list of network namespaces */
27 struct work_struct work; /* work struct for freeing */
29 struct proc_dir_entry *proc_net;
30 struct proc_dir_entry *proc_net_stat;
31 struct proc_dir_entry *proc_net_root;
33 struct list_head sysctl_table_headers;
35 struct net_device *loopback_dev; /* The loopback */
37 struct list_head dev_base_head;
38 struct hlist_head *dev_name_head;
39 struct hlist_head *dev_index_head;
41 struct sock *rtnl; /* rtnetlink socket */
44 struct ctl_table_header *sysctl_core_hdr;
47 struct netns_packet packet;
48 struct netns_unix unx;
52 /* Init's network namespace */
53 extern struct net init_net;
54 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
56 #define INIT_NET_NS(net_ns)
59 extern struct list_head net_namespace_list;
62 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
64 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
66 /* There is nothing to copy so this is a noop */
72 extern void __put_net(struct net *net);
74 static inline struct net *get_net(struct net *net)
76 atomic_inc(&net->count);
80 static inline struct net *maybe_get_net(struct net *net)
82 /* Used when we know struct net exists but we
83 * aren't guaranteed a previous reference count
84 * exists. If the reference count is zero this
85 * function fails and returns NULL.
87 if (!atomic_inc_not_zero(&net->count))
92 static inline void put_net(struct net *net)
94 if (atomic_dec_and_test(&net->count))
98 static inline struct net *hold_net(struct net *net)
100 atomic_inc(&net->use_count);
104 static inline void release_net(struct net *net)
106 atomic_dec(&net->use_count);
109 static inline struct net *get_net(struct net *net)
114 static inline void put_net(struct net *net)
118 static inline struct net *hold_net(struct net *net)
123 static inline void release_net(struct net *net)
127 static inline struct net *maybe_get_net(struct net *net)
133 #define for_each_net(VAR) \
134 list_for_each_entry(VAR, &net_namespace_list, list)
139 #define __net_initdata
141 #define __net_init __init
142 #define __net_exit __exit_refok
143 #define __net_initdata __initdata
146 struct pernet_operations {
147 struct list_head list;
148 int (*init)(struct net *net);
149 void (*exit)(struct net *net);
152 extern int register_pernet_subsys(struct pernet_operations *);
153 extern void unregister_pernet_subsys(struct pernet_operations *);
154 extern int register_pernet_device(struct pernet_operations *);
155 extern void unregister_pernet_device(struct pernet_operations *);
159 struct ctl_table_header;
160 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
161 const struct ctl_path *path, struct ctl_table *table);
162 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
164 #endif /* __NET_NET_NAMESPACE_H */