json: resolve multiple test case failures
Florian Westphal
maintainercover 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(-)
Florian Westphal
maintainerPATCH 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.
--- 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
@@ -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
@@ -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
@@ -49,7 +49,7 @@ "right": { "set": [ "prot-unreachable", - 4, + "frag-needed", 33, 54, 56
Signature · 1 line
2.26.2
Florian Westphal
maintainerPATCH 2/3 tests: avoid warning and add missing json test cases
In reply to Florian Westphalmake 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
@@ -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
Florian Westphal
maintainerPATCH 3/3 json: add missing nat_type flag and netmap nat flag
In reply to Florian WestphalJSON 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.
--- 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
@@ -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
Pablo Neira Ayuso
maintainerQuoted 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_typeand the netmap flag.
Patches LGTM, thanks.