]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: Expand tc_calc_xmittime, tc_calc_xmitsize to u64
authorJay Vosburgh <jay.vosburgh@canonical.com>
Tue, 16 Sep 2025 21:57:30 +0000 (14:57 -0700)
committerDavid Ahern <dsahern@kernel.org>
Thu, 18 Sep 2025 02:18:51 +0000 (02:18 +0000)
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 <jhs@mojatatu.com>
Signed-off-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
tc/tc_core.c
tc/tc_core.h

index 32fd094f6a05049d3c3f755a3445717affd85555..a422e02c87956d99c422942d4489268e010c87b0 100644 (file)
@@ -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;
 }
index c0fb7481420aec5655829d23287c1f4a7f04a8cf..d80370360dec0801e19f2478864818b8ca903b66 100644 (file)
@@ -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,