]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cache: include set elements in "nft set list"
authorFlorian Westphal <fw@strlen.de>
Sun, 18 Jun 2023 16:39:45 +0000 (18:39 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 19 Jun 2023 16:17:42 +0000 (18:17 +0200)
Make "nft list sets" include set elements in listing by default.
In nftables 1.0.0, "nft list sets" did not include the set elements,
but with "--json" they were included.

1.0.1 and newer never include them.
This causes a problem for people updating from 1.0.0 and relying
on the presence of the set elements.

Change nftables to always include the set elements.
The "--terse" option is honored to get the "no elements" behaviour.

Fixes: a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Link: https://marc.info/?l=netfilter&m=168704941828372&w=2
Signed-off-by: Florian Westphal <fw@strlen.de>
src/cache.c
src/rule.c

index 95adee7f8ac179c4e554ac8b3709ce5cb196fe69..becfa57fc33538aa6d3941b39b606f3d101123a9 100644 (file)
@@ -235,6 +235,8 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
        case CMD_OBJ_SETS:
        case CMD_OBJ_MAPS:
                flags |= NFT_CACHE_TABLE | NFT_CACHE_SET;
+               if (!nft_output_terse(&nft->output))
+                       flags |= NFT_CACHE_SETELEM;
                break;
        case CMD_OBJ_FLOWTABLE:
                if (filter &&
index 633a5a12486d067f5cde58ae1c97451abd51f25a..1faa1a27f38ecb925275218384601dcc01bbf5e1 100644 (file)
@@ -1574,11 +1574,6 @@ static int do_list_table(struct netlink_ctx *ctx, struct table *table)
 
 static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
 {
-       struct print_fmt_options opts = {
-               .tab            = "\t",
-               .nl             = "\n",
-               .stmt_separator = "\n",
-       };
        struct table *table;
        struct set *set;
 
@@ -1601,8 +1596,7 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
                        if (cmd->obj == CMD_OBJ_MAPS &&
                            !map_is_literal(set->flags))
                                continue;
-                       set_print_declaration(set, &opts, &ctx->nft->output);
-                       nft_print(&ctx->nft->output, "%s}%s", opts.tab, opts.nl);
+                       set_print(set, &ctx->nft->output);
                }
 
                nft_print(&ctx->nft->output, "}\n");