From: Maximilian Moehl <maximilian@moehl.eu>
To: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Maximilian Moehl <maximilian@moehl.eu>
Subject: [PATCH] net/ipv6: repeat route lookup with saddr set for ECMP
Date: Sun, 29 Mar 2026 11:12:01 +0200 [thread overview]
Message-ID: <20260329091201.63646-1-maximilian@moehl.eu> (raw)
When the routing decision involves ECMP, the initial hash is calculated
with saddr being :: and the decision which interface to select from an
ECMP group is based on that hash. If the route lookup has to be
repeated, e.g. because a route was updated, the hash is calculated with
saddr set to the previously selected address. This can cause the
selected interface to change, breaking ongoing connections.
To ensure the initial interface selection is based on an actual saddr
the route lookup is repeated after the source address selection if a
hash was calculated.
Signed-off-by: Maximilian Moehl <maximilian@moehl.eu>
Link: https://lore.kernel.org/all/aOYLRyIlc7XU7-7n@shredder/
---
I've created a write-up of what I've done, including the steps taken
to test the patch: https://moehl.eu/blog/linux-ipv6-ecmp-instability.html
net/ipv6/ip6_output.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 8e2a6b28cea7..465fce51d017 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1148,6 +1148,18 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
*dst = NULL;
}
+ /* If ECMP was involved the initial hash was calculted
+ * with saddr=:: which can result in instability
+ * when it is later re-calculated with the selected
+ * saddr. Lookup the route again with the chosen
+ * saddr to get a stable result.
+ */
+ if (fl6->mp_hash) {
+ fl6->mp_hash = 0;
+ dst_release(*dst);
+ *dst = NULL;
+ }
+
if (fl6->flowi6_oif)
flags |= RT6_LOOKUP_F_IFACE;
}
base-commit: dc9e9d61e301c087bcd990dbf2fa18ad3e2e1429
--
2.53.0
next reply other threads:[~2026-03-29 10:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 9:12 Maximilian Moehl [this message]
2026-03-30 7:56 ` [PATCH] net/ipv6: repeat route lookup with saddr set for ECMP Paolo Abeni
2026-03-31 12:50 ` Maximilian Moehl
2026-04-11 8:18 ` Maximilian Moehl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260329091201.63646-1-maximilian@moehl.eu \
--to=maximilian@moehl.eu \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox