Skip to contentSkip to conversation

cache: include set elements in "nft set list"

PATCH In review Florian Westphal 3 participants 5 messages Jun 18, 2023 – Jun 20, 2023 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 cache: include set elements in "nft set list"

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")
---
 src/cache.c | 2 ++
 src/rule.c  | 3 +--
 2 files changed, 3 insertions(+), 2 deletions(-)
src/cache.c +2 -0
index 95adee7f8ac1..becfa57fc335 100644
@@ -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 &&
src/rule.c +1 -2
index 633a5a12486d..305322ea7cc3 100644
@@ -1601,8 +1601,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");
Signature · 1 line
2.41.0
#1 lore raw
Quoted 11 lines · Florian Westphal

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.

Hi,

Would you recommend the debian package backports this fix for 1.0.6/1.0.7 ?

let me know, regards

#2 lore raw
Quoted 9 lines · Arturo Borrero Gonzalez
Quoted 8 lines · Florian Westphal

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.

Quoted 7 lines
Quoted 3 lines

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

Hi,

Would you recommend the debian package backports this fix for 1.0.6/1.0.7 ?

fine with me.

#3 lore raw
In reply to Florian Westphal
Quoted 10 lines · Florian Westphal

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.

LGTM.

Quoted 38 lines
Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
---
 src/cache.c | 2 ++
 src/rule.c  | 3 +--
 2 files changed, 3 insertions(+), 2 deletions(-)
src/cache.c +2 -0
index 95adee7f8ac1..becfa57fc335 100644
@@ -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 &&
src/rule.c +1 -2
index 633a5a12486d..305322ea7cc3 100644
@@ -1601,8 +1601,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");
Signature · 1 line
2.41.0
author maintainer
#4 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Florian Westphal

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.

I pushed this patch to master, with a minor change (removal of no-longer needed fmt struct).