Article View: linux.kernel.netdev
Article #10148[PATCH net v2 2/3] ipv6: ioam6: use transformed packet nexthdr for ECMP re-lookup
From: Hangbin Liu
Date: Tue, 03 Nov 2026 09:20
Date: Tue, 03 Nov 2026 09:20
132 lines
13011 bytes
13011 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
RFC 9486 (C2) requires that the ECMP hash of a packet carrying IOAM
options is the same as the hash of the identical packet without them.
On a destination-cache miss the old code always re-looked up the
transformed packet under hash policy 0 with NEXTHDR_HOP (and, for
local flows, keys that do not match the original socket lookup), so
it could pick a different ECMP sibling.
Inline insertion leaves the destination unchanged: reuse orig_dst and
cache the fake null_rt, keeping the sibling from the original lookup.
Encapsulation may switch the destination to tundst, so it still
re-looks up. Take flowi6_proto from the transformed packet HBH (41
after encap, so ipproto rules match as for plain ip6ip6) and
precompute fl6.mp_hash from the packet, since ip6_route_output()
carries no skb and would otherwise drop ICMPv6 quoted-flow and L4
keys.
Depends on patch "ipv6: route: consider IOAM options in ECMP hash
policy 0".
Fixes: 8cb3bf8bff3c ("ipv6: ioam: Add support for the ip6ip6 encapsulation")
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
For AI review:
The mp_hash precompute makes policy-2 hash inner keys while plain ip6ip6
baseline hashes outer — pre-patch also diverged (proto 0 vs 41);
C2 for policy 2 was broken before and after, no new violation class, and
the patches claim/test policy 0 only.
---
net/ipv6/ioam6_iptunnel.c | 79 +++++++++++++++++++++++++++++++----------------
1 file changed, 53 insertions(+), 26 deletions(-)
diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
index cfb2c41634a0..246533276be8 100644
--- a/net/ipv6/ioam6_iptunnel.c
+++ b/net/ipv6/ioam6_iptunnel.c
@@ -405,34 +405,61 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
if (unlikely(!dst)) {
struct ipv6hdr *hdr = ipv6_hdr(skb);
- struct flowi6 fl6;
-
- memset(&fl6, 0, sizeof(fl6));
- fl6.daddr = hdr->daddr;
- fl6.saddr = hdr->saddr;
- fl6.flowlabel = ip6_flowinfo(hdr);
- fl6.flowi6_mark = skb->mark;
- fl6.flowi6_proto = hdr->nexthdr;
-
- dst = ip6_route_output(net, NULL, &fl6);
- if (dst->error) {
- err = dst->error;
- goto drop;
- }
- /* If the destination is the same after transformation (which is
- * a valid use case for IOAM), then we don't want to add it to
- * the cache in order to avoid a reference loop. Instead, we add
- * our fake dst_entry to the cache as a way to detect this case.
- * Otherwise, we add the resolved destination to the cache.
+ /* Inline insertion does not change the destination. Keep
+ * orig_dst so the ECMP sibling from the original lookup is
+ * preserved (RFC 9486 C2 for locally generated traffic).
+ * Cache the fake null_rt so later packets take the same path.
*/
- local_bh_disable();
- if (orig_dst->lwtstate == dst->lwtstate)
- dst_cache_set_ip6(&ilwt->cache,
- &ilwt->null_rt.dst, &fl6.saddr);
- else
- dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
- local_bh_enable();
+ if (ilwt->mode == IOAM6_IPTUNNEL_MODE_INLINE ||
+ (ilwt->mode == IOAM6_IPTUNNEL_MODE_AUTO && !skb->dev)) {
+ dst = orig_dst;
+ dst_hold(dst);
+
+ local_bh_disable();
+ dst_cache_set_ip6(&ilwt->cache, &ilwt->null_rt.dst,
+ &hdr->saddr);
+ local_bh_enable();
+ } else {
+ /* Encapsulation may change the destination (tundst);
+ * re-lookup with the transformed packet keys so the
+ * outer hash matches the identical packet without IOAM.
+ */
+ const struct ipv6_opt_hdr *hhdr;
+ struct flowi6 fl6;
+
+ hhdr = (const struct ipv6_opt_hdr *)skb_transport_header(skb);
+
+ memset(&fl6, 0, sizeof(fl6));
+ fl6.daddr = hdr->daddr;
+ fl6.saddr = hdr->saddr;
+ fl6.flowlabel = ip6_flowinfo(hdr);
+ fl6.flowi6_mark = skb->mark;
+ fl6.flowi6_proto = hhdr->nexthdr;
+ fl6.mp_hash = rt6_multipath_hash(net, &fl6, skb, NULL);
+
+ dst = ip6_route_output(net, NULL, &fl6);
+ if (dst->error) {
+ err = dst->error;
+ goto drop;
+ }
+
+ /* If the destination is the same after transformation
+ * (which is a valid use case for IOAM), then we don't
+ * want to add it to the cache in order to avoid a
+ * reference loop. Instead, we add our fake dst_entry
+ * to the cache as a way to detect this case.
+ * Otherwise, we add the resolved destination to the
+ * cache.
+ */
+ local_bh_disable();
+ if (orig_dst->lwtstate == dst->lwtstate)
+ dst_cache_set_ip6(&ilwt->cache,
+ &ilwt->null_rt.dst, &fl6.saddr);
+ else
+ dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr);
+ local_bh_enable();
+ }
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst_dev(dst)));
if (unlikely(err))
--
2.56.0
Technical Details
Message-ID:
<20261103-ipv6_ioam_ecmp-v2-2-6ef0318bdb5e@kylinos.cn>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355319-linux-kernel-netdev=dewy.ruReferences:
<20261103-ipv6_ioam_ecmp-v2-0-6ef0318bdb5e@kylinos.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355319-linux-kernel-netdev=dewy.ru From: hangbin.liu@linux.dev (Hangbin Liu) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/3] ipv6: ioam6: use transformed packet nexthdr for ECMP re-lookup Date: Tue, 03 Nov 2026 17:20:51 +0800 Organization: Usenet Network Message-ID: <20261103-ipv6_ioam_ecmp-v2-2-6ef0318bdb5e@kylinos.cn> References: <20261103-ipv6_ioam_ecmp-v2-0-6ef0318bdb5e@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3131413"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:BxKmO87gnyrejvIKE8Qkd/KCyVU= sha256:jyeb4xQ4W/S00aj8QYLnzJyrZf/hjybWFBRF1vbaHhA= sha1:L5Rs0ekDBBEBDL9Za/Xwku5TK/Q= sha256:lUQt+5a4Tthgo+CSsPP8eTwFrmXa2UOmY+Sopl9Xa04= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 6D0FE112797; Tue, 3 Nov 2026 12:29:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r8UUw_0wnP7e; Tue, 3 Nov 2026 12:29:35 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-355319-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id D724A112793; Tue, 3 Nov 2026 12:29:25 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 896AB2DDA2; Tue, 3 Nov 2026 09:22:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793697698; b=48Z8bdtjI1tDNOkO2ZRAx3g5iPKOs+p43M3i4vroNxMa7KreRu0h0GwTNjkxY/qDuYhn 4U2D4eKJQKKTMl0f2so3tELVHZqiuoVQuBXhvhkb2aGVv8oErGQjtKrrjMenHV2/LWH5I Jsnk0w8Na5Swf9nQSrDAoHanNJj3kLeM7gLZLXUz1dznNs1HMVw38UDjiFNqIUe2bFlcy dV60OETL52T2QPk/aS7eMQ9u1uy05/gAWnDoGkDDq0uQ/d+gneDE9E9auIVcVrFg7IKyz n5GE0lxXAlU4VNqAaGNPBA4A0zrfx2xgP3Ad56wD9JcXAOfxhu2A7yNAGWioR/tX1bA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793697698; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer; bh=gZHsMDdpmPsnd9fVKQ5HXshg/Ennof29jt+F+15lfj0=; b=UjqwSjK0D4fdrfWKBlO1dqmbIn302nm2uIcVL8/ELb8R6MucFn15yH1ILwNUKUXzQKTS cX7JIQUapSOCulmkrI0N9TK0YM3oN8ZyxM8WK7IAM9EsnvR+ePMLfvI1rVGYtc6j/lOgj piODrtxA0+WMFr+tHmoEPbLgyvFdcT4wSN4kMVe+17RI+NIYWBsFdKBoosmC8HNCtVN6B hQ9m39KSLjj+Z43s0tIHtftmRvrEIgtwXKvFow9Hur9tcU/NY3WxCmE69C1a0tqjARn0v jRD/dcW4SQosnhdI4etPBSwrlAmWQ6baVoW9Kxo94N8KrV1ZBdKf5cEVmsVxGHa0dPw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="K3tC/zFB"; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD873606D814; Tue, 3 Nov 2026 09:21:37 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=K3tC/zFB X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.49 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793697697; b=x46y3Vxp5VZVDDVZp6tkrjbMuUwhNSr4D8SumA2nUatg96yVQLNKb5gCHiOJWkLRK7a/ NxJbAL1/Npd29tFJ5f07YQhqP9t+4Y4Y0CfmeFBKSbrrZZD7/UbWXMv4VWpChuL4wLX5V zLvvHL1JeuS0Q9TVXgTfj4zBhyBRJEyrexfMqmeAVDooq5Y69H+K5rkAGv3jo4vRRF8XT wwoEF+/JV/t+zT2soQvXpNMJJsK0cYkB/272o9IWvYaKZgXNKGgMzwSWryYCYhJq8NXUy skWi8RHFrwaE+34RUzI8Oic6Lqb2onqxFLm2e20xVEVEYSiRvcug3ELZBVylggWSgxw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793697697; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=gZHsMDdpmPsnd9fVKQ5HXshg/Ennof29jt+F+15lfj0=; b=OitjigpaMQHDpySwezAK1xXBBuukCH7E23fkPIDLKtkD1grNmy0CcAOugoYdmFWphBTW 9/yfOo0HZELOTTYPQDJL34zFS61FGkYwbS84XHt/LjrAOAHdaG1xWyjdBxvILxx/ok0+Z 1XTqBM8/N89eposawPYRsDyls9WlBjigXaqs7HTWb5GahzegcSbfiJ8IAahtv4OyCK0vz G7cPem+Sm4F6ZxNozj1CQvts3tLH+DCzsTtzH3bzY0pcohUbODAfzuEooOdqxQNkYbfI8 xpvyYtCrYwPrSWzJeAKLGDZzh02K9ypqrYUkLOSXt8gqzKNOQPXOqdOJ7AoHmongm6A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="K3tC/zFB"; arc=none smtp.remote-ip=91.218.175.49 X-Received: from mta0.migadu.com (out-49.mta0.migadu.com [91.218.175.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65613606A32D for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 09:21:36 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65613606A32D X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=+cX65HWUnORHAEQhsq35CFgzfw7YbOZo0pOLpUvDick=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793697694; v=1; x=1794302494; b=K3tC/zFBBRu4ADhoe1N2zLREOqd3FVjNSxtKLe0SuRZRBOxT2XDSserV5nj0LFXrncQ7KbyB sFaC5V24BpTtlNrl43iEJNiK6UNAt3Lnl7DwaCuN4LjvlRLc6zWUB80zfuHUuzT7OimvJeNGY90 M0+RziEd0Rb4k6S9T/6qMLK8= X-Envelope-To: netdev@vger.kernel.org X-Received: by mta10.migadu.com with ESMTPS id a7b269fb289dbe95; Tue, 03 Nov 2026 09:21:34 +0000 X-Mizu-Trace-ID: a7b269fb289dbe95 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261103-ipv6_ioam_ecmp-v2-0-6ef0318bdb5e@kylinos.cn> X-Cc: Hangbin Liu <hangbin.liu@linux.dev>, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Hangbin Liu <liuhangbin@kylinos.cn> X-Mailer: b4 0.16.0