path: root/src/parser_json.c
diff options
authorPhil Sutter <>2018-05-28 18:50:59 +0200
committerPablo Neira Ayuso <>2018-06-01 09:16:48 +0200
commitfb557b55460843ad04939488f95524e0c4951589 (patch)
tree5fa122aed1f9c31256b670de9023fb2689c35292 /src/parser_json.c
parentb32e20c51028cef839f8f40e95673c320a930f2b (diff)
JSON: Sort out rule position and handles in general
First of all, don't print the position property when listing rules. This was there only because libnftnl JSON output has it too, but since the preferred way to *add* a rule at some location is via 'handle' keyword, keeping "position" in output would be non-intuitive. Changing "position" property name to "handle" instead is also a no-go since that would clash with the real rule handle. Secondly, turn all handle output on regardless of octx->handle setting. For a programmatic API like JSON, this should be fine. Thirdly, fix rule locations when parsing JSON: Respect "handle" property for CMD_INSERT and CMD_ADD and ignore "pos" at all (actually even a typo, should have read "position"). Also support "index" property recently added to standard syntax. Finally, adjust for the above changes: There is no "position" property to drop from rule output, and "handle" property will always be present. Signed-off-by: Phil Sutter <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src/parser_json.c')
1 files changed, 9 insertions, 5 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index 60929386..1c5994f8 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -2770,14 +2770,18 @@ static struct cmd *json_parse_cmd_replace(struct json_ctx *ctx,
"chain", &,
"expr", &tmp))
return NULL;
+ json_unpack(root, "{s:I}", "handle", &;
+ json_unpack(root, "{s:I}", "index", &;
- if (op == CMD_REPLACE &&
- json_unpack_err(ctx, root, "{s:I}", "handle", &
+ if (op == CMD_REPLACE && ! {
+ json_error(ctx, "Handle is required when replacing a rule.");
return NULL;
+ }
- if (op == CMD_INSERT &&
- json_unpack_err(ctx, root, "{s:i}", "pos", &
- return NULL;
+ if ((op == CMD_INSERT || op == CMD_ADD) && {
+ =;
+ = 0;
+ } = parse_family(family);
if ( < 0) {