git: 1db6e2c6c355 - main - rtnetlink: Use default weight for unset weights in NHA_GROUP
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Nov 2026 21:51:20 UTC
The branch main has been updated by pouria:
URL: https://cgit.FreeBSD.org/src/commit/?id=1db6e2c6c3554efe5acdcc20bc7aa889e1efe372
commit 1db6e2c6c3554efe5acdcc20bc7aa889e1efe372
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-13 21:47:24 +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")
---
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 93c468e785c8..3d5546ffe317 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -174,7 +174,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 e5f776e9d052..2cbaffcebcbd 100644
--- a/sys/netlink/route/nexthop.c
+++ b/sys/netlink/route/nexthop.c
@@ -778,7 +778,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;