]> err.no Git - linux-2.6/blobdiff - drivers/net/tun.c
V4L/DVB (7851): Fix FW_LOADER depencency at v4l/dvb
[linux-2.6] / drivers / net / tun.c
index 1e655ea631022353487b0a05e474fc1938b65d5e..0ce07a339c7eee77a209fc365e664976ed4a6b57 100644 (file)
@@ -477,6 +477,7 @@ static void tun_setup(struct net_device *dev)
        dev->stop = tun_net_close;
        dev->ethtool_ops = &tun_ethtool_ops;
        dev->destructor = free_netdev;
+       dev->features |= NETIF_F_NETNS_LOCAL;
 }
 
 static struct tun_struct *tun_get_by_name(struct tun_net *tn, const char *name)
@@ -544,6 +545,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
                if (!dev)
                        return -ENOMEM;
 
+               dev_net_set(dev, net);
                tun = netdev_priv(dev);
                tun->dev = dev;
                tun->flags = flags;
@@ -583,6 +585,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
        file->private_data = tun;
        tun->attached = 1;
+       get_net(dev_net(tun->dev));
 
        strcpy(ifr->ifr_name, tun->dev->name);
        return 0;
@@ -665,16 +668,23 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
                break;
 
        case TUNSETLINK:
+       {
+               int ret;
+
                /* Only allow setting the type when the interface is down */
+               rtnl_lock();
                if (tun->dev->flags & IFF_UP) {
                        DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
                                tun->dev->name);
-                       return -EBUSY;
+                       ret = -EBUSY;
                } else {
                        tun->dev->type = (int) arg;
                        DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
+                       ret = 0;
                }
-               break;
+               rtnl_unlock();
+               return ret;
+       }
 
 #ifdef TUN_DEBUG
        case TUNSETDEBUG:
@@ -731,7 +741,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
        case SIOCADDMULTI:
                /** Add the specified group to the character device's multicast filter
                 * list. */
+               rtnl_lock();
+               netif_tx_lock_bh(tun->dev);
                add_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
+               netif_tx_unlock_bh(tun->dev);
+               rtnl_unlock();
+
                DBG(KERN_DEBUG "%s: add multi: %s\n",
                    tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
                return 0;
@@ -739,7 +754,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
        case SIOCDELMULTI:
                /** Remove the specified group from the character device's multicast
                 * filter list. */
+               rtnl_lock();
+               netif_tx_lock_bh(tun->dev);
                del_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
+               netif_tx_unlock_bh(tun->dev);
+               rtnl_unlock();
+
                DBG(KERN_DEBUG "%s: del multi: %s\n",
                    tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
                return 0;
@@ -798,6 +818,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
        /* Detach from net device */
        file->private_data = NULL;
        tun->attached = 0;
+       put_net(dev_net(tun->dev));
 
        /* Drop read queue */
        skb_queue_purge(&tun->readq);