net/sched: use tc_cls_stats_dump() in filter
authorZhengchao Shao <shaozhengchao@huawei.com>
Fri, 16 Sep 2022 02:02:44 +0000 (10:02 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 20 Sep 2022 22:54:13 +0000 (15:54 -0700)
use tc_cls_stats_dump() in filter.

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>
net/sched/cls_basic.c
net/sched/cls_bpf.c
net/sched/cls_flow.c
net/sched/cls_fw.c
net/sched/cls_route.c
net/sched/cls_rsvp.h
net/sched/cls_tcindex.c
net/sched/cls_u32.c

index 8158fc9..d9fbaa0 100644 (file)
@@ -251,15 +251,8 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg,
        struct basic_filter *f;
 
        list_for_each_entry(f, &head->flist, link) {
-               if (arg->count < arg->skip)
-                       goto skip;
-
-               if (arg->fn(tp, f, arg) < 0) {
-                       arg->stop = 1;
+               if (!tc_cls_stats_dump(tp, arg, f))
                        break;
-               }
-skip:
-               arg->count++;
        }
 }
 
index c85b85a..938be14 100644 (file)
@@ -650,14 +650,8 @@ static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg,
        struct cls_bpf_prog *prog;
 
        list_for_each_entry(prog, &head->plist, link) {
-               if (arg->count < arg->skip)
-                       goto skip;
-               if (arg->fn(tp, prog, arg) < 0) {
-                       arg->stop = 1;
+               if (!tc_cls_stats_dump(tp, arg, prog))
                        break;
-               }
-skip:
-               arg->count++;
        }
 }
 
index 972303a..014cd3d 100644 (file)
@@ -683,14 +683,8 @@ static void flow_walk(struct tcf_proto *tp, struct tcf_walker *arg,
        struct flow_filter *f;
 
        list_for_each_entry(f, &head->filters, list) {
-               if (arg->count < arg->skip)
-                       goto skip;
-               if (arg->fn(tp, f, arg) < 0) {
-                       arg->stop = 1;
+               if (!tc_cls_stats_dump(tp, arg, f))
                        break;
-               }
-skip:
-               arg->count++;
        }
 }
 
index 8654b0c..fa66191 100644 (file)
@@ -358,15 +358,8 @@ static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg,
 
                for (f = rtnl_dereference(head->ht[h]); f;
                     f = rtnl_dereference(f->next)) {
-                       if (arg->count < arg->skip) {
-                               arg->count++;
-                               continue;
-                       }
-                       if (arg->fn(tp, f, arg) < 0) {
-                               arg->stop = 1;
+                       if (!tc_cls_stats_dump(tp, arg, f))
                                return;
-                       }
-                       arg->count++;
                }
        }
 }
index 29adac7..17bb04a 100644 (file)
@@ -587,15 +587,8 @@ static void route4_walk(struct tcf_proto *tp, struct tcf_walker *arg,
                                for (f = rtnl_dereference(b->ht[h1]);
                                     f;
                                     f = rtnl_dereference(f->next)) {
-                                       if (arg->count < arg->skip) {
-                                               arg->count++;
-                                               continue;
-                                       }
-                                       if (arg->fn(tp, f, arg) < 0) {
-                                               arg->stop = 1;
+                                       if (!tc_cls_stats_dump(tp, arg, f))
                                                return;
-                                       }
-                                       arg->count++;
                                }
                        }
                }
index 5cd9d6b..fb60f2c 100644 (file)
@@ -671,15 +671,8 @@ static void rsvp_walk(struct tcf_proto *tp, struct tcf_walker *arg,
 
                                for (f = rtnl_dereference(s->ht[h1]); f;
                                     f = rtnl_dereference(f->next)) {
-                                       if (arg->count < arg->skip) {
-                                               arg->count++;
-                                               continue;
-                                       }
-                                       if (arg->fn(tp, f, arg) < 0) {
-                                               arg->stop = 1;
+                                       if (!tc_cls_stats_dump(tp, arg, f))
                                                return;
-                                       }
-                                       arg->count++;
                                }
                        }
                }
index 742c7d4..a330760 100644 (file)
@@ -566,13 +566,8 @@ static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker,
                for (i = 0; i < p->hash; i++) {
                        if (!p->perfect[i].res.class)
                                continue;
-                       if (walker->count >= walker->skip) {
-                               if (walker->fn(tp, p->perfect + i, walker) < 0) {
-                                       walker->stop = 1;
-                                       return;
-                               }
-                       }
-                       walker->count++;
+                       if (!tc_cls_stats_dump(tp, walker, p->perfect + i))
+                               return;
                }
        }
        if (!p->h)
@@ -580,13 +575,8 @@ static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker,
        for (i = 0; i < p->hash; i++) {
                for (f = rtnl_dereference(p->h[i]); f; f = next) {
                        next = rtnl_dereference(f->next);
-                       if (walker->count >= walker->skip) {
-                               if (walker->fn(tp, &f->result, walker) < 0) {
-                                       walker->stop = 1;
-                                       return;
-                               }
-                       }
-                       walker->count++;
+                       if (!tc_cls_stats_dump(tp, walker, &f->result))
+                               return;
                }
        }
 }
index 4d27300..58c7680 100644 (file)
@@ -1125,26 +1125,16 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg,
             ht = rtnl_dereference(ht->next)) {
                if (ht->prio != tp->prio)
                        continue;
-               if (arg->count >= arg->skip) {
-                       if (arg->fn(tp, ht, arg) < 0) {
-                               arg->stop = 1;
-                               return;
-                       }
-               }
-               arg->count++;
+
+               if (!tc_cls_stats_dump(tp, arg, ht))
+                       return;
+
                for (h = 0; h <= ht->divisor; h++) {
                        for (n = rtnl_dereference(ht->ht[h]);
                             n;
                             n = rtnl_dereference(n->next)) {
-                               if (arg->count < arg->skip) {
-                                       arg->count++;
-                                       continue;
-                               }
-                               if (arg->fn(tp, n, arg) < 0) {
-                                       arg->stop = 1;
+                               if (!tc_cls_stats_dump(tp, arg, n))
                                        return;
-                               }
-                               arg->count++;
                        }
                }
        }