From fb557b55460843ad04939488f95524e0c4951589 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 28 May 2018 18:50:59 +0200 Subject: 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 nft-test.py 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 --- tests/py/nft-test.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py index edc0b4b1..c02294ac 100755 --- a/tests/py/nft-test.py +++ b/tests/py/nft-test.py @@ -855,10 +855,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path): json_output = json.loads(json_output) for item in json_output["nftables"]: if "rule" in item: - if "handle" in item["rule"]: - del(item["rule"]["handle"]) - if "position" in item["rule"]: - del(item["rule"]["position"]) + del(item["rule"]["handle"]) json_output = item["rule"] break json_input = json.dumps(json_output["expr"], sort_keys = True) @@ -917,10 +914,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path): json_output = json.loads(json_output) for item in json_output["nftables"]: if "rule" in item: - if "handle" in item["rule"]: - del(item["rule"]["handle"]) - if "position" in item["rule"]: - del(item["rule"]["position"]) + del(item["rule"]["handle"]) json_output = item["rule"] break json_output = json.dumps(json_output["expr"], sort_keys = True) -- cgit v1.2.3