From: Phil Sutter Date: Mon, 28 May 2018 16:51:00 +0000 (+0200) Subject: JSON: Review meter statement support X-Git-Tag: v0.9.0~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c01c8e24e749e7f61b3cd1f4cf4ca8dc32ffd65;p=thirdparty%2Fnftables.git JSON: Review meter statement support 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 Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/json.c b/src/json.c index 622a10b3..e31e3132 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 1c5994f8..afcd10a3 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) {