On Wed, Nov 25, 2026 at 03:41:05PM +0100, Claudio Jeker wrote:
> With this diff I see both routes of a multipath couple used:
> Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
> default            10.83.0.1          UGSP       7      510     -     8 re0  
> default            10.83.0.2          UGSP       5      293     -     8 re0  
> 
> Before the 2nd one was never used.

Better than before.  But the use counter is still not evenly
distributed.  I have updated regress/sys/net/mpath to check that.

The route itself has npaths number 1.  Every next route counts one
more.  Diff below fixes distribution in my test.

Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
10.11.0.0          10.0.11.1          UGHSBP     0       42 32768     8 lo11
10.11.0.0          10.0.11.2          UGHSBP     0       35 32768     8 lo11
10.11.0.0          10.0.11.3          UGHSBP     0       34 32768     8 lo11
10.11.0.0          10.0.11.4          UGHSBP     0       29 32768     8 lo11
10.11.0.0          10.0.11.5          UGHSBP     0       39 32768     8 lo11
10.11.0.0          10.0.11.6          UGHSBP     0       33 32768     8 lo11
10.11.0.0          10.0.11.7          UGHSBP     0       38 32768     8 lo11

with that fix, OK bluhm@

Index: net/rtable.c
===================================================================
RCS file: /mount/openbsd/cvs/src/sys/net/rtable.c,v
diff -u -p -r1.97 rtable.c
--- net/rtable.c        25 Nov 2026 13:26:49 -0000      1.97
+++ net/rtable.c        25 Nov 2026 19:03:13 -0000
@@ -506,10 +506,11 @@ rtable_match(unsigned int rtableid, cons
                KASSERT(hash <= 0xffff);
 
                /* Only count nexthops with the same priority. */
-               mrt = rt;
-               while ((mrt = SMR_PTR_GET(&mrt->rt_next)) != NULL) {
-                       if (mrt->rt_priority == prio)
-                               npaths++;
+               for (mrt = SMR_PTR_GET(&rt->rt_next); mrt != NULL;
+                   mrt = SMR_PTR_GET(&mrt->rt_next)) {
+                       if (mrt->rt_priority != prio)
+                               break;
+                       npaths++;
                }
 
                threshold = (0xffff / npaths) + 1;
@@ -521,15 +522,14 @@ rtable_match(unsigned int rtableid, cons
                 * we'll pick a route that we wouldn't have if we only saw the
                 * list before or after the change.
                 */
-               mrt = rt;
-               while (hash > threshold) {
-                       if (mrt->rt_priority == prio) {
+               for (mrt = rt; mrt != NULL; mrt = SMR_PTR_GET(&mrt->rt_next)) {
+                       if (mrt->rt_priority != prio)
+                               break;
+                       if (hash <= threshold) {
                                rt = mrt;
-                               hash -= threshold;
-                       }
-                       mrt = SMR_PTR_GET(&mrt->rt_next);
-                       if (mrt == NULL)
                                break;
+                       }
+                       hash -= threshold;
                }
        }
        rtref(rt);

Reply via email to