Skip to contentSkip to conversation

Enhance cache filter for list commands

PATCH In review Phil Sutter 3 participants 19 messages Mar 10 – Mar 18 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Enhance cache filter for list commands

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

 src/cache.c                                 | 11 ++--
 src/mnl.c                                   | 60 ++++++++++++++++++---
 tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++
 3 files changed, 113 insertions(+), 11 deletions(-)
 create mode 100755 tests/shell/testcases/listing/cache_filters
Signature · 1 line
2.51.0
author reviewer
#1 lore raw

PATCH 1/5 cache: Include chains, flowtables and objects in netlink debug output

In order to test cache filter effectiveness, netlink debug output is useful as it shows what is actually received from the kernel and maybe discarded immediately by user space. Therefore add dump calls for these rule set elements as well.

While at it, move the netlink_dump_rule() call to an earlier spot, namely into the nft_mnl_talk() callback to match other netlink dump calls.

---
 src/cache.c |  1 -
 src/mnl.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 52 insertions(+), 9 deletions(-)
src/cache.c +0 -1
index bb005c10f9990..62eccef991933 100644
@@ -698,7 +698,6 @@ static int list_rule_cb(struct nftnl_rule *nlr, void *data)
 	    (h->chain.name && strcmp(chain, h->chain.name) != 0))
 		return 0;
 
-	netlink_dump_rule(nlr, ctx);
 	rule = netlink_delinearize_rule(ctx, nlr);
 	assert(rule);
 	list_add_tail(&rule->list, &ctx->list);
src/mnl.c +52 -8

164 lines not on this page · raw message

Signature · 1 line
2.51.0
author reviewer
#2 lore raw

PATCH 2/5 cache: Respect family in all list commands

In reply to Phil Sutter

Some list commands did not set filter->list.family even if one was given on command line, fix this.

---
 src/cache.c                                 |  6 ++-
 tests/shell/testcases/listing/cache_filters | 46 +++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100755 tests/shell/testcases/listing/cache_filters
src/cache.c +5 -1
index 62eccef991933..82efd476e3698 100644
@@ -246,10 +246,12 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
 			flags |= NFT_CACHE_FULL;
 		break;
 	case CMD_OBJ_CHAINS:
+		filter->list.family = cmd->handle.family;
 		flags |= NFT_CACHE_TABLE | NFT_CACHE_CHAIN;
 		break;
 	case CMD_OBJ_SETS:
 	case CMD_OBJ_MAPS:
+		filter->list.family = cmd->handle.family;
 		flags |= NFT_CACHE_TABLE | NFT_CACHE_SET;
 		if (!nft_output_terse(&nft->output))
 			flags |= NFT_CACHE_SETELEM;
@@ -257,12 +259,12 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
 	case CMD_OBJ_FLOWTABLE:
 		if (cmd->handle.table.name &&
 		    cmd->handle.flowtable.name) {
-			filter->list.family = cmd->handle.family;
 			filter->list.table = cmd->handle.table.name;
 			filter->list.ft = cmd->handle.flowtable.name;
 		}
 		/* fall through */
 	case CMD_OBJ_FLOWTABLES:
+		filter->list.family = cmd->handle.family;
 		flags |= NFT_CACHE_TABLE | NFT_CACHE_FLOWTABLE;
 		break;
 	case CMD_OBJ_COUNTER:
@@ -301,6 +303,8 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
 		obj_filter_setup(cmd, &flags, filter, NFT_OBJECT_TUNNEL);
 		break;
 	case CMD_OBJ_RULESET:
+		filter->list.family = cmd->handle.family;
+		/* fall through */
 	default:
 		flags |= NFT_CACHE_FULL;
 		break;
tests/shell/testcases/listing/cache_filters new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.51.0
author reviewer
#4 lore raw

Re: [nft PATCH 2/5] cache: Respect family in all list commands

Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter

Some list commands did not set filter->list.family even if one was given on command line, fix this.

Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")

Hmm. At that point, we didn't have 'filter' parameter in evaluate_cache_list(). Struct nft_cache_filter was introduced later, in commit 3f1d3912c3a6b ("cache: filter out tables that are not requested").

Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.

Do you still think we should add that tag?

Quoted 3 lines
Quoted 1 line

Thanks for reviewing!

#5 lore raw

Re: [nft PATCH 2/5] cache: Respect family in all list commands

Quoted 8 lines · Phil Sutter
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter

Some list commands did not set filter->list.family even if one was given on command line, fix this.

Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Quoted 7 lines

