diff options
author | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2022-09-11 00:11:14 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-09-16 09:37:31 +0200 |
commit | 05fcf8013def5274e0a66d16b44f34d39b31d594 (patch) | |
tree | e658700f25d3a0b28e8b8ff06bc2b9c0cdcd1b15 /src | |
parent | a7d2a042442494abae2970db53fa21bbef1a280a (diff) |
json: add stateful object comment support
When listing a stateful object with JSON support, the comment was ignored.
Output example:
{
"counter": {
"family": "inet",
"name": "mycounter",
"table": "t",
"handle": 1,
"comment": "my comment in counter",
"packets": 0,
"bytes": 0
}
}
Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1611
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/json.c | 6 | ||||
-rw-r--r-- | src/parser_json.c | 3 |
2 files changed, 9 insertions, 0 deletions
@@ -329,6 +329,12 @@ static json_t *obj_print_json(const struct obj *obj) "table", obj->handle.table.name, "handle", obj->handle.handle.id); + if (obj->comment) { + tmp = json_pack("{s:s}", "comment", obj->comment); + json_object_update(root, tmp); + json_decref(tmp); + } + switch (obj->type) { case NFT_OBJECT_COUNTER: tmp = json_pack("{s:I, s:I}", diff --git a/src/parser_json.c b/src/parser_json.c index 1ffca2d1..76c268f8 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -3357,6 +3357,9 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx, obj = obj_alloc(int_loc); + if (!json_unpack(root, "{s:s}", "comment", &obj->comment)) + obj->comment = xstrdup(obj->comment); + switch (cmd_obj) { case CMD_OBJ_COUNTER: obj->type = NFT_OBJECT_COUNTER; |