Blame view

include/net/net_namespace.h 6.83 KB
5f256becd   Eric W. Biederman   [NET]: Basic netw...
1
2
3
4
5
  /*
   * Operations on the network namespace
   */
  #ifndef __NET_NET_NAMESPACE_H
  #define __NET_NET_NAMESPACE_H
60063497a   Arun Sharma   atomic: use <linu...
6
  #include <linux/atomic.h>
5f256becd   Eric W. Biederman   [NET]: Basic netw...
7
8
  #include <linux/workqueue.h>
  #include <linux/list.h>
bee95250f   David S. Miller   net: Add linux/sy...
9
  #include <linux/sysctl.h>
5f256becd   Eric W. Biederman   [NET]: Basic netw...
10

8efa6e93c   Pavel Emelyanov   [NETNS]: Introduc...
11
  #include <net/netns/core.h>
852566f53   Pavel Emelyanov   mib: add netns/mi...
12
  #include <net/netns/mib.h>
a0a53c8ba   Denis V. Lunev   [NETNS]: struct n...
13
  #include <net/netns/unix.h>
2aaef4e47   Denis V. Lunev   [NETNS]: separate...
14
  #include <net/netns/packet.h>
8afd351c7   Pavel Emelyanov   [NETNS]: Add the ...
15
  #include <net/netns/ipv4.h>
b0f159db7   Daniel Lezcano   [NETNS][IPV6]: Ad...
16
  #include <net/netns/ipv6.h>
67019cc9e   Pavel Emelyanov   [NETNS]: Add an e...
17
  #include <net/netns/dccp.h>
8d8700520   Alexey Dobriyan   [NETFILTER]: x_ta...
18
  #include <net/netns/x_tables.h>
dfdb8d791   Alexey Dobriyan   netfilter: netns ...
19
20
21
  #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  #include <net/netns/conntrack.h>
  #endif
d62ddc21b   Alexey Dobriyan   netns xfrm: add n...
22
  #include <net/netns/xfrm.h>
a0a53c8ba   Denis V. Lunev   [NETNS]: struct n...
23

457c4cbc5   Eric W. Biederman   [NET]: Make /proc...
24
  struct proc_dir_entry;
2774c7aba   Eric W. Biederman   [NET]: Make the l...
25
  struct net_device;
97c53cacf   Denis V. Lunev   [NET]: Make rtnet...
26
  struct sock;
1597fbc0f   Pavel Emelyanov   [UNIX]: Make the ...
27
  struct ctl_table_header;
dec827d17   Pavel Emelyanov   [NETNS]: The gene...
28
  struct net_generic;
134e63756   Johannes Berg   genetlink: make n...
29
  struct sock;
2553d064f   Julian Anastasov   ipvs: move struct...
30
  struct netns_ipvs;
1597fbc0f   Pavel Emelyanov   [UNIX]: Make the ...
31

7c28bd0b8   Eric Dumazet   rtnetlink: speedu...
32
33
34
  
  #define NETDEV_HASHBITS    8
  #define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
