nftables/backport-Solves-Bug-1462-nft-j-list-set-does-not-show-counters.patch
2021-07-28 11:54:19 +08:00

46 lines
1.5 KiB
Diff

From d63064681a91fdfbd53e1ef07b6a8283f48fedb5 Mon Sep 17 00:00:00 2001
From: Gopal Yadav <gopunop@gmail.com>
Date: Wed, 7 Oct 2020 19:33:37 +0530
Subject: Solves Bug 1462 - `nft -j list set` does not show counters
Element counters reside in 'stmt' field as counter statement. Append
them to 'elem' object as additional 'counter' property, generated by
counter_stmt_json().
Signed-off-by: Gopal Yadav <gopunop@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Conflict:NA
Reference: http://git.netfilter.org/nftables/commit/?id=d63064681a91fdfbd53e1ef07b6a8283f48fedb5
---
src/json.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/json.c b/src/json.c
index 5856f9fc..121dfb24 100644
--- a/src/json.c
+++ b/src/json.c
@@ -589,7 +589,7 @@ json_t *set_elem_expr_json(const struct expr *expr, struct output_ctx *octx)
return NULL;
/* these element attributes require formal set elem syntax */
- if (expr->timeout || expr->expiration || expr->comment) {
+ if (expr->timeout || expr->expiration || expr->comment || expr->stmt) {
root = json_pack("{s:o}", "val", root);
if (expr->timeout) {
@@ -604,6 +604,12 @@ json_t *set_elem_expr_json(const struct expr *expr, struct output_ctx *octx)
tmp = json_string(expr->comment);
json_object_set_new(root, "comment", tmp);
}
+ if (expr->stmt) {
+ tmp = stmt_print_json(expr->stmt, octx);
+ /* XXX: detect and complain about clashes? */
+ json_object_update_missing(root, tmp);
+ json_decref(tmp);
+ }
return json_pack("{s:o}", "elem", root);
}
--
cgit v1.2.3