Hello, I believe there is a regression in the multipath route selection algorithm in sys/net/rtable.c, introduced by commit bdf12720a479 on July 10, 2025:
https://github.com/openbsd/src/commit/bdf12720a47942798ca6067c46b4be424af5eef5 During the SRP-to-SMR conversion, the selection logic in rtable_match() changed from advancing through the route list and then selecting the resulting entry to assigning the selected route before advancing. The current code contains: mrt = rt; while (hash > threshold) { if (mrt->rt_priority == prio) { rt = mrt; hash -= threshold; } mrt = SMR_PTR_GET(&mrt->rt_next); if (mrt == NULL) break; } With two equal-priority nexthops: - hash ranges from 0 to 65535. - threshold is 32768. - For hash <= 32768, the loop is not entered. - For hash > 32768, the first iteration assigns rt = mrt, where mrt still points to the first nexthop. - After subtracting 32768, the remaining hash is below the threshold, so the loop terminates without selecting the second nexthop. Consequently, the first nexthop is selected for all 65,536 possible hash values, and the second nexthop is never selected. The same issue affects larger multipath groups, producing an uneven distribution and leaving the last nexthop unreachable by the selection algorithm. The implementation before commit bdf12720a479 selected the route after advancing through the list. This appears to be an off-by-one error introduced during the SMR conversion, rather than an intentional change to the Hash-Threshold algorithm (RFC 2992). The issue appears to affect OpenBSD 7.8, 7.9, and 8.0, as well as the current source tree. I have verified the selection behavior by examining the source code and exhaustively evaluating the hash range, but I have not tested a patched kernel. Could you please review the route selection loop in rtable_match()? Thank you.
