1 #ifndef __NET_NET_NAMESPACE_WRAPPER_H
2 #define __NET_NET_NAMESPACE_WRAPPER_H 1
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>
8 /* No network namespace support. */
11 static inline struct net *hold_net(struct net *net)
16 static inline void release_net(struct net *net)
20 #define __net_init __init
21 #define __net_exit __exit
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
27 int net_eq(const struct net *net1, const struct net *net2)
33 int net_eq(const struct net *net1, const struct net *net2)
37 #endif /* CONFIG_NET_NS */
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
43 static inline void write_pnet(struct net **pnet, struct net *net)
48 static inline struct net *read_pnet(struct net * const *pnet)
55 #define write_pnet(pnet, net) do { (void)(net); } while (0)
57 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
58 #define read_pnet(pnet) (&init_net)
60 #define read_pnet(pnet) (NULL)
63 #endif /* CONFIG_NET_NS */
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);
72 struct pernet_operations ops;
74 #define pernet_operations rpl_pernet_operations
76 #define register_pernet_device rpl_register_pernet_gen_device
77 #define unregister_pernet_device rpl_unregister_pernet_gen_device
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);
83 #else /* for 2.6.32* */
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);
88 #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE) \
90 static struct rpl_pernet_operations *pnet_gen_##TYPE; \
91 static int __net_init compat_init_net_gen_##TYPE(struct net *net) \
93 return compat_init_net(net, pnet_gen_##TYPE); \
96 static void __net_exit compat_exit_net_gen_##TYPE(struct net *net) \
98 compat_exit_net(net, pnet_gen_##TYPE); \
101 static int __net_init rpl_register_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet) \
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); \
109 static void __net_exit rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet) \
111 unregister_pernet_gen_##TYPE(*pnet_gen_##TYPE->id, &rpl_pnet->ops); \
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)
121 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
123 #define for_each_net(net) { net = NULL; }
127 #endif /* net/net_namespace.h wrapper */