5f256becd   Eric W. Biederman   [NET]: Basic netw...
35
  struct net {
a685e0898   Al Viro   Delay struct net ...
36
37
38
  	atomic_t		passive;	/* To decided when the network
  						 * namespace should be freed.
  						 */
5f256becd   Eric W. Biederman   [NET]: Basic netw...
39
  	atomic_t		count;		/* To decided when the network
a685e0898   Al Viro   Delay struct net ...
40
  						 *  namespace should be shut down.
5f256becd   Eric W. Biederman   [NET]: Basic netw...
41
  						 */
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
42
  #ifdef NETNS_REFCNT_DEBUG
5f256becd   Eric W. Biederman   [NET]: Basic netw...
43
44
45
  	atomic_t		use_count;	/* To track references we
  						 * destroy on demand
  						 */
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
46
  #endif
8e602ce29   Eric Dumazet   netns: reorder fi...
47
  	spinlock_t		rules_mod_lock;
5f256becd   Eric W. Biederman   [NET]: Basic netw...
48
  	struct list_head	list;		/* list of network namespaces */
2b035b399   Eric W. Biederman   net: Batch networ...
49
  	struct list_head	cleanup_list;	/* namespaces on death row */
72ad937ab   Eric W. Biederman   net: Add support ...
50
  	struct list_head	exit_list;	/* Use only net_mutex */
457c4cbc5   Eric W. Biederman   [NET]: Make /proc...
51
52
53
  
  	struct proc_dir_entry 	*proc_net;
  	struct proc_dir_entry 	*proc_net_stat;
881d966b4   Eric W. Biederman   [NET]: Make the d...
54

734550921   Al Viro   [PATCH] beginning...
55
56
57
  #ifdef CONFIG_SYSCTL
  	struct ctl_table_set	sysctls;
  #endif
95bdfccb2   Eric W. Biederman   [NET]: Implement ...
58

8e602ce29   Eric Dumazet   netns: reorder fi...
59
60
  	struct sock 		*rtnl;			/* rtnetlink socket */
  	struct sock		*genl_sock;
2774c7aba   Eric W. Biederman   [NET]: Make the l...
61

881d966b4   Eric W. Biederman   [NET]: Make the d...
62
63
64
  	struct list_head 	dev_base_head;
  	struct hlist_head 	*dev_name_head;
  	struct hlist_head	*dev_index_head;
4e985adaa   Thomas Graf   rtnl: provide lin...
65
  	unsigned int		dev_base_seq;	/* protected by rtnl_mutex */
97c53cacf   Denis V. Lunev   [NET]: Make rtnet...
66

5fd30ee7c   Denis V. Lunev   [NETNS]: Namespac...
67
68
  	/* core fib_rules */
  	struct list_head	rules_ops;
5fd30ee7c   Denis V. Lunev   [NETNS]: Namespac...
69

d12d01d6b   Denis V. Lunev   [NET]: Make AF_PA...
70

8e602ce29   Eric Dumazet   netns: reorder fi...
71
  	struct net_device       *loopback_dev;          /* The loopback */
8efa6e93c   Pavel Emelyanov   [NETNS]: Introduc...
72
  	struct netns_core	core;
852566f53   Pavel Emelyanov   mib: add netns/mi...
73
  	struct netns_mib	mib;
2aaef4e47   Denis V. Lunev   [NETNS]: separate...
74
  	struct netns_packet	packet;
a0a53c8ba   Denis V. Lunev   [NETNS]: struct n...
75
  	struct netns_unix	unx;
8afd351c7   Pavel Emelyanov   [NETNS]: Add the ...
76
  	struct netns_ipv4	ipv4;
dfd56b8b3   Eric Dumazet   net: use IS_ENABL...
77
  #if IS_ENABLED(CONFIG_IPV6)
b0f159db7   Daniel Lezcano   [NETNS][IPV6]: Ad...
78
79
  	struct netns_ipv6	ipv6;
  #endif
67019cc9e   Pavel Emelyanov   [NETNS]: Add an e...
80
81
82
  #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
  	struct netns_dccp	dccp;
  #endif
8d8700520   Alexey Dobriyan   [NETFILTER]: x_ta...
83
84
  #ifdef CONFIG_NETFILTER
  	struct netns_xt		xt;
dfdb8d791   Alexey Dobriyan   netfilter: netns ...
85
86
87
  #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  	struct netns_ct		ct;
  #endif
cd8c20b65   Alexey Dobriyan   netfilter: nfnetl...
88
89
  	struct sock		*nfnl;
  	struct sock		*nfnl_stash;
8d8700520   Alexey Dobriyan   [NETFILTER]: x_ta...
90
  #endif
3d23e349d   Johannes Berg   wext: refactor
91
  #ifdef CONFIG_WEXT_CORE
b333b3d22   Johannes Berg   wireless extensio...
92
93
  	struct sk_buff_head	wext_nlevents;
  #endif
1c87733d0   Eric Dumazet   net_ns: add __rcu...
94
  	struct net_generic __rcu	*gen;
8e602ce29   Eric Dumazet   netns: reorder fi...
95
96
97
98
99
  
  	/* Note : following structs are cache line aligned */
  #ifdef CONFIG_XFRM
  	struct netns_xfrm	xfrm;
  #endif
61b1ab458   Hans Schillstrom   IPVS: netns, add ...
100
  	struct netns_ipvs	*ipvs;
5f256becd   Eric W. Biederman   [NET]: Basic netw...
101
  };
225c0a010   Denis V. Lunev   [NETNS]: Merge if...
102

c0f39322c   Denis V. Lunev   [NETNS]: Do not i...
103
  #include <linux/seq_file_net.h>
4fabcd711   Daniel Lezcano   [NETNS]: Fix alln...
104
  /* Init's network namespace */
5f256becd   Eric W. Biederman   [NET]: Basic netw...
105
  extern struct net init_net;
a4aa834a9   Denis V. Lunev   [NETNS]: Declare ...
106
107
  
  #ifdef CONFIG_NET
9dd776b6d   Eric W. Biederman   [NET]: Add networ...
108
  extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
225c0a010   Denis V. Lunev   [NETNS]: Merge if...
109
110
  
  #else /* CONFIG_NET */
9dd776b6d   Eric W. Biederman   [NET]: Add networ...
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   Denis V. Lunev   [NETNS]: Merge if...
116
117
118
119
  #endif /* CONFIG_NET */
  
  
  extern struct list_head net_namespace_list;
9dd776b6d   Eric W. Biederman   [NET]: Add networ...
120

30ffee848   Johannes Berg   net: move and exp...
121
  extern struct net *get_net_ns_by_pid(pid_t pid);
f06305294   Eric W. Biederman   net: Allow settin...
122
  extern struct net *get_net_ns_by_fd(int pid);
30ffee848   Johannes Berg   net: move and exp...
123

d46557955   Pavel Emelyanov   [NET]: Relax the ...
124
  #ifdef CONFIG_NET_NS
