netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 1/2] net: fib: restore ECMP balance from loopback
@ 2025-12-13 13:58 Vadim Fedorenko
  2025-12-13 13:58 ` [PATCH net 2/2] selftests: fib_nexthops: Add test case for ipv4 multi nexthops Vadim Fedorenko
  2025-12-13 20:54 ` [PATCH net 1/2] net: fib: restore ECMP balance from loopback Willem de Bruijn
  0 siblings, 2 replies; 11+ messages in thread
From: Vadim Fedorenko @ 2025-12-13 13:58 UTC (permalink / raw)
  To: David S. Miller, David Ahern, Eric Dumazet, Paolo Abeni,
	Simon Horman, Willem de Bruijn, Jakub Kicinski
  Cc: Shuah Khan, Ido Schimmel, netdev, Vadim Fedorenko

Preference of nexthop with source address broke ECMP for packets with
source address from loopback interface. Original behaviour was to
balance over nexthops while now it uses the latest nexthop from the
group.

For the case with 198.51.100.1/32 assigned to lo:

before:
   done | grep veth | awk ' {print $(NF-2)}' | sort | uniq -c:
    255 veth3

after:
   done | grep veth | awk ' {print $(NF-2)}' | sort | uniq -c:
    122 veth1
    133 veth3

Fixes: 32607a332cfe ("ipv4: prefer multipath nexthop that matches source address")
Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
---
 net/ipv4/fib_semantics.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index a5f3c8459758..c54b4ad9c280 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -2165,9 +2165,9 @@ static bool fib_good_nh(const struct fib_nh *nh)
 void fib_select_multipath(struct fib_result *res, int hash,
 			  const struct flowi4 *fl4)
 {
+	bool first = false, found = false;
 	struct fib_info *fi = res->fi;
 	struct net *net = fi->fib_net;
-	bool found = false;
 	bool use_neigh;
 	__be32 saddr;
 
@@ -2190,23 +2190,24 @@ void fib_select_multipath(struct fib_result *res, int hash,
 		    (use_neigh && !fib_good_nh(nexthop_nh)))
 			continue;
 
-		if (!found) {
+		if (saddr && nexthop_nh->nh_saddr == saddr) {
 			res->nh_sel = nhsel;
 			res->nhc = &nexthop_nh->nh_common;
-			found = !saddr || nexthop_nh->nh_saddr == saddr;
+			return;
 		}
 
-		if (hash > nh_upper_bound)
-			continue;
-
-		if (!saddr || nexthop_nh->nh_saddr == saddr) {
+		if (!first) {
 			res->nh_sel = nhsel;
 			res->nhc = &nexthop_nh->nh_common;
-			return;
+			first = true;
 		}
 
-		if (found)
-			return;
+		if (found || hash > nh_upper_bound)
+			continue;
+
+		res->nh_sel = nhsel;
+		res->nhc = &nexthop_nh->nh_common;
+		found = true;
 
 	} endfor_nexthops(fi);
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-12-15 21:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-13 13:58 [PATCH net 1/2] net: fib: restore ECMP balance from loopback Vadim Fedorenko
2025-12-13 13:58 ` [PATCH net 2/2] selftests: fib_nexthops: Add test case for ipv4 multi nexthops Vadim Fedorenko
2025-12-13 21:18   ` Willem de Bruijn
2025-12-13 21:26     ` Vadim Fedorenko
2025-12-13 22:02       ` David Ahern
2025-12-15  6:59   ` Ido Schimmel
2025-12-15 16:13     ` David Ahern
2025-12-15 19:01     ` Vadim Fedorenko
2025-12-13 20:54 ` [PATCH net 1/2] net: fib: restore ECMP balance from loopback Willem de Bruijn
2025-12-13 21:22   ` Vadim Fedorenko
2025-12-15 21:45     ` Willem de Bruijn

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).