]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/net/net_namespace.h
[NET]: Make rtnetlink infrastructure network namespace aware (v3)
[linux-2.6-omap-h63xx.git] / include / net / net_namespace.h
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
11 struct proc_dir_entry;
12 struct net_device;
13 struct sock;
14 struct net {
15         atomic_t                count;          /* To decided when the network
16                                                  *  namespace should be freed.
17                                                  */
18         atomic_t                use_count;      /* To track references we
19                                                  * destroy on demand
20                                                  */
21         struct list_head        list;           /* list of network namespaces */
22         struct work_struct      work;           /* work struct for freeing */
23
24         struct proc_dir_entry   *proc_net;
25         struct proc_dir_entry   *proc_net_stat;
26         struct proc_dir_entry   *proc_net_root;
27
28         struct net_device       *loopback_dev;          /* The loopback */
29
30         struct list_head        dev_base_head;
31         struct hlist_head       *dev_name_head;
32         struct hlist_head       *dev_index_head;
33
34         struct sock             *rtnl;                  /* rtnetlink socket */
35 };
36
37 #ifdef CONFIG_NET
38 /* Init's network namespace */
39 extern struct net init_net;
40 #define INIT_NET_NS(net_ns) .net_ns = &init_net,
41 #else
42 #define INIT_NET_NS(net_ns)
43 #endif
44
45 extern struct list_head net_namespace_list;
46
47 #ifdef CONFIG_NET
48 extern struct net *copy_net_ns(unsigned long flags, struct net *net_ns);
49 #else
50 static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
51 {
52         /* There is nothing to copy so this is a noop */
53         return net_ns;
54 }
55 #endif
56
57 #ifdef CONFIG_NET_NS
58 extern void __put_net(struct net *net);
59
60 static inline struct net *get_net(struct net *net)
61 {
62         atomic_inc(&net->count);
63         return net;
64 }
65
66 static inline struct net *maybe_get_net(struct net *net)
67 {
68         /* Used when we know struct net exists but we
69          * aren't guaranteed a previous reference count
70          * exists.  If the reference count is zero this
71          * function fails and returns NULL.
72          */
73         if (!atomic_inc_not_zero(&net->count))
74                 net = NULL;
75         return net;
76 }
77
78 static inline void put_net(struct net *net)
79 {
80         if (atomic_dec_and_test(&net->count))
81                 __put_net(net);
82 }
83
84 static inline struct net *hold_net(struct net *net)
85 {
86         atomic_inc(&net->use_count);
87         return net;
88 }
89
90 static inline void release_net(struct net *net)
91 {
92         atomic_dec(&net->use_count);
93 }
94 #else
95 static inline struct net *get_net(struct net *net)
96 {
97         return net;
98 }
99
100 static inline void put_net(struct net *net)
101 {
102 }
103
104 static inline struct net *hold_net(struct net *net)
105 {
106         return net;
107 }
108
109 static inline void release_net(struct net *net)
110 {
111 }
112
113 static inline struct net *maybe_get_net(struct net *net)
114 {
115         return net;
116 }
117 #endif
118
119 #define for_each_net(VAR)                               \
120         list_for_each_entry(VAR, &net_namespace_list, list)
121
122 #ifdef CONFIG_NET_NS
123 #define __net_init
124 #define __net_exit
125 #define __net_initdata
126 #else
127 #define __net_init      __init
128 #define __net_exit      __exit_refok
129 #define __net_initdata  __initdata
130 #endif
131
132 struct pernet_operations {
133         struct list_head list;
134         int (*init)(struct net *net);
135         void (*exit)(struct net *net);
136 };
137
138 extern int register_pernet_subsys(struct pernet_operations *);
139 extern void unregister_pernet_subsys(struct pernet_operations *);
140 extern int register_pernet_device(struct pernet_operations *);
141 extern void unregister_pernet_device(struct pernet_operations *);
142
143 #endif /* __NET_NET_NAMESPACE_H */