summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2023-02-02 18:15:22 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2023-11-02 11:56:19 +0100
commit2c76786b252dd5187bcd4729a3368b9d9fb27b4b (patch)
treebab3de03e3516faaf1ecdc0c428bcfcaea94685b
parent3e28feb7b571177f6b359959a0ad0d0cdbbbd9fe (diff)
optimize: wrap code to build concatenation in helper function
commit 9dbbf397b2f3d9fa40454648cb98c13c7c5515b7 upstream. Move code to build concatenations into helper function, this routine includes support for expansion of implicit sets containing singleton values. This is preparation work to reuse existing code in a follow up patch. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/optimize.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/optimize.c b/src/optimize.c
index d592aee0..c4f5b008 100644
--- a/src/optimize.c
+++ b/src/optimize.c
@@ -550,20 +550,19 @@ static void merge_stmts(const struct optimize_ctx *ctx,
}
}
-static void __merge_concat_stmts(const struct optimize_ctx *ctx, uint32_t i,
- const struct merge *merge, struct expr *set)
+static void __merge_concat(const struct optimize_ctx *ctx, uint32_t i,
+ const struct merge *merge, struct list_head *concat_list)
{
- struct expr *concat, *next, *expr, *concat_clone, *clone, *elem;
+ struct expr *concat, *next, *expr, *concat_clone, *clone;
LIST_HEAD(pending_list);
- LIST_HEAD(concat_list);
struct stmt *stmt_a;
uint32_t k;
concat = concat_expr_alloc(&internal_location);
- list_add(&concat->list, &concat_list);
+ list_add(&concat->list, concat_list);
for (k = 0; k < merge->num_stmts; k++) {
- list_for_each_entry_safe(concat, next, &concat_list, list) {
+ list_for_each_entry_safe(concat, next, concat_list, list) {
stmt_a = ctx->stmt_matrix[i][merge->stmt[k]];
switch (stmt_a->expr->right->etype) {
case EXPR_SET:
@@ -588,8 +587,17 @@ static void __merge_concat_stmts(const struct optimize_ctx *ctx, uint32_t i,
break;
}
}
- list_splice_init(&pending_list, &concat_list);
+ list_splice_init(&pending_list, concat_list);
}
+}
+
+static void __merge_concat_stmts(const struct optimize_ctx *ctx, uint32_t i,
+ const struct merge *merge, struct expr *set)
+{
+ struct expr *concat, *next, *elem;
+ LIST_HEAD(concat_list);
+
+ __merge_concat(ctx, i, merge, &concat_list);
list_for_each_entry_safe(concat, next, &concat_list, list) {
list_del(&concat->list);