All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhengchao Shao <shaozhengchao@huawei.com>
To: <netdev@vger.kernel.org>, <bpf@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <jhs@mojatatu.com>,
	<xiyou.wangcong@gmail.com>, <jiri@resnulli.us>,
	<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <shuah@kernel.org>
Cc: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
	<martin.lau@linux.dev>, <song@kernel.org>, <yhs@fb.com>,
	<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
	<sdf@google.com>, <haoluo@google.com>, <jolsa@kernel.org>,
	<weiyongjun1@huawei.com>, <yuehaibing@huawei.com>,
	<shaozhengchao@huawei.com>
Subject: [PATCH net-next,v2 1/9] net/sched: cls_api: add helper for tc cls walker stats updating
Date: Wed, 14 Sep 2022 18:02:13 +0800	[thread overview]
Message-ID: <20220914100221.386855-2-shaozhengchao@huawei.com> (raw)
In-Reply-To: <20220914100221.386855-1-shaozhengchao@huawei.com>

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>
---
 include/net/pkt_cls.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index d9d90e6925e1..d3cbbabf7592 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -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_update(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)
 {
-- 
2.17.1


  reply	other threads:[~2022-09-14 10:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 10:02 [PATCH net-next,v2 0/9] refactor duplicate codes in the tc cls walk function Zhengchao Shao
2022-09-14 10:02 ` Zhengchao Shao [this message]
2022-09-14 10:02 ` [PATCH net-next,v2 2/9] net/sched: use tc_cls_stats_update() in filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 3/9] selftests/tc-testings: add selftests for bpf filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 4/9] selftests/tc-testings: add selftests for cgroup filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 5/9] selftests/tc-testings: add selftests for flow filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 6/9] selftests/tc-testings: add selftests for route filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 7/9] selftests/tc-testings: add selftests for rsvp filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 8/9] selftests/tc-testings: add selftests for tcindex filter Zhengchao Shao
2022-09-14 10:02 ` [PATCH net-next,v2 9/9] selftests/tc-testings: add list case for basic filter Zhengchao Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220914100221.386855-2-shaozhengchao@huawei.com \
    --to=shaozhengchao@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=weiyongjun1@huawei.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yhs@fb.com \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.