Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH nft] evaluate: error out when existing set has incompatible key
@ 2023-12-13 16:29 Florian Westphal
  0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2023-12-13 16:29 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

Before:
BUG: invalid range expression type symbol
nft: expression.c:1494: range_expr_value_high: Assertion `0' failed.

After:
range_expr_value_high_assert:5:20-27: Error: Could not resolve protocol name
                elements = { 100-11.0.0.0, }
                                 ^^^^^^^^
range_expr_value_high_assert:7:6-7: Error: set definition has conflicting key (ipv4_addr vs inet_proto)

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/evaluate.c                                       |  3 +++
 .../bogons/nft-f/range_expr_value_high_assert        | 12 ++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/range_expr_value_high_assert

diff --git a/src/evaluate.c b/src/evaluate.c
index dd1c0b44c278..27adbf7f51ee 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -4769,6 +4769,9 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
 		existing_set = set_cache_find(table, set->handle.set.name);
 		if (!existing_set)
 			set_cache_add(set_get(set), table);
+		else if (!datatype_equal(existing_set->key->dtype, set->key->dtype))
+			return set_error(ctx, set, "%s definition has conflicting key (%s vs %s)\n",
+					 type, set->key->dtype->name, existing_set->key->dtype->name);
 
 		if (existing_set && existing_set->flags & NFT_SET_EVAL) {
 			uint32_t existing_flags = existing_set->flags & ~NFT_SET_EVAL;
diff --git a/tests/shell/testcases/bogons/nft-f/range_expr_value_high_assert b/tests/shell/testcases/bogons/nft-f/range_expr_value_high_assert
new file mode 100644
index 000000000000..a25ac028bb9b
--- /dev/null
+++ b/tests/shell/testcases/bogons/nft-f/range_expr_value_high_assert
@@ -0,0 +1,12 @@
+table inet t {
+	set s3 {
+		type inet_proto
+		flags interval
+		elements = { 100-11.0.0.0, }
+	}
+	set s3 {
+		type ipv4_addr
+		flags interval
+		elements = { 100-11.0.0.0, }
+	}
+}
-- 
2.41.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-13 16:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-13 16:29 [PATCH nft] evaluate: error out when existing set has incompatible key Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox