Otherwise set reference ends up included in an anonymous set, as an element, which is not supported. Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- src/optimize.c | 10 ++++++ .../optimizations/dumps/skip_merge.nft | 23 +++++++++++++ .../shell/testcases/optimizations/skip_merge | 34 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tests/shell/testcases/optimizations/dumps/skip_merge.nft create mode 100755 tests/shell/testcases/optimizations/skip_merge diff --git a/src/optimize.c b/src/optimize.c index a2a4e587e125..543d3ca5a9c7 100644 --- a/src/optimize.c +++ b/src/optimize.c @@ -105,6 +105,12 @@ static bool stmt_expr_supported(const struct expr *expr) return false; } +static bool expr_symbol_set(const struct expr *expr) +{ + return expr->right->etype == EXPR_SYMBOL && + expr->right->symtype == SYMBOL_SET; +} + static bool __stmt_type_eq(const struct stmt *stmt_a, const struct stmt *stmt_b, bool fully_compare) { @@ -122,6 +128,10 @@ static bool __stmt_type_eq(const struct stmt *stmt_a, const struct stmt *stmt_b, if (!stmt_expr_supported(expr_a) || !stmt_expr_supported(expr_b)) return false; + + if (expr_symbol_set(expr_a) || + expr_symbol_set(expr_b)) + return false; } return __expr_cmp(expr_a->left, expr_b->left); diff --git a/tests/shell/testcases/optimizations/dumps/skip_merge.nft b/tests/shell/testcases/optimizations/dumps/skip_merge.nft new file mode 100644 index 000000000000..9c10b74b4be2 --- /dev/null +++ b/tests/shell/testcases/optimizations/dumps/skip_merge.nft @@ -0,0 +1,23 @@ +table inet filter { + set udp_accepted { + type inet_service + elements = { 500, 4500 } + } + + set tcp_accepted { + type inet_service + elements = { 80, 443 } + } + + chain udp_input { + udp dport 1-128 accept + udp dport @udp_accepted accept + udp dport 53 accept + } + + chain tcp_input { + tcp dport { 1-128, 8888-9999 } accept + tcp dport @tcp_accepted accept + tcp dport 1024-65535 accept + } +} diff --git a/tests/shell/testcases/optimizations/skip_merge b/tests/shell/testcases/optimizations/skip_merge new file mode 100755 index 000000000000..8af976cac56d --- /dev/null +++ b/tests/shell/testcases/optimizations/skip_merge @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +RULESET="table inet filter { + set udp_accepted { + type inet_service; + elements = { + isakmp, ipsec-nat-t + } + } + + set tcp_accepted { + type inet_service; + elements = { + http, https + } + } + + chain udp_input { + udp dport 1-128 accept + udp dport @udp_accepted accept + udp dport domain accept + } + + chain tcp_input { + tcp dport 1-128 accept + tcp dport 8888-9999 accept + tcp dport @tcp_accepted accept + tcp dport 1024-65535 accept + } +}" + +$NFT -o -f - <<< $RULESET -- 2.30.2