Skip to contentSkip to conversation

src: use constant range expression for interval+concatenation sets

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Jun 11, 2025 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 src: use constant range expression for interval+concatenation sets

Expand 347039f64509 ("src: add symbol range expression to further compact intervals") to use constant range expression for elements with concatenation of intervals.

Ruleset with 100k elements of this type:

 table inet x {
        set y {
                typeof ip saddr . tcp dport
                flags interval
                elements = {
			0.1.2.0-0.1.2.240 . 0-1,
			...
		}
	}

}

This reduces memory consumption by 35.23%.

Before: 123.80 Mbytes
After: 80.19 Mbytes

This patch keeps the workaround 2fbade3cd990 ("netlink: bogus concatenated set ranges with netlink message overrun") in place.

---
Follow up to continue in this direction, to further reduce memory consumption.

 src/evaluate.c |  1 -
 src/netlink.c  | 11 +++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
src/evaluate.c +0 -1
index 9c7f23cb080e..56be7e90db15 100644
@@ -2368,7 +2368,6 @@ static int expr_evaluate_symbol_range(struct eval_ctx *ctx, struct expr **exprp)
 
 	/* concatenation and maps need more work to use constant_range_expr. */
 	if (ctx->set && !set_is_map(ctx->set->flags) &&
-	    set_is_non_concat_range(ctx->set) &&
 	    left->etype == EXPR_VALUE &&
 	    right->etype == EXPR_VALUE) {
 		constant_range = constant_range_expr_alloc(&expr->location,
src/netlink.c +11 -0
index bed816af3123..97a2dc90a040 100644
@@ -285,6 +285,17 @@ static int __netlink_gen_concat_key(uint32_t flags, const struct expr *i,
 			byteorder_switch_expr_value(value, expr);
 
 		i = expr;
+		break;
+	case EXPR_RANGE_VALUE:
+		if (flags & EXPR_F_INTERVAL_END)
+			mpz_init_set(value, i->range.high);
+		else
+			mpz_init_set(value, i->range.low);
+
+		if (expr_basetype(i)->type == TYPE_INTEGER &&
+		    i->byteorder == BYTEORDER_HOST_ENDIAN)
+			byteorder_switch_expr_value(value, i);
+
 		break;
 	case EXPR_PREFIX:
 		if (flags & EXPR_F_INTERVAL_END) {
Signature · 1 line
2.30.2