On Mon, Nov 16, 2026 at 3:46 PM Alexei Starovoitov
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
On Mon, Nov 16, 2026 at 11:01 AM Jamal Hadi Salim [off-list ref] wrote:
quoted
The release goes through skb_dst_drop_keep_metadata(), so encapsulation
parameters a route carries are handed over to a metadata dst instead of
being lost, and a metadata dst already on the packet is left in place. Both
wrappers take their existing drop path when that copy cannot be allocated,
so a packet is never sent with the stale route.
Just briefly looked at it. skb_dst_drop_keep_metadata() with kmalloc()
in the fast path is really no go.
Why not do something like this instead of patches 2, 3 and 4 ?
diff --git a/net/core/filter.c b/net/core/filter.c
index 946b07a..13f2d57 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2470,6 +2470,10 @@ static int __bpf_redirect_neigh(struct sk_buff *skb, struct net_device *dev,
skb_unset_mac_header(skb);
skb_reset_network_header(skb);
+ /* The route is for the old skb->dev. Keep the tunnel key. */
+ if (skb_valid_dst(skb))
+ skb_dst_drop(skb);
+
if (skb->protocol == htons(ETH_P_IP))
return __bpf_redirect_neigh_v4(skb, dev, nh);
else if (skb->protocol == htons(ETH_P_IPV6))diff --git a/net/netfilter/nft_fwd_netdev.c b/net/netfilter/nft_fwd_netdev.c
index 7447da9..d1ac4eb 100644
--- a/net/netfilter/nft_fwd_netdev.c
+++ b/net/netfilter/nft_fwd_netdev.c
@@ -15,6 +15,7 @@
#include <net/netfilter/nf_tables_offload.h>
#include <net/netfilter/nf_dup_netdev.h>
#include <net/netfilter/nf_recursion.h>
+#include <net/dst_metadata.h>
#include <net/neighbour.h>
#include <net/ip.h>
@@ -176,6 +177,9 @@ static void nft_fwd_neigh_eval(const struct nft_expr *expr,
}
}
+ /* The route is for the old skb->dev. Keep the tunnel template. */
+ if (skb_valid_dst(skb))
+ skb_dst_drop(skb);
skb->dev = dev;
skb_clear_tstamp(skb);
Agreed on the alloc cost (and i will send v5 to resolve that). Having said that:
skb_valid_dst() is essentially "a dst is present and it is not
DST_METADATA", so it is true for a route (skb_dst_drop() then releases
that route) and true for keys built with bpf_skb_set_tunnel_key(); for
encap ip/ip6 or encap xfrm template the tunnel template lives in
dst->lwtstate that wont work (packet reaches the tunnel or xfrm
device with no encapsulation).
For that reason we cant drop 3 and 4. I see the change in 2/4 (I see
1/4 not changing either) . The change is not that small because it
will have to touch multiple core files (although just small mechanical
surgeries). Summary it will still be 4 patches..
cheers,
jamal
pw-bot: cr