]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/f_matchall.c
treewide: refactor help messages
[mirror_iproute2.git] / tc / f_matchall.c
index d78660e79dbe4f94db6758ea03ebacd0f72321b8..253ed5ce42e0aa3e249a826724510289fc9921a5 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 static void explain(void)
 {
-       fprintf(stderr, "Usage: ... matchall [skip_sw | skip_hw]\n");
-       fprintf(stderr, "                 [ action ACTION_SPEC ] [ classid CLASSID ]\n");
-       fprintf(stderr, "\n");
-       fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
-       fprintf(stderr, "       FILTERID := X:Y:Z\n");
-       fprintf(stderr, "       ACTION_SPEC := ... look at individual actions\n");
-       fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
+       fprintf(stderr,
+               "Usage: ... matchall [skip_sw | skip_hw]\n"
+               "                 [ action ACTION_SPEC ] [ classid CLASSID ]\n"
+               "\n"
+               "Where: SELECTOR := SAMPLE SAMPLE ...\n"
+               "       FILTERID := X:Y:Z\n"
+               "       ACTION_SPEC := ... look at individual actions\n"
+               "\n"
+               "NOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
 static int matchall_parse_opt(struct filter_util *qu, char *handle,
@@ -115,6 +116,7 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,
                           struct rtattr *opt, __u32 handle)
 {
        struct rtattr *tb[TCA_MATCHALL_MAX+1];
+       struct tc_matchall_pcnt *pf = NULL;
 
        if (opt == NULL)
                return 0;
@@ -122,11 +124,11 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,
        parse_rtattr_nested(tb, TCA_MATCHALL_MAX, opt);
 
        if (handle)
-               fprintf(f, "handle 0x%x ", handle);
+               print_uint(PRINT_ANY, "handle", "handle 0x%x ", handle);
 
        if (tb[TCA_MATCHALL_CLASSID]) {
                SPRINT_BUF(b1);
-               fprintf(f, "flowid %s ",
+               print_string(PRINT_ANY, "flowid", "flowid %s ",
                        sprint_tc_classid(rta_getattr_u32(tb[TCA_MATCHALL_CLASSID]), b1));
        }
 
@@ -134,16 +136,29 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,
                __u32 flags = rta_getattr_u32(tb[TCA_MATCHALL_FLAGS]);
 
                if (flags & TCA_CLS_FLAGS_SKIP_HW)
-                       fprintf(f, "\n  skip_hw");
+                       print_bool(PRINT_ANY, "skip_hw", "\n  skip_hw", true);
                if (flags & TCA_CLS_FLAGS_SKIP_SW)
-                       fprintf(f, "\n  skip_sw");
+                       print_bool(PRINT_ANY, "skip_sw", "\n  skip_sw", true);
 
                if (flags & TCA_CLS_FLAGS_IN_HW)
-                       fprintf(f, "\n  in_hw");
+                       print_bool(PRINT_ANY, "in_hw", "\n  in_hw", true);
                else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-                       fprintf(f, "\n  not_in_hw");
+                       print_bool(PRINT_ANY, "not_in_hw", "\n  not_in_hw", true);
        }
 
+       if (tb[TCA_MATCHALL_PCNT]) {
+               if (RTA_PAYLOAD(tb[TCA_MATCHALL_PCNT])  < sizeof(*pf)) {
+                       print_string(PRINT_FP, NULL, "Broken perf counters\n", NULL);
+                       return -1;
+               }
+               pf = RTA_DATA(tb[TCA_MATCHALL_PCNT]);
+       }
+
+       if (show_stats && NULL != pf)
+               print_u64(PRINT_ANY, "rule_hit", " (rule hit %llu)",
+                       (unsigned long long) pf->rhit);
+
+
        if (tb[TCA_MATCHALL_ACT])
                tc_print_action(f, tb[TCA_MATCHALL_ACT], 0);