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 atomic_t count
; /* To decided when the network
15 * namespace should be freed.
17 atomic_t use_count
; /* To track references we
20 struct list_head list
; /* list of network namespaces */
21 struct work_struct work
; /* work struct for freeing */
23 struct proc_dir_entry
*proc_net
;
24 struct proc_dir_entry
*proc_net_stat
;
25 struct proc_dir_entry
*proc_net_root
;
27 struct net_device
*loopback_dev
; /* The loopback */
29 struct list_head dev_base_head
;
30 struct hlist_head
*dev_name_head
;
31 struct hlist_head
*dev_index_head
;
35 /* Init's network namespace */
36 extern struct net init_net
;
37 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
39 #define INIT_NET_NS(net_ns)
42 extern struct list_head net_namespace_list
;
45 extern struct net
*copy_net_ns(unsigned long flags
, struct net
*net_ns
);
47 static inline struct net
*copy_net_ns(unsigned long flags
, struct net
*net_ns
)
49 /* There is nothing to copy so this is a noop */
55 extern void __put_net(struct net
*net
);
57 static inline struct net
*get_net(struct net
*net
)
59 atomic_inc(&net
->count
);
63 static inline struct net
*maybe_get_net(struct net
*net
)
65 /* Used when we know struct net exists but we
66 * aren't guaranteed a previous reference count
67 * exists. If the reference count is zero this
68 * function fails and returns NULL.
70 if (!atomic_inc_not_zero(&net
->count
))
75 static inline void put_net(struct net
*net
)
77 if (atomic_dec_and_test(&net
->count
))
81 static inline struct net
*hold_net(struct net
*net
)
83 atomic_inc(&net
->use_count
);
87 static inline void release_net(struct net
*net
)
89 atomic_dec(&net
->use_count
);
92 static inline struct net
*get_net(struct net
*net
)
97 static inline void put_net(struct net
*net
)
101 static inline struct net
*hold_net(struct net
*net
)
106 static inline void release_net(struct net
*net
)
110 static inline struct net
*maybe_get_net(struct net
*net
)
116 #define for_each_net(VAR) \
117 list_for_each_entry(VAR, &net_namespace_list, list)
122 #define __net_initdata
124 #define __net_init __init
125 #define __net_exit __exit_refok
126 #define __net_initdata __initdata
129 struct pernet_operations
{
130 struct list_head list
;
131 int (*init
)(struct net
*net
);
132 void (*exit
)(struct net
*net
);
135 extern int register_pernet_subsys(struct pernet_operations
*);
136 extern void unregister_pernet_subsys(struct pernet_operations
*);
137 extern int register_pernet_device(struct pernet_operations
*);
138 extern void unregister_pernet_device(struct pernet_operations
*);
140 #endif /* __NET_NET_NAMESPACE_H */