DORMANTno replies REVIEWED: 3 (3M)

[PATCH net-next v2] net: ip6_tunnel: use tunnel parameters for fill_forward_path route lookup

From: Lorenzo Bianconi <lorenzo@kernel.org>
Date: 2026-07-22 07:13:09
Also in: netfilter-devel
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

Reuse the flowi6 template t->fl.u.ip6 built by ip6_tnl_link_config() in
ip6_tnl_fill_forward_path(), aligning the fast-path route lookup with
the slow path in ipxip6_tnl_xmit(). This automatically inherits the
correct conditional TCLASS and FLOWLABEL masking based on the
IP6_TNL_F_USE_ORIG_TCLASS and IP6_TNL_F_USE_ORIG_FLOWLABEL flags.

Return -EOPNOTSUPP when IP6_TNL_F_USE_ORIG_FLOWLABEL or
IP6_TNL_F_USE_ORIG_FWMARK is set, since fill_forward_path has no
access to the original skb and cannot recover the per-packet flowlabel
or mark needed for the route lookup.

IP6_TNL_F_USE_ORIG_TCLASS no longer triggers -EOPNOTSUPP: it only
affects the outer DS field, not the route lookup's flowi6.flowlabel
(the template leaves TCLASS bits zero when this flag is set, matching
the slow path).

Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
Changes in v2:
- Reuse flowi6 template for the route lookup
- Return EOPNOTSUPP if the tunnel is configured with
  IP6_TNL_F_USE_ORIG_FWMARK or IP6_TNL_F_USE_ORIG_FLOWLABEL
- Use flowi6 fields to setup net_device_path
- Link to v1: https://lore.kernel.org/r/20260708-ip6ip6-route-lookup-fill_forward_path-v1-1-863b9647102e@kernel.org (local)
---
 net/ipv6/ip6_tunnel.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index bf8e40af60b0..2708d5567c6a 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1845,24 +1845,26 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,
 				     struct net_device_path *path)
 {
 	struct ip6_tnl *t = netdev_priv(ctx->dev);
-	struct flowi6 fl6 = {
-		.daddr = t->parms.raddr,
-	};
 	struct dst_entry *dst;
+	struct flowi6 fl6;
 	int err;
 
-	if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) {
-		/* encaplimit option is currently not supported is
-		 * sw-acceleration path.
-		 */
+	if (t->parms.flags & (IP6_TNL_F_USE_ORIG_FLOWLABEL |
+			      IP6_TNL_F_USE_ORIG_FWMARK))
 		return -EOPNOTSUPP;
-	}
+
+	if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
+		return -EOPNOTSUPP;
+
+	memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
+	fl6.flowi6_mark = t->parms.fwmark;
+	fl6.flowi6_proto = 0;
 
 	dst = ip6_route_output(dev_net(ctx->dev), NULL, &fl6);
 	if (!dst->error) {
 		path->type = DEV_PATH_TUN;
-		path->tun.src_v6 = t->parms.laddr;
-		path->tun.dst_v6 = t->parms.raddr;
+		path->tun.src_v6 = fl6.saddr;
+		path->tun.dst_v6 = fl6.daddr;
 		path->tun.l3_proto = IPPROTO_IPV6;
 		path->dev = ctx->dev;
 		ctx->dev = dst->dev;
---
base-commit: df13c1df8147675470213ffff29dd5762fa321f5
change-id: 20260708-ip6ip6-route-lookup-fill_forward_path-9fc45a9118e9

Best regards,
-- 
Lorenzo Bianconi [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help