Skip to contentSkip to conversation

optimize: expand expression list when merging into concatenation

PATCH New Pablo Neira Ayuso 1 participant 1 message Apr 1, 2025

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 optimize: expand expression list when merging into concatenation

The following rules:

udp dport 137 ct state new,untracked accept
udp dport 138 ct state new,untracked accept

results in:

nft: src/optimize.c:670: __merge_concat: Assertion `0' failed.

The logic to expand to the new,untracked list in the concatenation is missing.

Fixes 187c6d01d357 ("optimize: expand implicit set element when merging into concatenation")
---
 src/optimize.c                                | 10 +++
 .../dumps/merge_stmts_concat.json-nft         | 61 +++++++++++++++++++
 .../dumps/merge_stmts_concat.nft              |  1 +
 .../optimizations/merge_stmts_concat          |  2 +
 4 files changed, 74 insertions(+)
src/optimize.c +10 -0
index 44010f2bb377..139bc2d73c3c 100644
@@ -666,6 +666,16 @@ static void __merge_concat(const struct optimize_ctx *ctx, uint32_t i,
 				clone = expr_clone(stmt_a->expr->right);
 				compound_expr_add(concat, clone);
 				break;
+			case EXPR_LIST:
+				list_for_each_entry(expr, &stmt_a->expr->right->expressions, list) {
+					concat_clone = expr_clone(concat);
+					clone = expr_clone(expr);
+					compound_expr_add(concat_clone, clone);
+					list_add_tail(&concat_clone->list, &pending_list);
+				}
+				list_del(&concat->list);
+				expr_free(concat);
+				break;
 			default:
 				assert(0);
 				break;
tests/shell/testcases/optimizations/dumps/merge_stmts_concat.json-nft +61 -0

67 lines not on this page · raw message

tests/shell/testcases/optimizations/dumps/merge_stmts_concat.nft +1 -0
index f56cea1c4fd7..d00ac417ca75 100644
@@ -2,6 +2,7 @@ table ip x {
 	chain y {
 		iifname . ip saddr . ip daddr { "eth1" . 1.1.1.1 . 2.2.2.3, "eth1" . 1.1.1.2 . 2.2.2.4, "eth1" . 1.1.1.2 . 2.2.3.0/24, "eth1" . 1.1.1.2 . 2.2.4.0-2.2.4.10, "eth2" . 1.1.1.3 . 2.2.2.5 } accept
 		ip protocol . th dport { tcp . 22, udp . 67 }
+		udp dport . ct state { 137 . new, 138 . new, 137 . untracked, 138 . untracked } accept
 	}
 
 	chain c1 {
tests/shell/testcases/optimizations/merge_stmts_concat +2 -0
index 4db4a6f90944..bae54e3665e0 100755
@@ -12,6 +12,8 @@ RULESET="table ip x {
 		meta iifname eth1 ip saddr 1.1.1.2 ip daddr 2.2.4.0-2.2.4.10 accept
 		meta iifname eth2 ip saddr 1.1.1.3 ip daddr 2.2.2.5 accept
 		ip protocol . th dport { tcp . 22, udp . 67 }
+		udp dport 137 ct state new,untracked accept
+		udp dport 138 ct state new,untracked accept
 	}
 }"
 
Signature · 1 line
2.30.2