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 --- src/parser_bison.y | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/parser_bison.y') diff --git a/src/parser_bison.y b/src/parser_bison.y index 58bc6805..ee6729f1 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -771,8 +771,6 @@ common_block : INCLUDE QUOTED_STRING stmt_separator { struct scope *scope = current_scope(state); - /* ignore missing identifier */ - symbol_unbind(scope, $2); symbol_bind(scope, $2, $4); xfree($2); } @@ -2584,16 +2582,17 @@ match_stmt : relational_expr variable_expr : '$' identifier { struct scope *scope = current_scope(state); + struct symbol *sym; - if (symbol_lookup(scope, $2) == NULL) { + sym = symbol_get(scope, $2); + if (!sym) { erec_queue(error(&@2, "unknown identifier '%s'", $2), state->msgs); xfree($2); YYERROR; } - $$ = symbol_expr_alloc(&@$, SYMBOL_DEFINE, - scope, $2); + $$ = variable_expr_alloc(&@$, scope, sym); xfree($2); } ; -- cgit v1.2.3