@@ -164,6 +164,7 @@ int get_be16(__be16 *val, const char *arg, int base);
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 hex2mem(const char *buf, uint8_t *mem, int count);
char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
@@ -592,6 +592,41 @@ int get_rate64(__u64 *rate, const char *str)
return 0;
}
+int get_size(unsigned int *size, const char *str)
+{
+ double sz;
+ char *p;
+
+ sz = strtod(str, &p);
+ if (p == str)
+ return -1;
+
+ if (*p) {
+ if (strcasecmp(p, "kb") == 0 || strcasecmp(p, "k") == 0)
+ sz *= 1024;
+ else if (strcasecmp(p, "gb") == 0 || strcasecmp(p, "g") == 0)
+ sz *= 1024*1024*1024;
+ else if (strcasecmp(p, "gbit") == 0)
+ sz *= 1024*1024*1024/8;
+ else if (strcasecmp(p, "mb") == 0 || strcasecmp(p, "m") == 0)
+ sz *= 1024*1024;
+ else if (strcasecmp(p, "mbit") == 0)
+ sz *= 1024*1024/8;
+ else if (strcasecmp(p, "kbit") == 0)
+ sz *= 1024/8;
+ else if (strcasecmp(p, "b") != 0)
+ return -1;
+ }
+
+ *size = sz;
+
+ /* detect if an overflow happened */
+ if (*size != floor(sz))
+ return -1;
+
+ return 0;
+}
+
static void set_address_type(inet_prefix *addr)
{
switch (addr->family) {
@@ -258,41 +258,6 @@ char *sprint_ticks(__u32 ticks, char *buf)
return sprint_time(tc_core_tick2time(ticks), buf);
}
-int get_size(unsigned int *size, const char *str)
-{
- double sz;
- char *p;
-
- sz = strtod(str, &p);
- if (p == str)
- return -1;
-
- if (*p) {
- if (strcasecmp(p, "kb") == 0 || strcasecmp(p, "k") == 0)
- sz *= 1024;
- else if (strcasecmp(p, "gb") == 0 || strcasecmp(p, "g") == 0)
- sz *= 1024*1024*1024;
- else if (strcasecmp(p, "gbit") == 0)
- sz *= 1024*1024*1024/8;
- else if (strcasecmp(p, "mb") == 0 || strcasecmp(p, "m") == 0)
- sz *= 1024*1024;
- else if (strcasecmp(p, "mbit") == 0)
- sz *= 1024*1024/8;
- else if (strcasecmp(p, "kbit") == 0)
- sz *= 1024/8;
- else if (strcasecmp(p, "b") != 0)
- return -1;
- }
-
- *size = sz;
-
- /* detect if an overflow happened */
- if (*size != floor(sz))
- return -1;
-
- return 0;
-}
-
int get_size_and_cell(unsigned int *size, int *cell_log, char *str)
{
char *slash = strchr(str, '/');
@@ -78,7 +78,6 @@ struct filter_util *get_filter_kind(const char *str);
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(unsigned int *size, const char *str);
int get_size_and_cell(unsigned int *size, int *cell_log, char *str);
int get_linklayer(unsigned int *val, const char *arg);
The function get_size() serves for parsing of sizes using a handly notation that supports units and their prefixes, such as 10Kbit. This will be useful for the DCB buffer size parsing. Move the function from TC to the general library, so that it can be reused. Signed-off-by: Petr Machata <me@pmachata.org> --- include/utils.h | 1 + lib/utils.c | 35 +++++++++++++++++++++++++++++++++++ tc/tc_util.c | 35 ----------------------------------- tc/tc_util.h | 1 - 4 files changed, 36 insertions(+), 36 deletions(-)