[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240210092107.53598a13@hermes.local>
Date: Sat, 10 Feb 2024 09:21:07 -0800
From: Stephen Hemminger <stephen@...workplumber.org>
To: Takanori Hirano <me@...tknr.net>
Cc: netdev@...r.kernel.org
Subject: Re: [PATCH iproute2 v2] tc: Add support json option in filter.
On Sat, 10 Feb 2024 10:08:03 +0000
Takanori Hirano <me@...tknr.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));
}
Powered by blists - more mailing lists