Commit | Line | Data |
---|---|---|
5f256bec EB |
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 | ||
457c4cbc | 11 | struct proc_dir_entry; |
2774c7ab | 12 | struct net_device; |
5f256bec EB |
13 | struct net { |
14 | atomic_t count; /* To decided when the network | |
15 | * namespace should be freed. | |
16 | */ | |
17 | atomic_t use_count; /* To track references we | |
18 | * destroy on demand | |
19 | */ | |
20 | struct list_head list; /* list of network namespaces */ | |
21 | struct work_struct work; /* work struct for freeing */ | |
457c4cbc EB |
22 | |
23 | struct proc_dir_entry *proc_net; | |
24 | struct proc_dir_entry *proc_net_stat; | |
25 | struct proc_dir_entry *proc_net_root; | |
881d966b | 26 | |
2774c7ab EB |
27 | struct net_device *loopback_dev; /* The loopback */ |
28 | ||
881d966b EB |
29 | struct list_head dev_base_head; |
30 | struct hlist_head *dev_name_head; | |
31 | struct hlist_head *dev_index_head; | |
5f256bec EB |
32 | }; |
33 | ||
4fabcd71 DL |
34 | #ifdef CONFIG_NET |
35 | /* Init's network namespace */ | |
5f256bec | 36 | extern struct net init_net; |
4fabcd71 DL |
37 | #define INIT_NET_NS(net_ns) .net_ns = &init_net, |
38 | #else | |
39 | #define INIT_NET_NS(net_ns) | |
40 | #endif | |
41 | ||
5f256bec EB |
42 | extern struct list_head net_namespace_list; |
43 | ||
9dd776b6 EB |
44 | #ifdef CONFIG_NET |
45 | extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); | |
46 | #else | |
47 | static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) | |
48 | { | |
49 | /* There is nothing to copy so this is a noop */ | |
50 | return net_ns; | |
51 | } | |
52 | #endif | |
53 | ||
5f256bec EB |
54 | extern void __put_net(struct net *net); |
55 | ||
56 | static inline struct net *get_net(struct net *net) | |
57 | { | |
9dd776b6 | 58 | #ifdef CONFIG_NET |
5f256bec | 59 | atomic_inc(&net->count); |
9dd776b6 | 60 | #endif |
5f256bec EB |
61 | return net; |
62 | } | |
63 | ||
077130c0 EB |
64 | static inline struct net *maybe_get_net(struct net *net) |
65 | { | |
66 | /* Used when we know struct net exists but we | |
67 | * aren't guaranteed a previous reference count | |
68 | * exists. If the reference count is zero this | |
69 | * function fails and returns NULL. | |
70 | */ | |
71 | if (!atomic_inc_not_zero(&net->count)) | |
72 | net = NULL; | |
73 | return net; | |
74 | } | |
75 | ||
5f256bec EB |
76 | static inline void put_net(struct net *net) |
77 | { | |
9dd776b6 | 78 | #ifdef CONFIG_NET |
5f256bec EB |
79 | if (atomic_dec_and_test(&net->count)) |
80 | __put_net(net); | |
9dd776b6 | 81 | #endif |
5f256bec EB |
82 | } |
83 | ||
84 | static inline struct net *hold_net(struct net *net) | |
85 | { | |
9dd776b6 | 86 | #ifdef CONFIG_NET |
5f256bec | 87 | atomic_inc(&net->use_count); |
9dd776b6 | 88 | #endif |
5f256bec EB |
89 | return net; |
90 | } | |
91 | ||
92 | static inline void release_net(struct net *net) | |
93 | { | |
9dd776b6 | 94 | #ifdef CONFIG_NET |
5f256bec | 95 | atomic_dec(&net->use_count); |
9dd776b6 | 96 | #endif |
5f256bec EB |
97 | } |
98 | ||
5f256bec EB |
99 | #define for_each_net(VAR) \ |
100 | list_for_each_entry(VAR, &net_namespace_list, list) | |
101 | ||
102 | ||
103 | struct pernet_operations { | |
104 | struct list_head list; | |
105 | int (*init)(struct net *net); | |
106 | void (*exit)(struct net *net); | |
107 | }; | |
108 | ||
109 | extern int register_pernet_subsys(struct pernet_operations *); | |
110 | extern void unregister_pernet_subsys(struct pernet_operations *); | |
111 | extern int register_pernet_device(struct pernet_operations *); | |
112 | extern void unregister_pernet_device(struct pernet_operations *); | |
113 | ||
114 | #endif /* __NET_NET_NAMESPACE_H */ |