Blame view
include/net/net_namespace.h
6.83 KB
5f256becd
|
1 2 3 4 5 |
/* * Operations on the network namespace */ #ifndef __NET_NET_NAMESPACE_H #define __NET_NET_NAMESPACE_H |
60063497a
|
6 |
#include <linux/atomic.h> |
5f256becd
|
7 8 |
#include <linux/workqueue.h> #include <linux/list.h> |
bee95250f
|
9 |
#include <linux/sysctl.h> |
5f256becd
|
10 |
|
8efa6e93c
|
11 |
#include <net/netns/core.h> |
852566f53
|
12 |
#include <net/netns/mib.h> |
a0a53c8ba
|
13 |
#include <net/netns/unix.h> |
2aaef4e47
|
14 |
#include <net/netns/packet.h> |
8afd351c7
|
15 |
#include <net/netns/ipv4.h> |
b0f159db7
|
16 |
#include <net/netns/ipv6.h> |
67019cc9e
|
17 |
#include <net/netns/dccp.h> |
8d8700520
|
18 |
#include <net/netns/x_tables.h> |
dfdb8d791
|
19 20 21 |
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) #include <net/netns/conntrack.h> #endif |
d62ddc21b
|
22 |
#include <net/netns/xfrm.h> |
a0a53c8ba
|
23 |
|
457c4cbc5
|
24 |
struct proc_dir_entry; |
2774c7aba
|
25 |
struct net_device; |
97c53cacf
|
26 |
struct sock; |
1597fbc0f
|
27 |
struct ctl_table_header; |
dec827d17
|
28 |
struct net_generic; |
134e63756
|
29 |
struct sock; |
2553d064f
|
30 |
struct netns_ipvs; |
1597fbc0f
|
31 |
|
7c28bd0b8
|
32 33 34 |
#define NETDEV_HASHBITS 8 #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS) |
5f256becd
|
35 |
struct net { |
a685e0898
|
36 37 38 |
atomic_t passive; /* To decided when the network * namespace should be freed. */ |
5f256becd
|
39 |
atomic_t count; /* To decided when the network |
a685e0898
|
40 |
* namespace should be shut down. |
5f256becd
|
41 |
*/ |
5d1e4468a
|
42 |
#ifdef NETNS_REFCNT_DEBUG |
5f256becd
|
43 44 45 |
atomic_t use_count; /* To track references we * destroy on demand */ |
5d1e4468a
|
46 |
#endif |
8e602ce29
|
47 |
spinlock_t rules_mod_lock; |
5f256becd
|
48 |
struct list_head list; /* list of network namespaces */ |
2b035b399
|
49 |
struct list_head cleanup_list; /* namespaces on death row */ |
72ad937ab
|
50 |
struct list_head exit_list; /* Use only net_mutex */ |
457c4cbc5
|
51 52 53 |
struct proc_dir_entry *proc_net; struct proc_dir_entry *proc_net_stat; |
881d966b4
|
54 |
|
734550921
|
55 56 57 |
#ifdef CONFIG_SYSCTL struct ctl_table_set sysctls; #endif |
95bdfccb2
|
58 |
|
8e602ce29
|
59 60 |
struct sock *rtnl; /* rtnetlink socket */ struct sock *genl_sock; |
2774c7aba
|
61 |
|
881d966b4
|
62 63 64 |
struct list_head dev_base_head; struct hlist_head *dev_name_head; struct hlist_head *dev_index_head; |
4e985adaa
|
65 |
unsigned int dev_base_seq; /* protected by rtnl_mutex */ |
97c53cacf
|
66 |
|
5fd30ee7c
|
67 68 |
/* core fib_rules */ struct list_head rules_ops; |
5fd30ee7c
|
69 |
|
d12d01d6b
|
70 |
|
8e602ce29
|
71 |
struct net_device *loopback_dev; /* The loopback */ |
8efa6e93c
|
72 |
struct netns_core core; |
852566f53
|
73 |
struct netns_mib mib; |
2aaef4e47
|
74 |
struct netns_packet packet; |
a0a53c8ba
|
75 |
struct netns_unix unx; |
8afd351c7
|
76 |
struct netns_ipv4 ipv4; |
dfd56b8b3
|
77 |
#if IS_ENABLED(CONFIG_IPV6) |
b0f159db7
|
78 79 |
struct netns_ipv6 ipv6; #endif |
67019cc9e
|
80 81 82 |
#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) struct netns_dccp dccp; #endif |
8d8700520
|
83 84 |
#ifdef CONFIG_NETFILTER struct netns_xt xt; |
dfdb8d791
|
85 86 87 |
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) struct netns_ct ct; #endif |
cd8c20b65
|
88 89 |
struct sock *nfnl; struct sock *nfnl_stash; |
8d8700520
|
90 |
#endif |
3d23e349d
|
91 |
#ifdef CONFIG_WEXT_CORE |
b333b3d22
|
92 93 |
struct sk_buff_head wext_nlevents; #endif |
1c87733d0
|
94 |
struct net_generic __rcu *gen; |
8e602ce29
|
95 96 97 98 99 |
/* Note : following structs are cache line aligned */ #ifdef CONFIG_XFRM struct netns_xfrm xfrm; #endif |
61b1ab458
|
100 |
struct netns_ipvs *ipvs; |
5f256becd
|
101 |
}; |
225c0a010
|
102 |
|
c0f39322c
|
103 |
#include <linux/seq_file_net.h> |
4fabcd711
|
104 |
/* Init's network namespace */ |
5f256becd
|
105 |
extern struct net init_net; |
a4aa834a9
|
106 107 |
#ifdef CONFIG_NET |
9dd776b6d
|
108 |
extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns); |
225c0a010
|
109 110 |
#else /* CONFIG_NET */ |
9dd776b6d
|
111 112 113 114 115 |
static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) { /* There is nothing to copy so this is a noop */ return net_ns; } |
225c0a010
|
116 117 118 119 |
#endif /* CONFIG_NET */ extern struct list_head net_namespace_list; |
9dd776b6d
|
120 |
|
30ffee848
|
121 |
extern struct net *get_net_ns_by_pid(pid_t pid); |
f06305294
|
122 |
extern struct net *get_net_ns_by_fd(int pid); |
30ffee848
|
123 |
|
d46557955
|
124 |
#ifdef CONFIG_NET_NS |
5f256becd
|
125 126 127 128 129 130 131 |
extern void __put_net(struct net *net); static inline struct net *get_net(struct net *net) { atomic_inc(&net->count); return net; } |
077130c0c
|
132 133 134 135 136 137 138 139 140 141 142 |
static inline struct net *maybe_get_net(struct net *net) { /* Used when we know struct net exists but we * aren't guaranteed a previous reference count * exists. If the reference count is zero this * function fails and returns NULL. */ if (!atomic_inc_not_zero(&net->count)) net = NULL; return net; } |
5f256becd
|
143 144 145 146 147 |
static inline void put_net(struct net *net) { if (atomic_dec_and_test(&net->count)) __put_net(net); } |
878628fbf
|
148 149 150 151 152 |
static inline int net_eq(const struct net *net1, const struct net *net2) { return net1 == net2; } |
a685e0898
|
153 154 |
extern void net_drop_ns(void *); |
d46557955
|
155 |
#else |
b9f75f45a
|
156 |
|
d46557955
|
157 158 159 160 161 162 163 164 |
static inline struct net *get_net(struct net *net) { return net; } static inline void put_net(struct net *net) { } |
5d1e4468a
|
165 166 167 168 169 170 171 172 173 174 |
static inline struct net *maybe_get_net(struct net *net) { return net; } static inline int net_eq(const struct net *net1, const struct net *net2) { return 1; } |
a685e0898
|
175 176 |
#define net_drop_ns NULL |
5d1e4468a
|
177 178 179 180 |
#endif #ifdef NETNS_REFCNT_DEBUG |
d46557955
|
181 182 |
static inline struct net *hold_net(struct net *net) { |
5d1e4468a
|
183 184 |
if (net) atomic_inc(&net->use_count); |
d46557955
|
185 186 187 188 189 |
return net; } static inline void release_net(struct net *net) { |
5d1e4468a
|
190 191 |
if (net) atomic_dec(&net->use_count); |
d46557955
|
192 |
} |
5d1e4468a
|
193 194 |
#else static inline struct net *hold_net(struct net *net) |
d46557955
|
195 196 197 |
{ return net; } |
878628fbf
|
198 |
|
5d1e4468a
|
199 |
static inline void release_net(struct net *net) |
878628fbf
|
200 |
{ |
878628fbf
|
201 |
} |
d46557955
|
202 |
#endif |
5f256becd
|
203 |
|
8f424b5f3
|
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
#ifdef CONFIG_NET_NS static inline void write_pnet(struct net **pnet, struct net *net) { *pnet = net; } static inline struct net *read_pnet(struct net * const *pnet) { return *pnet; } #else #define write_pnet(pnet, net) do { (void)(net);} while (0) #define read_pnet(pnet) (&init_net) #endif |
5d1e4468a
|
222 |
|
5f256becd
|
223 224 |
#define for_each_net(VAR) \ list_for_each_entry(VAR, &net_namespace_list, list) |
11a28d373
|
225 226 |
#define for_each_net_rcu(VAR) \ list_for_each_entry_rcu(VAR, &net_namespace_list, list) |
4665079cb
|
227 228 229 |
#ifdef CONFIG_NET_NS #define __net_init #define __net_exit |
022cbae61
|
230 |
#define __net_initdata |
4665079cb
|
231 232 233 |
#else #define __net_init __init #define __net_exit __exit_refok |
022cbae61
|
234 |
#define __net_initdata __initdata |
4665079cb
|
235 |
#endif |
5f256becd
|
236 237 238 239 240 |
struct pernet_operations { struct list_head list; int (*init)(struct net *net); void (*exit)(struct net *net); |
72ad937ab
|
241 |
void (*exit_batch)(struct list_head *net_exit_list); |
f875bae06
|
242 243 |
int *id; size_t size; |
5f256becd
|
244 |
}; |
17edde520
|
245 246 247 248 249 |
/* * Use these carefully. If you implement a network device and it * needs per network namespace operations use device pernet operations, * otherwise use pernet subsys operations. * |
4edf547b4
|
250 251 252 253 254 255 256 257 258 |
* Network interfaces need to be removed from a dying netns _before_ * subsys notifiers can be called, as most of the network code cleanup * (which is done from subsys notifiers) runs with the assumption that * dev_remove_pack has been called so no new packets will arrive during * and after the cleanup functions have been called. dev_remove_pack * is not per namespace so instead the guarantee of no more packets * arriving in a network namespace is provided by ensuring that all * network devices and all sockets have left the network namespace * before the cleanup methods are called. |
17edde520
|
259 260 261 262 263 |
* * For the longest time the ipv4 icmp code was registered as a pernet * device which caused kernel oops, and panics during network * namespace cleanup. So please don't get this wrong. */ |
5f256becd
|
264 265 266 267 |
extern int register_pernet_subsys(struct pernet_operations *); extern void unregister_pernet_subsys(struct pernet_operations *); extern int register_pernet_device(struct pernet_operations *); extern void unregister_pernet_device(struct pernet_operations *); |
f875bae06
|
268 |
|
95bdfccb2
|
269 270 271 |
struct ctl_path; struct ctl_table; struct ctl_table_header; |
d62c612ef
|
272 |
|
95bdfccb2
|
273 274 |
extern struct ctl_table_header *register_net_sysctl_table(struct net *net, const struct ctl_path *path, struct ctl_table *table); |
d62c612ef
|
275 276 |
extern struct ctl_table_header *register_net_sysctl_rotable( const struct ctl_path *path, struct ctl_table *table); |
95bdfccb2
|
277 |
extern void unregister_net_sysctl_table(struct ctl_table_header *header); |
5f256becd
|
278 |
#endif /* __NET_NET_NAMESPACE_H */ |