summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-10-27 11:44:09 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-29 15:07:35 +0100
commit0c6379953ab575b3b71dda4bcd94b940f0f68447 (patch)
tree5c05aef9bd8a372faa1317bfe7895f3858e8ed70 /src/json.c
parenta42d2865bc7e96fe63276e22acd523d996aaf0a4 (diff)
src: add nft_ctx_output_{get,set}_stateless() to nft_ctx_output_{get,flags}_flags
Add NFT_CTX_OUTPUT_STATELESS flag and enable stateless printing from new output flags interface. This patch adds nft_output_save_flags() and nft_output_restore_flags() to temporarily disable stateful printing Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/json.c b/src/json.c
index 5c426ce7..5c96bcd0 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1075,7 +1075,7 @@ json_t *quota_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
if (stmt->quota.flags & NFT_QUOTA_F_INV)
json_object_set_new(root, "inv", json_true());
- if (!octx->stateless && stmt->quota.used) {
+ if (!nft_output_stateless(octx) && stmt->quota.used) {
data_unit = get_rate(stmt->quota.used, &bytes);
json_object_set_new(root, "used", json_integer(bytes));
json_object_set_new(root, "used_unit", json_string(data_unit));
@@ -1324,7 +1324,7 @@ json_t *reject_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
json_t *counter_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
{
- if (octx->stateless)
+ if (nft_output_stateless(octx))
return json_pack("{s:n}", "counter");
return json_pack("{s:{s:I, s:I}}", "counter",
@@ -1354,11 +1354,12 @@ json_t *objref_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
json_t *meter_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
{
+ unsigned int flags = octx->flags;
json_t *root, *tmp;
- octx->stateless++;
+ octx->flags |= NFT_CTX_OUTPUT_STATELESS;
tmp = stmt_print_json(stmt->meter.stmt, octx);
- octx->stateless--;
+ octx->flags = flags;
root = json_pack("{s:o, s:o, s:i}",
"key", expr_print_json(stmt->meter.key, octx),