From: Jay Vosburgh Date: Tue, 16 Sep 2025 21:57:30 +0000 (-0700) Subject: tc: Expand tc_calc_xmittime, tc_calc_xmitsize to u64 X-Git-Tag: v6.18.0~14^2~3^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13b999aa74c88e90a7f6f033893c2a0974f827ae;p=thirdparty%2Fiproute2.git tc: Expand tc_calc_xmittime, tc_calc_xmitsize to u64 In preparation for accepting 64-bit burst sizes, modify tc_calc_xmittime and tc_calc_xmitsize to handle 64-bit values. tc_calc_xmittime continues to return a 32-bit value, as its range is limited by the kernel API, but overflow is now detected and the return value is limited to UINT_MAX. Acked-by: Jamal Hadi Salim Signed-off-by: Jay Vosburgh Signed-off-by: David Ahern --- diff --git a/tc/tc_core.c b/tc/tc_core.c index 32fd094f..a422e02c 100644 --- a/tc/tc_core.c +++ b/tc/tc_core.c @@ -43,12 +43,15 @@ unsigned int tc_core_ktime2time(unsigned int ktime) return ktime / clock_factor; } -unsigned int tc_calc_xmittime(__u64 rate, unsigned int size) +unsigned int tc_calc_xmittime(__u64 rate, __u64 size) { - return ceil(tc_core_time2tick(TIME_UNITS_PER_SEC*((double)size/(double)rate))); + double val; + + val = ceil(tc_core_time2tick(TIME_UNITS_PER_SEC*((double)size/(double)rate))); + return val > UINT_MAX ? UINT_MAX : val; } -unsigned int tc_calc_xmitsize(__u64 rate, unsigned int ticks) +__u64 tc_calc_xmitsize(__u64 rate, unsigned int ticks) { return ((double)rate*tc_core_tick2time(ticks))/TIME_UNITS_PER_SEC; } diff --git a/tc/tc_core.h b/tc/tc_core.h index c0fb7481..d8037036 100644 --- a/tc/tc_core.h +++ b/tc/tc_core.h @@ -15,8 +15,8 @@ enum link_layer { double tc_core_tick2time(double tick); unsigned tc_core_time2ktime(unsigned time); unsigned tc_core_ktime2time(unsigned ktime); -unsigned tc_calc_xmittime(__u64 rate, unsigned size); -unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks); +unsigned tc_calc_xmittime(__u64 rate, __u64 size); +__u64 tc_calc_xmitsize(__u64 rate, unsigned ticks); int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab, int cell_log, unsigned mtu, enum link_layer link_layer); int tc_calc_rtable_64(struct tc_ratespec *r, __u32 *rtab,