aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/net_namespace.h
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-09-12 05:50:50 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:49:03 -0400
commit5f256becd868bf63b70da8f2769033d6734670e9 (patch)
tree0a3550303488e7740f349e7b5f7b296dfeb276ef /include/net/net_namespace.h
parent32da477a5bfe96b6dfc8960e0d22d89ca09fd10a (diff)
[NET]: Basic network namespace infrastructure.
This is the basic infrastructure needed to support network namespaces. This infrastructure is: - Registration functions to support initializing per network namespace data when a network namespaces is created or destroyed. - struct net. The network namespace data structure. This structure will grow as variables are made per network namespace but this is the minimal starting point. - Functions to grab a reference to the network namespace. I provide both get/put functions that keep a network namespace from being freed. And hold/release functions serve as weak references and will warn if their count is not zero when the data structure is freed. Useful for dealing with more complicated data structures like the ipv4 route cache. - A list of all of the network namespaces so we can iterate over them. - A slab for the network namespace data structure allowing leaks to be spotted. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/net_namespace.h')
-rw-r--r--include/net/net_namespace.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
new file mode 100644
index 000000000000..6344b77f81a2
--- /dev/null
+++ b/include/net/net_namespace.h
@@ -0,0 +1,68 @@
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 net {
12 atomic_t count; /* To decided when the network
13 * namespace should be freed.
14 */
15 atomic_t use_count; /* To track references we
16 * destroy on demand
17 */
18 struct list_head list; /* list of network namespaces */
19 struct work_struct work; /* work struct for freeing */
20};
21
22extern struct net init_net;
23extern struct list_head net_namespace_list;
24
25extern void __put_net(struct net *net);
26
27static inline struct net *get_net(struct net *net)
28{
29 atomic_inc(&net->count);
30 return net;
31}
32
33static inline void put_net(struct net *net)
34{
35 if (atomic_dec_and_test(&net->count))
36 __put_net(net);
37}
38
39static inline struct net *hold_net(struct net *net)
40{
41 atomic_inc(&net->use_count);
42 return net;
43}
44
45static inline void release_net(struct net *net)
46{
47 atomic_dec(&net->use_count);
48}
49
50extern void net_lock(void);
51extern void net_unlock(void);
52
53#define for_each_net(VAR) \
54 list_for_each_entry(VAR, &net_namespace_list, list)
55
56
57struct pernet_operations {
58 struct list_head list;
59 int (*init)(struct net *net);
60 void (*exit)(struct net *net);
61};
62
63extern int register_pernet_subsys(struct pernet_operations *);
64extern void unregister_pernet_subsys(struct pernet_operations *);
65extern int register_pernet_device(struct pernet_operations *);
66extern void unregister_pernet_device(struct pernet_operations *);
67
68#endif /* __NET_NET_NAMESPACE_H */