]> git.ipfire.org Git - thirdparty/nftables.git/commit
src: detach set, list and concatenation expression layout
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 8 Jul 2025 22:51:24 +0000 (00:51 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 9 Jul 2025 22:13:04 +0000 (00:13 +0200)
commite0d92243be1cf1a485450a56d845e7bf2d1c6051
treef4617c607751577a635ed4c9ce4a386c19bd8add
parent01fdd7c7f445337c460738aa872cbdaabb5316ea
src: detach set, list and concatenation expression layout

These three expressions use the same layout, but they have a different
purpose. Several fields are specific of a given expression:

- set_flags is only required by set expressions.
- field_len and field_count are only used by concatenation expressions.

Add accessors to validate the expression type before accessing the union
fields:

 #define expr_set(__expr)       (assert((__expr)->etype == EXPR_SET), &(__expr)->expr_set)
 #define expr_concat(__expr)    (assert((__expr)->etype == EXPR_CONCAT), &(__expr)->expr_concat)
 #define expr_list(__expr)      (assert((__expr)->etype == EXPR_LIST), &(__expr)->expr_list)

This should help catch subtle bugs due to type confusion.

assert() could be later enabled only in debugging builds to run tests,
keep it by now.

compound_expr_*() still works and it needs the same initial layout for
all of these expressions:

      struct list_head        expressions;
      unsigned int            size;

This is implicitly reducing the size of one of the largest structs
in the union area of struct expr, still EXPR_SET_ELEM remains the
largest so no gain is achieved in this iteration.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
17 files changed:
include/expression.h
src/cmd.c
src/evaluate.c
src/expression.c
src/intervals.c
src/json.c
src/mergesort.c
src/mnl.c
src/monitor.c
src/netlink.c
src/netlink_delinearize.c
src/netlink_linearize.c
src/optimize.c
src/parser_bison.y
src/parser_json.c
src/rule.c
src/segtree.c