datapath: Add support for namespace.
[sliver-openvswitch.git] / datapath / linux / compat / include / net / net_namespace.h
1 #ifndef __NET_NET_NAMESPACE_WRAPPER_H
2 #define __NET_NET_NAMESPACE_WRAPPER_H 1
3
4 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
5 /* <net/net_namespace.h> exists, go ahead and include it. */
6 #include_next <net/net_namespace.h>
7 #else
8 /* No network namespace support. */
9 struct net;
10
11 static inline struct net *hold_net(struct net *net)
12 {
13         return net;
14 }
15
16 static inline void release_net(struct net *net)
17 {
18 }
19
20 #define __net_init      __init
21 #define __net_exit      __exit
22 #endif /* 2.6.24 */
23
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
25 #ifdef CONFIG_NET_NS
26 static inline
27 int net_eq(const struct net *net1, const struct net *net2)
28 {
29         return net1 == net2;
30 }
31 #else
32 static inline
33 int net_eq(const struct net *net1, const struct net *net2)
34 {
35         return 1;
36 }
37 #endif /* CONFIG_NET_NS */
38 #endif /* 2.6.26 */
39
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
41 #ifdef CONFIG_NET_NS
42
43 static inline void write_pnet(struct net **pnet, struct net *net)
44 {
45         *pnet = net;
46 }
47
48 static inline struct net *read_pnet(struct net * const *pnet)
49 {
50         return *pnet;
51 }
52
53 #else
54
55 #define write_pnet(pnet, net)   do { (void)(net); } while (0)
56
57 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
58 #define read_pnet(pnet)         (&init_net)
59 #else
60 #define read_pnet(pnet)         (NULL)
61 #endif /* 2.6.24 */
62
63 #endif /* CONFIG_NET_NS */
64 #endif /* 2.6.29 */
65
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
67 #define pernet_operations rpl_pernet_operations
68 struct pernet_operations {
69         int (*init)(struct net *net);
70         void (*exit)(struct net *net);
71         int *id;
72         size_t size;
73 };
74
75 extern int rpl_register_pernet_gen_device(struct rpl_pernet_operations *ops);
76 extern void rpl_unregister_pernet_gen_device(struct rpl_pernet_operations *ops);
77
78 #define register_pernet_device rpl_register_pernet_gen_device
79 #define unregister_pernet_device rpl_unregister_pernet_gen_device
80
81 #endif /* 2.6.33 */
82
83 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
84 #undef for_each_net
85 #define for_each_net(net)   { net = NULL; }
86
87 #endif /* 2.6.32 */
88
89 #endif /* net/net_namespace.h wrapper */