git: 3e6cc8543049 - stable/15 - rtnetlink: Use default weight for unset weights in NHA_GROUP

From: Pouria Mousavizadeh Tehrani <pouria_at_FreeBSD.org>
Date: Fri, 27 Nov 2026 08:35:47 UTC
The branch stable/15 has been updated by pouria:

URL: https://cgit.FreeBSD.org/src/commit/?id=3e6cc854304958dae40ae96458fccced32428d5f

commit 3e6cc854304958dae40ae96458fccced32428d5f
Author:     Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org>
AuthorDate: 2026-11-13 21:40:45 +0000
Commit:     Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org>
CommitDate: 2026-11-27 06:28:09 +0000

    rtnetlink: Use default weight for unset weights in NHA_GROUP
    
    newnhg() copied the weights of a nhgrp as is and a group
    whose members all have a zero weight, which is what
    userland sends when it leaves the weight unset, made
    calc_min_mpath_slots_fast() divide by zero.
    
    Therefore replace weight of zero with RT_DEFAULT_WEIGHT.
    
    While here, return early from calc_min_mpath_slots_fast()
    if all weights are zero.
    
    MFC after:      3 days
    Fixes:          7e5bf68495cc ("netlink: add netlink support")
    
    (cherry picked from commit 1db6e2c6c3554efe5acdcc20bc7aa889e1efe372)
---
 sys/net/route/nhgrp_ctl.c   | 2 +-
 sys/netlink/route/nexthop.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index c7a4e4e2619e..47372125160b 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -165,7 +165,7 @@ calc_min_mpath_slots_fast(struct weightened_nhop *wn, size_t num_items,
 	}
 	*ptotal = total;
 	/* xmin is the minimum unit of desired capacity */
-	if ((total % xmin) != 0)
+	if (xmin == 0 || (total % xmin) != 0)
 		return (0);
 	for (i = 0; i < num_items; i++) {
 		if ((wn[i].weight % xmin) != 0)
diff --git a/sys/netlink/route/nexthop.c b/sys/netlink/route/nexthop.c
index 8f3ebc123600..e01597970162 100644
--- a/sys/netlink/route/nexthop.c
+++ b/sys/netlink/route/nexthop.c
@@ -782,7 +782,7 @@ newnhg(struct unhop_ctl *ctl, struct nl_parsed_nhop *attrs, struct user_nhop *un
 		 * restrict nexthops with the same gateway
 		 */
 		wn[i].nh = unhop->un_nhop_src;
-		wn[i].weight = grp[i].weight;
+		wn[i].weight = grp[i].weight > 0 ? grp[i].weight : RT_DEFAULT_WEIGHT;
 	}
 	unhop->un_nhgrp_src = wn;
 	unhop->un_nhgrp_count = count;