diff options
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r-- | drivers/net/tun.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 5f7842e4d4ae..589a44acdc76 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -103,13 +103,10 @@ struct tun_struct { | |||
103 | uid_t owner; | 103 | uid_t owner; |
104 | gid_t group; | 104 | gid_t group; |
105 | 105 | ||
106 | struct sk_buff_head readq; | ||
107 | |||
108 | struct net_device *dev; | 106 | struct net_device *dev; |
109 | struct fasync_struct *fasync; | 107 | struct fasync_struct *fasync; |
110 | 108 | ||
111 | struct tap_filter txflt; | 109 | struct tap_filter txflt; |
112 | struct sock *sk; | ||
113 | struct socket socket; | 110 | struct socket socket; |
114 | 111 | ||
115 | #ifdef TUN_DEBUG | 112 | #ifdef TUN_DEBUG |
@@ -155,7 +152,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file) | |||
155 | tfile->tun = tun; | 152 | tfile->tun = tun; |
156 | tun->tfile = tfile; | 153 | tun->tfile = tfile; |
157 | dev_hold(tun->dev); | 154 | dev_hold(tun->dev); |
158 | sock_hold(tun->sk); | 155 | sock_hold(tun->socket.sk); |
159 | atomic_inc(&tfile->count); | 156 | atomic_inc(&tfile->count); |
160 | 157 | ||
161 | out: | 158 | out: |
@@ -171,7 +168,7 @@ static void __tun_detach(struct tun_struct *tun) | |||
171 | netif_tx_unlock_bh(tun->dev); | 168 | netif_tx_unlock_bh(tun->dev); |
172 | 169 | ||
173 | /* Drop read queue */ | 170 | /* Drop read queue */ |
174 | skb_queue_purge(&tun->readq); | 171 | skb_queue_purge(&tun->socket.sk->sk_receive_queue); |
175 | 172 | ||
176 | /* Drop the extra count on the net device */ | 173 | /* Drop the extra count on the net device */ |
177 | dev_put(tun->dev); | 174 | dev_put(tun->dev); |
@@ -340,7 +337,7 @@ static void tun_free_netdev(struct net_device *dev) | |||
340 | { | 337 | { |
341 | struct tun_struct *tun = netdev_priv(dev); | 338 | struct tun_struct *tun = netdev_priv(dev); |
342 | 339 | ||
343 | sock_put(tun->sk); | 340 | sock_put(tun->socket.sk); |
344 | } | 341 | } |
345 | 342 | ||
346 | /* Net device open. */ | 343 | /* Net device open. */ |
@@ -374,7 +371,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) | |||
374 | if (!check_filter(&tun->txflt, skb)) | 371 | if (!check_filter(&tun->txflt, skb)) |
375 | goto drop; | 372 | goto drop; |
376 | 373 | ||
377 | if (skb_queue_len(&tun->readq) >= dev->tx_queue_len) { | 374 | if (skb_queue_len(&tun->socket.sk->sk_receive_queue) >= dev->tx_queue_len) { |
378 | if (!(tun->flags & TUN_ONE_QUEUE)) { | 375 | if (!(tun->flags & TUN_ONE_QUEUE)) { |
379 | /* Normal queueing mode. */ | 376 | /* Normal queueing mode. */ |
380 | /* Packet scheduler handles dropping of further packets. */ | 377 | /* Packet scheduler handles dropping of further packets. */ |
@@ -391,7 +388,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) | |||
391 | } | 388 | } |
392 | 389 | ||
393 | /* Enqueue packet */ | 390 | /* Enqueue packet */ |
394 | skb_queue_tail(&tun->readq, skb); | 391 | skb_queue_tail(&tun->socket.sk->sk_receive_queue, skb); |
395 | dev->trans_start = jiffies; | 392 | dev->trans_start = jiffies; |
396 | 393 | ||
397 | /* Notify and wake up reader process */ | 394 | /* Notify and wake up reader process */ |
@@ -492,13 +489,13 @@ static unsigned int tun_chr_poll(struct file *file, poll_table * wait) | |||
492 | if (!tun) | 489 | if (!tun) |
493 | return POLLERR; | 490 | return POLLERR; |
494 | 491 | ||
495 | sk = tun->sk; | 492 | sk = tun->socket.sk; |
496 | 493 | ||
497 | DBG(KERN_INFO "%s: tun_chr_poll\n", tun->dev->name); | 494 | DBG(KERN_INFO "%s: tun_chr_poll\n", tun->dev->name); |
498 | 495 | ||
499 | poll_wait(file, &tun->socket.wait, wait); | 496 | poll_wait(file, &tun->socket.wait, wait); |
500 | 497 | ||
501 | if (!skb_queue_empty(&tun->readq)) | 498 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
502 | mask |= POLLIN | POLLRDNORM; | 499 | mask |= POLLIN | POLLRDNORM; |
503 | 500 | ||
504 | if (sock_writeable(sk) || | 501 | if (sock_writeable(sk) || |
@@ -519,7 +516,7 @@ static inline struct sk_buff *tun_alloc_skb(struct tun_struct *tun, | |||
519 | size_t prepad, size_t len, | 516 | size_t prepad, size_t len, |
520 | size_t linear, int noblock) | 517 | size_t linear, int noblock) |
521 | { | 518 | { |
522 | struct sock *sk = tun->sk; | 519 | struct sock *sk = tun->socket.sk; |
523 | struct sk_buff *skb; | 520 | struct sk_buff *skb; |
524 | int err; | 521 | int err; |
525 | 522 | ||
@@ -787,7 +784,7 @@ static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv, | |||
787 | current->state = TASK_INTERRUPTIBLE; | 784 | current->state = TASK_INTERRUPTIBLE; |
788 | 785 | ||
789 | /* Read frames from the queue */ | 786 | /* Read frames from the queue */ |
790 | if (!(skb=skb_dequeue(&tun->readq))) { | 787 | if (!(skb=skb_dequeue(&tun->socket.sk->sk_receive_queue))) { |
791 | if (file->f_flags & O_NONBLOCK) { | 788 | if (file->f_flags & O_NONBLOCK) { |
792 | ret = -EAGAIN; | 789 | ret = -EAGAIN; |
793 | break; | 790 | break; |
@@ -824,8 +821,6 @@ static void tun_setup(struct net_device *dev) | |||
824 | { | 821 | { |
825 | struct tun_struct *tun = netdev_priv(dev); | 822 | struct tun_struct *tun = netdev_priv(dev); |
826 | 823 | ||
827 | skb_queue_head_init(&tun->readq); | ||
828 | |||
829 | tun->owner = -1; | 824 | tun->owner = -1; |
830 | tun->group = -1; | 825 | tun->group = -1; |
831 | 826 | ||
@@ -991,7 +986,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
991 | sk->sk_write_space = tun_sock_write_space; | 986 | sk->sk_write_space = tun_sock_write_space; |
992 | sk->sk_sndbuf = INT_MAX; | 987 | sk->sk_sndbuf = INT_MAX; |
993 | 988 | ||
994 | tun->sk = sk; | ||
995 | container_of(sk, struct tun_sock, sk)->tun = tun; | 989 | container_of(sk, struct tun_sock, sk)->tun = tun; |
996 | 990 | ||
997 | tun_net_init(dev); | 991 | tun_net_init(dev); |
@@ -1249,7 +1243,7 @@ static long tun_chr_ioctl(struct file *file, unsigned int cmd, | |||
1249 | break; | 1243 | break; |
1250 | 1244 | ||
1251 | case TUNGETSNDBUF: | 1245 | case TUNGETSNDBUF: |
1252 | sndbuf = tun->sk->sk_sndbuf; | 1246 | sndbuf = tun->socket.sk->sk_sndbuf; |
1253 | if (copy_to_user(argp, &sndbuf, sizeof(sndbuf))) | 1247 | if (copy_to_user(argp, &sndbuf, sizeof(sndbuf))) |
1254 | ret = -EFAULT; | 1248 | ret = -EFAULT; |
1255 | break; | 1249 | break; |
@@ -1260,7 +1254,7 @@ static long tun_chr_ioctl(struct file *file, unsigned int cmd, | |||
1260 | break; | 1254 | break; |
1261 | } | 1255 | } |
1262 | 1256 | ||
1263 | tun->sk->sk_sndbuf = sndbuf; | 1257 | tun->socket.sk->sk_sndbuf = sndbuf; |
1264 | break; | 1258 | break; |
1265 | 1259 | ||
1266 | default: | 1260 | default: |
@@ -1343,7 +1337,7 @@ static int tun_chr_close(struct inode *inode, struct file *file) | |||
1343 | 1337 | ||
1344 | tun = tfile->tun; | 1338 | tun = tfile->tun; |
1345 | if (tun) | 1339 | if (tun) |
1346 | sock_put(tun->sk); | 1340 | sock_put(tun->socket.sk); |
1347 | 1341 | ||
1348 | put_net(tfile->net); | 1342 | put_net(tfile->net); |
1349 | kfree(tfile); | 1343 | kfree(tfile); |