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;
13 atomic_t count; /* To decided when the network
14 * namespace should be freed.
16 atomic_t use_count; /* To track references we
19 struct list_head list; /* list of network namespaces */
20 struct work_struct work; /* work struct for freeing */
22 struct proc_dir_entry *proc_net;
23 struct proc_dir_entry *proc_net_stat;
24 struct proc_dir_entry *proc_net_root;
26 struct list_head dev_base_head;
27 struct hlist_head *dev_name_head;
28 struct hlist_head *dev_index_head;
32 /* Init's network namespace */
33 extern struct net init_net;
34 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
36 #define INIT_NET_NS(net_ns)
39 extern struct list_head net_namespace_list;
42 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
44 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
46 /* There is nothing to copy so this is a noop */
51 extern void __put_net(struct net *net);
53 static inline struct net *get_net(struct net *net)
56 atomic_inc(&net->count);
61 static inline struct net *maybe_get_net(struct net *net)
63 /* Used when we know struct net exists but we
64 * aren't guaranteed a previous reference count
65 * exists. If the reference count is zero this
66 * function fails and returns NULL.
68 if (!atomic_inc_not_zero(&net->count))
73 static inline void put_net(struct net *net)
76 if (atomic_dec_and_test(&net->count))
81 static inline struct net *hold_net(struct net *net)
84 atomic_inc(&net->use_count);
89 static inline void release_net(struct net *net)
92 atomic_dec(&net->use_count);
96 extern void net_lock(void);
97 extern void net_unlock(void);
99 #define for_each_net(VAR) \
100 list_for_each_entry(VAR, &net_namespace_list, list)
103 struct pernet_operations {
104 struct list_head list;
105 int (*init)(struct net *net);
106 void (*exit)(struct net *net);
109 extern int register_pernet_subsys(struct pernet_operations *);
110 extern void unregister_pernet_subsys(struct pernet_operations *);
111 extern int register_pernet_device(struct pernet_operations *);
112 extern void unregister_pernet_device(struct pernet_operations *);
114 #endif /* __NET_NET_NAMESPACE_H */