summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-05-28 18:51:00 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-06-01 09:16:48 +0200
commit1c01c8e24e749e7f61b3cd1f4cf4ca8dc32ffd65 (patch)
treeffeb08390fd82b8601114080d70c18cf69fd9b8c
parentfb557b55460843ad04939488f95524e0c4951589 (diff)
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 <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/json.c5
-rw-r--r--src/parser_json.c11
2 files changed, 9 insertions, 7 deletions
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) {