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 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 11 | struct proc_dir_entry; |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 12 | struct net { |
| 13 | atomic_t count; /* To decided when the network |
| 14 | * namespace should be freed. |
| 15 | */ |
| 16 | atomic_t use_count; /* To track references we |
| 17 | * destroy on demand |
| 18 | */ |
| 19 | struct list_head list; /* list of network namespaces */ |
| 20 | struct work_struct work; /* work struct for freeing */ |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 21 | |
| 22 | struct proc_dir_entry *proc_net; |
| 23 | struct proc_dir_entry *proc_net_stat; |
| 24 | struct proc_dir_entry *proc_net_root; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 25 | |
| 26 | struct list_head dev_base_head; |
| 27 | struct hlist_head *dev_name_head; |
| 28 | struct hlist_head *dev_index_head; |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
Daniel Lezcano | 4fabcd7 | 2007-09-13 09:16:29 +0200 | [diff] [blame^] | 31 | #ifdef CONFIG_NET |
| 32 | /* Init's network namespace */ |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 33 | extern struct net init_net; |
Daniel Lezcano | 4fabcd7 | 2007-09-13 09:16:29 +0200 | [diff] [blame^] | 34 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
| 35 | #else |
| 36 | #define INIT_NET_NS(net_ns) |
| 37 | #endif |
| 38 | |
Eric W. Biederman | 5f256be | 2007-09-12 11:50:50 +0200 | [diff] [blame] | 39 | extern struct list_head net_namespace_list; |
| 40 | |
| 41 | extern void __put_net(struct net *net); |
| 42 | |
| 43 | static inline struct net *get_net(struct net *net) |
| 44 | { |
| 45 | atomic_inc(&net->count); |
| 46 | return net; |
| 47 | } |
| 48 | |
| 49 | static inline void put_net(struct net *net) |
| 50 | { |
| 51 | if (atomic_dec_and_test(&net->count)) |
| 52 | __put_net(net); |
| 53 | } |
| 54 | |
| 55 | static inline struct net *hold_net(struct net *net) |
| 56 | { |
| 57 | atomic_inc(&net->use_count); |
| 58 | return net; |
| 59 | } |
| 60 | |
| 61 | static inline void release_net(struct net *net) |
| 62 | { |
| 63 | atomic_dec(&net->use_count); |
| 64 | } |
| 65 | |
| 66 | extern void net_lock(void); |
| 67 | extern void net_unlock(void); |
| 68 | |
| 69 | #define for_each_net(VAR) \ |
| 70 | list_for_each_entry(VAR, &net_namespace_list, list) |
| 71 | |
| 72 | |
| 73 | struct pernet_operations { |
| 74 | struct list_head list; |
| 75 | int (*init)(struct net *net); |
| 76 | void (*exit)(struct net *net); |
| 77 | }; |
| 78 | |
| 79 | extern int register_pernet_subsys(struct pernet_operations *); |
| 80 | extern void unregister_pernet_subsys(struct pernet_operations *); |
| 81 | extern int register_pernet_device(struct pernet_operations *); |
| 82 | extern void unregister_pernet_device(struct pernet_operations *); |
| 83 | |
| 84 | #endif /* __NET_NET_NAMESPACE_H */ |