summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/json.c8
-rw-r--r--src/parser_json.c22
-rw-r--r--src/statement.c1
3 files changed, 31 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index 981d177b..305eb6e3 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1482,6 +1482,14 @@ json_t *counter_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
"bytes", stmt->counter.bytes);
}
+json_t *last_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
+{
+ if (nft_output_stateless(octx) || stmt->last.set == 0)
+ return json_pack("{s:n}", "last");
+
+ return json_pack("{s:{s:I}}", "last", "used", stmt->last.used);
+}
+
json_t *set_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
{
json_t *root;
diff --git a/src/parser_json.c b/src/parser_json.c
index f1cc3950..605dcc49 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1731,6 +1731,27 @@ static struct stmt *json_parse_counter_stmt(struct json_ctx *ctx,
return stmt;
}
+static struct stmt *json_parse_last_stmt(struct json_ctx *ctx,
+ const char *key, json_t *value)
+{
+ struct stmt *stmt;
+ int64_t used;
+
+ if (json_is_null(value))
+ return last_stmt_alloc(int_loc);
+
+ if (!json_unpack(value, "{s:I}", "used", &used)) {
+ stmt = last_stmt_alloc(int_loc);
+ if (used != -1) {
+ stmt->last.used = used;
+ stmt->last.set = 1;
+ }
+ return stmt;
+ }
+
+ return NULL;
+}
+
static struct stmt *json_parse_verdict_stmt(struct json_ctx *ctx,
const char *key, json_t *value)
{
@@ -2747,6 +2768,7 @@ static struct stmt *json_parse_stmt(struct json_ctx *ctx, json_t *root)
{ "counter", json_parse_counter_stmt },
{ "mangle", json_parse_mangle_stmt },
{ "quota", json_parse_quota_stmt },
+ { "last", json_parse_last_stmt },
{ "limit", json_parse_limit_stmt },
{ "flow", json_parse_flow_offload_stmt },
{ "fwd", json_parse_fwd_stmt },
diff --git a/src/statement.c b/src/statement.c
index 72455522..9ca7e208 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -268,6 +268,7 @@ static const struct stmt_ops last_stmt_ops = {
.type = STMT_LAST,
.name = "last",
.print = last_stmt_print,
+ .json = last_stmt_json,
};
struct stmt *last_stmt_alloc(const struct location *loc)