From: Victor Nogueira <victor@mojatatu.com>
To: stephen@networkplumber.org, dsahern@kernel.org, netdev@vger.kernel.org
Cc: liuhangbin@gmail.com, jhs@mojatatu.com, kernel@mojatatu.com
Subject: [PATCH iproute2-next 2/2] tc: Add NLM_F_ECHO support for filters
Date: Wed, 24 Jan 2024 12:34:56 -0300 [thread overview]
Message-ID: <20240124153456.117048-3-victor@mojatatu.com> (raw)
In-Reply-To: <20240124153456.117048-1-victor@mojatatu.com>
If the user specifies this flag for a filter command the kernel will
return the command's result back to user space.
For example:
tc -echo filter add dev lo parent ffff: protocol ip matchall action ok
added filter dev lo parent ffff: protocol ip pref 49152 matchall chain 0
As illustrated above, the kernel will give us a pref of 491252
The same can be done for other filter commands (replace, delete, and
change). For example:
tc -echo filter del dev lo parent ffff: pref 49152 protocol ip matchall
deleted filter dev lo parent ffff: protocol ip pref 49152 matchall chain 0
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
---
tc/tc_filter.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index eb45c5887..54790ddc6 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -76,6 +76,7 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
char d[IFNAMSIZ] = {};
char k[FILTER_NAMESZ] = {};
struct tc_estimator est = {};
+ int ret;
if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE)
protocol = htons(ETH_P_ALL);
@@ -221,7 +222,12 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
if (est.ewma_log)
addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est));
- if (rtnl_talk(&rth, &req.n, NULL) < 0) {
+ if (echo_request)
+ ret = rtnl_echo_talk(&rth, &req.n, json, print_filter);
+ else
+ ret = rtnl_talk(&rth, &req.n, NULL);
+
+ if (ret < 0) {
fprintf(stderr, "We have an error talking to the kernel\n");
return 2;
}
--
2.25.1
next prev parent reply other threads:[~2024-01-24 15:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 15:34 [PATCH iproute2-next 0/2] tc: add NLM_F_ECHO support for actions and filters Victor Nogueira
2024-01-24 15:34 ` [PATCH iproute2-next 1/2] tc: add NLM_F_ECHO support for actions Victor Nogueira
2024-01-24 15:34 ` Victor Nogueira [this message]
2024-01-25 2:37 ` [PATCH iproute2-next 0/2] tc: add NLM_F_ECHO support for actions and filters Hangbin Liu
2024-01-30 15:50 ` patchwork-bot+netdevbpf
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=20240124153456.117048-3-victor@mojatatu.com \
--to=victor@mojatatu.com \
--cc=dsahern@kernel.org \
--cc=jhs@mojatatu.com \
--cc=kernel@mojatatu.com \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox