From aafeff42a736990fe46727050d58536d68342bdc Mon Sep 17 00:00:00 2001 From: Gennaro Cimmino Date: Wed, 14 Oct 2026 19:13:43 +0200 Subject: [PATCH] realtek: l3: clear a route's counter when it takes it An RTL839x route counts its packets in a LOG counter it takes from otto_stats_packet_cntr_alloc(), and only the tc flower offload clears counters, those of its own rules. A counter last used by a route still holds that route's count when it is freed, so the next route that takes it shows those packets in debugfs before it has forwarded one. Clear the counter when the route takes it. On an HPE 1920-48G (RTL8393), a route to 10.99.0.0/17 that took the counter of a deleted route to 10.99.0.0/16 showed 8 packets before any traffic and 16 after 8 routed ones; with this change 0 and 8. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Gennaro Cimmino Link: https://github.com/openwrt/openwrt/pull/25907 Signed-off-by: Markus Stockhausen --- .../realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c index 7ad7c47823b..fb7428ba7ec 100644 --- a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c +++ b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c @@ -2116,11 +2116,16 @@ static void otto_l3_route_update_hw(struct otto_l3_ctrl *ctrl, struct otto_l3_ro if (ctrl->cfg->set_nexthop) ctrl->cfg->set_nexthop(ctrl, r->nh.id, r->nh.l2_id, r->nh.if_id); - /* A PIE rule counts the packets of its route while a counter is free */ + /* A PIE rule counts the packets of its route while a counter is free, + * from zero: the counter may still hold the count of its last user. + */ if (!ctrl->cfg->use_l3_tables && r->pr.packet_cntr < 0) { r->pr.packet_cntr = otto_stats_packet_cntr_alloc(priv); - if (r->pr.packet_cntr >= 0) + if (r->pr.packet_cntr >= 0) { dev_dbg(ctrl->dev, "Using packet counter %d\n", r->pr.packet_cntr); + scoped_guard(mutex, &priv->reg_mutex) + priv->r->packet_cntr_clear(priv, r->pr.packet_cntr); + } } if (otto_l3_route_install(ctrl, r)) {