]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: Add get_size64 and get_size64_and_cell
authorJay Vosburgh <jay.vosburgh@canonical.com>
Tue, 16 Sep 2025 21:57:29 +0000 (14:57 -0700)
committerDavid Ahern <dsahern@kernel.org>
Thu, 18 Sep 2025 02:18:49 +0000 (02:18 +0000)
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 <jhs@mojatatu.com>
Signed-off-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/utils.h
lib/utils_math.c
tc/tc_util.c
tc/tc_util.h

index 91e6e31f941118ed7cf480712a894af6cade62ec..7d9b3cfb35a66572e051a1fd5a90d0c78cb2475c 100644 (file)
@@ -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);
index 9ef3dd6ed93bf11b366f567f3c4278df415ddf8c..a7e747440039c2a06eb66cdf9fabe98bbb5fbc66 100644 (file)
@@ -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;
+}
index ff0ac170730bef8f6a992f2b2ef0035888a5a6ff..45d76e7578d44e250177860c949280930da9b4cf 100644 (file)
@@ -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);
index ec2063729b0729b3034b8c23a9e466b5d443a693..8ebca3963d947352707dae2bf7720d772654f67d 100644 (file)
@@ -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,