[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250724150042.6361-4-equinox@diac24.net>
Date: Thu, 24 Jul 2025 17:00:40 +0200
From: David Lamparter <equinox@...c24.net>
To: netdev@...r.kernel.org,
David Ahern <dsahern@...nel.org>,
"David S. Miller" <davem@...emloft.net>
Cc: David Lamparter <equinox@...c24.net>,
Lorenzo Colitti <lorenzo@...gle.com>,
Patrick Rohr <prohr@...gle.com>
Subject: [PATCH net-next v2 3/4] net/ipv6: use ipv6_fl_get_saddr in output
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@...c24.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 0412f8544695..73c2cc8db06d 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1115,27 +1115,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.47.2
Powered by blists - more mailing lists