From 83fa6ac68a19f16788d4d43c5d3f36021dea9e23 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Thu, 4 Jul 2019 19:10:27 +0000 Subject: [PATCH] [NOT-UPSTREAM] virtio-net: Add droppkt param to force drop packets for 20s --- drivers/net/virtio_net.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c70441f45..f14f67b94 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -36,10 +36,14 @@ static int napi_weight = NAPI_POLL_WEIGHT; module_param(napi_weight, int, 0444); static bool csum = true, gso = true, napi_tx; +static int droppkt=0, droppingpkt=1; + module_param(csum, bool, 0444); module_param(gso, bool, 0444); module_param(napi_tx, bool, 0644); +module_param(droppkt, int, 0644); + /* FIXME: MTU in config. */ #define GOOD_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN) #define GOOD_COPY_LEN 128 @@ -1340,11 +1344,25 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) /* timestamp packet in software */ skb_tx_timestamp(skb); + if (unlikely(droppkt)) { + pr_err_once("dropping pkts\n"); + if (droppingpkt == 1) + droppingpkt = jiffies; + else { + if (jiffies_to_msecs(jiffies - droppingpkt) > 20000) { /* 20s */ + droppingpkt = 1; + droppkt = 0; + } + } + goto fakedrop; + } + /* Try to transmit */ err = xmit_skb(sq, skb); /* This should not happen! */ if (unlikely(err)) { +fakedrop: dev->stats.tx_fifo_errors++; if (net_ratelimit()) dev_warn(&dev->dev, -- 2.17.1