summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2023-04-25 10:33:22 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2023-04-25 11:16:32 +0200
commitbd976ab13b4d57ebf5d02459c360905a76af9e58 (patch)
treed7c57f223c86eb3de00c7d8eaaeda61b6fc1b691 /src/parser_json.c
parentfd595286a68e2c676657d4ac753da517a4d0c3a2 (diff)
json: allow to specify comment on chain
Allow users to add a comment when declaring a chain. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index 95f6bdcd..50f8d1d9 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -2851,17 +2851,19 @@ static struct cmd *json_parse_cmd_add_chain(struct json_ctx *ctx, json_t *root,
struct handle h = {
.table.location = *int_loc,
};
- const char *family = "", *policy = "", *type, *hookstr, *name;
- struct chain *chain;
+ const char *family = "", *policy = "", *type, *hookstr, *name, *comment = NULL;
+ struct chain *chain = NULL;
int prio;
if (json_unpack_err(ctx, root, "{s:s, s:s}",
"family", &family,
"table", &h.table.name))
return NULL;
- if (op != CMD_DELETE &&
- json_unpack_err(ctx, root, "{s:s}", "name", &h.chain.name)) {
- return NULL;
+ if (op != CMD_DELETE) {
+ if (json_unpack_err(ctx, root, "{s:s}", "name", &h.chain.name))
+ return NULL;
+
+ json_unpack(root, "{s:s}", "comment", &comment);
} else if (op == CMD_DELETE &&
json_unpack(root, "{s:s}", "name", &h.chain.name) &&
json_unpack(root, "{s:I}", "handle", &h.handle.id)) {
@@ -2876,14 +2878,22 @@ static struct cmd *json_parse_cmd_add_chain(struct json_ctx *ctx, json_t *root,
if (h.chain.name)
h.chain.name = xstrdup(h.chain.name);
+ if (comment) {
+ chain = chain_alloc(NULL);
+ handle_merge(&chain->handle, &h);
+ chain->comment = xstrdup(comment);
+ }
+
if (op == CMD_DELETE ||
op == CMD_LIST ||
op == CMD_FLUSH ||
json_unpack(root, "{s:s, s:s, s:i}",
"type", &type, "hook", &hookstr, "prio", &prio))
- return cmd_alloc(op, obj, &h, int_loc, NULL);
+ return cmd_alloc(op, obj, &h, int_loc, chain);
+
+ if (!chain)
+ chain = chain_alloc(NULL);
- chain = chain_alloc(NULL);
chain->flags |= CHAIN_F_BASECHAIN;
chain->type.str = xstrdup(type);
chain->priority.expr = constant_expr_alloc(int_loc, &integer_type,