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