Skip to contentSkip to conversation

libnftables: remove set element uncollapse for error reporting

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Oct 9, 2024 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 libnftables: remove set element uncollapse for error reporting

Error reporting works fine with recent -stable kernels:

 # cat ruleset.nft
 add table ip x
 add chain ip x y
 add set ip x y { type ipv4_addr; }
 create element ip x y { 1.1.1.1 }
 create element ip x y { 1.1.1.1 }
 # nft -f ruleset.nft
 ruleset.nft:5:25-31: Error: Could not process rule: File exists
 create element ip x y { 1.1.1.1 }
                         ^^^^^^^

which is provided by this small "fix":

commit b53c116642502b0c85ecef78bff4f826a7dd4145
Author: Pablo Neira Ayuso <[email protected]>
Date: Fri May 20 00:02:06 2022 +0200

netfilter: nf_tables: set element extended ACK reporting support

no need to relate commands via sequence number, ditch this expensive workaround in userspace.

Fixes 498a5f0c219d ("rule: collapse set element commands")
---
 include/cmd.h        |  2 +-
 include/expression.h |  1 -
 include/rule.h       |  1 -
 src/cmd.c            | 41 +++--------------------------------------
 src/libnftables.c    |  7 +------
 src/rule.c           |  1 -
 6 files changed, 5 insertions(+), 48 deletions(-)
include/cmd.h +1 -1
index 92a4152bbaea..360d32d0099f 100644
@@ -7,7 +7,7 @@ void nft_cmd_error(struct netlink_ctx *ctx, struct cmd *cmd,
 
 void nft_cmd_expand(struct cmd *cmd);
 void nft_cmd_post_expand(struct cmd *cmd);
-bool nft_cmd_collapse(struct list_head *cmds);
+void nft_cmd_collapse(struct list_head *cmds);
 void nft_cmd_uncollapse(struct list_head *cmds);
 
 #endif
include/expression.h +0 -1
index 8982110cce95..da2f693e72d3 100644
@@ -255,7 +255,6 @@ struct expr {
 	enum expr_types		etype:8;
 	enum ops		op:8;
 	unsigned int		len;
-	struct cmd		*cmd;
 
 	union {
 		struct {
include/rule.h +0 -1
index 5b3e12b5d7dc..a1628d82d275 100644
@@ -718,7 +718,6 @@ struct cmd {
 	enum cmd_obj		obj;
 	struct handle		handle;
 	uint32_t		seqnum;
-	struct list_head	collapse_list;
 	union {
 		void		*data;
 		struct expr	*expr;
src/cmd.c +3 -38

57 lines not on this page · raw message

src/libnftables.c +1 -6
index 2ae215013cb0..1ea5640e81be 100644
@@ -513,7 +513,6 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,
 {
 	struct nft_cache_filter *filter;
 	struct cmd *cmd, *next;
-	bool collapsed = false;
 	unsigned int flags;
 	int err = 0;
 
@@ -529,8 +528,7 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,
 
 	nft_cache_filter_fini(filter);
 
-	if (nft_cmd_collapse(cmds))
-		collapsed = true;
+	nft_cmd_collapse(cmds);
 
 	list_for_each_entry(cmd, cmds, list) {
 		if (cmd->op != CMD_ADD &&
@@ -553,9 +551,6 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,
 		}
 	}
 
-	if (collapsed)
-		nft_cmd_uncollapse(cmds);
-
 	if (err < 0 || nft->state->nerrs)
 		return -1;
 
src/rule.c +0 -1
index 9bc160ec0d88..9536e68c7524 100644
@@ -1332,7 +1332,6 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
 	cmd->attr     = xzalloc_array(NFT_NLATTR_LOC_MAX,
 				      sizeof(struct nlerr_loc));
 	cmd->attr_array_len = NFT_NLATTR_LOC_MAX;
-	init_list_head(&cmd->collapse_list);
 
 	return cmd;
 }
Signature · 1 line
2.30.2