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 list_head sysctl_table_headers;
30 struct net_device *loopback_dev; /* The loopback */
32 struct list_head dev_base_head;
33 struct hlist_head *dev_name_head;
34 struct hlist_head *dev_index_head;
36 struct sock *rtnl; /* rtnetlink socket */
38 /* List of all packet sockets. */
39 rwlock_t packet_sklist_lock;
40 struct hlist_head packet_sklist;
43 int sysctl_unix_max_dgram_qlen;
47 /* Init's network namespace */
48 extern struct net init_net;
49 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
51 #define INIT_NET_NS(net_ns)
54 extern struct list_head net_namespace_list;
57 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
59 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
61 /* There is nothing to copy so this is a noop */
67 extern void __put_net(struct net *net);
69 static inline struct net *get_net(struct net *net)
71 atomic_inc(&net->count);
75 static inline struct net *maybe_get_net(struct net *net)
77 /* Used when we know struct net exists but we
78 * aren't guaranteed a previous reference count
79 * exists. If the reference count is zero this
80 * function fails and returns NULL.
82 if (!atomic_inc_not_zero(&net->count))
87 static inline void put_net(struct net *net)
89 if (atomic_dec_and_test(&net->count))
93 static inline struct net *hold_net(struct net *net)
95 atomic_inc(&net->use_count);
99 static inline void release_net(struct net *net)
101 atomic_dec(&net->use_count);
104 static inline struct net *get_net(struct net *net)
109 static inline void put_net(struct net *net)
113 static inline struct net *hold_net(struct net *net)
118 static inline void release_net(struct net *net)
122 static inline struct net *maybe_get_net(struct net *net)
128 #define for_each_net(VAR) \
129 list_for_each_entry(VAR, &net_namespace_list, list)
134 #define __net_initdata
136 #define __net_init __init
137 #define __net_exit __exit_refok
138 #define __net_initdata __initdata
141 struct pernet_operations {
142 struct list_head list;
143 int (*init)(struct net *net);
144 void (*exit)(struct net *net);
147 extern int register_pernet_subsys(struct pernet_operations *);
148 extern void unregister_pernet_subsys(struct pernet_operations *);
149 extern int register_pernet_device(struct pernet_operations *);
150 extern void unregister_pernet_device(struct pernet_operations *);
154 struct ctl_table_header;
155 extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
156 const struct ctl_path *path, struct ctl_table *table);
157 extern void unregister_net_sysctl_table(struct ctl_table_header *header);
159 #endif /* __NET_NET_NAMESPACE_H */