From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 1/3] json: add flow statement json export + parser
Date: Mon, 7 Feb 2022 14:28:14 +0100 [thread overview]
Message-ID: <20220207132816.21129-2-fw@strlen.de> (raw)
In-Reply-To: <20220207132816.21129-1-fw@strlen.de>
flow statement has no export, its shown as:
".. }, "flow add @ft" ] } }"
With this patch:
".. }, {"flow": {"op": "add", "flowtable": "@ft"}}]}}"
Signed-off-by: Florian Westphal <fw@strlen.de>
---
include/json.h | 2 ++
src/ct.c | 1 +
src/json.c | 7 +++++++
src/parser_json.c | 23 +++++++++++++++++++++++
4 files changed, 33 insertions(+)
diff --git a/include/json.h b/include/json.h
index 3db9f2782d11..a753f359aa52 100644
--- a/include/json.h
+++ b/include/json.h
@@ -69,6 +69,7 @@ json_t *uid_type_json(const struct expr *expr, struct output_ctx *octx);
json_t *gid_type_json(const struct expr *expr, struct output_ctx *octx);
json_t *expr_stmt_json(const struct stmt *stmt, struct output_ctx *octx);
+json_t *flow_offload_stmt_json(const struct stmt *stmt, struct output_ctx *octx);
json_t *payload_stmt_json(const struct stmt *stmt, struct output_ctx *octx);
json_t *exthdr_stmt_json(const struct stmt *stmt, struct output_ctx *octx);
json_t *quota_stmt_json(const struct stmt *stmt, struct output_ctx *octx);
@@ -169,6 +170,7 @@ EXPR_PRINT_STUB(uid_type)
EXPR_PRINT_STUB(gid_type)
STMT_PRINT_STUB(expr)
+STMT_PRINT_STUB(flow_offload)
STMT_PRINT_STUB(payload)
STMT_PRINT_STUB(exthdr)
STMT_PRINT_STUB(quota)
diff --git a/src/ct.c b/src/ct.c
index 6049157198ad..e246d3039240 100644
--- a/src/ct.c
+++ b/src/ct.c
@@ -578,6 +578,7 @@ static const struct stmt_ops flow_offload_stmt_ops = {
.name = "flow_offload",
.print = flow_offload_stmt_print,
.destroy = flow_offload_stmt_destroy,
+ .json = flow_offload_stmt_json,
};
struct stmt *flow_offload_stmt_alloc(const struct location *loc,
diff --git a/src/json.c b/src/json.c
index 63b325afc8d1..4f800c908c66 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1122,6 +1122,13 @@ json_t *expr_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
return expr_print_json(stmt->expr, octx);
}
+json_t *flow_offload_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
+{
+ return json_pack("{s:{s:s, s:s+}}", "flow",
+ "op", "add", "flowtable",
+ "@", stmt->flow.table_name);
+}
+
json_t *payload_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
{
return json_pack("{s: {s:o, s:o}}", "mangle",
diff --git a/src/parser_json.c b/src/parser_json.c
index 2fad308f7783..f07b798adecd 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1903,6 +1903,28 @@ out_err:
return NULL;
}
+static struct stmt *json_parse_flow_offload_stmt(struct json_ctx *ctx,
+ const char *key, json_t *value)
+{
+ const char *opstr, *flowtable;
+
+ if (json_unpack_err(ctx, value, "{s:s, s:s}",
+ "op", &opstr, "flowtable", &flowtable))
+ return NULL;
+
+ if (strcmp(opstr, "add")) {
+ json_error(ctx, "Unknown flow offload statement op '%s'.", opstr);
+ return NULL;
+ }
+
+ if (flowtable[0] != '@') {
+ json_error(ctx, "Illegal flowtable reference in flow offload statement.");
+ return NULL;
+ }
+
+ return flow_offload_stmt_alloc(int_loc, xstrdup(flowtable + 1));
+}
+
static struct stmt *json_parse_notrack_stmt(struct json_ctx *ctx,
const char *key, json_t *value)
{
@@ -2647,6 +2669,7 @@ static struct stmt *json_parse_stmt(struct json_ctx *ctx, json_t *root)
{ "mangle", json_parse_mangle_stmt },
{ "quota", json_parse_quota_stmt },
{ "limit", json_parse_limit_stmt },
+ { "flow", json_parse_flow_offload_stmt },
{ "fwd", json_parse_fwd_stmt },
{ "notrack", json_parse_notrack_stmt },
{ "dup", json_parse_dup_stmt },
--
2.34.1
next prev parent reply other threads:[~2022-02-07 13:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-07 13:28 [PATCH nft 0/3] flowtable json fixes Florian Westphal
2022-02-07 13:28 ` Florian Westphal [this message]
2022-02-07 13:29 ` [PATCH nft 1/3] json: add flow statement json export + parser Florian Westphal
2022-02-07 14:04 ` Pablo Neira Ayuso
2022-02-07 14:53 ` Florian Westphal
2022-02-07 17:35 ` Pablo Neira Ayuso
2022-02-07 15:03 ` Phil Sutter
2022-02-07 13:28 ` [PATCH nft 2/3] parser_json: fix flowtable device datatype Florian Westphal
2022-02-07 13:28 ` [PATCH nft 3/3] parser_json: permit empty device list Florian Westphal
2022-02-07 15:04 ` [PATCH nft 0/3] flowtable json fixes Phil Sutter
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=20220207132816.21129-2-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).