5f256becd   Eric W. Biederman   [NET]: Basic netw...
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   Eric W. Biederman   [NET]: Fix race w...
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   Eric W. Biederman   [NET]: Basic netw...
143
144
145
146
147
  static inline void put_net(struct net *net)
  {
  	if (atomic_dec_and_test(&net->count))
  		__put_net(net);
  }
878628fbf   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
148
149
150
151
152
  static inline
  int net_eq(const struct net *net1, const struct net *net2)
  {
  	return net1 == net2;
  }
a685e0898   Al Viro   Delay struct net ...
153
154
  
  extern void net_drop_ns(void *);
d46557955   Pavel Emelyanov   [NET]: Relax the ...
155
  #else
b9f75f45a   Eric W. Biederman   netns: Don't rece...
156

d46557955   Pavel Emelyanov   [NET]: Relax the ...
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   Denis V. Lunev   [NETNS]: Make net...
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   Al Viro   Delay struct net ...
175
176
  
  #define net_drop_ns NULL
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
177
178
179
180
  #endif
  
  
  #ifdef NETNS_REFCNT_DEBUG
d46557955   Pavel Emelyanov   [NET]: Relax the ...
181
182
  static inline struct net *hold_net(struct net *net)
  {
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
183
184
  	if (net)
  		atomic_inc(&net->use_count);
d46557955   Pavel Emelyanov   [NET]: Relax the ...
185
186
187
188
189
  	return net;
  }
  
  static inline void release_net(struct net *net)
  {
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
190
191
  	if (net)
  		atomic_dec(&net->use_count);
d46557955   Pavel Emelyanov   [NET]: Relax the ...
192
  }
5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
193
194
  #else
  static inline struct net *hold_net(struct net *net)
d46557955   Pavel Emelyanov   [NET]: Relax the ...
195
196
197
  {
  	return net;
  }
878628fbf   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
198

5d1e4468a   Denis V. Lunev   [NETNS]: Make net...
199
  static inline void release_net(struct net *net)
878628fbf   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
200
  {
878628fbf   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
201
  }
d46557955   Pavel Emelyanov   [NET]: Relax the ...
202
  #endif
5f256becd   Eric W. Biederman   [NET]: Basic netw...
203

8f424b5f3   Eric Dumazet   net: Introduce re...
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   Denis V. Lunev   [NETNS]: Make net...
222

5f256becd   Eric W. Biederman   [NET]: Basic netw...
223
224
  #define for_each_net(VAR)				\
  	list_for_each_entry(VAR, &net_namespace_list, list)
11a28d373   Johannes Berg   net: make namespa...
225
226
  #define for_each_net_rcu(VAR)				\
  	list_for_each_entry_rcu(VAR, &net_namespace_list, list)
4665079cb   Pavel Emelyanov   [NETNS]: Move som...
227
228
229
  #ifdef CONFIG_NET_NS
  #define __net_init
  #define __net_exit
022cbae61   Denis V. Lunev   [NET]: Move unnee...
230
  #define __net_initdata
4665079cb   Pavel Emelyanov   [NETNS]: Move som...
231
232
233
  #else
  #define __net_init	__init
  #define __net_exit	__exit_refok
022cbae61   Denis V. Lunev   [NET]: Move unnee...
234
  #define __net_initdata	__initdata
4665079cb   Pavel Emelyanov   [NETNS]: Move som...
235
  #endif
5f256becd   Eric W. Biederman   [NET]: Basic netw...
236
237
238
239
240
  
  struct pernet_operations {
  	struct list_head list;
  	int (*init)(struct net *net);
  	void (*exit)(struct net *net);
72ad937ab   Eric W. Biederman   net: Add support ...
241
  	void (*exit_batch)(struct list_head *net_exit_list);
f875bae06   Eric W. Biederman   net: Automaticall...
242
243
  	int *id;
  	size_t size;
5f256becd   Eric W. Biederman   [NET]: Basic netw...
244
  };
17edde520   Eric W. Biederman   netns: Remove net...
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   Johannes Berg   net: explain netn...
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   Eric W. Biederman   netns: Remove net...
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   Eric W. Biederman   [NET]: Basic netw...
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   Eric W. Biederman   net: Automaticall...
268

95bdfccb2   Eric W. Biederman   [NET]: Implement ...
269
270
271
  struct ctl_path;
  struct ctl_table;
  struct ctl_table_header;
d62c612ef   Pavel Emelyanov   netns: Introduce ...
272

95bdfccb2   Eric W. Biederman   [NET]: Implement ...
273
274
  extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
  	const struct ctl_path *path, struct ctl_table *table);
d62c612ef   Pavel Emelyanov   netns: Introduce ...
275
276
  extern struct ctl_table_header *register_net_sysctl_rotable(
  	const struct ctl_path *path, struct ctl_table *table);
95bdfccb2   Eric W. Biederman   [NET]: Implement ...
277
  extern void unregister_net_sysctl_table(struct ctl_table_header *header);
5f256becd   Eric W. Biederman   [NET]: Basic netw...
278
  #endif /* __NET_NET_NAMESPACE_H */