tun: add missing rx stats accounting in tun_xdp_act
authorYunjian Wang <wangyunjian@huawei.com>
Fri, 19 Jan 2024 10:22:56 +0000 (18:22 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Jan 2024 10:58:04 +0000 (10:58 +0000)
The TUN can be used as vhost-net backend, and it is necessary to
count the packets transmitted from TUN to vhost-net/virtio-net.
However, there are some places in the receive path that were not
taken into account when using XDP. It would be beneficial to also
include new accounting for successfully received bytes using
dev_sw_netstats_rx_add.

Fixes: 761876c857cb ("tap: XDP support")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c

index 237fef5..4a4f8c8 100644 (file)
@@ -1634,6 +1634,7 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
                        dev_core_stats_rx_dropped_inc(tun->dev);
                        return err;
                }
+               dev_sw_netstats_rx_add(tun->dev, xdp->data_end - xdp->data);
                break;
        case XDP_TX:
                err = tun_xdp_tx(tun->dev, xdp);
@@ -1641,6 +1642,7 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
                        dev_core_stats_rx_dropped_inc(tun->dev);
                        return err;
                }
+               dev_sw_netstats_rx_add(tun->dev, xdp->data_end - xdp->data);
                break;
        case XDP_PASS:
                break;