diff mbox series

[v2] Solves Bug 1462 - `nft -j list set` does not show counters

Message ID 20201007140337.21218-1-gopunop@gmail.com
State Accepted
Delegated to: Pablo Neira
Headers show
Series [v2] Solves Bug 1462 - `nft -j list set` does not show counters | expand

Commit Message

Gopal Yadav Oct. 7, 2020, 2:03 p.m. UTC
Solves Bug 1462 - `nft -j list set` does not show counters

Signed-off-by: Gopal Yadav <gopunop@gmail.com>
---
 src/json.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Phil Sutter Oct. 8, 2020, 5:02 p.m. UTC | #1
On Wed, Oct 07, 2020 at 07:33:37PM +0530, Gopal Yadav wrote:
> Solves Bug 1462 - `nft -j list set` does not show counters
> 
> Signed-off-by: Gopal Yadav <gopunop@gmail.com>

Added a comment about potential clashes (json_object_update_missing()
hides those) and replaced the duplicate subject line by a commit
message, then applied the result.

Thanks, Phil
Gopal Yadav Oct. 9, 2020, 5:45 a.m. UTC | #2
On Thu, Oct 8, 2020 at 10:32 PM Phil Sutter <phil@nwl.cc> wrote:
>
> On Wed, Oct 07, 2020 at 07:33:37PM +0530, Gopal Yadav wrote:
> > Solves Bug 1462 - `nft -j list set` does not show counters
> >
> > Signed-off-by: Gopal Yadav <gopunop@gmail.com>
>
> Added a comment about potential clashes (json_object_update_missing()
> hides those) and replaced the duplicate subject line by a commit
> message, then applied the result.

Any description of those potential clashes?
Phil Sutter Oct. 9, 2020, 8:31 a.m. UTC | #3
On Fri, Oct 09, 2020 at 11:15:48AM +0530, Gopal Yadav wrote:
> On Thu, Oct 8, 2020 at 10:32 PM Phil Sutter <phil@nwl.cc> wrote:
> >
> > On Wed, Oct 07, 2020 at 07:33:37PM +0530, Gopal Yadav wrote:
> > > Solves Bug 1462 - `nft -j list set` does not show counters
> > >
> > > Signed-off-by: Gopal Yadav <gopunop@gmail.com>
> >
> > Added a comment about potential clashes (json_object_update_missing()
> > hides those) and replaced the duplicate subject line by a commit
> > message, then applied the result.
> 
> Any description of those potential clashes?

AFAICT, none are possible right now. Though the design allows for it and
we might miss that.

Cheers, Phil
diff mbox series

Patch

diff --git a/src/json.c b/src/json.c
index 5856f9fc..ea6e392c 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,11 @@  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);
+			json_object_update_missing(root, tmp);
+			json_decref(tmp);
+		}
 		return json_pack("{s:o}", "elem", root);
 	}