mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Menninger <tmenninger@everpuredata.com>
To: leon@kernel.org
Cc: jgg@ziepe.ca, bharat@chelsio.com, dsahern@kernel.org,
	idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	shuah@kernel.org, slingappa@everpuredata.com,
	rpatil@everpuredata.com, linux-rdma@vger.kernel.org,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Tim Menninger <tmenninger@everpuredata.com>
Subject: [PATCH v2 1/3] ipv6: Use the selected nexthop for source address selection
Date: Thu,  3 Dec 2026 23:47:18 +0000	[thread overview]
Message-ID: <20261203234720.2428689-2-tmenninger@everpuredata.com> (raw)
In-Reply-To: <20261203234720.2428689-1-tmenninger@everpuredata.com>

When a route uses a multipath nexthop group and has no preferred
source, ip6_route_get_saddr() selects the source address for
fib6_info_nh_dev(), which is the group's first nexthop. The lookup may
have selected a different nexthop, so the source address can belong to
another interface than the one the packet leaves through:

  $ ip -6 route get fd00:ecb:eeee::1
  ... via fe80::b2cf:eff:feaf:6eb6 dev ens6np0 src fd00:ecb::3 ...

where fd00:ecb::3 is assigned to ens3np0. IPv6 legacy multipath routes
and IPv4 nexthop groups both select the source address for the chosen
path. TCP and UDP can operate with a source address assigned to another
interface, but RoCE address resolution requires a matching GID on the
selected device, and rdma_cm address resolution fails with -ENODEV
whenever the hash selects a nexthop other than the first.

Pass the dst to ip6_route_get_saddr() and, for a multipath nexthop
group, select the source address for the device of the selected path.
A configured preferred source still takes precedence, and routes without
a multipath nexthop group are unchanged.

Tested on a host with two ConnectX-7 ports, an IPv6 route through a
two-member nexthop group and hash policy 1, with rdma_cm resolving the
address and route of 64 IDs per destination. Before this change, every
ID failed for three destinations whose hash selected the second
nexthop. After it, every ID resolved, with the source address on the
egress port. A route with a preferred source on another interface kept
that source, and local destinations resolved as before.

Fixes: f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")
Signed-off-by: Tim Menninger <tmenninger@everpuredata.com>
---
Changes in v2:
- New patch, replacing the addr6_resolve() fix proposed on v1

 include/net/ip6_route.h | 9 +++++++--
 net/ipv6/ip6_output.c   | 3 ++-
 net/ipv6/route.c        | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 95f936be32c6..d5754f6442bb 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -143,6 +143,7 @@ void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args,
 			unsigned long now);
 
 static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
+				      const struct dst_entry *dst,
 				      const struct in6_addr *daddr,
 				      unsigned int prefs, int l3mdev_index,
 				      struct in6_addr *saddr)
@@ -155,8 +156,12 @@ static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
 	rcu_read_lock();
 
 	l3mdev = dev_get_by_index_rcu(net, l3mdev_index);
-	if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev)
-		dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
+	if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev) {
+		if (dst && f6i && f6i->nh && nexthop_is_multipath(f6i->nh))
+			dev = dst_dev_rcu(dst);
+		else
+			dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
+	}
 	same_vrf = !l3mdev || l3mdev_master_dev_rcu(dev) == l3mdev;
 	if (f6i && f6i->fib6_prefsrc.plen && same_vrf)
 		*saddr = f6i->fib6_prefsrc.addr;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index cb648c839431..6627dac626e8 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1162,7 +1162,8 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
 
 		rcu_read_lock();
 		from = rt ? rcu_dereference(rt->from) : NULL;
-		err = ip6_route_get_saddr(net, from, &fl6->daddr,
+		err = ip6_route_get_saddr(net, from, rt ? &rt->dst : NULL,
+					  &fl6->daddr,
 					  sk ? READ_ONCE(inet6_sk(sk)->srcprefs) : 0,
 					  fl6->flowi6_l3mdev,
 					  &fl6->saddr);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066e19..aec54368e1ba 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5881,7 +5881,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
 				goto nla_put_failure;
 	} else if (dest) {
 		struct in6_addr saddr_buf;
-		if (ip6_route_get_saddr(net, rt, dest, 0, 0, &saddr_buf) == 0 &&
+		if (ip6_route_get_saddr(net, rt, dst, dest, 0, 0, &saddr_buf) == 0 &&
 		    nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
 			goto nla_put_failure;
 	}
-- 
2.53.0


  reply	other threads:[~2026-12-03 23:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 23:47 [PATCH v2 0/3] Spread rdma_cm connections across ECMP paths Tim Menninger
2026-12-03 23:47 ` Tim Menninger [this message]
2026-12-03 23:47 ` [PATCH v2 2/3] selftests: fib_nexthops: Check the IPv6 multipath source address Tim Menninger
2026-12-03 23:47 ` [PATCH v2 3/3] RDMA/core: Use the CM source port in IP route lookups Tim Menninger

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=20261203234720.2428689-2-tmenninger@everpuredata.com \
    --to=tmenninger@everpuredata.com \
    --cc=bharat@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rpatil@everpuredata.com \
    --cc=shuah@kernel.org \
    --cc=slingappa@everpuredata.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

all inboxes | Powered by JetHome®