[NET]: Make device event notification network namespace safe
[safe/jmp/linux-2.6] / net / ipv4 / ipmr.c
index 0ebae41..0365988 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/mroute.h>
 #include <linux/init.h>
 #include <linux/if_ether.h>
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <linux/skbuff.h>
@@ -152,9 +153,11 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v)
                        dev->flags |= IFF_MULTICAST;
 
                        in_dev = __in_dev_get_rtnl(dev);
-                       if (in_dev == NULL && (in_dev = inetdev_init(dev)) == NULL)
+                       if (in_dev == NULL)
                                goto failure;
-                       in_dev->cnf.rp_filter = 0;
+
+                       ipv4_devconf_setall(in_dev);
+                       IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
 
                        if (dev_open(dev))
                                goto failure;
@@ -218,10 +221,15 @@ static struct net_device *ipmr_reg_vif(void)
        }
        dev->iflink = 0;
 
-       if ((in_dev = inetdev_init(dev)) == NULL)
+       rcu_read_lock();
+       if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
+               rcu_read_unlock();
                goto failure;
+       }
 
-       in_dev->cnf.rp_filter = 0;
+       ipv4_devconf_setall(in_dev);
+       IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
+       rcu_read_unlock();
 
        if (dev_open(dev))
                goto failure;
@@ -281,7 +289,7 @@ static int vif_delete(int vifi)
        dev_set_allmulti(dev, -1);
 
        if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
-               in_dev->cnf.mc_forwarding--;
+               IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)--;
                ip_rt_multicast_event(in_dev);
        }
 
@@ -426,7 +434,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock)
 
        if ((in_dev = __in_dev_get_rtnl(dev)) == NULL)
                return -EADDRNOTAVAIL;
-       in_dev->cnf.mc_forwarding++;
+       IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)++;
        dev_set_allmulti(dev, +1);
        ip_rt_multicast_event(in_dev);
 
@@ -841,7 +849,7 @@ static void mrtsock_destruct(struct sock *sk)
 {
        rtnl_lock();
        if (sk == mroute_socket) {
-               ipv4_devconf.mc_forwarding--;
+               IPV4_DEVCONF_ALL(MC_FORWARDING)--;
 
                write_lock_bh(&mrt_lock);
                mroute_socket=NULL;
@@ -890,7 +898,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
                        mroute_socket=sk;
                        write_unlock_bh(&mrt_lock);
 
-                       ipv4_devconf.mc_forwarding++;
+                       IPV4_DEVCONF_ALL(MC_FORWARDING)++;
                }
                rtnl_unlock();
                return ret;
@@ -1075,13 +1083,18 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
 
 static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr)
 {
+       struct net_device *dev = ptr;
        struct vif_device *v;
        int ct;
+
+       if (dev->nd_net != &init_net)
+               return NOTIFY_DONE;
+
        if (event != NETDEV_UNREGISTER)
                return NOTIFY_DONE;
        v=&vif_table[0];
        for (ct=0;ct<maxvif;ct++,v++) {
-               if (v->dev==ptr)
+               if (v->dev==dev)
                        vif_delete(ct);
        }
        return NOTIFY_DONE;
@@ -1910,12 +1923,12 @@ void __init ip_mr_init(void)
        mrt_cachep = kmem_cache_create("ip_mrt_cache",
                                       sizeof(struct mfc_cache),
                                       0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
-                                      NULL, NULL);
+                                      NULL);
        init_timer(&ipmr_expire_timer);
        ipmr_expire_timer.function=ipmr_expire_process;
        register_netdevice_notifier(&ip_mr_notifier);
 #ifdef CONFIG_PROC_FS
-       proc_net_fops_create("ip_mr_vif", 0, &ipmr_vif_fops);
-       proc_net_fops_create("ip_mr_cache", 0, &ipmr_mfc_fops);
+       proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops);
+       proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops);
 #endif
 }