Commit 29815972fa for frr
commit 29815972fa5a26953a0ca4a6e28e326ef92df424
Author: Srinivasan Koona Lokabiraman <srinivasan@nexthop.ai>
Date: Fri Oct 23 05:55:06 2026 +0000
bgpd: keep the fraction when displaying link bandwidth
ecommunity_lb_str() and ipv6_ecommunity_lb_str() format the bandwidth
as (float)(bw / ONE_GBPS_BYTES), and likewise for Mbps and Kbps. The
division is done in integers before the cast, so the fraction is lost:
1.5 Gbps (187500000 bytes/s) is shown as "1.000 Gbps" and 2.5 Mbps as
"2.000 Mbps", although the "%.3f" format is there to show it.
Divide as floats.
Signed-off-by: Srinivasan Koona Lokabiraman <srinivasan@nexthop.ai>
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index bfedaa2b3e..6e035b7ea1 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -1138,13 +1138,13 @@ static int ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt,
if (bw >= ONE_GBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Gbps",
- (float)(bw / ONE_GBPS_BYTES));
+ (float)bw / (float)ONE_GBPS_BYTES);
else if (bw >= ONE_MBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Mbps",
- (float)(bw / ONE_MBPS_BYTES));
+ (float)bw / (float)ONE_MBPS_BYTES);
else if (bw >= ONE_KBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Kbps",
- (float)(bw / ONE_KBPS_BYTES));
+ (float)bw / (float)ONE_KBPS_BYTES);
else
snprintfrr(bps_buf, sizeof(bps_buf), "%" PRIu64 " bps", bw * 8);
@@ -1169,13 +1169,13 @@ static int ipv6_ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt,
if (bw >= ONE_GBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Gbps",
- (float)(bw / ONE_GBPS_BYTES));
+ (float)bw / (float)ONE_GBPS_BYTES);
else if (bw >= ONE_MBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Mbps",
- (float)(bw / ONE_MBPS_BYTES));
+ (float)bw / (float)ONE_MBPS_BYTES);
else if (bw >= ONE_KBPS_BYTES)
snprintf(bps_buf, sizeof(bps_buf), "%.3f Kbps",
- (float)(bw / ONE_KBPS_BYTES));
+ (float)bw / (float)ONE_KBPS_BYTES);
else
snprintfrr(bps_buf, sizeof(bps_buf), "%" PRIu64 " bps", bw * 8);