From: Jay Vosburgh Date: Tue, 16 Sep 2025 21:57:29 +0000 (-0700) Subject: tc: Add get_size64 and get_size64_and_cell X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8798ab4c4c0258bf69f787ce45aa94325e66ea6f;p=thirdparty%2Fiproute2.git tc: Add get_size64 and get_size64_and_cell In preparation for accepting 64 bit burst sizes, create 64-bit versions of get_size and get_size_and_cell. The 32-bit versions become wrappers around the 64-bit versions. Acked-by: Jamal Hadi Salim Signed-off-by: Jay Vosburgh Signed-off-by: David Ahern --- diff --git a/include/utils.h b/include/utils.h index 91e6e31f..7d9b3cfb 100644 --- a/include/utils.h +++ b/include/utils.h @@ -165,6 +165,7 @@ int get_addr64(__u64 *ap, const char *cp); int get_rate(unsigned int *rate, const char *str); int get_rate64(__u64 *rate, const char *str); int get_size(unsigned int *size, const char *str); +int get_size64(__u64 *size, const char *str); int hex2mem(const char *buf, uint8_t *mem, int count); char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen); diff --git a/lib/utils_math.c b/lib/utils_math.c index 9ef3dd6e..a7e74744 100644 --- a/lib/utils_math.c +++ b/lib/utils_math.c @@ -87,7 +87,7 @@ int get_rate64(__u64 *rate, const char *str) return 0; } -int get_size(unsigned int *size, const char *str) +int get_size64(__u64 *size, const char *str) { double sz; char *p; @@ -121,3 +121,20 @@ int get_size(unsigned int *size, const char *str) return 0; } + +int get_size(unsigned int *size, const char *str) +{ + __u64 sz64; + int rv; + + rv = get_size64(&sz64, str); + *size = sz64; + + if (rv) + return rv; + + if (sz64 > UINT_MAX) + return -1; + + return 0; +} diff --git a/tc/tc_util.c b/tc/tc_util.c index ff0ac170..45d76e75 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -257,14 +257,14 @@ tc_print_rate(enum output_type t, const char *key, const char *fmt, print_rate(use_iec, t, key, fmt, rate); } -int get_size_and_cell(unsigned int *size, int *cell_log, char *str) +int get_size64_and_cell(__u64 *size, int *cell_log, char *str) { char *slash = strchr(str, '/'); if (slash) *slash = 0; - if (get_size(size, str)) + if (get_size64(size, str)) return -1; if (slash) { @@ -286,6 +286,23 @@ int get_size_and_cell(unsigned int *size, int *cell_log, char *str) return 0; } +int get_size_and_cell(unsigned int *size, int *cell_log, char *str) +{ + __u64 size64; + int rv; + + rv = get_size64_and_cell(&size64, cell_log, str); + if (rv) + return rv; + + if (size64 > UINT32_MAX) + return -1; + + *size = size64; + + return 0; +} + void print_devname(enum output_type type, int ifindex) { const char *ifname = ll_index_to_name(ifindex); diff --git a/tc/tc_util.h b/tc/tc_util.h index ec206372..8ebca396 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -80,6 +80,7 @@ int get_qdisc_handle(__u32 *h, const char *str); int get_percent_rate(unsigned int *rate, const char *str, const char *dev); int get_percent_rate64(__u64 *rate, const char *str, const char *dev); int get_size_and_cell(unsigned int *size, int *cell_log, char *str); +int get_size64_and_cell(__u64 *size, int *cell_log, char *str); int get_linklayer(unsigned int *val, const char *arg); void tc_print_rate(enum output_type t, const char *key, const char *fmt,