1 #include <linux/version.h>
2 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
4 #include <linux/sched.h>
5 #include <net/net_namespace.h>
6 #include <net/netns/generic.h>
8 #undef pernet_operations
9 #undef register_pernet_device
10 #undef unregister_pernet_device
11 #undef net_assign_generic
14 /* This trivial implementation assumes that there is only a single pernet
15 * device registered and that the caller is well behaved. It only weakly
16 * attempts to check that these conditions are true. */
18 static struct extended_pernet_operations *dev_ops;
19 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
22 static struct pernet_operations new_ops;
25 static int device_init_net(struct net *net)
28 if (dev_ops->id && dev_ops->size) {
29 void *data = kzalloc(dev_ops->size, GFP_KERNEL);
33 err = rpl_net_assign_generic(net, *dev_ops->id, data);
40 return dev_ops->init(net);
44 static void device_exit_net(struct net *net)
49 if (dev_ops->id && dev_ops->size) {
50 int id = *dev_ops->id;
51 kfree(rpl_net_generic(net, id));
55 int rpl_register_pernet_device(struct extended_pernet_operations *ops)
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
64 return device_init_net(NULL);
66 memcpy(&new_ops, dev_ops, sizeof new_ops);
67 new_ops.init = device_init_net;
68 new_ops.exit = device_exit_net;
71 return register_pernet_gen_device(dev_ops->id, &new_ops);
73 return register_pernet_device(&new_ops);
77 void rpl_unregister_pernet_device(struct extended_pernet_operations *ops)
80 BUG_ON(dev_ops != ops);
82 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
83 device_exit_net(NULL);
86 unregister_pernet_gen_device(*dev_ops->id, &new_ops);
88 unregister_pernet_device(&new_ops);
94 int rpl_net_assign_generic(struct net *net, int id, void *data)
96 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
102 return net_assign_generic(net, id, data);
106 void *rpl_net_generic(struct net *net, int id)
108 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
113 return net_generic(net, id);
117 #endif /* kernel < 2.6.33 */