Skip to contentSkip to conversation

Misc minor fixes

PATCH Applied Phil Sutter 2 participants 6 messages Apr 25, 2019 – Apr 30, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Misc minor fixes

This series contains a few smaller fixes to tests and JSON parser.

Phil Sutter (4):
tests: monitor: Adjust to changed events ordering tests/py: Fix error messages in chain_delete()
parser_json: Fix typo in ct timeout policy parser
parser_json: Fix parser for list maps command

 src/parser_json.c                | 4 ++--
 tests/monitor/testcases/simple.t | 4 ++--
 tests/py/nft-test.py             | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.21.0
author reviewer
#1 lore raw

PATCH 1/4 tests: monitor: Adjust to changed events ordering

When replacing a rule, kernel nowadays seems to report rule add event before rule delete one. Since both events belong to the same transaction, this is harmless per definition and merely needs adjustment in expected output.

---
 tests/monitor/testcases/simple.t | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/monitor/testcases/simple.t +2 -2
index 78d8f8b04bd36..78fd6616eb074 100644
@@ -18,10 +18,10 @@ O add rule ip t c counter packets 0 bytes 0 accept
 J {"add": {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"counter": {"packets": 0, "bytes": 0}}, {"accept": null}]}}}
 
 I replace rule ip t c handle 2 accept comment "foo bar"
-O delete rule ip t c handle 2
 O add rule ip t c accept comment "foo bar"
-J {"delete": {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"accept": null}]}}}
+O delete rule ip t c handle 2
 J {"add": {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "comment": "foo bar", "expr": [{"accept": null}]}}}
+J {"delete": {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"accept": null}]}}}
 
 I add counter ip t cnt
 O add counter ip t cnt { packets 0 bytes 0 }
Signature · 1 line
2.21.0
author reviewer
#2 lore raw

PATCH 2/4 tests/py: Fix error messages in chain_delete()

In reply to Phil Sutter

Adding string and chain object is an illegal operation in Python. Instead concatenate with cmd string since that contains all required information already.

Fixes 820fd08b5f1d4 ("tests/py: Review print statements in nft-test.py")
---
 tests/py/nft-test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/py/nft-test.py +2 -2
index 5c7e28a070204..1c0afd0ec0eb3 100755
@@ -310,14 +310,14 @@ def chain_delete(chain, table, filename=None, lineno=None):
     cmd = "flush chain %s %s" % (table, chain)
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = "I cannot flush this chain " + chain
+        reason = "I cannot " + cmd
         print_error(reason, filename, lineno)
         return -1
 
     cmd = "delete chain %s %s" % (table, chain)
     ret = execute_cmd(cmd, filename, lineno)
     if ret != 0:
-        reason = cmd + "I cannot delete this chain " + chain
+        reason = "I cannot " + cmd
         print_error(reason, filename, lineno)
         return -1
 
Signature · 1 line
2.21.0
author reviewer
#3 lore raw

PATCH 3/4 parser_json: Fix typo in ct timeout policy parser

In reply to Phil Sutter

Parser expects an object in policy property and json_is_object() returns true if given parameter is an object. The check was inverse by accident.

Fixes c82a26ebf7e9f ("json: Add ct timeout support")
---
 src/parser_json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/parser_json.c +1 -1
index 53017935eba53..01f340802bec9 100644
@@ -2782,7 +2782,7 @@ static int json_parse_ct_timeout_policy(struct json_ctx *ctx,
 	if (!json_unpack(root, "{s:o}", "policy", &tmp))
 		return 0;
 
-	if (json_is_object(tmp)) {
+	if (!json_is_object(tmp)) {
 		json_error(ctx, "Invalid ct timeout policy.");
 		return 1;
 	}
Signature · 1 line
2.21.0
author reviewer
#4 lore raw

PATCH 4/4 parser_json: Fix parser for list maps command

In reply to Phil Sutter

Wrong callback in json_parse_cmd_list() for "maps" key.

Fixes 586ad210368b7 ("libnftables: Implement JSON parser")
---
 src/parser_json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/parser_json.c +1 -1
index 01f340802bec9..5c00c9b003b60 100644
@@ -3147,7 +3147,7 @@ static struct cmd *json_parse_cmd_list(struct json_ctx *ctx,
 		{ "set", CMD_OBJ_SET, json_parse_cmd_add_set },
 		{ "sets", CMD_OBJ_SETS, json_parse_cmd_list_multiple },
 		{ "map", CMD_OBJ_MAP, json_parse_cmd_add_set },
-		{ "maps", CMD_OBJ_MAPS, json_parse_cmd_add_set },
+		{ "maps", CMD_OBJ_MAPS, json_parse_cmd_list_multiple },
 		{ "counter", CMD_OBJ_COUNTER, json_parse_cmd_add_object },
 		{ "counters", CMD_OBJ_COUNTERS, json_parse_cmd_list_multiple },
 		{ "quota", CMD_OBJ_QUOTA, json_parse_cmd_add_object },
Signature · 1 line
2.21.0