mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] tun: add missing rx stats accounting in tun_xdp_act
@ 2024-01-16  9:36 Yunjian Wang
  2024-01-16 11:25 ` Denis Kirjanov
  0 siblings, 1 reply; 2+ messages in thread
From: Yunjian Wang @ 2024-01-16  9:36 UTC (permalink / raw)
  To: willemdebruijn.kernel, jasowang, kuba, davem
  Cc: netdev, linux-kernel, xudingke, Yunjian Wang

There are few places on the receive path where packet receives and packet
drops were not accounted for. This patch fixes that issue.

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/tun.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index afa5497f7c35..232e5319ac77 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1626,17 +1626,14 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
 		       struct xdp_buff *xdp, u32 act)
 {
 	int err;
+	unsigned int datasize = xdp->data_end - xdp->data;
 
 	switch (act) {
 	case XDP_REDIRECT:
 		err = xdp_do_redirect(tun->dev, xdp, xdp_prog);
-		if (err)
-			return err;
 		break;
 	case XDP_TX:
 		err = tun_xdp_tx(tun->dev, xdp);
-		if (err < 0)
-			return err;
 		break;
 	case XDP_PASS:
 		break;
@@ -1651,6 +1648,13 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
 		break;
 	}
 
+	if (err < 0) {
+		act = err;
+		dev_core_stats_rx_dropped_inc(tun->dev);
+	} else if (act == XDP_REDIRECT || act == XDP_TX) {
+		dev_sw_netstats_rx_add(tun->dev, datasize);
+	}
+
 	return act;
 }
 
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-16 11:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16  9:36 [PATCH net] tun: add missing rx stats accounting in tun_xdp_act Yunjian Wang
2024-01-16 11:25 ` Denis Kirjanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®