aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPouria Mousavizadeh Tehrani <pouria@FreeBSD.org>2026-05-27 09:58:34 +0000
committerPouria Mousavizadeh Tehrani <pouria@FreeBSD.org>2026-05-28 20:00:15 +0000
commit97f7b21dd52542421bc883e336e35af078af47fe (patch)
treee879cfc8014fe5a1997a5e4a070b383316cdea47
parent774543072db4949a4177ad4bbdac9fb712bc86f6 (diff)
rtnetlink: Fix weight overflow in RTA_MULTIPATH
If the weight value is larger than 8 bits, set it to the maximum. Also, only send RTA_WEIGHT if its value is not the default. This reduces message size and matches the behavior of non-multipath routes. Reviewed by: emaste, markj Differential Revision: https://reviews.freebsd.org/D57266
-rw-r--r--sys/netlink/route/rt.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index ee17737426ed..17aae399c10a 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -217,7 +217,7 @@ dump_rc_nhg(struct nl_writer *nw, const struct route_nhop_data *rnd, struct rtms
return;
rtnh->rtnh_flags = 0;
rtnh->rtnh_ifindex = if_getindex(wn[i].nh->nh_ifp);
- rtnh->rtnh_hops = wn[i].weight;
+ rtnh->rtnh_hops = MIN(wn[i].weight, UINT8_MAX);
dump_rc_nhop_gw(nw, wn[i].nh);
uint32_t rtflags = nhop_get_rtflags(wn[i].nh);
if (rtflags != base_rtflags)
@@ -242,7 +242,8 @@ dump_rc_nhg(struct nl_writer *nw, const struct route_nhop_data *rnd, struct rtms
}
nlattr_set_len(nw, off);
nlattr_add_u32(nw, NL_RTA_PRIORITY, nhop_metric);
- nlattr_add_u32(nw, NL_RTA_WEIGHT, nhop_weight);
+ if (nhop_weight != RT_DEFAULT_WEIGHT)
+ nlattr_add_u32(nw, NL_RTA_WEIGHT, nhop_weight);
}
static void