Hmm. At that point, we didn't have 'filter' parameter in evaluate_cache_list(). Struct nft_cache_filter was introduced later, in commit 3f1d3912c3a6b ("cache: filter out tables that are not requested").

Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.

Good point.

Helping identify backporting in a semi-automated way is good, specially for small fixes like this.

At least for me, it helps me identify if it is an update/enhancement/feature or fix, it is just a bit more context information.

Quoted 1 line

Do you still think we should add that tag?

I get your point that tags need to be right if we use them.

author reviewer
#6 lore raw

Re: [nft PATCH 2/5] cache: Respect family in all list commands

Quoted 22 lines · Pablo Neira Ayuso
Quoted 8 lines · Phil Sutter
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter

Some list commands did not set filter->list.family even if one was given on command line, fix this.

Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Quoted 7 lines

Hmm. At that point, we didn't have 'filter' parameter in evaluate_cache_list(). Struct nft_cache_filter was introduced later, in commit 3f1d3912c3a6b ("cache: filter out tables that are not requested").

Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.

Good point.

Helping identify backporting in a semi-automated way is good, specially for small fixes like this.

Quoted 7 lines

At least for me, it helps me identify if it is an update/enhancement/feature or fix, it is just a bit more context information.

Quoted 1 line

Do you still think we should add that tag?

I get your point that tags need to be right if we use them.

How about:

Fixes b3ed8fd8c9f33 ("cache: missing family in cache filtering")
author reviewer
#7 lore raw

PATCH 3/5 cache: Relax chain_cache_dump filter application

In reply to Phil Sutter

While populating chain cache, a filter was only effective if it limited fetching to both a table and a chain. Make it apply to 'list chains' command as well which at most specifies a family and table.

Since the code is OK with filter->list fields being NULL, merely check for filter to be non-NULL (which is the case if nft_cache_update() is called by nft_cmd_enoent_chain()).

---
 src/cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/cache.c +1 -1
