]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: separate action print for filter and action dump
authorBaowen Zheng <baowen.zheng@corigine.com>
Fri, 4 Mar 2022 02:01:40 +0000 (10:01 +0800)
committerDavid Ahern <dsahern@kernel.org>
Mon, 7 Mar 2022 22:45:41 +0000 (15:45 -0700)
We need to separate action print for filter and action dump since
in action dump, we need to print hardware status and flags. But in
filter dump, we do not need to print action hardware status and
hardware related flags.

In filter dump, actions hardware status should be same with filter.
so we will not print action hardware status in this case.

Action print for action dump:
  action order 0:  police 0xff000100 rate 0bit burst 0b mtu 64Kb pkts_rate 50000 pkts_burst 10000 action drop/pipe overhead 0b linklayer unspec
  ref 4 bind 3  installed 666 sec used 0 sec firstused 106 sec
  Action statistics:
  Sent 7634140154 bytes 5109889 pkt (dropped 0, overlimits 0 requeues 0)
  Sent software 84 bytes 3 pkt
  Sent hardware 7634140070 bytes 5109886 pkt
  backlog 0b 0p requeues 0
  in_hw in_hw_count 1
  used_hw_stats delayed

Action print for filter dump:
  action order 1:  police 0xff000100 rate 0bit burst 0b mtu 64Kb pkts_rate 50000 pkts_burst 10000 action drop/pipe overhead 0b linklayer unspec
  ref 4 bind 3  installed 680 sec used 0 sec firstused 119 sec
  Action statistics:
  Sent 8627975846 bytes 5775107 pkt (dropped 0, overlimits 0 requeues 0)
  Sent software 84 bytes 3 pkt
  Sent hardware 8627975762 bytes 5775104 pkt
  backlog 0b 0p requeues 0
  used_hw_stats delayed

Signed-off-by: Baowen Zheng <baowen.zheng@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
tc/m_action.c

index 1dd5425ce4da09c7549590fc15df55fc66597913..b3fd019350b297ca1876997ecf99a5cd8b98d0f1 100644 (file)
@@ -364,7 +364,7 @@ bad_val:
        return -1;
 }
 
-static int tc_print_one_action(FILE *f, struct rtattr *arg)
+static int tc_print_one_action(FILE *f, struct rtattr *arg, bool bind)
 {
 
        struct rtattr *tb[TCA_ACT_MAX + 1];
@@ -415,26 +415,37 @@ static int tc_print_one_action(FILE *f, struct rtattr *arg)
        }
        if (tb[TCA_ACT_FLAGS] || tb[TCA_ACT_IN_HW_COUNT]) {
                bool skip_hw = false;
+               bool newline = false;
+
                if (tb[TCA_ACT_FLAGS]) {
                        struct nla_bitfield32 *flags = RTA_DATA(tb[TCA_ACT_FLAGS]);
 
-                       if (flags->selector & TCA_ACT_FLAGS_NO_PERCPU_STATS)
+                       if (flags->selector & TCA_ACT_FLAGS_NO_PERCPU_STATS) {
+                               newline = true;
                                print_bool(PRINT_ANY, "no_percpu", "\tno_percpu",
                                           flags->value &
                                           TCA_ACT_FLAGS_NO_PERCPU_STATS);
-                       if (flags->selector & TCA_ACT_FLAGS_SKIP_HW) {
-                               print_bool(PRINT_ANY, "skip_hw", "\tskip_hw",
-                                          flags->value &
-                                          TCA_ACT_FLAGS_SKIP_HW);
-                               skip_hw = !!(flags->value & TCA_ACT_FLAGS_SKIP_HW);
                        }
-                       if (flags->selector & TCA_ACT_FLAGS_SKIP_SW)
-                               print_bool(PRINT_ANY, "skip_sw", "\tskip_sw",
-                                          flags->value &
-                                          TCA_ACT_FLAGS_SKIP_SW);
+                       if (!bind) {
+                               if (flags->selector & TCA_ACT_FLAGS_SKIP_HW) {
+                                       newline = true;
+                                       print_bool(PRINT_ANY, "skip_hw", "\tskip_hw",
+                                                  flags->value &
+                                                  TCA_ACT_FLAGS_SKIP_HW);
+                                       skip_hw = !!(flags->value & TCA_ACT_FLAGS_SKIP_HW);
+                               }
+                               if (flags->selector & TCA_ACT_FLAGS_SKIP_SW) {
+                                       newline = true;
+                                       print_bool(PRINT_ANY, "skip_sw", "\tskip_sw",
+                                                  flags->value &
+                                                  TCA_ACT_FLAGS_SKIP_SW);
+                               }
+                       }
                }
-               if (tb[TCA_ACT_IN_HW_COUNT] && !skip_hw) {
+               if (tb[TCA_ACT_IN_HW_COUNT] && !bind && !skip_hw) {
                        __u32 count = rta_getattr_u32(tb[TCA_ACT_IN_HW_COUNT]);
+
+                       newline = true;
                        if (count) {
                                print_bool(PRINT_ANY, "in_hw", "\tin_hw",
                                           true);
@@ -446,7 +457,8 @@ static int tc_print_one_action(FILE *f, struct rtattr *arg)
                        }
                }
 
-               print_nl();
+               if (newline)
+                       print_nl();
        }
        if (tb[TCA_ACT_HW_STATS])
                print_hw_stats(tb[TCA_ACT_HW_STATS], false);
@@ -483,8 +495,9 @@ tc_print_action_flush(FILE *f, const struct rtattr *arg)
        return 0;
 }
 
-int
-tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
+static int
+tc_dump_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts,
+              bool bind)
 {
 
        int i;
@@ -509,7 +522,7 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
                        print_nl();
                        print_uint(PRINT_ANY, "order",
                                   "\taction order %u: ", i);
-                       if (tc_print_one_action(f, tb[i]) < 0)
+                       if (tc_print_one_action(f, tb[i], bind) < 0)
                                fprintf(stderr, "Error printing action\n");
                        close_json_object();
                }
@@ -520,6 +533,12 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
        return 0;
 }
 
+int
+tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
+{
+       return tc_dump_action(f, arg, tot_acts, true);
+}
+
 int print_action(struct nlmsghdr *n, void *arg)
 {
        FILE *fp = (FILE *)arg;
@@ -570,7 +589,7 @@ int print_action(struct nlmsghdr *n, void *arg)
        }
 
        open_json_object(NULL);
-       tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0);
+       tc_dump_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0, false);
        close_json_object();
 
        return 0;