]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
JSON: Review meter statement support
authorPhil Sutter <phil@nwl.cc>
Mon, 28 May 2018 16:51:00 +0000 (18:51 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 1 Jun 2018 07:16:48 +0000 (09:16 +0200)
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@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/json.c
src/parser_json.c

index 622a10b30c580a6cd81dab792f07c66df05453bc..e31e31327866f0e70097029d52af8cdd82f04f56 100644 (file)
@@ -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);
index 1c5994f811e30ecbfd4e79f2d6df685c2f55bc39..afcd10a34d718f03ef0b7e12d404a5d138f154e6 100644 (file)
@@ -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) {