]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
Solves Bug 1462 - `nft -j list set` does not show counters
authorGopal Yadav <gopunop@gmail.com>
Wed, 7 Oct 2020 14:03:37 +0000 (19:33 +0530)
committerPhil Sutter <phil@nwl.cc>
Thu, 8 Oct 2020 16:57:06 +0000 (18:57 +0200)
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>
src/json.c

index 5856f9fc3a4da8405c86d3c0b0b4b869ae5f745d..121dfb247d96732a6d304f4b33870dccba7099da 100644 (file)
@@ -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);
        }