]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - tc/tc.c
Add reference to tc-codel(8) to the SEE ALSO section
[lisovros/iproute2_canprio.git] / tc / tc.c
diff --git a/tc/tc.c b/tc/tc.c
index 793eab24a50ebdc191cc9ecf119aa7fe8fdc9131..8e362d285d0cda1d5cc24f3a3e9052d6e2cac222 100644 (file)
--- a/tc/tc.c
+++ b/tc/tc.c
 int show_stats = 0;
 int show_details = 0;
 int show_raw = 0;
+int show_pretty = 0;
+
 int resolve_hosts = 0;
 int use_iec = 0;
 int force = 0;
 struct rtnl_handle rth;
 
-static void *BODY;     /* cached handle dlopen(NULL) */
+static void *BODY = NULL;      /* cached handle dlopen(NULL) */
 static struct qdisc_util * qdisc_list;
 static struct filter_util * filter_list;
 
-static int print_noqopt(struct qdisc_util *qu, FILE *f, 
+static int print_noqopt(struct qdisc_util *qu, FILE *f,
                        struct rtattr *opt)
 {
        if (opt && RTA_PAYLOAD(opt))
-               fprintf(f, "[Unknown qdisc, optlen=%u] ", 
+               fprintf(f, "[Unknown qdisc, optlen=%u] ",
                        (unsigned) RTA_PAYLOAD(opt));
        return 0;
 }
@@ -63,7 +65,7 @@ static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv, struct nlm
 static int print_nofopt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle)
 {
        if (opt && RTA_PAYLOAD(opt))
-               fprintf(f, "fh %08x [Unknown filter, optlen=%u] ", 
+               fprintf(f, "fh %08x [Unknown filter, optlen=%u] ",
                        fhandle, (unsigned) RTA_PAYLOAD(opt));
        else if (fhandle)
                fprintf(f, "fh %08x ", fhandle);
@@ -99,7 +101,7 @@ struct qdisc_util *get_qdisc_kind(const char *str)
                if (strcmp(q->id, str) == 0)
                        return q;
 
-       snprintf(buf, sizeof(buf), "/usr/lib/tc/q_%s.so", str);
+       snprintf(buf, sizeof(buf), "%s/q_%s.so", get_tc_lib(), str);
        dlh = dlopen(buf, RTLD_LAZY);
        if (!dlh) {
                /* look in current binary, only open once */
@@ -145,7 +147,7 @@ struct filter_util *get_filter_kind(const char *str)
                if (strcmp(q->id, str) == 0)
                        return q;
 
-       snprintf(buf, sizeof(buf), "/usr/lib/tc/f_%s.so", str);
+       snprintf(buf, sizeof(buf), "%s/f_%s.so", get_tc_lib(), str);
        dlh = dlopen(buf, RTLD_LAZY);
        if (dlh == NULL) {
                dlh = BODY;
@@ -180,9 +182,9 @@ noexist:
 static void usage(void)
 {
        fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
-                       "       tc [-force] -batch file\n"
-                       "where  OBJECT := { qdisc | class | filter | action }\n"
-                       "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -b[atch] [file] }\n");
+                       "       tc [-force] -batch filename\n"
+                       "where  OBJECT := { qdisc | class | filter | action | monitor }\n"
+                       "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] }\n");
 }
 
 static int do_cmd(int argc, char **argv)
@@ -199,12 +201,15 @@ static int do_cmd(int argc, char **argv)
        if (matches(*argv, "actions") == 0)
                return do_action(argc-1, argv+1);
 
+       if (matches(*argv, "monitor") == 0)
+               return do_tcmonitor(argc-1, argv+1);
+
        if (matches(*argv, "help") == 0) {
                usage();
                return 0;
        }
-       
-       fprintf(stderr, "Object \"%s\" is unknown, try \"tc help\".\n", 
+
+       fprintf(stderr, "Object \"%s\" is unknown, try \"tc help\".\n",
                *argv);
        return -1;
 }
@@ -217,7 +222,7 @@ static int batch(const char *name)
 
        if (name && strcmp(name, "-") != 0) {
                if (freopen(name, "r", stdin) == NULL) {
-                       fprintf(stderr, "Cannot open file \"%s\" for reading: %s=n",
+                       fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
                                name, strerror(errno));
                        return -1;
                }
@@ -246,6 +251,8 @@ static int batch(const char *name)
                                break;
                }
        }
+       if (line)
+               free(line);
 
        rtnl_close(&rth);
        return ret;
@@ -268,6 +275,8 @@ int main(int argc, char **argv)
                        ++show_details;
                } else if (matches(argv[1], "-raw") == 0) {
                        ++show_raw;
+               } else if (matches(argv[1], "-pretty") == 0) {
+                       ++show_pretty;
                } else if (matches(argv[1], "-Version") == 0) {
                        printf("tc utility, iproute2-ss%s\n", SNAPSHOT);
                        return 0;