]> err.no Git - linux-2.6/blobdiff - drivers/net/tun.c
Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6] / drivers / net / tun.c
index 1e655ea631022353487b0a05e474fc1938b65d5e..7ab94c825b577f13b606bc938b834db6003559ad 100644 (file)
@@ -313,6 +313,21 @@ static __inline__ ssize_t tun_get_user(struct tun_struct *tun, struct iovec *iv,
 
        switch (tun->flags & TUN_TYPE_MASK) {
        case TUN_TUN_DEV:
+               if (tun->flags & TUN_NO_PI) {
+                       switch (skb->data[0] & 0xf0) {
+                       case 0x40:
+                               pi.proto = htons(ETH_P_IP);
+                               break;
+                       case 0x60:
+                               pi.proto = htons(ETH_P_IPV6);
+                               break;
+                       default:
+                               tun->dev->stats.rx_dropped++;
+                               kfree_skb(skb);
+                               return -EINVAL;
+                       }
+               }
+
                skb_reset_mac_header(skb);
                skb->protocol = pi.proto;
                skb->dev = tun->dev;
@@ -477,6 +492,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 +560,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 +600,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 +683,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 +756,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 +769,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 +833,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);