aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/net_namespace.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-11 22:40:14 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-11 22:40:14 -0400
commit038a5008b2f395c85e6e71d6ddf3c684e7c405b0 (patch)
tree4735eab577e97e5a22c3141e3f60071c8065585e /include/net/net_namespace.h
parentdd6d1844af33acb4edd0a40b1770d091a22c94be (diff)
parent266918303226cceac7eca38ced30f15f277bd89c (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6: (867 commits) [SKY2]: status polling loop (post merge) [NET]: Fix NAPI completion handling in some drivers. [TCP]: Limit processing lost_retrans loop to work-to-do cases [TCP]: Fix lost_retrans loop vs fastpath problems [TCP]: No need to re-count fackets_out/sacked_out at RTO [TCP]: Extract tcp_match_queue_to_sack from sacktag code [TCP]: Kill almost unused variable pcount from sacktag [TCP]: Fix mark_head_lost to ignore R-bit when trying to mark L [TCP]: Add bytes_acked (ABC) clearing to FRTO too [IPv6]: Update setsockopt(IPV6_MULTICAST_IF) to support RFC 3493, try2 [NETFILTER]: x_tables: add missing ip6t_modulename aliases [NETFILTER]: nf_conntrack_tcp: fix connection reopening [QETH]: fix qeth_main.c [NETLINK]: fib_frontend build fixes [IPv6]: Export userland ND options through netlink (RDNSS support) [9P]: build fix with !CONFIG_SYSCTL [NET]: Fix dev_put() and dev_hold() comments [NET]: make netlink user -> kernel interface synchronious [NET]: unify netlink kernel socket recognition [NET]: cleanup 3rd argument in netlink_sendskb ... Fix up conflicts manually in Documentation/feature-removal-schedule.txt and my new least favourite crap, the "mod_devicetable" support in the files include/linux/mod_devicetable.h and scripts/mod/file2alias.c. (The latter files seem to be explicitly _designed_ to get conflicts when different subsystems work with them - that have an absolutely horrid lack of subsystem separation!) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/net/net_namespace.h')
-rw-r--r--include/net/net_namespace.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
new file mode 100644
index 000000000000..93aa87d32804
--- /dev/null
+++ b/include/net/net_namespace.h
@@ -0,0 +1,123 @@
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
11struct proc_dir_entry;
12struct net_device;
13struct 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 */
22
23 struct proc_dir_entry *proc_net;
24 struct proc_dir_entry *proc_net_stat;
25 struct proc_dir_entry *proc_net_root;
26
27 struct net_device *loopback_dev; /* The loopback */
28
29 struct list_head dev_base_head;
30 struct hlist_head *dev_name_head;
31 struct hlist_head *dev_index_head;
32};
33
34#ifdef CONFIG_NET
35/* Init's network namespace */
36extern struct net init_net;
37#define INIT_NET_NS(net_ns) .net_ns = &init_net,
38#else
39#define INIT_NET_NS(net_ns)
40#endif
41
42extern struct list_head net_namespace_list;
43
44#ifdef CONFIG_NET
45extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
46#else
47static 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
54extern void __put_net(struct net *net);
55
56static inline struct net *get_net(struct net *net)
57{
58#ifdef CONFIG_NET
59 atomic_inc(&net->count);
60#endif
61 return net;
62}
63
64static 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
76static inline void put_net(struct net *net)
77{
78#ifdef CONFIG_NET
79 if (atomic_dec_and_test(&net->count))
80 __put_net(net);
81#endif
82}
83
84static inline struct net *hold_net(struct net *net)
85{
86#ifdef CONFIG_NET
87 atomic_inc(&net->use_count);
88#endif
89 return net;
90}
91
92static inline void release_net(struct net *net)
93{
94#ifdef CONFIG_NET
95 atomic_dec(&net->use_count);
96#endif
97}
98
99#define for_each_net(VAR) \
100 list_for_each_entry(VAR, &net_namespace_list, list)
101
102#ifdef CONFIG_NET_NS
103#define __net_init
104#define __net_exit
105#define __net_initdata
106#else
107#define __net_init __init
108#define __net_exit __exit_refok
109#define __net_initdata __initdata
110#endif
111
112struct pernet_operations {
113 struct list_head list;
114 int (*init)(struct net *net);
115 void (*exit)(struct net *net);
116};
117
118extern int register_pernet_subsys(struct pernet_operations *);
119extern void unregister_pernet_subsys(struct pernet_operations *);
120extern int register_pernet_device(struct pernet_operations *);
121extern void unregister_pernet_device(struct pernet_operations *);
122
123#endif /* __NET_NET_NAMESPACE_H */