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 struct proc_dir_entry;
15 atomic_t count; /* To decided when the network
16 * namespace should be freed.
18 atomic_t use_count; /* To track references we
21 struct list_head list; /* list of network namespaces */
22 struct work_struct work; /* work struct for freeing */
24 struct proc_dir_entry *proc_net;
25 struct proc_dir_entry *proc_net_stat;
26 struct proc_dir_entry *proc_net_root;
28 struct net_device *loopback_dev; /* The loopback */
30 struct list_head dev_base_head;
31 struct hlist_head *dev_name_head;
32 struct hlist_head *dev_index_head;
34 struct sock *rtnl; /* rtnetlink socket */
38 /* Init's network namespace */
39 extern struct net init_net;
40 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
42 #define INIT_NET_NS(net_ns)
45 extern struct list_head net_namespace_list;
48 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
50 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
52 /* There is nothing to copy so this is a noop */
58 extern void __put_net(struct net *net);
60 static inline struct net *get_net(struct net *net)
62 atomic_inc(&net->count);
66 static inline struct net *maybe_get_net(struct net *net)
68 /* Used when we know struct net exists but we
69 * aren't guaranteed a previous reference count
70 * exists. If the reference count is zero this
71 * function fails and returns NULL.
73 if (!atomic_inc_not_zero(&net->count))
78 static inline void put_net(struct net *net)
80 if (atomic_dec_and_test(&net->count))
84 static inline struct net *hold_net(struct net *net)
86 atomic_inc(&net->use_count);
90 static inline void release_net(struct net *net)
92 atomic_dec(&net->use_count);
95 static inline struct net *get_net(struct net *net)
100 static inline void put_net(struct net *net)
104 static inline struct net *hold_net(struct net *net)
109 static inline void release_net(struct net *net)
113 static inline struct net *maybe_get_net(struct net *net)
119 #define for_each_net(VAR) \
120 list_for_each_entry(VAR, &net_namespace_list, list)
125 #define __net_initdata
127 #define __net_init __init
128 #define __net_exit __exit_refok
129 #define __net_initdata __initdata
132 struct pernet_operations {
133 struct list_head list;
134 int (*init)(struct net *net);
135 void (*exit)(struct net *net);
138 extern int register_pernet_subsys(struct pernet_operations *);
139 extern void unregister_pernet_subsys(struct pernet_operations *);
140 extern int register_pernet_device(struct pernet_operations *);
141 extern void unregister_pernet_device(struct pernet_operations *);
143 #endif /* __NET_NET_NAMESPACE_H */