X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tc%2Ftc_util.c;fp=tc%2Ftc_util.c;h=fe2c7eb53e6bb0d4d4deecc84ef8357130b78e66;hb=7132284647c15ca30d942926bc506d6019d3b61c;hp=9cde14416e7fbf89cbf2d8528ed9d9038dece963;hpb=105da95218c9d30375efc43f9edd8ef32998fedb;p=iproute2.git diff --git a/tc/tc_util.c b/tc/tc_util.c index 9cde144..fe2c7eb 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -24,6 +24,21 @@ #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; @@ -209,7 +224,7 @@ char * sprint_rate(__u32 rate, char *buf) return buf; } -int get_usecs(unsigned *usecs, const char *str) +int get_time(unsigned *time, const char *str) { double t; char *p; @@ -221,40 +236,45 @@ int get_usecs(unsigned *usecs, const char *str) if (*p) { if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec")==0 || strcasecmp(p, "secs")==0) - t *= 1000000; + t *= TIME_UNITS_PER_SEC; else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec")==0 || strcasecmp(p, "msecs") == 0) - t *= 1000; + t *= TIME_UNITS_PER_SEC/1000; else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec")==0 || strcasecmp(p, "usecs") == 0) - t *= 1; + t *= TIME_UNITS_PER_SEC/1000000; else return -1; } - *usecs = t; + *time = t; return 0; } -void print_usecs(char *buf, int len, __u32 usec) +void print_time(char *buf, int len, __u32 time) { - double tmp = usec; + double tmp = time; - if (tmp >= 1000000) - snprintf(buf, len, "%.1fs", tmp/1000000); - else if (tmp >= 1000) - snprintf(buf, len, "%.1fms", tmp/1000); + if (tmp >= TIME_UNITS_PER_SEC) + 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 - snprintf(buf, len, "%uus", usec); + snprintf(buf, len, "%uus", time); } -char * sprint_usecs(__u32 usecs, char *buf) +char * sprint_time(__u32 time, char *buf) { - print_usecs(buf, SPRINT_BSIZE-1, usecs); + print_time(buf, SPRINT_BSIZE-1, time); return buf; } +char * sprint_ticks(__u32 ticks, char *buf) +{ + return sprint_time(tc_core_tick2time(ticks), buf); +} + int get_size(unsigned *size, const char *str) { double sz; @@ -419,6 +439,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(); @@ -450,7 +511,7 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat fprintf(fp, " (dropped %u, overlimits %u requeues %u) ", q.drops, q.overlimits, q.requeues); } - + if (tbs[TCA_STATS_RATE_EST]) { struct gnet_stats_rate_est re = {0}; memcpy(&re, RTA_DATA(tbs[TCA_STATS_RATE_EST]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST]), sizeof(re))); @@ -490,7 +551,7 @@ void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtat memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st))); fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ", - prefix, (unsigned long long)st.bytes, st.packets, st.drops, + prefix, (unsigned long long)st.bytes, st.packets, st.drops, st.overlimits); if (st.bps || st.pps || st.qlen || st.backlog) {