From: David Lamparter <equinox@diac24.net>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Cc: David Lamparter <equinox@diac24.net>,
Lorenzo Colitti <lorenzo@google.com>,
Patrick Rohr <prohr@google.com>
Subject: [RESEND PATCH net-next v2 3/4] net/ipv6: use ipv6_fl_get_saddr in output
Date: Tue, 4 Nov 2025 09:48:21 -0500 [thread overview]
Message-ID: <20251104144824.19648-4-equinox@diac24.net> (raw)
In-Reply-To: <20251104144824.19648-1-equinox@diac24.net>
Flatten ip6_route_get_saddr() into ip6_dst_lookup_tail (which really
just means handling fib6_prefsrc), and then replace ipv6_dev_get_saddr
with ipv6_fl_get_saddr to pass down the flow information.
Signed-off-by: David Lamparter <equinox@diac24.net>
---
net/ipv6/ip6_output.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index f904739e99b9..28406ed5ddfb 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1126,27 +1126,40 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
int flags = 0;
/* The correct way to handle this would be to do
- * ip6_route_get_saddr, and then ip6_route_output; however,
+ * ipv6_fl_get_saddr, and then ip6_route_output; however,
* the route-specific preferred source forces the
- * ip6_route_output call _before_ ip6_route_get_saddr.
+ * ip6_route_output call _before_ ipv6_fl_get_saddr.
*
* In source specific routing (no src=any default route),
* ip6_route_output will fail given src=any saddr, though, so
* that's why we try it again later.
*/
if (ipv6_addr_any(&fl6->saddr)) {
+ struct net_device *l3mdev;
+ struct net_device *dev;
struct fib6_info *from;
struct rt6_info *rt;
+ bool same_vrf;
*dst = ip6_route_output(net, sk, fl6);
rt = (*dst)->error ? NULL : dst_rt6_info(*dst);
rcu_read_lock();
from = rt ? rcu_dereference(rt->from) : NULL;
- err = ip6_route_get_saddr(net, from, &fl6->daddr,
- sk ? READ_ONCE(inet6_sk(sk)->srcprefs) : 0,
- fl6->flowi6_l3mdev,
- &fl6->saddr);
+
+ l3mdev = dev_get_by_index_rcu(net, fl6->flowi6_l3mdev);
+ if (!from || !from->fib6_prefsrc.plen || l3mdev)
+ dev = from ? fib6_info_nh_dev(from) : NULL;
+ same_vrf = !l3mdev || l3mdev_master_dev_rcu(dev) == l3mdev;
+ if (from && from->fib6_prefsrc.plen && same_vrf) {
+ fl6->saddr = from->fib6_prefsrc.addr;
+ err = 0;
+ } else
+ err = ipv6_fl_get_saddr(net, *dst,
+ same_vrf ? dev : l3mdev, sk,
+ sk ? READ_ONCE(inet6_sk(sk)->srcprefs) : 0,
+ fl6);
+
rcu_read_unlock();
if (err)
--
2.50.1
next prev parent reply other threads:[~2025-11-04 14:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 14:48 [RESEND PATCH net-next v2 0/4] net/ipv6: RFC6724 rule 5.5 preparations David Lamparter
2025-11-04 14:48 ` [RESEND PATCH net-next v2 1/4] net/ipv6: flatten ip6_route_get_saddr David Lamparter
2025-11-04 17:52 ` Lorenzo Colitti
2025-11-04 14:48 ` [RESEND PATCH net-next v2 2/4] net/ipv6: create ipv6_fl_get_saddr David Lamparter
2025-11-04 17:51 ` Lorenzo Colitti
2025-11-04 20:47 ` David Lamparter
2025-11-04 21:16 ` David Lamparter
2025-11-11 9:50 ` Paolo Abeni
2025-11-04 14:48 ` David Lamparter [this message]
2025-11-04 17:52 ` [RESEND PATCH net-next v2 3/4] net/ipv6: use ipv6_fl_get_saddr in output Lorenzo Colitti
2025-11-11 9:56 ` Paolo Abeni
2025-11-04 14:48 ` [RESEND PATCH net-next v2 4/4] net/ipv6: drop ip6_route_get_saddr David Lamparter
2025-11-04 17:51 ` Lorenzo Colitti
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=20251104144824.19648-4-equinox@diac24.net \
--to=equinox@diac24.net \
--cc=kuba@kernel.org \
--cc=lorenzo@google.com \
--cc=netdev@vger.kernel.org \
--cc=prohr@google.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;
as well as URLs for NNTP newsgroup(s).