diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-10-27 11:44:09 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-10-29 15:07:35 +0100 |
commit | 0c6379953ab575b3b71dda4bcd94b940f0f68447 (patch) | |
tree | 5c05aef9bd8a372faa1317bfe7895f3858e8ed70 /src/statement.c | |
parent | a42d2865bc7e96fe63276e22acd523d996aaf0a4 (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/statement.c')
-rw-r--r-- | src/statement.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/statement.c b/src/statement.c index e50ac706..1eaaf585 100644 --- a/src/statement.c +++ b/src/statement.c @@ -112,6 +112,8 @@ struct stmt *verdict_stmt_alloc(const struct location *loc, struct expr *expr) static void meter_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { + unsigned int flags = octx->flags; + nft_print(octx, "meter "); if (stmt->meter.set) { expr_print(stmt->meter.set, octx); @@ -121,9 +123,9 @@ static void meter_stmt_print(const struct stmt *stmt, struct output_ctx *octx) expr_print(stmt->meter.key, octx); nft_print(octx, " "); - octx->stateless++; + octx->flags |= NFT_CTX_OUTPUT_STATELESS; stmt_print(stmt->meter.stmt, octx); - octx->stateless--; + octx->flags = flags; nft_print(octx, "} "); @@ -175,7 +177,7 @@ static void counter_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { nft_print(octx, "counter"); - if (octx->stateless) + if (nft_output_stateless(octx)) return; nft_print(octx, " packets %" PRIu64 " bytes %" PRIu64, @@ -463,7 +465,7 @@ static void quota_stmt_print(const struct stmt *stmt, struct output_ctx *octx) nft_print(octx, "quota %s%" PRIu64 " %s", inv ? "over " : "", bytes, data_unit); - if (!octx->stateless && stmt->quota.used) { + if (!nft_output_stateless(octx) && stmt->quota.used) { data_unit = get_rate(stmt->quota.used, &used); nft_print(octx, " used %" PRIu64 " %s", used, data_unit); } @@ -631,15 +633,17 @@ const char * const set_stmt_op_names[] = { static void set_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { + unsigned int flags = octx->flags; + nft_print(octx, "%s ", set_stmt_op_names[stmt->set.op]); expr_print(stmt->set.set, octx); nft_print(octx, " { "); expr_print(stmt->set.key, octx); if (stmt->set.stmt) { nft_print(octx, " "); - octx->stateless++; + octx->flags |= NFT_CTX_OUTPUT_STATELESS; stmt_print(stmt->set.stmt, octx); - octx->stateless--; + octx->flags = flags; } nft_print(octx, " }"); } @@ -665,15 +669,17 @@ struct stmt *set_stmt_alloc(const struct location *loc) static void map_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { + unsigned int flags = octx->flags; + nft_print(octx, "%s ", set_stmt_op_names[stmt->map.op]); expr_print(stmt->map.set, octx); nft_print(octx, " { "); expr_print(stmt->map.key, octx); if (stmt->map.stmt) { nft_print(octx, " "); - octx->stateless++; + octx->flags |= NFT_CTX_OUTPUT_STATELESS; stmt_print(stmt->map.stmt, octx); - octx->stateless--; + octx->flags = flags; } nft_print(octx, " : "); expr_print(stmt->map.data, octx); |