optimize: fix vmap with anonymous sets
Pablo Neira Ayuso
maintainerPATCH 1/1 optimize: fix vmap with anonymous sets
The following example ruleset crashes:
table inet a {
chain b {
tcp dport { 1 } accept
tcp dport 2-3 drop
}
}
because handling for EXPR_SET is missing.
Fixes 1542082e259b ("optimize: merge same selector with different verdict into verdict map")
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/optimize.c | 8 ++++++-- .../testcases/optimizations/dumps/merge_stmts_vmap.nft | 4 ++++ tests/shell/testcases/optimizations/merge_stmts_vmap | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-)
src/optimize.c +6 -2
@@ -435,18 +435,22 @@ static void build_verdict_map(struct expr *expr, struct stmt *verdict, struct ex {struct expr *item, *elem, *mapping; -if (expr->etype ==EXPR_LIST ) { +switch (expr->etype) { +case EXPR_LIST : +case EXPR_SET :list_for_each_entry (item, &expr->expressions, list) { elem =set_elem_expr_alloc (&internal_location,expr_get (item)); mapping =mapping_expr_alloc (&internal_location, elem,expr_get (verdict->expr));compound_expr_add (set, mapping); } - }else { +break ; +default : elem =set_elem_expr_alloc (&internal_location,expr_get (expr)); mapping =mapping_expr_alloc (&internal_location, elem,expr_get (verdict->expr));compound_expr_add (set, mapping); +break ; } }
tests/shell/testcases/optimizations/dumps/merge_stmts_vmap.nft +4 -0
@@ -2,4 +2,8 @@ table ip x { chain y { ct state vmap { invalid : drop, established : accept, related : accept } } + + chain z { + tcp dport vmap { 1 : accept, 2-3 : drop } + } }
tests/shell/testcases/optimizations/merge_stmts_vmap +4 -0
@@ -7,6 +7,10 @@ RULESET="table ip x { ct state invalid drop ct state established,related accept } + chain z { + tcp dport { 1 } accept + tcp dport 2-3 drop + } }" $NFT -o -f - <<< $RULESET
Signature · 1 line
2.30.2