]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/net/net_namespace.h
net: de4x5: Omit check for multicast bit in netdev_for_each_mc_addr
[mirror_ubuntu-artful-kernel.git] / include / net / net_namespace.h
CommitLineData
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>
bee95250 10#include <linux/sysctl.h>
5f256bec 11
8efa6e93 12#include <net/netns/core.h>
852566f5 13#include <net/netns/mib.h>
a0a53c8b 14#include <net/netns/unix.h>
2aaef4e4 15#include <net/netns/packet.h>
8afd351c 16#include <net/netns/ipv4.h>
b0f159db 17#include <net/netns/ipv6.h>
67019cc9 18#include <net/netns/dccp.h>
8d870052 19#include <net/netns/x_tables.h>
dfdb8d79
AD
20#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
21#include <net/netns/conntrack.h>
22#endif
d62ddc21 23#include <net/netns/xfrm.h>
a0a53c8b 24
457c4cbc 25struct proc_dir_entry;
2774c7ab 26struct net_device;
97c53cac 27struct sock;
1597fbc0 28struct ctl_table_header;
dec827d1 29struct net_generic;
134e6375 30struct sock;
2553d064 31struct netns_ipvs;
1597fbc0 32
7c28bd0b
ED
33
34#define NETDEV_HASHBITS 8
35#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
36
5f256bec 37struct net {
a685e089
AV
38 atomic_t passive; /* To decided when the network
39 * namespace should be freed.
40 */
5f256bec 41 atomic_t count; /* To decided when the network
a685e089 42 * namespace should be shut down.
5f256bec 43 */
5d1e4468 44#ifdef NETNS_REFCNT_DEBUG
5f256bec
EB
45 atomic_t use_count; /* To track references we
46 * destroy on demand
47 */
5d1e4468 48#endif
8e602ce2
ED
49 spinlock_t rules_mod_lock;
50
5f256bec 51 struct list_head list; /* list of network namespaces */
2b035b39 52 struct list_head cleanup_list; /* namespaces on death row */
72ad937a 53 struct list_head exit_list; /* Use only net_mutex */
457c4cbc
EB
54
55 struct proc_dir_entry *proc_net;
56 struct proc_dir_entry *proc_net_stat;
881d966b 57
73455092
AV
58#ifdef CONFIG_SYSCTL
59 struct ctl_table_set sysctls;
60#endif
95bdfccb 61
8e602ce2
ED
62 struct sock *rtnl; /* rtnetlink socket */
63 struct sock *genl_sock;
2774c7ab 64
881d966b
EB
65 struct list_head dev_base_head;
66 struct hlist_head *dev_name_head;
67 struct hlist_head *dev_index_head;
97c53cac 68
5fd30ee7
DL
69 /* core fib_rules */
70 struct list_head rules_ops;
5fd30ee7 71
d12d01d6 72
8e602ce2 73 struct net_device *loopback_dev; /* The loopback */
8efa6e93 74 struct netns_core core;
852566f5 75 struct netns_mib mib;
2aaef4e4 76 struct netns_packet packet;
a0a53c8b 77 struct netns_unix unx;
8afd351c 78 struct netns_ipv4 ipv4;
b0f159db
DL
79#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
80 struct netns_ipv6 ipv6;
81#endif
67019cc9
PE
82#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
83 struct netns_dccp dccp;
84#endif
8d870052
AD
85#ifdef CONFIG_NETFILTER
86 struct netns_xt xt;
dfdb8d79
AD
87#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
88 struct netns_ct ct;
89#endif
cd8c20b6
AD
90 struct sock *nfnl;
91 struct sock *nfnl_stash;
d62ddc21 92#endif
3d23e349 93#ifdef CONFIG_WEXT_CORE
b333b3d2 94 struct sk_buff_head wext_nlevents;
8d870052 95#endif
1c87733d 96 struct net_generic __rcu *gen;
8e602ce2
ED
97
98 /* Note : following structs are cache line aligned */
99#ifdef CONFIG_XFRM
100 struct netns_xfrm xfrm;
101#endif
61b1ab45 102 struct netns_ipvs *ipvs;
5f256bec
EB
103};
104
225c0a01 105
c0f39322
DL
106#include <linux/seq_file_net.h>
107
4fabcd71 108/* Init's network namespace */
5f256bec 109extern struct net init_net;
a4aa834a
DL
110
111#ifdef CONFIG_NET
9dd776b6 112extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
225c0a01
DL
113
114#else /* CONFIG_NET */
9dd776b6
EB
115static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
116{
117 /* There is nothing to copy so this is a noop */
118 return net_ns;
119}
225c0a01
DL
120#endif /* CONFIG_NET */
121
122
123extern struct list_head net_namespace_list;
9dd776b6 124
30ffee84 125extern struct net *get_net_ns_by_pid(pid_t pid);
f0630529 126extern struct net *get_net_ns_by_fd(int pid);
30ffee84 127
d4655795 128#ifdef CONFIG_NET_NS
5f256bec
EB
129extern void __put_net(struct net *net);
130
131static inline struct net *get_net(struct net *net)
132{
133 atomic_inc(&net->count);
134 return net;
135}
136
077130c0
EB
137static inline struct net *maybe_get_net(struct net *net)
138{
139 /* Used when we know struct net exists but we
140 * aren't guaranteed a previous reference count
141 * exists. If the reference count is zero this
142 * function fails and returns NULL.
143 */
144 if (!atomic_inc_not_zero(&net->count))
145 net = NULL;
146 return net;
147}
148
5f256bec
EB
149static inline void put_net(struct net *net)
150{
151 if (atomic_dec_and_test(&net->count))
152 __put_net(net);
153}
154
878628fb
YH
155static inline
156int net_eq(const struct net *net1, const struct net *net2)
157{
158 return net1 == net2;
159}
a685e089
AV
160
161extern void net_drop_ns(void *);
162
d4655795 163#else
b9f75f45 164
d4655795
PE
165static inline struct net *get_net(struct net *net)
166{
167 return net;
168}
169
170static inline void put_net(struct net *net)
171{
172}
173
5d1e4468
DL
174static inline struct net *maybe_get_net(struct net *net)
175{
176 return net;
177}
178
179static inline
180int net_eq(const struct net *net1, const struct net *net2)
181{
182 return 1;
183}
a685e089
AV
184
185#define net_drop_ns NULL
5d1e4468
DL
186#endif
187
188
189#ifdef NETNS_REFCNT_DEBUG
d4655795
PE
190static inline struct net *hold_net(struct net *net)
191{
5d1e4468
DL
192 if (net)
193 atomic_inc(&net->use_count);
d4655795
PE
194 return net;
195}
196
197static inline void release_net(struct net *net)
198{
5d1e4468
DL
199 if (net)
200 atomic_dec(&net->use_count);
d4655795 201}
5d1e4468
DL
202#else
203static inline struct net *hold_net(struct net *net)
d4655795
PE
204{
205 return net;
206}
878628fb 207
5d1e4468 208static inline void release_net(struct net *net)
878628fb 209{
878628fb 210}
d4655795 211#endif
5f256bec 212
8f424b5f
ED
213#ifdef CONFIG_NET_NS
214
215static inline void write_pnet(struct net **pnet, struct net *net)
216{
217 *pnet = net;
218}
219
220static inline struct net *read_pnet(struct net * const *pnet)
221{
222 return *pnet;
223}
224
225#else
226
227#define write_pnet(pnet, net) do { (void)(net);} while (0)
228#define read_pnet(pnet) (&init_net)
229
230#endif
5d1e4468 231
5f256bec
EB
232#define for_each_net(VAR) \
233 list_for_each_entry(VAR, &net_namespace_list, list)
234
11a28d37
JB
235#define for_each_net_rcu(VAR) \
236 list_for_each_entry_rcu(VAR, &net_namespace_list, list)
237
4665079c
PE
238#ifdef CONFIG_NET_NS
239#define __net_init
240#define __net_exit
022cbae6 241#define __net_initdata
4665079c
PE
242#else
243#define __net_init __init
244#define __net_exit __exit_refok
022cbae6 245#define __net_initdata __initdata
4665079c 246#endif
5f256bec
EB
247
248struct pernet_operations {
249 struct list_head list;
250 int (*init)(struct net *net);
251 void (*exit)(struct net *net);
72ad937a 252 void (*exit_batch)(struct list_head *net_exit_list);
f875bae0
EB
253 int *id;
254 size_t size;
5f256bec
EB
255};
256
17edde52
EB
257/*
258 * Use these carefully. If you implement a network device and it
259 * needs per network namespace operations use device pernet operations,
260 * otherwise use pernet subsys operations.
261 *
4edf547b
JB
262 * Network interfaces need to be removed from a dying netns _before_
263 * subsys notifiers can be called, as most of the network code cleanup
264 * (which is done from subsys notifiers) runs with the assumption that
265 * dev_remove_pack has been called so no new packets will arrive during
266 * and after the cleanup functions have been called. dev_remove_pack
267 * is not per namespace so instead the guarantee of no more packets
268 * arriving in a network namespace is provided by ensuring that all
269 * network devices and all sockets have left the network namespace
270 * before the cleanup methods are called.
17edde52
EB
271 *
272 * For the longest time the ipv4 icmp code was registered as a pernet
273 * device which caused kernel oops, and panics during network
274 * namespace cleanup. So please don't get this wrong.
275 */
5f256bec
EB
276extern int register_pernet_subsys(struct pernet_operations *);
277extern void unregister_pernet_subsys(struct pernet_operations *);
278extern int register_pernet_device(struct pernet_operations *);
279extern void unregister_pernet_device(struct pernet_operations *);
f875bae0 280
95bdfccb
EB
281struct ctl_path;
282struct ctl_table;
283struct ctl_table_header;
d62c612e 284
95bdfccb
EB
285extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
286 const struct ctl_path *path, struct ctl_table *table);
d62c612e
PE
287extern struct ctl_table_header *register_net_sysctl_rotable(
288 const struct ctl_path *path, struct ctl_table *table);
95bdfccb
EB
289extern void unregister_net_sysctl_table(struct ctl_table_header *header);
290
5f256bec 291#endif /* __NET_NET_NAMESPACE_H */