From mboxrd@z Thu Jan 1 00:00:00 1970 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=SXGRATtkt0Jj8eQBoGw9pPGSJeSHX9WanTTq/fE84E4f5nJXOP0a197iNLet/fQQy58x bpza36R7SAyTfBDzrvp0hfkuMia1YaViUA0WIpV2yQseEDmICExpzjiRKcHRXlXEXXLqA /bRn3AfFh5yr826sVB6Qoj4AuOr/CMGHvauPv4cipQam9GD5vju/etiGuUrN8FJg2uoxy tyWt/4emhEe1FrSkr7Z1B0O0cuOJZ6koB/b66VTC1SAc9GT356/BXb7RmvwsoFNqwetck d4cZPC5eqgPKrj04sObu2F5Kc2IXAC1H966d+4nMAZP9BWrDLdCVhgT2hVU4ZmxdOsg== 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=299WOiUGKPztnPHpi0qUNYGe78aLNI0ji04Wd/haykA7LCkiy01UVfY/mxY2gHWMHklb AGJqWt5NtyQ9zSOpyufsc8BECE9zG7T0J8ZxtMtqx7ZrrCvHzM8m5oJHR9y2ReLoGzPWW MnyIp2wPn/Wpw981Xp3z/le+nG8ZyCSWlPOhGXjXsW2jwD4v4r2/3ED60iHeLM/GS4XhO h9SmNAX6vSEphiLZdYX6rMPnthQZQQDKwXg9V/+OULup86XezuOn0teJOU7xnSw2fqEFA O6JdonW6p08DoaLS2DohxxncKEJ7+NJxROYseNMPfFlDpvs9aQrBjTYuNS+P4SQ3EYA== 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 54664606A335 for ; Thu, 3 Dec 2026 23:48:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 54664606A335 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-4bb5b8ef642so3050935e9.1 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=seVCJptyiDh9jBeSU0t8GiQZv543KREMC61eE9Dpi05UthC0496SLHtBOiXLgnlIEz FbNRab5jGZoLvvbCBdbn6VS28xtUstRyHvCO0HUdZHlhtTeYnXB7xQvMMr3aI3grjTFn myiuV63yJatzGkXWr0ucZeDVvQGO9dBKI/xNpUAwalDn9yeiqO5RB2DH+NZ7uoQGsWiA Uxvg00kdzQ57NggOP2CUylnFMS9tafpD6Sq2SaBUB5tE+fPN0AwaYOVHS6YICwejc5+f aLR5jQtFM2TnEyQi8J9FJiv4XKsDt8V1BJIYTTUnkdtGBu6W489O59jXy7zY0r7DzqKq L77A== X-Forwarded-Encrypted: i=1; AL+hErHiLo+x+WNpUY+xns5S7c09BwIvX/sdwQJ5hILCwFj3hySqIrof7T3MPhHJvPD0XfOSKnSIqML2WbOCgKI=@vger.kernel.org X-Gm-Message-State: APuU4Z/zeUh0t27CoO/xMk7wNMrnCW+8P/OKEst2jBwwwqzNu+OqIxk6 fsKmNd1NJXLn1DM8RgbzYAnPoGY2JbH1QR0qDntqBwMDulupUnXsXgbMofB7iiFB5NsRd03BGgI J/4eDbp3WSIP6ARFm9fb4ISKNdeiv3BJYOwGU X-Gm-Gg: AZFdTZdxZ1jg9O3rx3NkQ/ke8ENErEZBUr95Ta5B/JczaJaHuSap1xlXDQUAMJCA9By 0EbXxIXkRzgAihg6qEIJBkwUIamVnJDBtekTXTOcLAz0+d8obggCociavFQgBdwlIzFOHjOuGAH ++I5nhrp7GDIZ7e2wZU+rydiTkdk/Lb+X2t7R/l7JiWHoVZex4QQHRspKYqk+FusWf8dzSQHLgZ yBSIxEO8IP7pfX7bSgYZekuZM+dHMLbkT0+TccG6ikczqvWS8NFRSSGsYpdjtx8o5vZA14Yp0p3 5thQAxXc0KHXu55nW6eeBoPgJ5XQBbFwXEvPDS7dZyhNRVcI68A/zZJmgcgTO4V6LZbxhjWiYmH WnpcZBxJJ01k6tUGDCn8Zc3+DmsWlonILgHJgIC8= 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-kernel@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