net/sched: cls_api: add helper for tc cls walker stats dump
authorZhengchao Shao <shaozhengchao@huawei.com>
Fri, 16 Sep 2022 02:02:43 +0000 (10:02 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 20 Sep 2022 22:54:07 +0000 (15:54 -0700)
The walk implementation of most tc cls modules is basically the same.
That is, the values of count and skip are checked first. If count is
greater than or equal to skip, the registered fn function is executed.
Otherwise, increase the value of count. So we can reconstruct them.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Victor Nogueira <victor@mojatatu.com>
Tested-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/pkt_cls.h

index d9d90e6..d376c99 100644 (file)
@@ -81,6 +81,19 @@ int tcf_classify(struct sk_buff *skb,
                 const struct tcf_proto *tp, struct tcf_result *res,
                 bool compat_mode);
 
+static inline bool tc_cls_stats_dump(struct tcf_proto *tp,
+                                    struct tcf_walker *arg,
+                                    void *filter)
+{
+       if (arg->count >= arg->skip && arg->fn(tp, filter, arg) < 0) {
+               arg->stop = 1;
+               return false;
+       }
+
+       arg->count++;
+       return true;
+}
+
 #else
 static inline bool tcf_block_shared(struct tcf_block *block)
 {