datapath: Add support for 4.1 kernel.
[cascardo/ovs.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 #include_next <net/net_namespace.h>
5
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
7 /* for 2.6.32* */
8 struct rpl_pernet_operations {
9         int (*init)(struct net *net);
10         void (*exit)(struct net *net);
11         int *id;
12         size_t size;
13         struct pernet_operations ops;
14 };
15 #define pernet_operations rpl_pernet_operations
16
17 #define register_pernet_device rpl_register_pernet_gen_device
18 #define unregister_pernet_device rpl_unregister_pernet_gen_device
19
20 #define compat_init_net ovs_compat_init_net
21 int ovs_compat_init_net(struct net *net, struct rpl_pernet_operations *pnet);
22 #define compat_exit_net ovs_compat_exit_net
23 void ovs_compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet);
24
25 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)                                       \
26                                                                         \
27 static struct rpl_pernet_operations *pnet_gen_##TYPE;                   \
28 static int compat_init_net_gen_##TYPE(struct net *net)  \
29 {                                                                       \
30         return compat_init_net(net, pnet_gen_##TYPE);                   \
31 }                                                                       \
32                                                                         \
33 static void compat_exit_net_gen_##TYPE(struct net *net) \
34 {                                                                       \
35         compat_exit_net(net, pnet_gen_##TYPE);                          \
36 }                                                                       \
37                                                                         \
38 static int rpl_register_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)       \
39 {                                                                               \
40         pnet_gen_##TYPE = rpl_pnet;                                             \
41         rpl_pnet->ops.init = compat_init_net_gen_##TYPE;                        \
42         rpl_pnet->ops.exit = compat_exit_net_gen_##TYPE;                        \
43         return register_pernet_gen_##TYPE(pnet_gen_##TYPE->id, &rpl_pnet->ops); \
44 }                                                                                       \
45                                                                                         \
46 static void rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)            \
47 {                                                                                       \
48         unregister_pernet_gen_##TYPE(*pnet_gen_##TYPE->id, &rpl_pnet->ops);             \
49 }
50 #else
51 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)
52 #endif /* 2.6.33 */
53
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0)
55 typedef struct {
56 #ifdef CONFIG_NET_NS
57         struct net *net;
58 #endif
59 } possible_net_t;
60
61 static inline void rpl_write_pnet(possible_net_t *pnet, struct net *net)
62 {
63 #ifdef CONFIG_NET_NS
64         pnet->net = net;
65 #endif
66 }
67
68 static inline struct net *rpl_read_pnet(const possible_net_t *pnet)
69 {
70 #ifdef CONFIG_NET_NS
71         return pnet->net;
72 #else
73         return &init_net;
74 #endif
75 }
76 #else /* Linux >= 4.1 */
77 #define rpl_read_pnet read_pnet
78 #define rpl_write_pnet write_pnet
79 #endif /* Linux >= 4.1 */
80
81 #endif /* net/net_namespace.h wrapper */