Skip to content

Commit fdf3f68

Browse files
committed
net: don't touch dev->stats in BPF redirect paths
Gal reports that BPF redirect increments dev->stats.tx_errors on failure. This is not correct, most modern drivers completely ignore dev->stats so these drops will be invisible to the user. Core code should use the dedicated core stats which are folded into device stats in dev_get_stats(). Note that we're switching from tx_errors to tx_dropped. Core only has tx_dropped, hence presumably users already expect that counter to increment for "stack" Tx issues. Reported-by: Gal Pressman <gal@nvidia.com> Link: https://lore.kernel.org/c5df3b60-246a-4030-9c9a-0a35cd1ca924@nvidia.com Fixes: b4ab314 ("bpf: Add redirect_neigh helper as redirect drop-in") Acked-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20260130033827.698841-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6d06bc8 commit fdf3f68

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

net/core/filter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,12 +2289,12 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,
22892289

22902290
err = bpf_out_neigh_v6(net, skb, dev, nh);
22912291
if (unlikely(net_xmit_eval(err)))
2292-
DEV_STATS_INC(dev, tx_errors);
2292+
dev_core_stats_tx_dropped_inc(dev);
22932293
else
22942294
ret = NET_XMIT_SUCCESS;
22952295
goto out_xmit;
22962296
out_drop:
2297-
DEV_STATS_INC(dev, tx_errors);
2297+
dev_core_stats_tx_dropped_inc(dev);
22982298
kfree_skb(skb);
22992299
out_xmit:
23002300
return ret;
@@ -2396,12 +2396,12 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,
23962396

23972397
err = bpf_out_neigh_v4(net, skb, dev, nh);
23982398
if (unlikely(net_xmit_eval(err)))
2399-
DEV_STATS_INC(dev, tx_errors);
2399+
dev_core_stats_tx_dropped_inc(dev);
24002400
else
24012401
ret = NET_XMIT_SUCCESS;
24022402
goto out_xmit;
24032403
out_drop:
2404-
DEV_STATS_INC(dev, tx_errors);
2404+
dev_core_stats_tx_dropped_inc(dev);
24052405
kfree_skb(skb);
24062406
out_xmit:
24072407
return ret;

0 commit comments

Comments
 (0)