]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/tc_util.c
iproute2 - Fix up and simplify variables pointing to install directories
[mirror_iproute2.git] / tc / tc_util.c
index a07c6aad9ee55d0ca51987d6cc1891990b8401b9..926ed08bd4edc159c4cc93d15bf19b4583cecc0f 100644 (file)
 #include "utils.h"
 #include "tc_util.h"
 
+#ifndef LIBDIR
+#define LIBDIR "/usr/lib"
+#endif
+
+const char *get_tc_lib(void)
+{
+       const char *lib_dir;
+
+       lib_dir = getenv("TC_LIB_DIR");
+       if (!lib_dir)
+               lib_dir = LIBDIR "/tc/";
+
+       return lib_dir;
+}
+
 int get_qdisc_handle(__u32 *h, const char *str)
 {
        __u32 maj;
@@ -188,7 +203,7 @@ void print_rate(char *buf, int len, __u32 rate)
 
        if (use_iec) {
                if (tmp >= 1000.0*1024.0*1024.0)
-                       snprintf(buf, len, "%.0fMibit", tmp/1024.0*1024.0);
+                       snprintf(buf, len, "%.0fMibit", tmp/(1024.0*1024.0));
                else if (tmp >= 1000.0*1024)
                        snprintf(buf, len, "%.0fKibit", tmp/1024);
                else
@@ -228,9 +243,6 @@ int get_time(unsigned *time, const char *str)
                else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec")==0 ||
                         strcasecmp(p, "usecs") == 0)
                        t *= TIME_UNITS_PER_SEC/1000000;
-               else if (strcasecmp(p, "ns") == 0 || strcasecmp(p, "nsec")==0 ||
-                        strcasecmp(p, "nsecs") == 0)
-                       t *= TIME_UNITS_PER_SEC/1000000000;
                else
                        return -1;
        }
@@ -248,10 +260,8 @@ void print_time(char *buf, int len, __u32 time)
                snprintf(buf, len, "%.1fs", tmp/TIME_UNITS_PER_SEC);
        else if (tmp >= TIME_UNITS_PER_SEC/1000)
                snprintf(buf, len, "%.1fms", tmp/(TIME_UNITS_PER_SEC/1000));
-       else if (tmp >= TIME_UNITS_PER_SEC/1000000)
-               snprintf(buf, len, "%.1fus", tmp/(TIME_UNITS_PER_SEC/1000000));
        else
-               snprintf(buf, len, "%uns", time);
+               snprintf(buf, len, "%uus", time);
 }
 
 char * sprint_time(__u32 time, char *buf)
@@ -342,33 +352,6 @@ char * sprint_size(__u32 size, char *buf)
        return buf;
 }
 
-static const double max_percent_value = 0xffffffff;
-
-int get_percent(__u32 *percent, const char *str)
-{
-       char *p;
-       double per = strtod(str, &p) / 100.;
-
-       if (per > 1. || per < 0)
-               return -1;
-       if (*p && strcmp(p, "%"))
-               return -1;
-
-       *percent = (unsigned) rint(per * max_percent_value);
-       return 0;
-}
-
-void print_percent(char *buf, int len, __u32 per)
-{
-       snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value);
-}
-
-char * sprint_percent(__u32 per, char *buf)
-{
-       print_percent(buf, SPRINT_BSIZE-1, per);
-       return buf;
-}
-
 void print_qdisc_handle(char *buf, int len, __u32 h)
 {
        snprintf(buf, len, "%x:", TC_H_MAJ(h)>>16);
@@ -429,6 +412,47 @@ int action_a2n(char *arg, int *result)
        return 0;
 }
 
+int get_linklayer(unsigned *val, const char *arg)
+{
+       int res;
+
+       if (matches(arg, "ethernet") == 0)
+               res = LINKLAYER_ETHERNET;
+       else if (matches(arg, "atm") == 0)
+               res = LINKLAYER_ATM;
+       else if (matches(arg, "adsl") == 0)
+               res = LINKLAYER_ATM;
+       else
+               return -1; /* Indicate error */
+
+       *val = res;
+       return 0;
+}
+
+void print_linklayer(char *buf, int len, unsigned linklayer)
+{
+       switch (linklayer) {
+       case LINKLAYER_UNSPEC:
+               snprintf(buf, len, "%s", "unspec");
+               return;
+       case LINKLAYER_ETHERNET:
+               snprintf(buf, len, "%s", "ethernet");
+               return;
+       case LINKLAYER_ATM:
+               snprintf(buf, len, "%s", "atm");
+               return;
+       default:
+               snprintf(buf, len, "%s", "unknown");
+               return;
+       }
+}
+
+char *sprint_linklayer(unsigned linklayer, char *buf)
+{
+       print_linklayer(buf, SPRINT_BSIZE-1, linklayer);
+       return buf;
+}
+
 void print_tm(FILE * f, const struct tcf_t *tm)
 {
        int hz = get_user_hz();