From 3b20f47277c0cb4ea07ad30f94496c9f383035e7 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 3 Mar 2018 22:52:35 +0100 Subject: src: add variable expression and use it to allow redefinitions Add new variable expression that we can use to attach symbols in runtime, this allows us to redefine variables via new keyword, eg. table ip x { chain y { define address = { 1.1.1.1, 2.2.2.2 } ip saddr $address redefine address = { 3.3.3.3 } ip saddr $address } } # nft list ruleset table ip x { chain y { ip saddr { 1.1.1.1, 2.2.2.2 } ip saddr { 3.3.3.3 } } } Note that redefinition just places a new symbol version before the existing one, so symbol lookups always find the latest version. The undefine keyword decrements the reference counter and removes the symbol from the list, so it cannot be used anymore. Still, previous references to this symbol via variable expression are still valid. Signed-off-by: Pablo Neira Ayuso --- include/expression.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'include/expression.h') diff --git a/include/expression.h b/include/expression.h index 26182120..7b9b6229 100644 --- a/include/expression.h +++ b/include/expression.h @@ -16,6 +16,7 @@ * @EXPR_INVALID: uninitialized type, should not happen * @EXPR_VERDICT: nftables verdict expression * @EXPR_SYMBOL: unparsed symbol + * @EXPR_VARIABLE: variable * @EXPR_VALUE: literal numeric or string expression * @EXPR_PREFIX: prefixed expression * @EXPR_RANGE: literal range @@ -41,6 +42,7 @@ enum expr_types { EXPR_INVALID, EXPR_VERDICT, EXPR_SYMBOL, + EXPR_VARIABLE, EXPR_VALUE, EXPR_PREFIX, EXPR_RANGE, @@ -97,7 +99,6 @@ extern const char *expr_op_symbols[]; enum symbol_types { SYMBOL_VALUE, - SYMBOL_DEFINE, SYMBOL_SET, }; @@ -225,6 +226,10 @@ struct expr { const char *identifier; enum symbol_types symtype; }; + struct { + /* EXPR_VARIABLE */ + struct symbol *sym; + }; struct { /* EXPR_VERDICT */ int verdict; @@ -387,6 +392,9 @@ static inline void symbol_expr_set_type(struct expr *expr, expr->dtype = dtype; } +struct expr *variable_expr_alloc(const struct location *loc, + struct scope *scope, struct symbol *sym); + extern struct expr *constant_expr_alloc(const struct location *loc, const struct datatype *dtype, enum byteorder byteorder, -- cgit v1.2.3