From: Yu Gao <Supe…@qq.com>
lapbeth queues LAPB's indications on rx_queue and passes them up from
its NAPI poll. Nothing limits that queue, so it grows when a peer
makes LAPB produce indications faster than the poll delivers them.
The transmit change later in this series makes that easier to hit.
Drop received frames in lapbeth_rcv() once the queue reaches
netdev_max_backlog, the limit netif_rx() applied before the commit
below. The frame is dropped before LAPB sees it, so the peer retransmits
it and nothing LAPB has accepted is lost. Purge the queue on close, so
stale entries don't count against the limit after the device is
reopened.
Fixes: 514e1150da9c ("net: x25: Queue received packets in the drivers instead of per-CPU queues")
Signed-off-by: Yu Gao <Supe…@qq.com>
---
drivers/net/wan/lapbether.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a8..ab71afa 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -39,6 +39,7 @@
#include <linux/lapb.h>
#include <linux/init.h>
+#include <net/hotdata.h>
#include <net/netdev_lock.h>
#include <net/x25device.h>
@@ -132,6 +133,16 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
if (!lapbeth->up)
goto drop_unlock;
+ /* A frame dropped before LAPB sees it is like one lost on the wire,
+ * and the peer retransmits it. This keeps a peer from growing
+ * rx_queue without limit.
+ */
+ if (skb_queue_len_lockless(&lapbeth->rx_queue) >=
+ READ_ONCE(net_hotdata.max_backlog)) {
+ DEV_STATS_INC(lapbeth->axdev, rx_dropped);
+ goto drop_unlock;
+ }
+
len = skb->data[0] + skb->data[1] * 256;
dev->stats.rx_packets++;
dev->stats.rx_bytes += len;
@@ -352,6 +363,7 @@ static int lapbeth_close(struct net_device *dev)
pr_err("lapb_unregister error: %d\n", err);
napi_disable(&lapbeth->napi);
+ skb_queue_purge(&lapbeth->rx_queue);
return 0;
}
--
Git-157)