Commit 10dc4c7bb70533d16184aaaa69e137a7d2b9a3a8
Committed by
David S. Miller
1 parent
30688a9a3e
Exists in
master
and in
7 other branches
[IPIP]: Introduce empty ipip_net structure and net init/exit ops.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 50 additions and 0 deletions Side-by-side Diff
net/ipv4/ipip.c
... | ... | @@ -115,10 +115,16 @@ |
115 | 115 | #include <net/ipip.h> |
116 | 116 | #include <net/inet_ecn.h> |
117 | 117 | #include <net/xfrm.h> |
118 | +#include <net/net_namespace.h> | |
119 | +#include <net/netns/generic.h> | |
118 | 120 | |
119 | 121 | #define HASH_SIZE 16 |
120 | 122 | #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) |
121 | 123 | |
124 | +static int ipip_net_id; | |
125 | +struct ipip_net { | |
126 | +}; | |
127 | + | |
122 | 128 | static int ipip_fb_tunnel_init(struct net_device *dev); |
123 | 129 | static int ipip_tunnel_init(struct net_device *dev); |
124 | 130 | static void ipip_tunnel_setup(struct net_device *dev); |
... | ... | @@ -867,6 +873,41 @@ |
867 | 873 | static char banner[] __initdata = |
868 | 874 | KERN_INFO "IPv4 over IPv4 tunneling driver\n"; |
869 | 875 | |
876 | +static int ipip_init_net(struct net *net) | |
877 | +{ | |
878 | + int err; | |
879 | + struct ipip_net *ipn; | |
880 | + | |
881 | + err = -ENOMEM; | |
882 | + ipn = kmalloc(sizeof(struct ipip_net), GFP_KERNEL); | |
883 | + if (ipn == NULL) | |
884 | + goto err_alloc; | |
885 | + | |
886 | + err = net_assign_generic(net, ipip_net_id, ipn); | |
887 | + if (err < 0) | |
888 | + goto err_assign; | |
889 | + | |
890 | + return 0; | |
891 | + | |
892 | +err_assign: | |
893 | + kfree(ipn); | |
894 | +err_alloc: | |
895 | + return err; | |
896 | +} | |
897 | + | |
898 | +static void ipip_exit_net(struct net *net) | |
899 | +{ | |
900 | + struct ipip_net *ipn; | |
901 | + | |
902 | + ipn = net_generic(net, ipip_net_id); | |
903 | + kfree(ipn); | |
904 | +} | |
905 | + | |
906 | +static struct pernet_operations ipip_net_ops = { | |
907 | + .init = ipip_init_net, | |
908 | + .exit = ipip_exit_net, | |
909 | +}; | |
910 | + | |
870 | 911 | static int __init ipip_init(void) |
871 | 912 | { |
872 | 913 | int err; |
... | ... | @@ -890,6 +931,10 @@ |
890 | 931 | |
891 | 932 | if ((err = register_netdev(ipip_fb_tunnel_dev))) |
892 | 933 | goto err2; |
934 | + | |
935 | + err = register_pernet_gen_device(&ipip_net_id, &ipip_net_ops); | |
936 | + if (err) | |
937 | + goto err3; | |
893 | 938 | out: |
894 | 939 | return err; |
895 | 940 | err2: |
... | ... | @@ -897,6 +942,9 @@ |
897 | 942 | err1: |
898 | 943 | xfrm4_tunnel_deregister(&ipip_handler, AF_INET); |
899 | 944 | goto out; |
945 | +err3: | |
946 | + unregister_netdevice(ipip_fb_tunnel_dev); | |
947 | + goto err1; | |
900 | 948 | } |
901 | 949 | |
902 | 950 | static void __exit ipip_destroy_tunnels(void) |
... | ... | @@ -922,6 +970,8 @@ |
922 | 970 | ipip_destroy_tunnels(); |
923 | 971 | unregister_netdevice(ipip_fb_tunnel_dev); |
924 | 972 | rtnl_unlock(); |
973 | + | |
974 | + unregister_pernet_gen_device(ipip_net_id, &ipip_net_ops); | |
925 | 975 | } |
926 | 976 | |
927 | 977 | module_init(ipip_init); |