Driver Core: misc: add nodename support for misc devices.
[safe/jmp/linux-2.6] / drivers / net / tun.c
index 94622e5..11a0ba4 100644 (file)
@@ -565,9 +565,13 @@ static __inline__ ssize_t tun_get_user(struct tun_struct *tun,
                if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
                        return -EFAULT;
 
+               if ((gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
+                   gso.csum_start + gso.csum_offset + 2 > gso.hdr_len)
+                       gso.hdr_len = gso.csum_start + gso.csum_offset + 2;
+
                if (gso.hdr_len > len)
                        return -EINVAL;
-               offset += sizeof(pi);
+               offset += sizeof(gso);
        }
 
        if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) {
@@ -844,12 +848,12 @@ static void tun_sock_write_space(struct sock *sk)
        if (!sock_writeable(sk))
                return;
 
-       if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
-               wake_up_interruptible_sync(sk->sk_sleep);
-
        if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags))
                return;
 
+       if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
+               wake_up_interruptible_sync(sk->sk_sleep);
+
        tun = container_of(sk, struct tun_sock, sk)->tun;
        kill_fasync(&tun->fasync, SIGIO, POLL_OUT);
 }
@@ -865,6 +869,52 @@ static struct proto tun_proto = {
        .obj_size       = sizeof(struct tun_sock),
 };
 
+static int tun_flags(struct tun_struct *tun)
+{
+       int flags = 0;
+
+       if (tun->flags & TUN_TUN_DEV)
+               flags |= IFF_TUN;
+       else
+               flags |= IFF_TAP;
+
+       if (tun->flags & TUN_NO_PI)
+               flags |= IFF_NO_PI;
+
+       if (tun->flags & TUN_ONE_QUEUE)
+               flags |= IFF_ONE_QUEUE;
+
+       if (tun->flags & TUN_VNET_HDR)
+               flags |= IFF_VNET_HDR;
+
+       return flags;
+}
+
+static ssize_t tun_show_flags(struct device *dev, struct device_attribute *attr,
+                             char *buf)
+{
+       struct tun_struct *tun = netdev_priv(to_net_dev(dev));
+       return sprintf(buf, "0x%x\n", tun_flags(tun));
+}
+
+static ssize_t tun_show_owner(struct device *dev, struct device_attribute *attr,
+                             char *buf)
+{
+       struct tun_struct *tun = netdev_priv(to_net_dev(dev));
+       return sprintf(buf, "%d\n", tun->owner);
+}
+
+static ssize_t tun_show_group(struct device *dev, struct device_attribute *attr,
+                             char *buf)
+{
+       struct tun_struct *tun = netdev_priv(to_net_dev(dev));
+       return sprintf(buf, "%d\n", tun->group);
+}
+
+static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL);
+static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL);
+static DEVICE_ATTR(group, 0444, tun_show_group, NULL);
+
 static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 {
        struct sock *sk;
@@ -950,6 +1000,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
                if (err < 0)
                        goto err_free_sk;
 
+               if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
+                   device_create_file(&tun->dev->dev, &dev_attr_owner) ||
+                   device_create_file(&tun->dev->dev, &dev_attr_group))
+                       printk(KERN_ERR "Failed to create tun sysfs files\n");
+
                sk->sk_destruct = tun_sock_destruct;
 
                err = tun_attach(tun, file);
@@ -1002,21 +1057,7 @@ static int tun_get_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
        strcpy(ifr->ifr_name, tun->dev->name);
 
-       ifr->ifr_flags = 0;
-
-       if (ifr->ifr_flags & TUN_TUN_DEV)
-               ifr->ifr_flags |= IFF_TUN;
-       else
-               ifr->ifr_flags |= IFF_TAP;
-
-       if (tun->flags & TUN_NO_PI)
-               ifr->ifr_flags |= IFF_NO_PI;
-
-       if (tun->flags & TUN_ONE_QUEUE)
-               ifr->ifr_flags |= IFF_ONE_QUEUE;
-
-       if (tun->flags & TUN_VNET_HDR)
-               ifr->ifr_flags |= IFF_VNET_HDR;
+       ifr->ifr_flags = tun_flags(tun);
 
        tun_put(tun);
        return 0;
@@ -1281,21 +1322,22 @@ static int tun_chr_open(struct inode *inode, struct file * file)
 static int tun_chr_close(struct inode *inode, struct file *file)
 {
        struct tun_file *tfile = file->private_data;
-       struct tun_struct *tun = __tun_get(tfile);
+       struct tun_struct *tun;
 
 
+       rtnl_lock();
+       tun = __tun_get(tfile);
        if (tun) {
                DBG(KERN_INFO "%s: tun_chr_close\n", tun->dev->name);
 
-               rtnl_lock();
                __tun_detach(tun);
 
                /* If desireable, unregister the netdevice. */
                if (!(tun->flags & TUN_PERSIST))
                        unregister_netdevice(tun->dev);
 
-               rtnl_unlock();
        }
+       rtnl_unlock();
 
        tun = tfile->tun;
        if (tun)
@@ -1324,6 +1366,7 @@ static const struct file_operations tun_fops = {
 static struct miscdevice tun_miscdev = {
        .minor = TUN_MINOR,
        .name = "tun",
+       .devnode = "net/tun",
        .fops = &tun_fops,
 };