From c7d2d484bc7cc43f575409d5359ce3e016d18466 Mon Sep 17 00:00:00 2001 From: renato Date: Sun, 25 Oct 2015 00:42:02 +0000 Subject: [PATCH] When converting the real bandwidth to the composite bandwidth, truncate before applying the scaling factor. When converting the composite bandwidth to the real bandwidth, apply the scaling factor before the division and only then truncate. This is to keep consistent with what Cisco does, the draft is unclear on this point. --- usr.sbin/eigrpd/rde_dual.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/usr.sbin/eigrpd/rde_dual.c b/usr.sbin/eigrpd/rde_dual.c index 3134e9558a9..b1df17ecaf9 100644 --- a/usr.sbin/eigrpd/rde_dual.c +++ b/usr.sbin/eigrpd/rde_dual.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_dual.c,v 1.8 2015/10/25 00:39:14 renato Exp $ */ +/* $OpenBSD: rde_dual.c,v 1.9 2015/10/25 00:42:02 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal @@ -328,13 +328,18 @@ eigrp_real_delay(uint32_t delay) uint32_t eigrp_composite_bandwidth(uint32_t bandwidth) { - return ((EIGRP_SCALING_FACTOR * (uint32_t)10000000) / bandwidth); + /* truncate before applying the scaling factor */ + bandwidth = 10000000 / bandwidth; + return (EIGRP_SCALING_FACTOR * bandwidth); } -/* the formula is the same but let's focus on keeping the code readable */ uint32_t eigrp_real_bandwidth(uint32_t bandwidth) { + /* + * apply the scaling factor before the division and only then truncate. + * this is to keep consistent with what cisco does. + */ return ((EIGRP_SCALING_FACTOR * (uint32_t)10000000) / bandwidth); } -- 2.20.1