[nft PATCH 05/14] JSON: Review meter statement support

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

 



Meter name being optional seems to come from old flow statement, so
don't support this. Also add size support as was recently added to
standard syntax.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 src/json.c        |  5 +++--
 src/parser_json.c | 11 ++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/json.c b/src/json.c
index 622a10b30c580..e31e31327866f 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1212,9 +1212,10 @@ json_t *meter_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
 	tmp = stmt_print_json(stmt->meter.stmt, octx);
 	octx->stateless--;
 
-	root = json_pack("{s:o, s:o}",
+	root = json_pack("{s:o, s:o, s:i}",
 			 "key", expr_print_json(stmt->meter.key, octx),
-			 "stmt", tmp);
+			 "stmt", tmp,
+			 "size", stmt->meter.size);
 	if (stmt->meter.set) {
 		tmp = json_string(stmt->meter.set->set->handle.set.name);
 		json_object_set_new(root, "name", tmp);
diff --git a/src/parser_json.c b/src/parser_json.c
index 1c5994f811e30..afcd10a34d718 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1989,15 +1989,16 @@ static struct stmt *json_parse_meter_stmt(struct json_ctx *ctx,
 	json_t *jkey, *jstmt;
 	struct stmt *stmt;
 	const char *name;
+	uint32_t size = 0xffff;
 
-	if (json_unpack_err(ctx, value, "{s:o, s:o}",
-			    "key", &jkey, "stmt", &jstmt))
+	if (json_unpack_err(ctx, value, "{s:s, s:o, s:o}",
+			    "name", &name, "key", &jkey, "stmt", &jstmt))
 		return NULL;
+	json_unpack(value, "{s:i}", "size", &size);
 
 	stmt = meter_stmt_alloc(int_loc);
-
-	if (!json_unpack(value, "{s:s}", "name", &name))
-		stmt->meter.name = xstrdup(name);
+	stmt->meter.name = xstrdup(name);
+	stmt->meter.size = size;
 
 	stmt->meter.key = json_parse_expr(ctx, jkey);
 	if (!stmt->meter.key) {
-- 
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