]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/net/net_namespace.h
net: delete excess kernel-doc notation
[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>
10
8efa6e93 11#include <net/netns/core.h>
852566f5 12#include <net/netns/mib.h>
a0a53c8b 13#include <net/netns/unix.h>
2aaef4e4 14#include <net/netns/packet.h>
8afd351c 15#include <net/netns/ipv4.h>
b0f159db 16#include <net/netns/ipv6.h>
67019cc9 17#include <net/netns/dccp.h>
8d870052 18#include <net/netns/x_tables.h>
dfdb8d79
AD
19#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
20#include <net/netns/conntrack.h>
21#endif
a0a53c8b 22
457c4cbc 23struct proc_dir_entry;
2774c7ab 24struct net_device;
97c53cac 25struct sock;
1597fbc0 26struct ctl_table_header;
dec827d1 27struct net_generic;
1597fbc0 28
5f256bec
EB
29struct net {
30 atomic_t count; /* To decided when the network
31 * namespace should be freed.
32 */
5d1e4468 33#ifdef NETNS_REFCNT_DEBUG
5f256bec
EB
34 atomic_t use_count; /* To track references we
35 * destroy on demand
36 */
5d1e4468 37#endif
5f256bec
EB
38 struct list_head list; /* list of network namespaces */
39 struct work_struct work; /* work struct for freeing */
457c4cbc
EB
40
41 struct proc_dir_entry *proc_net;
42 struct proc_dir_entry *proc_net_stat;
881d966b 43
73455092
AV
44#ifdef CONFIG_SYSCTL
45 struct ctl_table_set sysctls;
46#endif
95bdfccb 47
2774c7ab
EB
48 struct net_device *loopback_dev; /* The loopback */
49
881d966b
EB
50 struct list_head dev_base_head;
51 struct hlist_head *dev_name_head;
52 struct hlist_head *dev_index_head;
97c53cac 53
5fd30ee7
DL
54 /* core fib_rules */
55 struct list_head rules_ops;
56 spinlock_t rules_mod_lock;
57
97c53cac 58 struct sock *rtnl; /* rtnetlink socket */
d12d01d6 59
8efa6e93 60 struct netns_core core;
852566f5 61 struct netns_mib mib;
2aaef4e4 62 struct netns_packet packet;
a0a53c8b 63 struct netns_unix unx;
8afd351c 64 struct netns_ipv4 ipv4;
b0f159db
DL
65#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66 struct netns_ipv6 ipv6;
67#endif
67019cc9
PE
68#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
69 struct netns_dccp dccp;
70#endif
8d870052
AD
71#ifdef CONFIG_NETFILTER
72 struct netns_xt xt;
dfdb8d79
AD
73#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
74 struct netns_ct ct;
75#endif
8d870052 76#endif
dec827d1 77 struct net_generic *gen;
5f256bec
EB
78};
79
225c0a01 80
c0f39322
DL
81#include <linux/seq_file_net.h>
82
4fabcd71 83/* Init's network namespace */
5f256bec 84extern struct net init_net;
a4aa834a
DL
85
86#ifdef CONFIG_NET
4fabcd71 87#define INIT_NET_NS(net_ns) .net_ns = &init_net,
4fabcd71 88
9dd776b6 89extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
225c0a01
DL
90
91#else /* CONFIG_NET */
92
93#define INIT_NET_NS(net_ns)
94
9dd776b6
EB
95static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
96{
97 /* There is nothing to copy so this is a noop */
98 return net_ns;
99}
225c0a01
DL
100#endif /* CONFIG_NET */
101
102
103extern struct list_head net_namespace_list;
9dd776b6 104
d4655795 105#ifdef CONFIG_NET_NS
5f256bec
EB
106extern void __put_net(struct net *net);
107
b9f75f45
EB
108static inline int net_alive(struct net *net)
109{
110 return net && atomic_read(&net->count);
111}
112
5f256bec
EB
113static inline struct net *get_net(struct net *net)
114{
115 atomic_inc(&net->count);
116 return net;
117}
118
077130c0
EB
119static inline struct net *maybe_get_net(struct net *net)
120{
121 /* Used when we know struct net exists but we
122 * aren't guaranteed a previous reference count
123 * exists. If the reference count is zero this
124 * function fails and returns NULL.
125 */
126 if (!atomic_inc_not_zero(&net->count))
127 net = NULL;
128 return net;
129}
130
5f256bec
EB
131static inline void put_net(struct net *net)
132{
133 if (atomic_dec_and_test(&net->count))
134 __put_net(net);
135}
136
878628fb
YH
137static inline
138int net_eq(const struct net *net1, const struct net *net2)
139{
140 return net1 == net2;
141}
d4655795 142#else
b9f75f45
EB
143
144static inline int net_alive(struct net *net)
145{
146 return 1;
147}
148
d4655795
PE
149static inline struct net *get_net(struct net *net)
150{
151 return net;
152}
153
154static inline void put_net(struct net *net)
155{
156}
157
5d1e4468
DL
158static inline struct net *maybe_get_net(struct net *net)
159{
160 return net;
161}
162
163static inline
164int net_eq(const struct net *net1, const struct net *net2)
165{
166 return 1;
167}
168#endif
169
170
171#ifdef NETNS_REFCNT_DEBUG
d4655795
PE
172static inline struct net *hold_net(struct net *net)
173{
5d1e4468
DL
174 if (net)
175 atomic_inc(&net->use_count);
d4655795
PE
176 return net;
177}
178
179static inline void release_net(struct net *net)
180{
5d1e4468
DL
181 if (net)
182 atomic_dec(&net->use_count);
d4655795 183}
5d1e4468
DL
184#else
185static inline struct net *hold_net(struct net *net)
d4655795
PE
186{
187 return net;
188}
878628fb 189
5d1e4468 190static inline void release_net(struct net *net)
878628fb 191{
878628fb 192}
d4655795 193#endif
5f256bec 194
5d1e4468 195
5f256bec
EB
196#define for_each_net(VAR) \
197 list_for_each_entry(VAR, &net_namespace_list, list)
198
4665079c
PE
199#ifdef CONFIG_NET_NS
200#define __net_init
201#define __net_exit
022cbae6 202#define __net_initdata
4665079c
PE
203#else
204#define __net_init __init
205#define __net_exit __exit_refok
022cbae6 206#define __net_initdata __initdata
4665079c 207#endif
5f256bec
EB
208
209struct pernet_operations {
210 struct list_head list;
211 int (*init)(struct net *net);
212 void (*exit)(struct net *net);
213};
214
215extern int register_pernet_subsys(struct pernet_operations *);
216extern void unregister_pernet_subsys(struct pernet_operations *);
217extern int register_pernet_device(struct pernet_operations *);
218extern void unregister_pernet_device(struct pernet_operations *);
c93cf61f
PE
219extern int register_pernet_gen_device(int *id, struct pernet_operations *);
220extern void unregister_pernet_gen_device(int id, struct pernet_operations *);
5f256bec 221
95bdfccb
EB
222struct ctl_path;
223struct ctl_table;
224struct ctl_table_header;
d62c612e 225
95bdfccb
EB
226extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
227 const struct ctl_path *path, struct ctl_table *table);
d62c612e
PE
228extern struct ctl_table_header *register_net_sysctl_rotable(
229 const struct ctl_path *path, struct ctl_table *table);
95bdfccb
EB
230extern void unregister_net_sysctl_table(struct ctl_table_header *header);
231
5f256bec 232#endif /* __NET_NET_NAMESPACE_H */