index 82efd476e3698..13d4cb19eb4f6 100644
@@ -625,7 +625,7 @@ chain_cache_dump(struct netlink_ctx *ctx,
 	const char *chain = NULL;
 	int family = NFPROTO_UNSPEC;
 
-	if (filter && filter->list.table && filter->list.chain) {
+	if (filter) {
 		family = filter->list.family;
 		table = filter->list.table;
 		chain = filter->list.chain;
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 3/5
#8 lore raw

Re: [nft PATCH 3/5] cache: Relax chain_cache_dump filter application

Quoted 7 lines · Phil Sutter

While populating chain cache, a filter was only effective if it limited fetching to both a table and a chain. Make it apply to 'list chains' command as well which at most specifies a family and table.

Since the code is OK with filter->list fields being NULL, merely check for filter to be non-NULL (which is the case if nft_cache_update() is called by nft_cmd_enoent_chain()).

Fixes 17297d1acbbf ("cache: Filter chain list on kernel side")
Quoted 1 line
author reviewer
#9 lore raw

PATCH 4/5 cache: Filter for table when listing sets or maps

In reply to Phil Sutter

Respect an optionally specified table name to filter listed sets or maps to by populating the filter accordingly.

---
 src/cache.c                                 | 1 +
 tests/shell/testcases/listing/cache_filters | 4 ++++
 2 files changed, 5 insertions(+)
src/cache.c +1 -0
index 13d4cb19eb4f6..f86d000690929 100644
@@ -252,6 +252,7 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
 	case CMD_OBJ_SETS:
 	case CMD_OBJ_MAPS:
 		filter->list.family = cmd->handle.family;
+		filter->list.table = cmd->handle.table.name;
 		flags |= NFT_CACHE_TABLE | NFT_CACHE_SET;
 		if (!nft_output_terse(&nft->output))
 			flags |= NFT_CACHE_SETELEM;
tests/shell/testcases/listing/cache_filters +4 -0
index 37c8f845dd4c7..7a89330d2b6c0 100755
@@ -22,6 +22,8 @@ table ip ip_t {
 	chain ip_t_c2 {
 	}
 }
+table ip ip_t2 {
+}
 EOF
 
 $NFT --debug=netlink list ruleset | \
@@ -38,6 +40,8 @@ $NFT --debug=netlink list sets | \
 	grep -q 'family 2 ip_t_s ip_t' || fail "broken list sets"
 $NFT --debug=netlink list sets ip6 | \
 	grep -q 'family 2 ip_t_s ip_t' && fail "broken list sets family filter"
+$NFT --debug=netlink list sets ip ip_t2 | \
+	grep -q 'family 2 ip_t_s ip_t' && fail "broken list sets table filter"
 
 $NFT --debug=netlink list flowtables | \
 	grep -q 'flow table ip_t ip_t_ft' || fail "broken list flowtables"
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 4/5
#10 lore raw

Re: [nft PATCH 4/5] cache: Filter for table when listing sets or maps

Quoted 3 lines · Phil Sutter

Respect an optionally specified table name to filter listed sets or maps to by populating the filter accordingly.

Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Quoted 1 line
author reviewer
#11 lore raw

PATCH 5/5 cache: Filter for table when listing flowtables

In reply to Phil Sutter

Respect an optionally specified table name to filter listed flowtables to by populating the filter accordingly.

---
 src/cache.c                                 | 1 +
 tests/shell/testcases/listing/cache_filters | 3 +++
 2 files changed, 4 insertions(+)
src/cache.c +1 -0
index f86d000690929..bad8275326c76 100644
@@ -266,6 +266,7 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
 		/* fall through */
 	case CMD_OBJ_FLOWTABLES:
 		filter->list.family = cmd->handle.family;
+		filter->list.table = cmd->handle.table.name;
 		flags |= NFT_CACHE_TABLE | NFT_CACHE_FLOWTABLE;
 		break;
 	case CMD_OBJ_COUNTER:
tests/shell/testcases/listing/cache_filters +3 -0
index 7a89330d2b6c0..e3d0e5e5a7217 100755
@@ -47,4 +47,7 @@ $NFT --debug=netlink list flowtables | \
 	grep -q 'flow table ip_t ip_t_ft' || fail "broken list flowtables"
 $NFT --debug=netlink list flowtables ip6 | \
 	grep -q 'flow table ip_t ip_t_ft' && fail "broken list flowtables family filter"
+$NFT --debug=netlink list flowtables ip ip_t2 | \
+	grep -q 'flow table ip_t ip_t_ft' && fail "broken list flowtables table filter"
+
 exit 0
Signature · 1 line
2.51.0
Tested-by on the v1 series
#13 lore raw
In reply to Phil Sutter
Quoted 21 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Quoted 5 lines
 src/cache.c                                 | 11 ++--
 src/mnl.c                                   | 60 ++++++++++++++++++---
 tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++
 3 files changed, 113 insertions(+), 11 deletions(-)
 create mode 100755 tests/shell/testcases/listing/cache_filters

I ran this series against the firewalld testsuite. All green. Thanks Phil!

For the series:

author reviewer
#14 lore raw
Quoted 22 lines · Eric Garver
Quoted 21 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Quoted 8 lines
Quoted 5 lines
 src/cache.c                                 | 11 ++--
 src/mnl.c                                   | 60 ++++++++++++++++++---
 tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++
 3 files changed, 113 insertions(+), 11 deletions(-)
 create mode 100755 tests/shell/testcases/listing/cache_filters

I ran this series against the firewalld testsuite. All green. Thanks Phil!

Thanks for testing, Eric! Shame on me for not putting you in Cc as you asked for. Next time I'll probably best add a Cc: tag to one of the commits immediately. ;)

Cheers, Phil

author reviewer
#15 lore raw
In reply to Phil Sutter
Quoted 12 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

Quoted 8 lines

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Series applied after inserting suggested Fixes: tags.

#16 lore raw
Quoted 15 lines · Phil Sutter
Quoted 14 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Quoted 8 lines
Quoted 6 lines

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Series applied after inserting suggested Fixes: tags.

Uoh.

I did not even get here to review.

#17 lore raw
Quoted 23 lines · Pablo Neira Ayuso
Quoted 22 lines · Phil Sutter
Quoted 20 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Quoted 5 lines
Quoted 1 line

Series applied after inserting suggested Fixes: tags.

Uoh.

I did not even get here to review.

Oh sorry, it looks good to me.

I thought you applied the one to fix "list table ...; list table ...;".

That other series I would like to have a closer look.

author reviewer
#18 lore raw
Quoted 24 lines · Pablo Neira Ayuso
Quoted 23 lines · Pablo Neira Ayuso
Quoted 22 lines · Phil Sutter
Quoted 20 lines · Phil Sutter

Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.

This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.

The remaining patches actually increase filter use.

Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Series applied after inserting suggested Fixes: tags.

Uoh.

I did not even get here to review.

Oh sorry, it looks good to me.

Yes, you gave your Reviewed-by: for all but the first patch! O:-)

Quoted 3 lines

I thought you applied the one to fix "list table ...; list table ...;".

That other series I would like to have a closer look.

Yes, I also appreciate some review of that one. Also I wanted to try implementing cache update per command, if only to see how troublesome that will be.

Thanks, Phil