85dee1a53d47cf74f4a032572bc92157be1df02e
[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 struct rpl_pernet_operations {
68         int (*init)(struct net *net);
69         void (*exit)(struct net *net);
70         int *id;
71         size_t size;
72         struct pernet_operations ops;
73 };
74 #define pernet_operations rpl_pernet_operations
75
76 #define register_pernet_device rpl_register_pernet_gen_device
77 #define unregister_pernet_device rpl_unregister_pernet_gen_device
78
79 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
80 extern int rpl_register_pernet_gen_device(struct rpl_pernet_operations *ops);
81 extern void rpl_unregister_pernet_gen_device(struct rpl_pernet_operations *ops);
82
83 #else /* for 2.6.32* */
84
85 int __net_init compat_init_net(struct net *net, struct rpl_pernet_operations *pnet);
86 void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet);
87
88 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)                                       \
89                                                                         \
90 static struct rpl_pernet_operations *pnet_gen_##TYPE;                   \
91 static int __net_init compat_init_net_gen_##TYPE(struct net *net)       \
92 {                                                                       \
93         return compat_init_net(net, pnet_gen_##TYPE);                   \
94 }                                                                       \
95                                                                         \
96 static void __net_exit compat_exit_net_gen_##TYPE(struct net *net)      \
97 {                                                                       \
98         compat_exit_net(net, pnet_gen_##TYPE);                          \
99 }                                                                       \
100                                                                         \
101 static int __net_init rpl_register_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)    \
102 {                                                                               \
103         pnet_gen_##TYPE = rpl_pnet;                                             \
104         rpl_pnet->ops.init = compat_init_net_gen_##TYPE;                        \
105         rpl_pnet->ops.exit = compat_exit_net_gen_##TYPE;                        \
106         return register_pernet_gen_##TYPE(pnet_gen_##TYPE->id, &rpl_pnet->ops); \
107 }                                                                                       \
108                                                                                         \
109 static void __net_exit rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)         \
110 {                                                                                       \
111         unregister_pernet_gen_##TYPE(*pnet_gen_##TYPE->id, &rpl_pnet->ops);             \
112 }
113 #endif
114 #endif /* 2.6.33 */
115
116 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) || \
117     LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
118 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)
119 #endif /* 2.6.33 */
120
121 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
122 #undef for_each_net
123 #define for_each_net(net)   { net = NULL; }
124
125 #endif /* 2.6.32 */
126
127 #endif /* net/net_namespace.h wrapper */