Skip to contentSkip to conversation

json: resolve multiple test case failures

PATCH In review Florian Westphal 2 participants 5 messages Nov 3, 2020 – Nov 4, 2020 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

cover json: resolve multiple test case failures

Over the last few months nft gained a few new features and test cases that either do not have a json test case or fail in json mode.

First two patches only touch the test cases themselves, but the snat.t failure turned out to be due to lack of feature parity with the normal bison parser.

Thus that patch adds needed export/import facility for nat_type and the netmap flag.

 src/json.c                     |   43 +++++++++++++---
 src/parser_json.c              |   70 +++++++++++++++++++++++++-
 tests/py/bridge/reject.t       |    2 
 tests/py/bridge/reject.t.json  |   72 +++++++++++++++++++++++++++
 tests/py/inet/dnat.t           |    4 -
 tests/py/inet/dnat.t.json      |   55 ++++++++++++++++++++
 tests/py/inet/sets.t.json      |   74 ++++++++++++++++++++++++++++
 tests/py/ip/icmp.t.json        |    4 -
 tests/py/ip/icmp.t.json.output |    2 
 tests/py/ip/snat.t.json        |  108 +++++++++++++++++++++++++++++++++++++++++
 10 files changed, 418 insertions(+), 16 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 tests: json: add missing test case output

Fix warnings and errors when running nf-test.py -j due to missing json test case updates. This also makes bridge/reject.t pass in json mode.

No code changes.

Fixes 8615ed93f6e4c4 ("evaluate: enable reject with 802.1q")
Fixes fae0a0972d7a71 ("tests: py: Enable anonymous set rule with concatenated ranges in inet/sets.t")
Fixes 2a20b5bdbde8a1 ("datatype: add frag-needed (ipv4) to reject options")
---
 tests/py/bridge/reject.t       |  2 +-
 tests/py/bridge/reject.t.json  | 72 +++++++++++++++++++++++++++++++++
 tests/py/inet/sets.t.json      | 74 ++++++++++++++++++++++++++++++++++
 tests/py/ip/icmp.t.json        |  4 +-
 tests/py/ip/icmp.t.json.output |  2 +-
 5 files changed, 150 insertions(+), 4 deletions(-)
tests/py/bridge/reject.t +1 -1
index f5ed203815e5..ee33af77eab6 100644
@@ -32,7 +32,7 @@ ether type ip6 reject with icmp type host-unreachable;fail
 ether type ip reject with icmpv6 type no-route;fail
 ether type vlan reject;ok
 ether type arp reject;fail
-ether type vlan reject with tcp reset;ok
+ether type vlan reject with tcp reset;ok;meta l4proto 6 ether type vlan reject with tcp reset
 ether type arp reject with tcp reset;fail
 ip protocol udp reject with tcp reset;fail
 
tests/py/bridge/reject.t.json +72 -0

75 lines not on this page · raw message

tests/py/inet/sets.t.json +74 -0

77 lines not on this page · raw message

tests/py/ip/icmp.t.json +2 -2
index 4e1727458779..965eb10be9ed 100644
@@ -480,7 +480,7 @@
     }
 ]
 
