Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Operations on the network namespace |
| 3 | */ |
| 4 | #ifndef __NET_NET_NAMESPACE_H |
| 5 | #define __NET_NET_NAMESPACE_H |
| 6 | |
| 7 | #include <asm/atomic.h> |
| 8 | #include <linux/workqueue.h> |
| 9 | #include <linux/list.h> |
| 10 | |
| 11 | struct net { |
| 12 | atomic_t count; /* To decided when the network |
| 13 | * namespace should be freed. |
| 14 | */ |
| 15 | atomic_t use_count; /* To track references we |
| 16 | * destroy on demand |
| 17 | */ |
| 18 | struct list_head list; /* list of network namespaces */ |
| 19 | struct work_struct work; /* work struct for freeing */ |
| 20 | }; |
| 21 | |
| 22 | extern struct net init_net; |
| 23 | extern struct list_head net_namespace_list; |
| 24 | |
| 25 | extern void __put_net(struct net *net); |
| 26 | |
| 27 | static inline struct net *get_net(struct net *net) |
| 28 | { |
| 29 | atomic_inc(&net->count); |
| 30 | return net; |
| 31 | } |
| 32 | |
| 33 | static inline void put_net(struct net *net) |
| 34 | { |
| 35 | if (atomic_dec_and_test(&net->count)) |
| 36 | __put_net(net); |
| 37 | } |
| 38 | |
| 39 | static inline struct net *hold_net(struct net *net) |
| 40 | { |
| 41 | atomic_inc(&net->use_count); |
| 42 | return net; |
| 43 | } |
| 44 | |
| 45 | static inline void release_net(struct net *net) |
| 46 | { |
| 47 | atomic_dec(&net->use_count); |
| 48 | } |
| 49 | |
| 50 | extern void net_lock(void); |
| 51 | extern void net_unlock(void); |
| 52 | |
| 53 | #define for_each_net(VAR) \ |
| 54 | list_for_each_entry(VAR, &net_namespace_list, list) |
| 55 | |
| 56 | |
| 57 | struct pernet_operations { |
| 58 | struct list_head list; |
| 59 | int (*init)(struct net *net); |
| 60 | void (*exit)(struct net *net); |
| 61 | }; |
| 62 | |
| 63 | extern int register_pernet_subsys(struct pernet_operations *); |
| 64 | extern void unregister_pernet_subsys(struct pernet_operations *); |
| 65 | extern int register_pernet_device(struct pernet_operations *); |
| 66 | extern void unregister_pernet_device(struct pernet_operations *); |
| 67 | |
| 68 | #endif /* __NET_NET_NAMESPACE_H */ |