summaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2012-12-03 05:07:14 -0500
committerDavid S. Miller <davem@davemloft.net>2012-12-03 15:07:36 -0500
commit5d097109257c03a71845729f8db6b5770c4bbedc (patch)
tree4ef14ea47b21f6f81412c95889ca30147e0f0458 /drivers/net/tun.c
parent9ba2add3cf5c103b7236f82a023c8ee05a51e4d1 (diff)
tun: only queue packets on device
Historically tun supported two modes of operation: - in default mode, a small number of packets would get queued at the device, the rest would be queued in qdisc - in one queue mode, all packets would get queued at the device This might have made sense up to a point where we made the queue depth for both modes the same and set it to a huge value (500) so unless the consumer is stuck the chance of losing packets is small. Thus in practice both modes behave the same, but the default mode has some problems: - if packets are never consumed, fragments are never orphaned which cases a DOS for sender using zero copy transmit - overrun errors are hard to diagnose: fifo error is incremented only once so you can not distinguish between userspace that is stuck and a transient failure, tcpdump on the device does not show any traffic Userspace solves this simply by enabling IFF_ONE_QUEUE but there seems to be little point in not doing the right thing for everyone, by default. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 71f6874d8048..a1b2389e6d7f 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -690,21 +690,8 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
690 * number of queues. 690 * number of queues.
691 */ 691 */
692 if (skb_queue_len(&tfile->socket.sk->sk_receive_queue) 692 if (skb_queue_len(&tfile->socket.sk->sk_receive_queue)
693 >= dev->tx_queue_len / tun->numqueues){ 693 >= dev->tx_queue_len / tun->numqueues)
694 if (!(tun->flags & TUN_ONE_QUEUE)) { 694 goto drop;
695 /* Normal queueing mode. */
696 /* Packet scheduler handles dropping of further packets. */
697 netif_stop_subqueue(dev, txq);
698
699 /* We won't see all dropped packets individually, so overrun
700 * error is more appropriate. */
701 dev->stats.tx_fifo_errors++;
702 } else {
703 /* Single queue mode.
704 * Driver handles dropping of all packets itself. */
705 goto drop;
706 }
707 }
708 695
709 /* Orphan the skb - required as we might hang on to it 696 /* Orphan the skb - required as we might hang on to it
710 * for indefinite time. */ 697 * for indefinite time. */
@@ -1319,7 +1306,6 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1319 schedule(); 1306 schedule();
1320 continue; 1307 continue;
1321 } 1308 }
1322 netif_wake_subqueue(tun->dev, tfile->queue_index);
1323 1309
1324 ret = tun_put_user(tun, tfile, skb, iv, len); 1310 ret = tun_put_user(tun, tfile, skb, iv, len);
1325 kfree_skb(skb); 1311 kfree_skb(skb);
@@ -1482,6 +1468,9 @@ static int tun_flags(struct tun_struct *tun)
1482 if (tun->flags & TUN_NO_PI) 1468 if (tun->flags & TUN_NO_PI)
1483 flags |= IFF_NO_PI; 1469 flags |= IFF_NO_PI;
1484 1470
1471 /* This flag has no real effect. We track the value for backwards
1472 * compatibility.
1473 */
1485 if (tun->flags & TUN_ONE_QUEUE) 1474 if (tun->flags & TUN_ONE_QUEUE)
1486 flags |= IFF_ONE_QUEUE; 1475 flags |= IFF_ONE_QUEUE;
1487 1476
@@ -1632,6 +1621,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1632 else 1621 else
1633 tun->flags &= ~TUN_NO_PI; 1622 tun->flags &= ~TUN_NO_PI;
1634 1623
1624 /* This flag has no real effect. We track the value for backwards
1625 * compatibility.
1626 */
1635 if (ifr->ifr_flags & IFF_ONE_QUEUE) 1627 if (ifr->ifr_flags & IFF_ONE_QUEUE)
1636 tun->flags |= TUN_ONE_QUEUE; 1628 tun->flags |= TUN_ONE_QUEUE;
1637 else 1629 else