#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;
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
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;
}
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)
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);
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();