Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341733; b=47HsET/pd+Ed4iyvGUBzG+VVpxBwb1PqDWcrxBBfyRdq1oBeJYVqJgDRBFXxE8Oc7sHE O5aMxjDoBhSlIVbfMTXZLKMmW4BTMP03xShYgOUB3SrzoxfexFd5OXCJFw7CXVIRAdUTD aTv15X5dZKWm5y/k4VzeaU9I82yFULqHcIMbVkAgy9f9SraiLuOlD21Q292gyNSJ3tF/A zQa6CII+xujgqiWI+REP8S0/MY4S/EVc05N4kSoMmpAgvm09UdBVG5JC5MZ+nhW0s2G2g zm18lUe1EebTcibhkdCT1ALMAetpwLJT3aDIlZGe3VdZfD6hrDcxZTDyb+36i5NdDHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341733; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: X-Relaying-Domain:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=okeUmTqKAR2nipG/oudqkzOJ2G5TepPZtmmbg0mWFl4=; b=EHM6ygX3Lc1YuZXMKUQLs/jvB8dFmKZQob5ih093rDVcO0wLgrcIokcSDceDX0wFXSaR HyNyODAaBpYZQkkcDNgNBTwFmEi0OicdNEvPKCZmsLBxBELqYtQ4c1yjU8IGcphG4zuw0 TIDeDWCW7xMTxaJJXPxZa6n9H1GY8X0izxIKrSqleNtnAa30jeXmMra1KQHI/HQN3uU2C dgQPKEUlXXnIngePndaPQmbgAdzuOgVyjn/HE6597Lgx3yz1+uiLf4LnDHXKCGExI8w5D OPKLfnNii7os+md57M3B7W0Fr9PVncjj/DhY/QvDiNrJAXbKKcBKSIF9rz2wQxqJ96Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=everpuredata.com; spf=pass smtp.mailfrom=everpuredata.com; dkim=pass header.d=everpuredata.com header.i=@everpuredata.com header.a=rsa-sha256 header.s=google header.b=Jg3UDJdg; arc=none smtp.remote-ip=209.85.128.100 Received: from mail-wm1-f100.google.com (mail-wm1-f100.google.com [209.85.128.100]) (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 54642606A333 for ; Thu, 3 Dec 2026 23:48:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54642606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=everpuredata.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=everpuredata.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=everpuredata.com header.i=@everpuredata.com header.a=rsa-sha256 header.s=google header.b=Jg3UDJdg Received: by mail-wm1-f100.google.com with SMTP id 5b1f17b1804b1-4bb6adaf0f1so2397635e9.0 for ; Thu, 03 Dec 2026 15:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=everpuredata.com; s=google; t=1796341731; x=1796946531; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=okeUmTqKAR2nipG/oudqkzOJ2G5TepPZtmmbg0mWFl4=; b=Jg3UDJdgWupdzG28/1FNZw+K779hpcvaA3YZVVzVcU6WvQIMFExE+cXS/fZ1V3eylw 5ZDydkpuYr+7CvdF/CWILNoEm5iFZCoxdK1YXWVHwZ/pRXBknNMZJLE47I2vUQJHsLfO nHYoV7L638OurgC4hdP9GJtFokBbJiV35V9FMzWF/eL+agoaia4YAZCpoirCUnhX/vPN mGhJNdz7XQheituVRVkGEMJI3UgAMORSMV3rUbaAmKu7sxZ8NPpxGkwYigJhRAnsGwOw bP/euo5oWCYlzd7yWO3sAkrQf6wykd2AV6iNZIPdbiVzgvSvTE4X95cSZVNjSxzymB1a 886g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796341731; x=1796946531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=okeUmTqKAR2nipG/oudqkzOJ2G5TepPZtmmbg0mWFl4=; b=F3P2mLxMv8YKP4NhUfLD9YNSu+lxzK7CwI3YuaPUCZ6+f6L8zvgGfFDAUU/apmkGsN pMv6t0kygFlI1Yi02z4s3UsJ8KS7NIFd2IRdAID7/wwxI4ZD2E/GR1AuGW9CUA4og/Rm VBmqUVF+ourd+BgR2cJPLQ+qYeumXouhNeYbwpS3PgVh1wsrIDdazq908C0tVJINmEDp UsTvVrI/HgJi/KXiUEV8PvruoaQn768M8wCcC+Q+bLiEstx/a33RDpx5RacgLFZsG0o6 JpnI5338Nq8pGnYIfS6WnToV6y42hy9X8YH7sZWt0My60wu63crAwqSuNKHzxnFNgCc8 Mrkw== X-Forwarded-Encrypted: i=1; AL+hErFHf9GdkpR/AeabW1eR2j0M10QMtEcKl5//UoPHtuTIBG8MOKc4IPxvLCXlpS4kVuqXG7BuEc6CjhXCzF0207Q=@vger.kernel.org X-Gm-Message-State: APuU4Z8rAw9Kw2g97+sUipJBdjxS4tYmciazE2c6Uu9b78fxXMZwJiaD a0l8+L8HJexwHSYZstGMGAAqCKOQ+jr+tMy2LL/O5hvCWT06VgF9z1NKu/sk5S1uXnQDLTE0xeX 7xSA7b1Zf3R6ka4h4FyXiZiYGfy1WRdekADzm X-Gm-Gg: AZFdTZdP6W0t6jQte7V8RZWx/ySy3IAed5PKUrd5nW5lfR43tOuxSuV3FurIIcgCotm b7qee8tAsp4WVm7aP6cFfew9O/9DJbOzbq+ibyGqDSYa463vC+a1uwUOb+Fpc+P6wuksXqDFIzQ ks9u6ARzYbgW9Psk7lfkcS4igVD9lR8rZNESt/J2Z9Yjgb/MCVeX5ND8FvnCwPSs8W1Cs7GixKY 9tUAiCFvFVC9lCYiX6/FqLcT5cn9nInoZqw4fVtTVk+WdEYQV72dmWGB7ycF4Pb0Ed+rUMhBt+h LlVbFBLv93jJmaDF5ISfTs00IziRZtOO6LCx6/ryQbRkcUuYIpihZ9bCg5m4UHOBKGCFPE7+D3Y 59RZ+nt/vcdT4oTB6ljLMMLSiOJrWNwWpjvBEerA= X-Received: by 2002:a05:600c:310b:b0:4bb:872a:f500 with SMTP id 5b1f17b1804b1-4bbeb6ed14amr3887295e9.3.1796341730735; Thu, 03 Dec 2026 15:48:50 -0800 (PST) Received: from c14-smtp-2023.dev.purestorage.com ([208.88.158.128]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-4bbdff6174asm14436595e9.0.2026.12.03.15.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 15:48:50 -0800 (PST) X-Relaying-Domain: everpuredata.com Received: from irdv-tmenninger.dev.purestorage.com (irdv-tmenninger.dev.purestorage.com [10.32.149.15]) by c14-smtp-2023.dev.purestorage.com (Postfix) with ESMTPS id 50BC834050C; Thu, 3 Dec 2026 15:48:19 -0800 (PST) From: Tim Menninger 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 Subject: [PATCH v2 1/3] ipv6: Use the selected nexthop for source address selection Date: Thu, 3 Dec 2026 23:47:18 +0000 Message-ID: <20261203234720.2428689-2-tmenninger@everpuredata.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203234720.2428689-1-tmenninger@everpuredata.com> References: <20261203234720.2428689-1-tmenninger@everpuredata.com> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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