* [PATCH iproute2-next] tc: full JSON support for 'bpf' filter
@ 2020-04-28 9:00 Davide Caratti
2020-04-28 9:09 ` Andrea Claudi
2020-04-28 15:39 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Davide Caratti @ 2020-04-28 9:00 UTC (permalink / raw)
To: David Ahern; +Cc: Jamal Hadi Salim, Andrea Claudi, netdev
example using eBPF:
# tc filter add dev dummy0 ingress bpf \
> direct-action obj ./bpf/filter.o sec tc-ingress
# tc -j filter show dev dummy0 ingress | jq
[
{
"protocol": "all",
"pref": 49152,
"kind": "bpf",
"chain": 0
},
{
"protocol": "all",
"pref": 49152,
"kind": "bpf",
"chain": 0,
"options": {
"handle": "1",
"bpf_name": "filter.o:[tc-ingress]",
"direct-action": true,
"not_in_hw": true,
"prog": {
"id": 101,
"tag": "a04f5eef06a7f555",
"jited": 1
}
}
}
]
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
---
tc/f_bpf.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/tc/f_bpf.c b/tc/f_bpf.c
index 135271aa1697..519186f929e5 100644
--- a/tc/f_bpf.c
+++ b/tc/f_bpf.c
@@ -203,22 +203,24 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
parse_rtattr_nested(tb, TCA_BPF_MAX, opt);
if (handle)
- fprintf(f, "handle 0x%x ", handle);
+ print_hex(PRINT_ANY, "handle", "handle 0x%x ", handle);
if (tb[TCA_BPF_CLASSID]) {
SPRINT_BUF(b1);
- fprintf(f, "flowid %s ",
+ print_string(PRINT_ANY, "flowid", "flowid %s ",
sprint_tc_classid(rta_getattr_u32(tb[TCA_BPF_CLASSID]), b1));
}
if (tb[TCA_BPF_NAME])
- fprintf(f, "%s ", rta_getattr_str(tb[TCA_BPF_NAME]));
+ print_string(PRINT_ANY, "bpf_name", "%s ",
+ rta_getattr_str(tb[TCA_BPF_NAME]));
if (tb[TCA_BPF_FLAGS]) {
unsigned int flags = rta_getattr_u32(tb[TCA_BPF_FLAGS]);
if (flags & TCA_BPF_FLAG_ACT_DIRECT)
- fprintf(f, "direct-action ");
+ print_bool(PRINT_ANY,
+ "direct-action", "direct-action ", true);
}
if (tb[TCA_BPF_FLAGS_GEN]) {
@@ -226,14 +228,14 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
rta_getattr_u32(tb[TCA_BPF_FLAGS_GEN]);
if (flags & TCA_CLS_FLAGS_SKIP_HW)
- fprintf(f, "skip_hw ");
+ print_bool(PRINT_ANY, "skip_hw", "skip_hw ", true);
if (flags & TCA_CLS_FLAGS_SKIP_SW)
- fprintf(f, "skip_sw ");
-
+ print_bool(PRINT_ANY, "skip_sw", "skip_sw ", true);
if (flags & TCA_CLS_FLAGS_IN_HW)
- fprintf(f, "in_hw ");
+ print_bool(PRINT_ANY, "in_hw", "in_hw ", true);
else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
- fprintf(f, "not_in_hw ");
+ print_bool(PRINT_ANY,
+ "not_in_hw", "not_in_hw ", true);
}
if (tb[TCA_BPF_OPS] && tb[TCA_BPF_OPS_LEN])
@@ -245,14 +247,13 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
if (!dump_ok && tb[TCA_BPF_TAG]) {
SPRINT_BUF(b);
- fprintf(f, "tag %s ",
- hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]),
- RTA_PAYLOAD(tb[TCA_BPF_TAG]),
- b, sizeof(b)));
+ print_string(PRINT_ANY, "tag", "tag %s ",
+ hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]),
+ RTA_PAYLOAD(tb[TCA_BPF_TAG]), b, sizeof(b)));
}
if (tb[TCA_BPF_POLICE]) {
- fprintf(f, "\n");
+ print_string(PRINT_FP, NULL, "\n", "");
tc_print_police(f, tb[TCA_BPF_POLICE]);
}
--
2.25.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2-next] tc: full JSON support for 'bpf' filter
2020-04-28 9:00 [PATCH iproute2-next] tc: full JSON support for 'bpf' filter Davide Caratti
@ 2020-04-28 9:09 ` Andrea Claudi
2020-04-28 15:39 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Andrea Claudi @ 2020-04-28 9:09 UTC (permalink / raw)
To: Davide Caratti; +Cc: David Ahern, Jamal Hadi Salim, linux-netdev
On Tue, Apr 28, 2020 at 11:00 AM Davide Caratti <dcaratti@redhat.com> wrote:
>
> example using eBPF:
>
> # tc filter add dev dummy0 ingress bpf \
> > direct-action obj ./bpf/filter.o sec tc-ingress
> # tc -j filter show dev dummy0 ingress | jq
> [
> {
> "protocol": "all",
> "pref": 49152,
> "kind": "bpf",
> "chain": 0
> },
> {
> "protocol": "all",
> "pref": 49152,
> "kind": "bpf",
> "chain": 0,
> "options": {
> "handle": "1",
> "bpf_name": "filter.o:[tc-ingress]",
> "direct-action": true,
> "not_in_hw": true,
> "prog": {
> "id": 101,
> "tag": "a04f5eef06a7f555",
> "jited": 1
> }
> }
> }
> ]
>
> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
> ---
> tc/f_bpf.c | 29 +++++++++++++++--------------
> 1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/tc/f_bpf.c b/tc/f_bpf.c
> index 135271aa1697..519186f929e5 100644
> --- a/tc/f_bpf.c
> +++ b/tc/f_bpf.c
> @@ -203,22 +203,24 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
> parse_rtattr_nested(tb, TCA_BPF_MAX, opt);
>
> if (handle)
> - fprintf(f, "handle 0x%x ", handle);
> + print_hex(PRINT_ANY, "handle", "handle 0x%x ", handle);
>
> if (tb[TCA_BPF_CLASSID]) {
> SPRINT_BUF(b1);
> - fprintf(f, "flowid %s ",
> + print_string(PRINT_ANY, "flowid", "flowid %s ",
> sprint_tc_classid(rta_getattr_u32(tb[TCA_BPF_CLASSID]), b1));
> }
>
> if (tb[TCA_BPF_NAME])
> - fprintf(f, "%s ", rta_getattr_str(tb[TCA_BPF_NAME]));
> + print_string(PRINT_ANY, "bpf_name", "%s ",
> + rta_getattr_str(tb[TCA_BPF_NAME]));
>
> if (tb[TCA_BPF_FLAGS]) {
> unsigned int flags = rta_getattr_u32(tb[TCA_BPF_FLAGS]);
>
> if (flags & TCA_BPF_FLAG_ACT_DIRECT)
> - fprintf(f, "direct-action ");
> + print_bool(PRINT_ANY,
> + "direct-action", "direct-action ", true);
> }
>
> if (tb[TCA_BPF_FLAGS_GEN]) {
> @@ -226,14 +228,14 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
> rta_getattr_u32(tb[TCA_BPF_FLAGS_GEN]);
>
> if (flags & TCA_CLS_FLAGS_SKIP_HW)
> - fprintf(f, "skip_hw ");
> + print_bool(PRINT_ANY, "skip_hw", "skip_hw ", true);
> if (flags & TCA_CLS_FLAGS_SKIP_SW)
> - fprintf(f, "skip_sw ");
> -
> + print_bool(PRINT_ANY, "skip_sw", "skip_sw ", true);
> if (flags & TCA_CLS_FLAGS_IN_HW)
> - fprintf(f, "in_hw ");
> + print_bool(PRINT_ANY, "in_hw", "in_hw ", true);
> else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
> - fprintf(f, "not_in_hw ");
> + print_bool(PRINT_ANY,
> + "not_in_hw", "not_in_hw ", true);
> }
>
> if (tb[TCA_BPF_OPS] && tb[TCA_BPF_OPS_LEN])
> @@ -245,14 +247,13 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
> if (!dump_ok && tb[TCA_BPF_TAG]) {
> SPRINT_BUF(b);
>
> - fprintf(f, "tag %s ",
> - hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]),
> - RTA_PAYLOAD(tb[TCA_BPF_TAG]),
> - b, sizeof(b)));
> + print_string(PRINT_ANY, "tag", "tag %s ",
> + hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]),
> + RTA_PAYLOAD(tb[TCA_BPF_TAG]), b, sizeof(b)));
> }
>
> if (tb[TCA_BPF_POLICE]) {
> - fprintf(f, "\n");
> + print_string(PRINT_FP, NULL, "\n", "");
> tc_print_police(f, tb[TCA_BPF_POLICE]);
> }
>
You may want to use print_nl() here, lib/json_print.c:228. It fits
exactly this use case.
All the rest LGTM.
> --
> 2.25.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2-next] tc: full JSON support for 'bpf' filter
2020-04-28 9:00 [PATCH iproute2-next] tc: full JSON support for 'bpf' filter Davide Caratti
2020-04-28 9:09 ` Andrea Claudi
@ 2020-04-28 15:39 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2020-04-28 15:39 UTC (permalink / raw)
To: Davide Caratti; +Cc: David Ahern, Jamal Hadi Salim, Andrea Claudi, netdev
On Tue, 28 Apr 2020 11:00:07 +0200
Davide Caratti <dcaratti@redhat.com> wrote:
> + print_hex(PRINT_ANY, "handle", "handle 0x%x ", handle);
Do you want print_0xhex instead?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-28 15:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 9:00 [PATCH iproute2-next] tc: full JSON support for 'bpf' filter Davide Caratti
2020-04-28 9:09 ` Andrea Claudi
2020-04-28 15:39 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).