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