Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[linux-2.6-block.git] / drivers / net / tun.c
index cb376b2d548a1e448f40bf573f819e82dbfc1b43..06a039414628de9a9d91c73e9f8790c23fce71a3 100644 (file)
@@ -147,7 +147,6 @@ struct tun_file {
        struct socket socket;
        struct socket_wq wq;
        struct tun_struct __rcu *tun;
-       struct net *net;
        struct fasync_struct *fasync;
        /* only used for fasnyc */
        unsigned int flags;
@@ -548,10 +547,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
                            tun->dev->reg_state == NETREG_REGISTERED)
                                unregister_netdevice(tun->dev);
                }
-
-               BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
-                                &tfile->socket.flags));
-               sk_release_kernel(&tfile->sk);
+               sock_put(&tfile->sk);
        }
 }
 
@@ -1547,18 +1543,10 @@ out:
        return ret;
 }
 
-static int tun_release(struct socket *sock)
-{
-       if (sock->sk)
-               sock_put(sock->sk);
-       return 0;
-}
-
 /* Ops structure to mimic raw sockets with tun */
 static const struct proto_ops tun_socket_ops = {
        .sendmsg = tun_sendmsg,
        .recvmsg = tun_recvmsg,
-       .release = tun_release,
 };
 
 static struct proto tun_proto = {
@@ -1920,7 +1908,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
        if (cmd == TUNSETIFF && !tun) {
                ifr.ifr_name[IFNAMSIZ-1] = '\0';
 
-               ret = tun_set_iff(tfile->net, file, &ifr);
+               ret = tun_set_iff(sock_net(&tfile->sk), file, &ifr);
 
                if (ret)
                        goto unlock;
@@ -2217,16 +2205,16 @@ out:
 
 static int tun_chr_open(struct inode *inode, struct file * file)
 {
+       struct net *net = current->nsproxy->net_ns;
        struct tun_file *tfile;
 
        DBG1(KERN_INFO, "tunX: tun_chr_open\n");
 
-       tfile = (struct tun_file *)sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL,
-                                           &tun_proto);
+       tfile = (struct tun_file *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL,
+                                           &tun_proto, 0);
        if (!tfile)
                return -ENOMEM;
        RCU_INIT_POINTER(tfile->tun, NULL);
-       tfile->net = get_net(current->nsproxy->net_ns);
        tfile->flags = 0;
        tfile->ifindex = 0;
 
@@ -2237,13 +2225,11 @@ static int tun_chr_open(struct inode *inode, struct file * file)
        tfile->socket.ops = &tun_socket_ops;
 
        sock_init_data(&tfile->socket, &tfile->sk);
-       sk_change_net(&tfile->sk, tfile->net);
 
        tfile->sk.sk_write_space = tun_sock_write_space;
        tfile->sk.sk_sndbuf = INT_MAX;
 
        file->private_data = tfile;
-       set_bit(SOCK_EXTERNALLY_ALLOCATED, &tfile->socket.flags);
        INIT_LIST_HEAD(&tfile->next);
 
        sock_set_flag(&tfile->sk, SOCK_ZEROCOPY);
@@ -2254,10 +2240,8 @@ 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 net *net = tfile->net;
 
        tun_detach(tfile, true);
-       put_net(net);
 
        return 0;
 }