-# icmp code != { prot-unreachable, 4, 33, 54, 56}
+# icmp code != { prot-unreachable, frag-needed, 33, 54, 56}
 [
     {
         "match": {
@@ -494,7 +494,7 @@
             "right": {
                 "set": [
                     "prot-unreachable",
-                    4,
+                    "frag-needed",
                     33,
                     54,
                     56
tests/py/ip/icmp.t.json.output +1 -1
index e8045bb8182e..2391983ab826 100644
@@ -49,7 +49,7 @@
             "right": {
                 "set": [
                     "prot-unreachable",
-                    4,
+                    "frag-needed",
                     33,
                     54,
                     56
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH 2/3 tests: avoid warning and add missing json test cases

In reply to Florian Westphal

make dnat.t pass in json mode.

---
 tests/py/inet/dnat.t      |  4 +--
 tests/py/inet/dnat.t.json | 55 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
tests/py/inet/dnat.t +2 -2
index a266100890e3..b460af392557 100644
@@ -15,7 +15,7 @@ dnat to 1.2.3.4;fail
 dnat ip6 to ct mark . ip daddr map { 0x00000014 . 1.1.1.1 : 1.2.3.4};fail
 ip6 daddr dead::beef dnat to 10.1.2.3;fail
 
-meta l4proto { tcp, udp } dnat ip to 1.1.1.1:80;ok
-ip protocol { tcp, udp } dnat ip to 1.1.1.1:80;ok
+meta l4proto { tcp, udp } dnat ip to 1.1.1.1:80;ok;meta l4proto { 6, 17} dnat ip to 1.1.1.1:80
+ip protocol { tcp, udp } dnat ip to 1.1.1.1:80;ok;ip protocol { 6, 17} dnat ip to 1.1.1.1:80
 meta l4proto { tcp, udp } tcp dport 20 dnat to 1.1.1.1:80;fail
 ip protocol { tcp, udp } tcp dport 20 dnat to 1.1.1.1:80;fail
tests/py/inet/dnat.t.json +55 -0

58 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#3 lore raw

PATCH 3/3 json: add missing nat_type flag and netmap nat flag

In reply to Florian Westphal

JSON in/output doesn't know about nat_type and thus cannot save/restore nat mappings involving prefixes or concatenations because the snat statement lacks the prefix/concat/interval type flags.

Furthermore, bison parser was extended to support netmap. This is done with an internal 'netmap' flag that is passed to the kernel. We need to dump/restore that as well.

Also make sure ip/snat.t passes in json mode.

Fixes 35a6b10c1bc4 ("src: add netmap support")
Fixes 9599d9d25a6b ("src: NAT support for intervals in maps")
---
 src/json.c              |  43 +++++++++++++---
 src/parser_json.c       |  70 +++++++++++++++++++++++++-
 tests/py/ip/snat.t.json | 108 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+), 10 deletions(-)
src/json.c +35 -8
index a8824d3fc05a..3c4654d6dada 100644
@@ -1288,7 +1288,7 @@ json_t *log_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
 	return json_pack("{s:o}", "log", root);
 }
 
-static json_t *nat_flags_json(int flags)
+static json_t *nat_flags_json(uint32_t flags)
 {
 	json_t *array = json_array();
 
@@ -1298,9 +1298,37 @@ static json_t *nat_flags_json(int flags)
 		json_array_append_new(array, json_string("fully-random"));
 	if (flags & NF_NAT_RANGE_PERSISTENT)
 		json_array_append_new(array, json_string("persistent"));
+	if (flags & NF_NAT_RANGE_NETMAP)
+		json_array_append_new(array, json_string("netmap"));
 	return array;
 }
 
+static json_t *nat_type_flags_json(uint32_t type_flags)
+{
+	json_t *array = json_array();
+
+	if (type_flags & STMT_NAT_F_INTERVAL)
+		json_array_append_new(array, json_string("interval"));
+	if (type_flags & STMT_NAT_F_PREFIX)
+		json_array_append_new(array, json_string("prefix"));
+	if (type_flags & STMT_NAT_F_CONCAT)
+		json_array_append_new(array, json_string("concat"));
+
+	return array;
+}
+
+static void nat_stmt_add_array(json_t *root, const char *name, json_t *array)
+{
+	if (json_array_size(array) > 1) {
+		json_object_set_new(root, name, array);
+	} else {
+		if (json_array_size(array))
+			json_object_set(root, name,
+					json_array_get(array, 0));
+		json_decref(array);
+	}
+}
+
 json_t *nat_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
 {
 	json_t *root = json_object();
@@ -1322,13 +1350,12 @@ json_t *nat_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
 		json_object_set_new(root, "port",
 				    expr_print_json(stmt->nat.proto, octx));
 
-	if (json_array_size(array) > 1) {
-		json_object_set_new(root, "flags", array);
-	} else {
-		if (json_array_size(array))
-			json_object_set(root, "flags",
-					json_array_get(array, 0));
-		json_decref(array);
+	nat_stmt_add_array(root, "flags", array);
+
+	if (stmt->nat.type_flags) {
+		array = nat_type_flags_json(stmt->nat.type_flags);
+
+		nat_stmt_add_array(root, "type_flags", array);
 	}
 
 	if (!json_object_size(root)) {
src/parser_json.c +68 -2

94 lines not on this page · raw message

tests/py/ip/snat.t.json +108 -0

111 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw
In reply to Florian Westphal
Quoted 9 lines · Florian Westphal

Over the last few months nft gained a few new features and test cases that either do not have a json test case or fail in json mode.

First two patches only touch the test cases themselves, but the snat.t failure turned out to be due to lack of feature parity with the normal bison parser.

Thus that patch adds needed export/import facility for nat_type and the netmap flag.

Patches LGTM, thanks.