From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.97 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341732; b=siGoyIpdQbU8fy26nf109ZkKaCx5EyPypg0qkNrSwvl+hwD4IOQ57Dy4bQ5dqLrjW/LK ecx/KkDenl5NbA6cKs6e+Gy1xHLypMePCa61ADf8JUeolNxWS+desxvwPZefNZXF/9zHg HxYWisIyLf9qBV9HcDvwU25DjoFVc01ZPBpeQEmIn9CWBBz7EeEbiAul57OOSVJWpTx8F m7aQU0Wp2bD9+NCERqWBXQLfUEyLEcdaoyvuH43MxL6BOtenSXBj7vsI6SNGEhQsEnFcL 9H10I38tb+/kBiliVtxx2oC0tK6O/1Qg3ZZVEJ7ztgxJVvdIiZjw21MnYG+6Ryq9d/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341732; 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=jI/MVwCrvpfSQiGfFzbIloeI0d5RAQC3hG9h7M7iNHCuI9cxA9RojZBllw/iC0AjUB+L dhJKsC5m0HmpXGnJpge6/abTqWh3AE2YeUmrJ0oV3qTfjMaDepD/KhrgllcMv/7zWvtxG wpqiWAX1jhSlaYAeOzaVYC10jS9FsR5mw+WYr9k9G4Iqj4S0sb4hcOT7vSTqaSl4bZ8h0 Pprv1kb23CJdm+ZowmMGlijwW/np/rCGCBU6D6a+375p6F2020Bu1zLYtfw3tDMMjDSze ldPtbVgYnIax7X7OzzEiCbftJLGGRxHLOG8QQReJGiwX2xQHWZk/Mz+HOkiDYZEGcpA== 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.97 Received: from mail-wm1-f97.google.com (mail-wm1-f97.google.com [209.85.128.97]) (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 52FB0606A330 for ; Thu, 3 Dec 2026 23:48:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52FB0606A330 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-f97.google.com with SMTP id 5b1f17b1804b1-4bbd2c5931bso2033215e9.2 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=k6rFAmB4NMxyUuHz72TA6PDyZHGjpgvtgt7BKwOQhJZorl93Ij2TSrt3prA9jQEj7k I56QAjDRNaTdeK0JH0i8TOj3jTQgSRPPpihyd3A6Mxtmjbfspi2fQnz616X/ClSTZEd+ SX0dfOQUFZVXLNHmH/qyR6DVIzvFegRRtf5U8v9JmmeIglWbkGlGPNRUiYRoDm63MB9D ZpEYKyc9cCCUYuAhfc9Pq6yU8nzGlmGp1jAMREhIHMr7pucf6Uzrc36YuYh6LeLaEces Zt9/DKdCSTHMISqk4SQWTRXMjpaebqlgRx0JXbVFKDx2Tktw/MVfarLXOHxLni7ztf3b Xz6Q== X-Forwarded-Encrypted: i=1; AL+hErGH3bYtml58D1+DGqfsROwu7hYDSZMosjUjO/7w6U6BagKhbk2K8ssC/LMduNZ5imkvM1PGAUA=@vger.kernel.org X-Gm-Message-State: APuU4Z+d0RimSfJvpnBFBkQNFENsc2dSQYQb3P5027dPFX2jOyVlvXqp MtOHLMi5bQ0zltriJ5BdPMUuws7xeL7Z7sC6izIec0jiJcz1v0Wk73Zqppu73L8C624baCyh1XZ s/G55cufK5pI0aiu3BaW6AuiFx4OIBb/ZXeEO X-Gm-Gg: AZFdTZcivhdL2bdIRXjnbUeJ+t63wT1HNp2QilrKcW/idBHDBd2tnJKRj6UAL8/dU49 ONC/k2BRifBHwokQk2meL0lv7bLuE4l0FGAHPqFCz4WKIqdDj3hj1Jl6VKE8YJQBrQ/0beUY19o wcICMphcIjnKGr7I2k5kL9l2b7ltLLOgn3sifWgKOEfkmoUyQx/Bu9HwIzVA2XMsgv2L7JkIPl0 eLGm0+r/RdiY0MXgKwMfPfCMkcX/iH7ZHsLsIBC810T6pXBoPlhoDMrmgoSzbIvf0mGE7om1YQF CvpdwUm7Bo9bCvbjLpaKXgsl4C/AZscvVO6EVwaQOJ/zffS1aykbR8ZgHUKlay+h6REr4Rao/YU XeWwLmDt0Sd4YVq4nvjJomngayl4uh/oEtnSNvDM= 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: netdev@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