[NET]: fix oops after tunnel module unload

Tunnel modules used to obtain module refcount each time when
some tunnel was created, which meaned that tunnel could be unloaded
only after all the tunnels are deleted.

Since killing old MOD_*_USE_COUNT macros this protection has gone.
It is possible to return it back as module_get/put, but it looks
more natural and practically useful to force destruction of all
the child tunnels on module unload.

Signed-off-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Alexey Kuznetsov and committed by David S. Miller db44575f 1f494c0e

+55 -7
+18 -3
net/ipv4/ip_gre.c
··· 290 291 dev_hold(dev); 292 ipgre_tunnel_link(nt); 293 - /* Do not decrement MOD_USE_COUNT here. */ 294 return nt; 295 296 failed: ··· 1276 goto out; 1277 } 1278 1279 - static void ipgre_fini(void) 1280 { 1281 if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) 1282 printk(KERN_INFO "ipgre close: can't remove protocol\n"); 1283 1284 - unregister_netdev(ipgre_fb_tunnel_dev); 1285 } 1286 1287 module_init(ipgre_init);
··· 290 291 dev_hold(dev); 292 ipgre_tunnel_link(nt); 293 return nt; 294 295 failed: ··· 1277 goto out; 1278 } 1279 1280 + static void __exit ipgre_destroy_tunnels(void) 1281 + { 1282 + int prio; 1283 + 1284 + for (prio = 0; prio < 4; prio++) { 1285 + int h; 1286 + for (h = 0; h < HASH_SIZE; h++) { 1287 + struct ip_tunnel *t; 1288 + while ((t = tunnels[prio][h]) != NULL) 1289 + unregister_netdevice(t->dev); 1290 + } 1291 + } 1292 + } 1293 + 1294 + static void __exit ipgre_fini(void) 1295 { 1296 if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0) 1297 printk(KERN_INFO "ipgre close: can't remove protocol\n"); 1298 1299 + rtnl_lock(); 1300 + ipgre_destroy_tunnels(); 1301 + rtnl_unlock(); 1302 } 1303 1304 module_init(ipgre_init);
+18 -2
net/ipv4/ipip.c
··· 255 256 dev_hold(dev); 257 ipip_tunnel_link(nt); 258 - /* Do not decrement MOD_USE_COUNT here. */ 259 return nt; 260 261 failed: ··· 919 goto out; 920 } 921 922 static void __exit ipip_fini(void) 923 { 924 if (ipip_unregister() < 0) 925 printk(KERN_INFO "ipip close: can't deregister tunnel\n"); 926 927 - unregister_netdev(ipip_fb_tunnel_dev); 928 } 929 930 module_init(ipip_init);
··· 255 256 dev_hold(dev); 257 ipip_tunnel_link(nt); 258 return nt; 259 260 failed: ··· 920 goto out; 921 } 922 923 + static void __exit ipip_destroy_tunnels(void) 924 + { 925 + int prio; 926 + 927 + for (prio = 1; prio < 4; prio++) { 928 + int h; 929 + for (h = 0; h < HASH_SIZE; h++) { 930 + struct ip_tunnel *t; 931 + while ((t = tunnels[prio][h]) != NULL) 932 + unregister_netdevice(t->dev); 933 + } 934 + } 935 + } 936 + 937 static void __exit ipip_fini(void) 938 { 939 if (ipip_unregister() < 0) 940 printk(KERN_INFO "ipip close: can't deregister tunnel\n"); 941 942 + rtnl_lock(); 943 + ipip_destroy_tunnels(); 944 + unregister_netdevice(ipip_fb_tunnel_dev); 945 + rtnl_unlock(); 946 } 947 948 module_init(ipip_init);
+19 -2
net/ipv6/sit.c
··· 195 dev_hold(dev); 196 197 ipip6_tunnel_link(nt); 198 - /* Do not decrement MOD_USE_COUNT here. */ 199 return nt; 200 201 failed: ··· 793 .err_handler = ipip6_err, 794 }; 795 796 void __exit sit_cleanup(void) 797 { 798 inet_del_protocol(&sit_protocol, IPPROTO_IPV6); 799 - unregister_netdev(ipip6_fb_tunnel_dev); 800 } 801 802 int __init sit_init(void)
··· 195 dev_hold(dev); 196 197 ipip6_tunnel_link(nt); 198 return nt; 199 200 failed: ··· 794 .err_handler = ipip6_err, 795 }; 796 797 + static void __exit sit_destroy_tunnels(void) 798 + { 799 + int prio; 800 + 801 + for (prio = 1; prio < 4; prio++) { 802 + int h; 803 + for (h = 0; h < HASH_SIZE; h++) { 804 + struct ip_tunnel *t; 805 + while ((t = tunnels[prio][h]) != NULL) 806 + unregister_netdevice(t->dev); 807 + } 808 + } 809 + } 810 + 811 void __exit sit_cleanup(void) 812 { 813 inet_del_protocol(&sit_protocol, IPPROTO_IPV6); 814 + 815 + rtnl_lock(); 816 + sit_destroy_tunnels(); 817 + unregister_netdevice(ipip6_fb_tunnel_dev); 818 + rtnl_unlock(); 819 } 820 821 int __init sit_init(void)