[nft PATCH 1/7] JSON: Call verdict maps 'vmap' in JSON as well

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This way JSON format is more consistent with the standard one.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 src/json.c                      |  8 +++-
 src/parser_json.c               |  2 +-
 tests/py/any/ct.t.json          |  2 +-
 tests/py/any/ct.t.json.output   |  2 +-
 tests/py/any/meta.t.json        |  2 +-
 tests/py/inet/fib.t.json        |  2 +-
 tests/py/inet/fib.t.json.output |  2 +-
 tests/py/inet/tcp.t.json        |  6 +--
 tests/py/ip/ip.t.json           |  4 +-
 tests/py/ip/masquerade.t.json   |  2 +-
 tests/py/ip/redirect.t.json     |  2 +-
 tests/py/ip6/ip6.t.json         |  4 +-
 tests/py/ip6/ip6.t.json.output  |  2 +-
 tests/py/ip6/masquerade.t.json  |  2 +-
 tests/py/ip6/redirect.t.json    |  2 +-
 tests/py/ip6/vmap.t.json        | 84 ++++++++++++++++-----------------
 tests/py/ip6/vmap.t.json.output | 26 +++++-----
 17 files changed, 80 insertions(+), 74 deletions(-)

diff --git a/src/json.c b/src/json.c
index b6e6ca9c6c383..306cab7b5426c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -560,7 +560,13 @@ json_t *mapping_expr_json(const struct expr *expr, struct output_ctx *octx)
 
 json_t *map_expr_json(const struct expr *expr, struct output_ctx *octx)
 {
-	return json_pack("{s:{s:o, s:o}}", "map",
+	const char *type = "map";
+
+	if (expr->mappings->ops->type == EXPR_SET_REF &&
+	    expr->mappings->set->datatype->type == TYPE_VERDICT)
+		type = "vmap";
+
+	return json_pack("{s:{s:o, s:o}}", type,
 			 "left", expr_print_json(expr->map, octx),
 			 "right", expr_print_json(expr->mappings, octx));
 }
diff --git a/src/parser_json.c b/src/parser_json.c
index 6e14fb7278fb0..e340bebc03b6d 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -2064,7 +2064,7 @@ static struct stmt *json_parse_stmt(struct json_ctx *ctx, json_t *root)
 		return NULL;
 
 	/* Yes, verdict_map_stmt is actually an expression */
-	if (!strcmp(type, "map")) {
+	if (!strcmp(type, "vmap")) {
 		struct expr *expr = json_parse_map_expr(ctx, type, tmp);
 
 		if (!expr) {
diff --git a/tests/py/any/ct.t.json b/tests/py/any/ct.t.json
index 3ec00ab3b5d78..e393e52456a36 100644
--- a/tests/py/any/ct.t.json
+++ b/tests/py/any/ct.t.json
@@ -1009,7 +1009,7 @@
 # ct state . ct mark vmap { new . 0x12345678 : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "concat": [
                     {
diff --git a/tests/py/any/ct.t.json.output b/tests/py/any/ct.t.json.output
index ce33a6810a496..f6b6a90701aab 100644
--- a/tests/py/any/ct.t.json.output
+++ b/tests/py/any/ct.t.json.output
@@ -570,7 +570,7 @@
 # ct state . ct mark vmap { new . 0x12345678 : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "concat": [
                     {
diff --git a/tests/py/any/meta.t.json b/tests/py/any/meta.t.json
index ae74507892f70..7aea79eb32386 100644
--- a/tests/py/any/meta.t.json
+++ b/tests/py/any/meta.t.json
@@ -2361,7 +2361,7 @@
 # meta iif . meta oif vmap { "lo" . "lo" : drop }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "concat": [
                     {
diff --git a/tests/py/inet/fib.t.json b/tests/py/inet/fib.t.json
index cb15e39709d6c..00c79abc05006 100644
--- a/tests/py/inet/fib.t.json
+++ b/tests/py/inet/fib.t.json
@@ -56,7 +56,7 @@
 # fib daddr . iif type vmap { blackhole : drop, prohibit : drop, unicast : accept }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "fib": {
                     "flags": [
diff --git a/tests/py/inet/fib.t.json.output b/tests/py/inet/fib.t.json.output
index c473b2afc4ffe..b06e488ac2d14 100644
--- a/tests/py/inet/fib.t.json.output
+++ b/tests/py/inet/fib.t.json.output
@@ -1,7 +1,7 @@
 # fib daddr . iif type vmap { blackhole : drop, prohibit : drop, unicast : accept }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "fib": {
                     "flags": [
diff --git a/tests/py/inet/tcp.t.json b/tests/py/inet/tcp.t.json
index f5df72aa252a6..2f83566d4fab6 100644
--- a/tests/py/inet/tcp.t.json
+++ b/tests/py/inet/tcp.t.json
@@ -175,7 +175,7 @@
 # tcp dport vmap { 22 : accept, 23 : drop }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
@@ -205,7 +205,7 @@
 # tcp dport vmap { 25:accept, 28:drop }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
@@ -430,7 +430,7 @@
 # tcp sport vmap { 25:accept, 28:drop }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "sport",
diff --git a/tests/py/ip/ip.t.json b/tests/py/ip/ip.t.json
index abd45ce760159..d66e42643acb3 100644
--- a/tests/py/ip/ip.t.json
+++ b/tests/py/ip/ip.t.json
@@ -123,7 +123,7 @@
 # ip dscp vmap { cs1 : continue , cs4 : accept } counter
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dscp",
@@ -1542,7 +1542,7 @@
 # ip hdrlength vmap { 0-4 : drop, 5 : accept, 6 : continue } counter
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "hdrlength",
diff --git a/tests/py/ip/masquerade.t.json b/tests/py/ip/masquerade.t.json
index 44f371ad4dec2..4eae3b9808e43 100644
--- a/tests/py/ip/masquerade.t.json
+++ b/tests/py/ip/masquerade.t.json
@@ -379,7 +379,7 @@
         }
     },
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
diff --git a/tests/py/ip/redirect.t.json b/tests/py/ip/redirect.t.json
index b22a327df2cea..58e78ee91db51 100644
--- a/tests/py/ip/redirect.t.json
+++ b/tests/py/ip/redirect.t.json
@@ -537,7 +537,7 @@
         }
     },
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
diff --git a/tests/py/ip6/ip6.t.json b/tests/py/ip6/ip6.t.json
index 8e217bb19f8ec..272ef0d0456b4 100644
--- a/tests/py/ip6/ip6.t.json
+++ b/tests/py/ip6/ip6.t.json
@@ -102,7 +102,7 @@
 # ip6 dscp vmap { 0x04 : accept, 0x3f : continue } counter
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dscp",
@@ -250,7 +250,7 @@
 # ip6 flowlabel vmap { 0 : accept, 2 : continue } 
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "flowlabel",
diff --git a/tests/py/ip6/ip6.t.json.output b/tests/py/ip6/ip6.t.json.output
index ea7cf777bf124..6f9835334e147 100644
--- a/tests/py/ip6/ip6.t.json.output
+++ b/tests/py/ip6/ip6.t.json.output
@@ -71,7 +71,7 @@
 # ip6 dscp vmap { 0x04 : accept, 0x3f : continue } counter
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dscp",
diff --git a/tests/py/ip6/masquerade.t.json b/tests/py/ip6/masquerade.t.json
index 65f65ee5187a9..a54761d3c1eaa 100644
--- a/tests/py/ip6/masquerade.t.json
+++ b/tests/py/ip6/masquerade.t.json
@@ -373,7 +373,7 @@
         }
     },
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
diff --git a/tests/py/ip6/redirect.t.json b/tests/py/ip6/redirect.t.json
index 08d6a086db2f4..757fbb607e264 100644
--- a/tests/py/ip6/redirect.t.json
+++ b/tests/py/ip6/redirect.t.json
@@ -503,7 +503,7 @@
         }
     },
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "dport",
diff --git a/tests/py/ip6/vmap.t.json b/tests/py/ip6/vmap.t.json
index 1fbe0093dac5d..0dfa0e0d135ec 100644
--- a/tests/py/ip6/vmap.t.json
+++ b/tests/py/ip6/vmap.t.json
@@ -1,7 +1,7 @@
 # ip6 saddr vmap { abcd::3 : accept }
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -25,7 +25,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -49,7 +49,7 @@
 # ip6 saddr vmap { ::1234:1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -73,7 +73,7 @@
 # ip6 saddr vmap { 1234::1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -97,7 +97,7 @@
 # ip6 saddr vmap { 1234:1234::1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -121,7 +121,7 @@
 # ip6 saddr vmap { 1234:1234:1234::1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -145,7 +145,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -169,7 +169,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -193,7 +193,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -217,7 +217,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -241,7 +241,7 @@
 # ip6 saddr vmap { ::1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -265,7 +265,7 @@
 # ip6 saddr vmap { 1234::1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -289,7 +289,7 @@
 # ip6 saddr vmap { 1234:1234::1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -313,7 +313,7 @@
 # ip6 saddr vmap { 1234:1234:1234::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -337,7 +337,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -361,7 +361,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -385,7 +385,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -409,7 +409,7 @@
 # ip6 saddr vmap { ::1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -433,7 +433,7 @@
 # ip6 saddr vmap { 1234::1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -457,7 +457,7 @@
 # ip6 saddr vmap { 1234:1234::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -481,7 +481,7 @@
 # ip6 saddr vmap { 1234:1234:1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -505,7 +505,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -529,7 +529,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -553,7 +553,7 @@
 # ip6 saddr vmap { ::1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -577,7 +577,7 @@
 # ip6 saddr vmap { 1234::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -601,7 +601,7 @@
 # ip6 saddr vmap { 1234:1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -625,7 +625,7 @@
 # ip6 saddr vmap { 1234:1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -649,7 +649,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -673,7 +673,7 @@
 # ip6 saddr vmap { ::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -697,7 +697,7 @@
 # ip6 saddr vmap { 1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -721,7 +721,7 @@
 # ip6 saddr vmap { 1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -745,7 +745,7 @@
 # ip6 saddr vmap { 1234:1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -769,7 +769,7 @@
 # ip6 saddr vmap { ::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -793,7 +793,7 @@
 # ip6 saddr vmap { 1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -817,7 +817,7 @@
 # ip6 saddr vmap { 1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -841,7 +841,7 @@
 # ip6 saddr vmap { ::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -865,7 +865,7 @@
 # ip6 saddr vmap { 1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -889,7 +889,7 @@
 # ip6 saddr vmap { ::/64 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -918,7 +918,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:: : accept, ::aaaa : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -948,7 +948,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept, ::bbbb : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -978,7 +978,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept,::cccc : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -1008,7 +1008,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept,::dddd: drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
diff --git a/tests/py/ip6/vmap.t.json.output b/tests/py/ip6/vmap.t.json.output
index aba563fc78b92..3b5bc78e05e18 100644
--- a/tests/py/ip6/vmap.t.json.output
+++ b/tests/py/ip6/vmap.t.json.output
@@ -1,7 +1,7 @@
 # ip6 saddr vmap { ::1234:1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -25,7 +25,7 @@
 # ip6 saddr vmap { 1234::1234:1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -49,7 +49,7 @@
 # ip6 saddr vmap { 1234:1234::1234:1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -73,7 +73,7 @@
 # ip6 saddr vmap { 1234:1234:1234::1234:1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -97,7 +97,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234::1234:1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -121,7 +121,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -145,7 +145,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234::1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -169,7 +169,7 @@
 # ip6 saddr vmap { 1234:1234:1234:1234:1234:1234:1234:: : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -193,7 +193,7 @@
 # ip6 saddr vmap { ::1234:1234 : accept}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -217,7 +217,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:: : accept, ::aaaa : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -247,7 +247,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept, ::bbbb : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -277,7 +277,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept,::cccc : drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
@@ -307,7 +307,7 @@
 # ip6 saddr vmap {1234:1234:1234:1234:1234:1234:aaaa:::accept,::dddd: drop}
 [
     {
-        "map": {
+        "vmap": {
             "left": {
                 "payload": {
                     "field": "saddr",
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux