* [PATCH iproute2] tc: Support json option in tc-fw. @ 2024-02-09 14:22 Takanori Hirano 2024-02-09 16:37 ` Stephen Hemminger 2024-02-10 17:50 ` [PATCH iproute2] tc: Support json option in tc-fw patchwork-bot+netdevbpf 0 siblings, 2 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-09 14:22 UTC (permalink / raw) To: netdev; +Cc: stephen, Takanori Hirano Fix json corruption when using the "-json" option in cases where tc-fw is set. Signed-off-by: Takanori Hirano <me@hrntknr.net> --- tc/f_fw.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tc/f_fw.c b/tc/f_fw.c index 38bec492..fe99cd42 100644 --- a/tc/f_fw.c +++ b/tc/f_fw.c @@ -124,18 +124,25 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; + open_json_object("handle"); if (handle) mark = handle; if (tb[TCA_FW_MASK] && - (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) - fprintf(f, "handle 0x%x/0x%x ", mark, mask); - else - fprintf(f, "handle 0x%x ", handle); + (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) { + print_hex(PRINT_ANY, "mark", "handle 0x%x", mark); + print_hex(PRINT_ANY, "mask", "/0x%x ", mask); + } else { + print_hex(PRINT_ANY, "mark", "handle 0x%x ", mark); + print_hex(PRINT_JSON, "mask", NULL, 0xFFFFFFFF); + } + close_json_object(); } if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "classid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); + print_string(PRINT_ANY, "classid", "classid %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) @@ -143,11 +150,12 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; - fprintf(f, "input dev %s ", rta_getattr_str(idev)); + print_string(PRINT_ANY, "indev", "input dev %s ", + rta_getattr_str(idev)); } if (tb[TCA_FW_ACT]) { - fprintf(f, "\n"); + print_string(PRINT_FP, NULL, "\n", ""); tc_print_action(f, tb[TCA_FW_ACT], 0); } return 0; -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2] tc: Support json option in tc-fw. 2024-02-09 14:22 [PATCH iproute2] tc: Support json option in tc-fw Takanori Hirano @ 2024-02-09 16:37 ` Stephen Hemminger 2024-02-10 10:02 ` Takanori Hirano 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano 2024-02-10 17:50 ` [PATCH iproute2] tc: Support json option in tc-fw patchwork-bot+netdevbpf 1 sibling, 2 replies; 17+ messages in thread From: Stephen Hemminger @ 2024-02-09 16:37 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev On Fri, 9 Feb 2024 14:22:50 +0000 Takanori Hirano <me@hrntknr.net> wrote: > Fix json corruption when using the "-json" option in cases where tc-fw is set. > > Signed-off-by: Takanori Hirano <me@hrntknr.net> This looks correct, but there area a number of other places in the filter (f_XXX.c) files that still are broken with JSON. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2] tc: Support json option in tc-fw. 2024-02-09 16:37 ` Stephen Hemminger @ 2024-02-10 10:02 ` Takanori Hirano 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano 1 sibling, 0 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-10 10:02 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev On Fri, Feb 09, 2024 at 08:37:43AM -0800, Stephen Hemminger wrote: > On Fri, 9 Feb 2024 14:22:50 +0000 > Takanori Hirano <me@hrntknr.net> wrote: > > > Fix json corruption when using the "-json" option in cases where tc-fw is set. > > > > Signed-off-by: Takanori Hirano <me@hrntknr.net> > > This looks correct, but there area a number of other places in the filter (f_XXX.c) > files that still are broken with JSON. > Thanks for the review. I will send you v2 patch with the other filters fixed. ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-09 16:37 ` Stephen Hemminger 2024-02-10 10:02 ` Takanori Hirano @ 2024-02-10 10:08 ` Takanori Hirano 2024-02-10 17:18 ` Stephen Hemminger ` (2 more replies) 1 sibling, 3 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-10 10:08 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev, Takanori Hirano Add support for "-json" output in tc-fw, tc-cgroup, tc-flow, and tc-route. Signed-off-by: Takanori Hirano <me@hrntknr.net> --- Changes in v2: - Fix terminology, in f_fw, handle -> fw - Add json option support for tc-cgroup, tc-flow, and tc-route --- tc/f_cgroup.c | 4 ++-- tc/f_flow.c | 51 ++++++++++++++++++++++++++++++--------------------- tc/f_fw.c | 22 +++++++++++++++------- tc/f_route.c | 38 ++++++++++++++++++++++++++++++-------- 4 files changed, 77 insertions(+), 38 deletions(-) diff --git a/tc/f_cgroup.c b/tc/f_cgroup.c index a4fc03d1..0b69db6d 100644 --- a/tc/f_cgroup.c +++ b/tc/f_cgroup.c @@ -86,13 +86,13 @@ static int cgroup_print_opt(struct filter_util *qu, FILE *f, parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); if (handle) - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_CGROUP_EMATCHES]) print_ematch(f, tb[TCA_CGROUP_EMATCHES]); if (tb[TCA_CGROUP_POLICE]) { - fprintf(f, "\n"); + print_string(PRINT_FP, NULL, "\n", NULL); tc_print_police(f, tb[TCA_CGROUP_POLICE]); } diff --git a/tc/f_flow.c b/tc/f_flow.c index 2445aaef..1c9a636d 100644 --- a/tc/f_flow.c +++ b/tc/f_flow.c @@ -272,33 +272,37 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_FLOW_MAX, opt); - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_FLOW_MODE]) { __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); switch (mode) { case FLOW_MODE_MAP: - fprintf(f, "map "); + open_json_object("map"); + print_string(PRINT_FP, NULL, "map ", NULL); break; case FLOW_MODE_HASH: - fprintf(f, "hash "); + open_json_object("hash"); + print_string(PRINT_FP, NULL, "hash ", NULL); break; } } if (tb[TCA_FLOW_KEYS]) { __u32 keymask = rta_getattr_u32(tb[TCA_FLOW_KEYS]); - char *sep = ""; + char *sep = " "; - fprintf(f, "keys "); + open_json_array(PRINT_ANY, "keys"); for (i = 0; i <= FLOW_KEY_MAX; i++) { if (keymask & (1 << i)) { - fprintf(f, "%s%s", sep, flow_keys[i]); + print_string(PRINT_FP, NULL, "%s", sep); + print_string(PRINT_ANY, NULL, "%s", + flow_keys[i]); sep = ","; } } - fprintf(f, " "); + close_json_array(PRINT_ANY, " "); } if (tb[TCA_FLOW_MASK]) @@ -311,39 +315,44 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 xor = mask & val; if (mask != ~0) - fprintf(f, "and 0x%.8x ", mask); + print_0xhex(PRINT_ANY, "and", "and 0x%.8x ", mask); if (xor != 0) - fprintf(f, "xor 0x%.8x ", xor); + print_0xhex(PRINT_ANY, "xor", "xor 0x%.8x ", xor); if (or != 0) - fprintf(f, "or 0x%.8x ", or); + print_0xhex(PRINT_ANY, "or", "or 0x%.8x ", or); } if (tb[TCA_FLOW_RSHIFT]) - fprintf(f, "rshift %u ", - rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); + print_uint(PRINT_ANY, "rshift", "rshift %u ", + rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); if (tb[TCA_FLOW_ADDEND]) - fprintf(f, "addend 0x%x ", - rta_getattr_u32(tb[TCA_FLOW_ADDEND])); + print_0xhex(PRINT_ANY, "addend", "addend 0x%x ", + rta_getattr_u32(tb[TCA_FLOW_ADDEND])); if (tb[TCA_FLOW_DIVISOR]) - fprintf(f, "divisor %u ", - rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); + print_uint(PRINT_ANY, "divisor", "divisor %u ", + rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); if (tb[TCA_FLOW_BASECLASS]) - fprintf(f, "baseclass %s ", - sprint_tc_classid(rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), b1)); + print_string(PRINT_ANY, "baseclass", "baseclass %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), + b1)); if (tb[TCA_FLOW_PERTURB]) - fprintf(f, "perturb %usec ", - rta_getattr_u32(tb[TCA_FLOW_PERTURB])); + print_uint(PRINT_ANY, "perturb", "perturb %usec ", + rta_getattr_u32(tb[TCA_FLOW_PERTURB])); if (tb[TCA_FLOW_EMATCHES]) print_ematch(f, tb[TCA_FLOW_EMATCHES]); if (tb[TCA_FLOW_POLICE]) tc_print_police(f, tb[TCA_FLOW_POLICE]); if (tb[TCA_FLOW_ACT]) { - fprintf(f, "\n"); + print_string(PRINT_FP, NULL, "\n", NULL); tc_print_action(f, tb[TCA_FLOW_ACT], 0); } + if (tb[TCA_FLOW_MODE]) { + close_json_object(); + } return 0; } diff --git a/tc/f_fw.c b/tc/f_fw.c index 38bec492..1af6b6a7 100644 --- a/tc/f_fw.c +++ b/tc/f_fw.c @@ -124,18 +124,25 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; + open_json_object("fw"); if (handle) mark = handle; if (tb[TCA_FW_MASK] && - (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) - fprintf(f, "handle 0x%x/0x%x ", mark, mask); - else - fprintf(f, "handle 0x%x ", handle); + (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) { + print_0xhex(PRINT_ANY, "mark", "handle 0x%x", mark); + print_0xhex(PRINT_ANY, "mask", "/0x%x ", mask); + } else { + print_0xhex(PRINT_ANY, "mark", "handle 0x%x ", mark); + print_0xhex(PRINT_JSON, "mask", NULL, 0xFFFFFFFF); + } + close_json_object(); } if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "classid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); + print_string(PRINT_ANY, "classid", "classid %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) @@ -143,11 +150,12 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; - fprintf(f, "input dev %s ", rta_getattr_str(idev)); + print_string(PRINT_ANY, "indev", "input dev %s ", + rta_getattr_str(idev)); } if (tb[TCA_FW_ACT]) { - fprintf(f, "\n"); + print_string(PRINT_FP, NULL, "\n", ""); tc_print_action(f, tb[TCA_FW_ACT], 0); } return 0; diff --git a/tc/f_route.c b/tc/f_route.c index e92c7985..21ca7f75 100644 --- a/tc/f_route.c +++ b/tc/f_route.c @@ -146,20 +146,42 @@ static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_ROUTE4_MAX, opt); if (handle) - fprintf(f, "fh 0x%08x ", handle); + print_0xhex(PRINT_ANY, "fh", "fh 0x%08x ", handle); if (handle&0x7F00) - fprintf(f, "order %d ", (handle>>8)&0x7F); + print_uint(PRINT_ANY, "order", "order %d ", + (handle >> 8) & 0x7F); if (tb[TCA_ROUTE4_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), b1)); + print_string(PRINT_ANY, "flowid", "flowid %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), + b1)); + } + if (tb[TCA_ROUTE4_TO]) { + open_json_object("to"); + print_string( + PRINT_ANY, "name", "to %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, + sizeof(b1))); + print_uint(PRINT_JSON, "id", NULL, + rta_getattr_u32(tb[TCA_ROUTE4_TO])); + close_json_object(); + } + if (tb[TCA_ROUTE4_FROM]) { + open_json_object("from"); + print_string( + PRINT_ANY, "name", "from %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), + b1, sizeof(b1))); + print_uint(PRINT_JSON, "id", NULL, + rta_getattr_u32(tb[TCA_ROUTE4_FROM])); + close_json_object(); } - if (tb[TCA_ROUTE4_TO]) - fprintf(f, "to %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, sizeof(b1))); - if (tb[TCA_ROUTE4_FROM]) - fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1))); if (tb[TCA_ROUTE4_IIF]) - fprintf(f, "fromif %s", ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); + print_string( + PRINT_ANY, "fromif", "fromif %s", + ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); if (tb[TCA_ROUTE4_POLICE]) tc_print_police(f, tb[TCA_ROUTE4_POLICE]); if (tb[TCA_ROUTE4_ACT]) -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano @ 2024-02-10 17:18 ` Stephen Hemminger 2024-02-10 17:21 ` Stephen Hemminger 2024-02-11 1:00 ` [PATCH iproute2 v2] tc: Add support json option in filter Stephen Hemminger 2 siblings, 0 replies; 17+ messages in thread From: Stephen Hemminger @ 2024-02-10 17:18 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev On Sat, 10 Feb 2024 10:08:03 +0000 Takanori Hirano <me@hrntknr.net> wrote: > if (tb[TCA_CGROUP_POLICE]) { > - fprintf(f, "\n"); > + print_string(PRINT_FP, NULL, "\n", NULL) This should probably just be print_nl() ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano 2024-02-10 17:18 ` Stephen Hemminger @ 2024-02-10 17:21 ` Stephen Hemminger 2024-02-11 0:56 ` Takanori Hirano ` (3 more replies) 2024-02-11 1:00 ` [PATCH iproute2 v2] tc: Add support json option in filter Stephen Hemminger 2 siblings, 4 replies; 17+ messages in thread From: Stephen Hemminger @ 2024-02-10 17:21 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev On Sat, 10 Feb 2024 10:08:03 +0000 Takanori Hirano <me@hrntknr.net> wrote: > if (tb[TCA_FLOW_MODE]) { > __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); > > switch (mode) { > case FLOW_MODE_MAP: > - fprintf(f, "map "); > + open_json_object("map"); > + print_string(PRINT_FP, NULL, "map ", NULL); > break; > case FLOW_MODE_HASH: > - fprintf(f, "hash "); > + open_json_object("hash"); > + print_string(PRINT_FP, NULL, "hash ", NULL); > break; > } > } Since this is two values for mode, in my version it looks like +static const char *flow_mode2str(__u32 mode) +{ + static char buf[128]; + + switch (mode) { + case FLOW_MODE_MAP: + return "map"; + case FLOW_MODE_HASH: + return "hash"; + default: + snprintf(buf, sizeof(buf), "%#x", mode); + return buf; + } +} + if (tb[TCA_FLOW_MODE]) { __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); - switch (mode) { - case FLOW_MODE_MAP: - fprintf(f, "map "); - break; - case FLOW_MODE_HASH: - fprintf(f, "hash "); - break; - } + print_string(PRINT_ANY, "mode", "%s ", flow_mode2str(mode)); } ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-10 17:21 ` Stephen Hemminger @ 2024-02-11 0:56 ` Takanori Hirano 2024-02-11 0:59 ` [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route Takanori Hirano ` (2 subsequent siblings) 3 siblings, 0 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-11 0:56 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev On Sat, Feb 10, 2024 at 09:21:07AM -0800, Stephen Hemminger wrote: > On Sat, 10 Feb 2024 10:08:03 +0000 > Takanori Hirano <me@hrntknr.net> wrote: > > > if (tb[TCA_FLOW_MODE]) { > > __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); > > > > switch (mode) { > > case FLOW_MODE_MAP: > > - fprintf(f, "map "); > > + open_json_object("map"); > > + print_string(PRINT_FP, NULL, "map ", NULL); > > break; > > case FLOW_MODE_HASH: > > - fprintf(f, "hash "); > > + open_json_object("hash"); > > + print_string(PRINT_FP, NULL, "hash ", NULL); > > break; > > } > > } > > Since this is two values for mode, in my version it looks like > > +static const char *flow_mode2str(__u32 mode) > +{ > + static char buf[128]; > + > + switch (mode) { > + case FLOW_MODE_MAP: > + return "map"; > + case FLOW_MODE_HASH: > + return "hash"; > + default: > + snprintf(buf, sizeof(buf), "%#x", mode); > + return buf; > + } > +} > + > > > if (tb[TCA_FLOW_MODE]) { > __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); > > - switch (mode) { > - case FLOW_MODE_MAP: > - fprintf(f, "map "); > - break; > - case FLOW_MODE_HASH: > - fprintf(f, "hash "); > - break; > - } > + print_string(PRINT_ANY, "mode", "%s ", flow_mode2str(mode)); > } > Thank you for the v1 merge. We will send the remaining diff as a separate patch to reflect your review. ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route 2024-02-10 17:21 ` Stephen Hemminger 2024-02-11 0:56 ` Takanori Hirano @ 2024-02-11 0:59 ` Takanori Hirano 2024-02-13 4:16 ` Stephen Hemminger 2024-02-11 1:27 ` [PATCH] tc: Change of json key: options.handle -> options.fw in tc-fw Takanori Hirano 2024-02-11 1:38 ` [PATCH v2] tc: Change of json format " Takanori Hirano 3 siblings, 1 reply; 17+ messages in thread From: Takanori Hirano @ 2024-02-11 0:59 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev, Takanori Hirano Fix json corruption when using the "-json" option in some cases Signed-off-by: Takanori Hirano <me@hrntknr.net> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- tc/f_cgroup.c | 4 +-- tc/f_flow.c | 67 ++++++++++++++++++++++++++++++--------------------- tc/f_route.c | 38 +++++++++++++++++++++++------ 3 files changed, 71 insertions(+), 38 deletions(-) diff --git a/tc/f_cgroup.c b/tc/f_cgroup.c index a4fc03d1..291d6e7e 100644 --- a/tc/f_cgroup.c +++ b/tc/f_cgroup.c @@ -86,13 +86,13 @@ static int cgroup_print_opt(struct filter_util *qu, FILE *f, parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); if (handle) - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_CGROUP_EMATCHES]) print_ematch(f, tb[TCA_CGROUP_EMATCHES]); if (tb[TCA_CGROUP_POLICE]) { - fprintf(f, "\n"); + print_nl(); tc_print_police(f, tb[TCA_CGROUP_POLICE]); } diff --git a/tc/f_flow.c b/tc/f_flow.c index 2445aaef..f37e360c 100644 --- a/tc/f_flow.c +++ b/tc/f_flow.c @@ -258,6 +258,21 @@ static int flow_parse_opt(struct filter_util *fu, char *handle, return 0; } +static const char *flow_mode2str(__u32 mode) +{ + static char buf[128]; + + switch (mode) { + case FLOW_MODE_MAP: + return "map"; + case FLOW_MODE_HASH: + return "hash"; + default: + snprintf(buf, sizeof(buf), "%#x", mode); + return buf; + } +} + static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 handle) { @@ -272,33 +287,27 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_FLOW_MAX, opt); - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_FLOW_MODE]) { __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); - - switch (mode) { - case FLOW_MODE_MAP: - fprintf(f, "map "); - break; - case FLOW_MODE_HASH: - fprintf(f, "hash "); - break; - } + print_string(PRINT_ANY, "mode", "%s ", flow_mode2str(mode)); } if (tb[TCA_FLOW_KEYS]) { __u32 keymask = rta_getattr_u32(tb[TCA_FLOW_KEYS]); - char *sep = ""; + char *sep = " "; - fprintf(f, "keys "); + open_json_array(PRINT_ANY, "keys"); for (i = 0; i <= FLOW_KEY_MAX; i++) { if (keymask & (1 << i)) { - fprintf(f, "%s%s", sep, flow_keys[i]); + print_string(PRINT_FP, NULL, "%s", sep); + print_string(PRINT_ANY, NULL, "%s", + flow_keys[i]); sep = ","; } } - fprintf(f, " "); + close_json_array(PRINT_ANY, " "); } if (tb[TCA_FLOW_MASK]) @@ -311,37 +320,39 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 xor = mask & val; if (mask != ~0) - fprintf(f, "and 0x%.8x ", mask); + print_0xhex(PRINT_ANY, "and", "and 0x%.8x ", mask); if (xor != 0) - fprintf(f, "xor 0x%.8x ", xor); + print_0xhex(PRINT_ANY, "xor", "xor 0x%.8x ", xor); if (or != 0) - fprintf(f, "or 0x%.8x ", or); + print_0xhex(PRINT_ANY, "or", "or 0x%.8x ", or); } if (tb[TCA_FLOW_RSHIFT]) - fprintf(f, "rshift %u ", - rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); + print_uint(PRINT_ANY, "rshift", "rshift %u ", + rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); if (tb[TCA_FLOW_ADDEND]) - fprintf(f, "addend 0x%x ", - rta_getattr_u32(tb[TCA_FLOW_ADDEND])); + print_0xhex(PRINT_ANY, "addend", "addend 0x%x ", + rta_getattr_u32(tb[TCA_FLOW_ADDEND])); if (tb[TCA_FLOW_DIVISOR]) - fprintf(f, "divisor %u ", - rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); + print_uint(PRINT_ANY, "divisor", "divisor %u ", + rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); if (tb[TCA_FLOW_BASECLASS]) - fprintf(f, "baseclass %s ", - sprint_tc_classid(rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), b1)); + print_string(PRINT_ANY, "baseclass", "baseclass %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), + b1)); if (tb[TCA_FLOW_PERTURB]) - fprintf(f, "perturb %usec ", - rta_getattr_u32(tb[TCA_FLOW_PERTURB])); + print_uint(PRINT_ANY, "perturb", "perturb %usec ", + rta_getattr_u32(tb[TCA_FLOW_PERTURB])); if (tb[TCA_FLOW_EMATCHES]) print_ematch(f, tb[TCA_FLOW_EMATCHES]); if (tb[TCA_FLOW_POLICE]) tc_print_police(f, tb[TCA_FLOW_POLICE]); if (tb[TCA_FLOW_ACT]) { - fprintf(f, "\n"); + print_nl(); tc_print_action(f, tb[TCA_FLOW_ACT], 0); } return 0; diff --git a/tc/f_route.c b/tc/f_route.c index e92c7985..21ca7f75 100644 --- a/tc/f_route.c +++ b/tc/f_route.c @@ -146,20 +146,42 @@ static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_ROUTE4_MAX, opt); if (handle) - fprintf(f, "fh 0x%08x ", handle); + print_0xhex(PRINT_ANY, "fh", "fh 0x%08x ", handle); if (handle&0x7F00) - fprintf(f, "order %d ", (handle>>8)&0x7F); + print_uint(PRINT_ANY, "order", "order %d ", + (handle >> 8) & 0x7F); if (tb[TCA_ROUTE4_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), b1)); + print_string(PRINT_ANY, "flowid", "flowid %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), + b1)); + } + if (tb[TCA_ROUTE4_TO]) { + open_json_object("to"); + print_string( + PRINT_ANY, "name", "to %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, + sizeof(b1))); + print_uint(PRINT_JSON, "id", NULL, + rta_getattr_u32(tb[TCA_ROUTE4_TO])); + close_json_object(); + } + if (tb[TCA_ROUTE4_FROM]) { + open_json_object("from"); + print_string( + PRINT_ANY, "name", "from %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), + b1, sizeof(b1))); + print_uint(PRINT_JSON, "id", NULL, + rta_getattr_u32(tb[TCA_ROUTE4_FROM])); + close_json_object(); } - if (tb[TCA_ROUTE4_TO]) - fprintf(f, "to %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, sizeof(b1))); - if (tb[TCA_ROUTE4_FROM]) - fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1))); if (tb[TCA_ROUTE4_IIF]) - fprintf(f, "fromif %s", ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); + print_string( + PRINT_ANY, "fromif", "fromif %s", + ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); if (tb[TCA_ROUTE4_POLICE]) tc_print_police(f, tb[TCA_ROUTE4_POLICE]); if (tb[TCA_ROUTE4_ACT]) -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route 2024-02-11 0:59 ` [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route Takanori Hirano @ 2024-02-13 4:16 ` Stephen Hemminger 2024-02-13 10:01 ` [PATCH v2] " Takanori Hirano 0 siblings, 1 reply; 17+ messages in thread From: Stephen Hemminger @ 2024-02-13 4:16 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev On Sun, 11 Feb 2024 00:59:41 +0000 Takanori Hirano <me@hrntknr.net> wrote: > + if (tb[TCA_ROUTE4_TO]) { > + open_json_object("to"); > + print_string( > + PRINT_ANY, "name", "to %s ", > + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, > + sizeof(b1))); > + print_uint(PRINT_JSON, "id", NULL, > + rta_getattr_u32(tb[TCA_ROUTE4_TO])); > + close_json_object(); > + } > + if (tb[TCA_ROUTE4_FROM]) { > + open_json_object("from"); > + print_string( > + PRINT_ANY, "name", "from %s ", > + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), > + b1, sizeof(b1))); > + print_uint(PRINT_JSON, "id", NULL, > + rta_getattr_u32(tb[TCA_ROUTE4_FROM])); > + close_json_object(); > } Both to and from don't need to be sub-objects, simpler to just print as to and from. Also, avoid unnecessary line breaks in source. print_string(PRINT_ANY, "from", "from %s ", rtln_rtrealm_n2a... > + print_string( > + PRINT_ANY, "fromif", "fromif %s", > + ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); This looks like a good place to add color: print_color_string(PRINT_ANY, COLOR_IFNAME, "fromif", "fromif %s", ll_indext_to_name... ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2] tc: Support json option in tc-cgroup, tc-flow and tc-route 2024-02-13 4:16 ` Stephen Hemminger @ 2024-02-13 10:01 ` Takanori Hirano 2024-02-19 18:20 ` patchwork-bot+netdevbpf 0 siblings, 1 reply; 17+ messages in thread From: Takanori Hirano @ 2024-02-13 10:01 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev, Takanori Hirano Fix json corruption when using the "-json" option in some cases Signed-off-by: Takanori Hirano <me@hrntknr.net> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- Changes in v2: - Use print_color_string at print iface. - Fix json object structure in f_route (to/from). - Avoid line breaks. --- tc/f_cgroup.c | 4 ++-- tc/f_flow.c | 64 +++++++++++++++++++++++++++++---------------------- tc/f_route.c | 16 ++++++++----- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/tc/f_cgroup.c b/tc/f_cgroup.c index a4fc03d1..291d6e7e 100644 --- a/tc/f_cgroup.c +++ b/tc/f_cgroup.c @@ -86,13 +86,13 @@ static int cgroup_print_opt(struct filter_util *qu, FILE *f, parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); if (handle) - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_CGROUP_EMATCHES]) print_ematch(f, tb[TCA_CGROUP_EMATCHES]); if (tb[TCA_CGROUP_POLICE]) { - fprintf(f, "\n"); + print_nl(); tc_print_police(f, tb[TCA_CGROUP_POLICE]); } diff --git a/tc/f_flow.c b/tc/f_flow.c index 2445aaef..4a29af22 100644 --- a/tc/f_flow.c +++ b/tc/f_flow.c @@ -258,6 +258,21 @@ static int flow_parse_opt(struct filter_util *fu, char *handle, return 0; } +static const char *flow_mode2str(__u32 mode) +{ + static char buf[128]; + + switch (mode) { + case FLOW_MODE_MAP: + return "map"; + case FLOW_MODE_HASH: + return "hash"; + default: + snprintf(buf, sizeof(buf), "%#x", mode); + return buf; + } +} + static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 handle) { @@ -272,33 +287,26 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_FLOW_MAX, opt); - fprintf(f, "handle 0x%x ", handle); + print_0xhex(PRINT_ANY, "handle", "handle %#llx ", handle); if (tb[TCA_FLOW_MODE]) { __u32 mode = rta_getattr_u32(tb[TCA_FLOW_MODE]); - - switch (mode) { - case FLOW_MODE_MAP: - fprintf(f, "map "); - break; - case FLOW_MODE_HASH: - fprintf(f, "hash "); - break; - } + print_string(PRINT_ANY, "mode", "%s ", flow_mode2str(mode)); } if (tb[TCA_FLOW_KEYS]) { __u32 keymask = rta_getattr_u32(tb[TCA_FLOW_KEYS]); - char *sep = ""; + char *sep = " "; - fprintf(f, "keys "); + open_json_array(PRINT_ANY, "keys"); for (i = 0; i <= FLOW_KEY_MAX; i++) { if (keymask & (1 << i)) { - fprintf(f, "%s%s", sep, flow_keys[i]); + print_string(PRINT_FP, NULL, "%s", sep); + print_string(PRINT_ANY, NULL, "%s", flow_keys[i]); sep = ","; } } - fprintf(f, " "); + close_json_array(PRINT_ANY, " "); } if (tb[TCA_FLOW_MASK]) @@ -311,37 +319,37 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt, __u32 xor = mask & val; if (mask != ~0) - fprintf(f, "and 0x%.8x ", mask); + print_0xhex(PRINT_ANY, "and", "and 0x%.8x ", mask); if (xor != 0) - fprintf(f, "xor 0x%.8x ", xor); + print_0xhex(PRINT_ANY, "xor", "xor 0x%.8x ", xor); if (or != 0) - fprintf(f, "or 0x%.8x ", or); + print_0xhex(PRINT_ANY, "or", "or 0x%.8x ", or); } if (tb[TCA_FLOW_RSHIFT]) - fprintf(f, "rshift %u ", - rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); + print_uint(PRINT_ANY, "rshift", "rshift %u ", + rta_getattr_u32(tb[TCA_FLOW_RSHIFT])); if (tb[TCA_FLOW_ADDEND]) - fprintf(f, "addend 0x%x ", - rta_getattr_u32(tb[TCA_FLOW_ADDEND])); + print_0xhex(PRINT_ANY, "addend", "addend 0x%x ", + rta_getattr_u32(tb[TCA_FLOW_ADDEND])); if (tb[TCA_FLOW_DIVISOR]) - fprintf(f, "divisor %u ", - rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); + print_uint(PRINT_ANY, "divisor", "divisor %u ", + rta_getattr_u32(tb[TCA_FLOW_DIVISOR])); if (tb[TCA_FLOW_BASECLASS]) - fprintf(f, "baseclass %s ", - sprint_tc_classid(rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), b1)); + print_string(PRINT_ANY, "baseclass", "baseclass %s ", + sprint_tc_classid(rta_getattr_u32(tb[TCA_FLOW_BASECLASS]), b1)); if (tb[TCA_FLOW_PERTURB]) - fprintf(f, "perturb %usec ", - rta_getattr_u32(tb[TCA_FLOW_PERTURB])); + print_uint(PRINT_ANY, "perturb", "perturb %usec ", + rta_getattr_u32(tb[TCA_FLOW_PERTURB])); if (tb[TCA_FLOW_EMATCHES]) print_ematch(f, tb[TCA_FLOW_EMATCHES]); if (tb[TCA_FLOW_POLICE]) tc_print_police(f, tb[TCA_FLOW_POLICE]); if (tb[TCA_FLOW_ACT]) { - fprintf(f, "\n"); + print_nl(); tc_print_action(f, tb[TCA_FLOW_ACT], 0); } return 0; diff --git a/tc/f_route.c b/tc/f_route.c index e92c7985..ca8a8ddd 100644 --- a/tc/f_route.c +++ b/tc/f_route.c @@ -146,20 +146,24 @@ static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, parse_rtattr_nested(tb, TCA_ROUTE4_MAX, opt); if (handle) - fprintf(f, "fh 0x%08x ", handle); + print_0xhex(PRINT_ANY, "fh", "fh 0x%08x ", handle); if (handle&0x7F00) - fprintf(f, "order %d ", (handle>>8)&0x7F); + print_uint(PRINT_ANY, "order", "order %d ", (handle >> 8) & 0x7F); if (tb[TCA_ROUTE4_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), b1)); + print_string(PRINT_ANY, "flowid", "flowid %s ", + sprint_tc_classid(rta_getattr_u32(tb[TCA_ROUTE4_CLASSID]), b1)); } if (tb[TCA_ROUTE4_TO]) - fprintf(f, "to %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, sizeof(b1))); + print_string(PRINT_ANY, "name", "to %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_TO]), b1, sizeof(b1))); if (tb[TCA_ROUTE4_FROM]) - fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1))); + print_string(PRINT_ANY, "name", "from %s ", + rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1))); if (tb[TCA_ROUTE4_IIF]) - fprintf(f, "fromif %s", ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); + print_color_string(PRINT_ANY, COLOR_IFNAME, "fromif", "fromif %s", + ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF]))); if (tb[TCA_ROUTE4_POLICE]) tc_print_police(f, tb[TCA_ROUTE4_POLICE]); if (tb[TCA_ROUTE4_ACT]) -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2] tc: Support json option in tc-cgroup, tc-flow and tc-route 2024-02-13 10:01 ` [PATCH v2] " Takanori Hirano @ 2024-02-19 18:20 ` patchwork-bot+netdevbpf 0 siblings, 0 replies; 17+ messages in thread From: patchwork-bot+netdevbpf @ 2024-02-19 18:20 UTC (permalink / raw) To: Takanori Hirano; +Cc: stephen, netdev Hello: This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <stephen@networkplumber.org>: On Tue, 13 Feb 2024 10:01:04 +0000 you wrote: > Fix json corruption when using the "-json" option in some cases > > Signed-off-by: Takanori Hirano <me@hrntknr.net> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > Changes in v2: > - Use print_color_string at print iface. > - Fix json object structure in f_route (to/from). > - Avoid line breaks. > > [...] Here is the summary with links: - [v2] tc: Support json option in tc-cgroup, tc-flow and tc-route https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=4b6e97b5f3d8 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH] tc: Change of json key: options.handle -> options.fw in tc-fw 2024-02-10 17:21 ` Stephen Hemminger 2024-02-11 0:56 ` Takanori Hirano 2024-02-11 0:59 ` [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route Takanori Hirano @ 2024-02-11 1:27 ` Takanori Hirano 2024-02-11 1:38 ` [PATCH v2] tc: Change of json format " Takanori Hirano 3 siblings, 0 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-11 1:27 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev, Takanori Hirano In the case of a process such as mapping a json to a structure, it can be difficult if the keys have the same name but different types. Since handle is used in hex string, change it to fw. Signed-off-by: Takanori Hirano <me@hrntknr.net> --- tc/f_fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tc/f_fw.c b/tc/f_fw.c index fe99cd42..56f5176c 100644 --- a/tc/f_fw.c +++ b/tc/f_fw.c @@ -124,7 +124,7 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; - open_json_object("handle"); + open_json_object("fw"); if (handle) mark = handle; if (tb[TCA_FW_MASK] && -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2] tc: Change of json format in tc-fw 2024-02-10 17:21 ` Stephen Hemminger ` (2 preceding siblings ...) 2024-02-11 1:27 ` [PATCH] tc: Change of json key: options.handle -> options.fw in tc-fw Takanori Hirano @ 2024-02-11 1:38 ` Takanori Hirano 2024-02-19 18:20 ` patchwork-bot+netdevbpf 3 siblings, 1 reply; 17+ messages in thread From: Takanori Hirano @ 2024-02-11 1:38 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev, Takanori Hirano In the case of a process such as mapping a json to a structure, it can be difficult if the keys have the same name but different types. Since handle is used in hex string, change it to fw. Signed-off-by: Takanori Hirano <me@hrntknr.net> --- Changes in v2: - Modified to use print_nl. - Modified to use print_0xhex from print_hex. --- tc/f_fw.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tc/f_fw.c b/tc/f_fw.c index fe99cd42..5e72e526 100644 --- a/tc/f_fw.c +++ b/tc/f_fw.c @@ -124,16 +124,16 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; - open_json_object("handle"); + open_json_object("fw"); if (handle) mark = handle; if (tb[TCA_FW_MASK] && (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) { - print_hex(PRINT_ANY, "mark", "handle 0x%x", mark); - print_hex(PRINT_ANY, "mask", "/0x%x ", mask); + print_0xhex(PRINT_ANY, "mark", "handle 0x%x", mark); + print_0xhex(PRINT_ANY, "mask", "/0x%x ", mask); } else { - print_hex(PRINT_ANY, "mark", "handle 0x%x ", mark); - print_hex(PRINT_JSON, "mask", NULL, 0xFFFFFFFF); + print_0xhex(PRINT_ANY, "mark", "handle 0x%x ", mark); + print_0xhex(PRINT_JSON, "mask", NULL, 0xFFFFFFFF); } close_json_object(); } @@ -155,7 +155,7 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u } if (tb[TCA_FW_ACT]) { - print_string(PRINT_FP, NULL, "\n", ""); + print_nl(); tc_print_action(f, tb[TCA_FW_ACT], 0); } return 0; -- 2.34.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2] tc: Change of json format in tc-fw 2024-02-11 1:38 ` [PATCH v2] tc: Change of json format " Takanori Hirano @ 2024-02-19 18:20 ` patchwork-bot+netdevbpf 0 siblings, 0 replies; 17+ messages in thread From: patchwork-bot+netdevbpf @ 2024-02-19 18:20 UTC (permalink / raw) To: Takanori Hirano; +Cc: stephen, netdev Hello: This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <stephen@networkplumber.org>: On Sun, 11 Feb 2024 01:38:48 +0000 you wrote: > In the case of a process such as mapping a json to a structure, > it can be difficult if the keys have the same name but different types. > Since handle is used in hex string, change it to fw. > > Signed-off-by: Takanori Hirano <me@hrntknr.net> > --- > Changes in v2: > - Modified to use print_nl. > - Modified to use print_0xhex from print_hex. > > [...] Here is the summary with links: - [v2] tc: Change of json format in tc-fw https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=bc5468c5ebc5 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano 2024-02-10 17:18 ` Stephen Hemminger 2024-02-10 17:21 ` Stephen Hemminger @ 2024-02-11 1:00 ` Stephen Hemminger 2024-02-11 1:08 ` Takanori Hirano 2 siblings, 1 reply; 17+ messages in thread From: Stephen Hemminger @ 2024-02-11 1:00 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev On Sat, 10 Feb 2024 10:08:03 +0000 Takanori Hirano <me@hrntknr.net> wrote: > } > + if (tb[TCA_FLOW_MODE]) { > + close_json_object(); > + } > return 0; > } This last bit is problematic, the JSON encoding should not change based on whether flow mode is present or not. Also, brackets not needed around single statement ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2 v2] tc: Add support json option in filter. 2024-02-11 1:00 ` [PATCH iproute2 v2] tc: Add support json option in filter Stephen Hemminger @ 2024-02-11 1:08 ` Takanori Hirano 0 siblings, 0 replies; 17+ messages in thread From: Takanori Hirano @ 2024-02-11 1:08 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev On Sat, Feb 10, 2024 at 05:00:55PM -0800, Stephen Hemminger wrote: > On Sat, 10 Feb 2024 10:08:03 +0000 > Takanori Hirano <me@hrntknr.net> wrote: > > > } > > + if (tb[TCA_FLOW_MODE]) { > > + close_json_object(); > > + } > > return 0; > > } > > This last bit is problematic, the JSON encoding should not change > based on whether flow mode is present or not. > > Also, brackets not needed around single statement Thanks for the review. Yes, I agree with that. In the v2 patch, it was present because I was using open_json_object to open the map/hash. In the latest patch I just sent you, it has been moved to the "mode" key. I have also removed the close section because it does not do json open. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH iproute2] tc: Support json option in tc-fw. 2024-02-09 14:22 [PATCH iproute2] tc: Support json option in tc-fw Takanori Hirano 2024-02-09 16:37 ` Stephen Hemminger @ 2024-02-10 17:50 ` patchwork-bot+netdevbpf 1 sibling, 0 replies; 17+ messages in thread From: patchwork-bot+netdevbpf @ 2024-02-10 17:50 UTC (permalink / raw) To: Takanori Hirano; +Cc: netdev, stephen Hello: This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <stephen@networkplumber.org>: On Fri, 9 Feb 2024 14:22:50 +0000 you wrote: > Fix json corruption when using the "-json" option in cases where tc-fw is set. > > Signed-off-by: Takanori Hirano <me@hrntknr.net> > --- > tc/f_fw.c | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) Here is the summary with links: - [iproute2] tc: Support json option in tc-fw. https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=49a8b895adb4 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2024-02-19 18:20 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-02-09 14:22 [PATCH iproute2] tc: Support json option in tc-fw Takanori Hirano 2024-02-09 16:37 ` Stephen Hemminger 2024-02-10 10:02 ` Takanori Hirano 2024-02-10 10:08 ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano 2024-02-10 17:18 ` Stephen Hemminger 2024-02-10 17:21 ` Stephen Hemminger 2024-02-11 0:56 ` Takanori Hirano 2024-02-11 0:59 ` [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route Takanori Hirano 2024-02-13 4:16 ` Stephen Hemminger 2024-02-13 10:01 ` [PATCH v2] " Takanori Hirano 2024-02-19 18:20 ` patchwork-bot+netdevbpf 2024-02-11 1:27 ` [PATCH] tc: Change of json key: options.handle -> options.fw in tc-fw Takanori Hirano 2024-02-11 1:38 ` [PATCH v2] tc: Change of json format " Takanori Hirano 2024-02-19 18:20 ` patchwork-bot+netdevbpf 2024-02-11 1:00 ` [PATCH iproute2 v2] tc: Add support json option in filter Stephen Hemminger 2024-02-11 1:08 ` Takanori Hirano 2024-02-10 17:50 ` [PATCH iproute2] tc: Support json option in tc-fw patchwork-bot+netdevbpf
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).