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 <gcimmino@rayonra.net>
Link: https://github.com/openwrt/openwrt/pull/25907
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
This commit is contained in:
Gennaro Cimmino authored and Markus Stockhausen committed 2026-10-14 21:19:26 +02:00
1 parent 8bd2d79d7d
commit aafeff42a7
1 file changed
+7 -2
@@ -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)) {