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;
14 struct ctl_table_header;
17 atomic_t count; /* To decided when the network
18 * namespace should be freed.
20 atomic_t use_count; /* To track references we
23 struct list_head list; /* list of network namespaces */
24 struct work_struct work; /* work struct for freeing */
26 struct proc_dir_entry *proc_net;
27 struct proc_dir_entry *proc_net_stat;
28 struct proc_dir_entry *proc_net_root;
30 struct list_head sysctl_table_headers;
32 struct net_device *loopback_dev; /* The loopback */
34 struct list_head dev_base_head;
35 struct hlist_head *dev_name_head;
36 struct hlist_head *dev_index_head;
38 struct sock *rtnl; /* rtnetlink socket */
41 struct ctl_table_header *sysctl_core_hdr;
44 /* List of all packet sockets. */
45 rwlock_t packet_sklist_lock;
46 struct hlist_head packet_sklist;
49 int sysctl_unix_max_dgram_qlen;
50 struct ctl_table_header *unix_ctl;
54 /* Init's network namespace */
55 extern struct net init_net;
56 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
58 #define INIT_NET_NS(net_ns)
61 extern struct list_head net_namespace_list;
64 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
66 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
68 /* There is nothing to copy so this is a noop */
74 extern void __put_net(struct net *net);
76 static inline struct net *get_net(struct net *net)
78 atomic_inc(&net->count);
82 static inline struct net *maybe_get_net(struct net *net)
84 /* Used when we know struct net exists but we
85 * aren't guaranteed a previous reference count
86 * exists. If the reference count is zero this
87 * function fails and returns NULL.
89 if (!atomic_inc_not_zero(&net->count))
94 static inline void put_net(struct net *net)
96 if (atomic_dec_and_test(&net->count))
100 static inline struct net *hold_net(struct net *net)
102 atomic_inc(&net->use_count);
106 static inline void release_net(struct net *net)
108 atomic_dec(&net->use_count);
111 static inline struct net *get_net(struct net *net)
116 static inline void put_net(struct net *net)
120 static inline struct net *hold_net(struct net *net)
125 static inline void release_net(struct net *net)
129 static inline struct net *maybe_get_net(struct net *net)
135 #define for_each_net(VAR) \
136 list_for_each_entry(VAR, &net_namespace_list, list)
141 #define __net_initdata
143 #define __net_init __init
144 #define __net_exit __exit_refok
145 #define __net_initdata __initdata
148 struct pernet_operations {
149 struct list_head list;
150 int (*init)(struct net *net);
151 void (*exit)(struct net *net);
154 extern int register_pernet_subsys(struct pernet_operations *);
155 extern void unregister_pernet_subsys(struct pernet_operations *);
156 extern int register_pernet_device(struct pernet_operations *);
157 extern void unregister_pernet_device(struct pernet_operations *);
161 struct ctl_table_header;
162 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
163 const struct ctl_path *path, struct ctl_table *table);
164 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
166 #endif /* __NET_NET_NAMESPACE_H */