]> err.no Git - linux-2.6/blobdiff - drivers/net/tun.c
Pull kvm-patches into release branch
[linux-2.6] / drivers / net / tun.c
index 46339f6bcd004b9ca6b443cad05df2c82742cf32..5b5d87585d914cf29dbad9c0f84d466590f7d537 100644 (file)
 #include <asm/system.h>
 #include <asm/uaccess.h>
 
+/* Uncomment to enable debugging */
+/* #define TUN_DEBUG 1 */
+
 #ifdef TUN_DEBUG
 static int debug;
+
+#define DBG  if(tun->debug)printk
+#define DBG1 if(debug==2)printk
+#else
+#define DBG( a... )
+#define DBG1( a... )
 #endif
 
+struct tun_struct {
+       struct list_head        list;
+       unsigned long           flags;
+       int                     attached;
+       uid_t                   owner;
+       gid_t                   group;
+
+       wait_queue_head_t       read_wait;
+       struct sk_buff_head     readq;
+
+       struct net_device       *dev;
+
+       struct fasync_struct    *fasync;
+
+       unsigned long if_flags;
+       u8 dev_addr[ETH_ALEN];
+       u32 chr_filter[2];
+       u32 net_filter[2];
+
+#ifdef TUN_DEBUG
+       int debug;
+#endif
+};
+
 /* Network device part of the driver */
 
 static LIST_HEAD(tun_dev_list);
@@ -253,8 +286,11 @@ static __inline__ ssize_t tun_get_user(struct tun_struct *tun, struct iovec *iv,
                        return -EFAULT;
        }
 
-       if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV)
+       if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) {
                align = NET_IP_ALIGN;
+               if (unlikely(len < ETH_HLEN))
+                       return -EINVAL;
+       }
 
        if (!(skb = alloc_skb(len + align, GFP_KERNEL))) {
                tun->dev->stats.rx_dropped++;
@@ -529,9 +565,13 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr)
 
        if (ifr->ifr_flags & IFF_NO_PI)
                tun->flags |= TUN_NO_PI;
+       else
+               tun->flags &= ~TUN_NO_PI;
 
        if (ifr->ifr_flags & IFF_ONE_QUEUE)
                tun->flags |= TUN_ONE_QUEUE;
+       else
+               tun->flags &= ~TUN_ONE_QUEUE;
 
        file->private_data = tun;
        tun->attached = 1;
@@ -659,7 +699,11 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
        case SIOCSIFHWADDR:
        {
                /* try to set the actual net device's hw address */
-               int ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr);
+               int ret;
+
+               rtnl_lock();
+               ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr);
+               rtnl_unlock();
 
                if (ret == 0) {
                        /** Set the character device's hardware address. This is used when