diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2025-01-03 17:40:54 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2025-01-10 11:21:02 +0100 |
commit | c9ee9032b0ee9e802f73dda90f5c84357aff8148 (patch) | |
tree | cdc07e291d03ebacbe4a3dff9d5d2bcfca3f96ec /include/expression.h | |
parent | da0bac050c8b2588242727f9915a1ea8bc48ceb2 (diff) |
src: add EXPR_RANGE_VALUE expression and use it
set element with range takes 4 instances of struct expr:
EXPR_SET_ELEM -> EXPR_RANGE -> (2) EXPR_VALUE
where EXPR_RANGE represents two references to struct expr with constant
value.
This new EXPR_RANGE_VALUE trims it down to two expressions:
EXPR_SET_ELEM -> EXPR_RANGE_VALUE
with two direct low and high values that represent the range:
struct {
mpz_t low;
mpz_t high;
};
this two new direct values in struct expr do not modify its size.
setelem_expr_to_range() translates EXPR_RANGE to EXPR_RANGE_VALUE, this
conversion happens at a later stage.
constant_range_expr_print() translates this structure to constant values
to reuse the existing datatype_print() which relies in singleton values.
The automerge routine has been updated to use EXPR_RANGE_VALUE.
This requires a follow up patch to rework the conversion from range
expression to singleton element to provide a noticeable memory
consumption reduction.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/expression.h')
-rw-r--r-- | include/expression.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/expression.h b/include/expression.h index 877887ff..f2b45250 100644 --- a/include/expression.h +++ b/include/expression.h @@ -48,6 +48,7 @@ * @EXPR_XFRM XFRM (ipsec) expression * @EXPR_SET_ELEM_CATCHALL catchall element expression * @EXPR_FLAGCMP flagcmp expression + * @EXPR_RANGE_VALUE constant range expression */ enum expr_types { EXPR_INVALID, @@ -80,6 +81,7 @@ enum expr_types { EXPR_XFRM, EXPR_SET_ELEM_CATCHALL, EXPR_FLAGCMP, + EXPR_RANGE_VALUE, EXPR_MAX = EXPR_FLAGCMP }; @@ -279,6 +281,11 @@ struct expr { mpz_t value; }; struct { + /* EXPR_RANGE_VALUE */ + mpz_t low; + mpz_t high; + } range; + struct { /* EXPR_PREFIX */ struct expr *prefix; unsigned int prefix_len; @@ -473,6 +480,12 @@ extern struct expr *constant_expr_join(const struct expr *e1, const struct expr *e2); extern struct expr *constant_expr_splice(struct expr *expr, unsigned int len); +extern struct expr *constant_range_expr_alloc(const struct location *loc, + const struct datatype *dtype, + enum byteorder byteorder, + unsigned int len, + mpz_t low, mpz_t high); + extern struct expr *flag_expr_alloc(const struct location *loc, const struct datatype *dtype, enum byteorder byteorder, |