1 #include <linux/if_vlan.h>
2 #include <linux/netdevice.h>
3 #include <net/net_namespace.h>
4 #include <net/netns/generic.h>
6 #undef pernet_operations
8 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,32)
9 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
10 static int net_assign_generic(struct net *net, int id, void *data);
13 static int __net_init compat_init_net(struct net *net, struct rpl_pernet_operations *pnet)
16 void *ovs_net = kzalloc(pnet->size, GFP_KERNEL);
21 err = net_assign_generic(net, *pnet->id, ovs_net);
26 err = pnet->init(net);
37 static void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet)
39 void *ovs_net = net_generic(net, *pnet->id);
47 #if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32)
48 #define DEFINE_PNET_REG_FUNC(PNET_TYPE) \
49 static struct rpl_pernet_operations *pnet_##PNET_TYPE; \
50 static int __net_init compat_init_net_##PNET_TYPE(struct net *net) \
52 return compat_init_net(net, pnet_##PNET_TYPE); \
55 static void __net_exit compat_exit_net_##PNET_TYPE(struct net *net) \
57 compat_exit_net(net, pnet_##PNET_TYPE); \
60 static struct pernet_operations pnet_compat_##PNET_TYPE = { \
61 .init = compat_init_net_##PNET_TYPE, \
62 .exit = compat_exit_net_##PNET_TYPE, \
65 int rpl_register_pernet_##PNET_TYPE(struct rpl_pernet_operations *rpl_pnet) \
67 pnet_##PNET_TYPE = rpl_pnet; \
68 return register_pernet_##PNET_TYPE(pnet_##PNET_TYPE->id, &pnet_compat_##PNET_TYPE); \
71 void rpl_unregister_pernet_##PNET_TYPE(struct rpl_pernet_operations *pnet) \
73 unregister_pernet_##PNET_TYPE(*pnet->id, &pnet_compat_##PNET_TYPE); \
76 DEFINE_PNET_REG_FUNC(gen_device);
78 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
79 #define MAX_DATA_COUNT 1
80 static struct net *net;
82 static void *__ovs_net_data[MAX_DATA_COUNT];
85 static int net_assign_generic(struct net *net, int id, void *data)
87 BUG_ON(id >= MAX_DATA_COUNT);
88 __ovs_net_data[id] = data;
92 void *net_generic(const struct net *net, int id)
94 return __ovs_net_data[id];
97 int rpl_register_pernet_gen_device(struct rpl_pernet_operations *rpl_pnet)
99 *rpl_pnet->id = count++;
100 return compat_init_net(net, rpl_pnet);
103 void rpl_unregister_pernet_gen_device(struct rpl_pernet_operations *rpl_pnet)
105 compat_exit_net(net, rpl_pnet);