path: root/include/rule.h
diff options
authorPablo Neira Ayuso <>2018-03-03 22:52:35 +0100
committerPablo Neira Ayuso <>2018-03-04 00:22:50 +0100
commit3b20f47277c0cb4ea07ad30f94496c9f383035e7 (patch)
treec5b0b1fc569dd64cd3fdcedaecfacf22b0abe6dd /include/rule.h
parent8162d2b96718041dadc52ab127db9d91a2c223cc (diff)
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 = {, } ip saddr $address redefine address = { } ip saddr $address } } # nft list ruleset table ip x { chain y { ip saddr {, } ip saddr { } } } 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 <>
Diffstat (limited to 'include/rule.h')
1 files changed, 4 insertions, 1 deletions
diff --git a/include/rule.h b/include/rule.h
index 531222ce..58c4aeef 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -73,18 +73,21 @@ extern void scope_release(const struct scope *scope);
* @list: scope symbol list node
* @identifier: identifier
* @expr: initializer
+ * @refcnt: reference counter
struct symbol {
struct list_head list;
const char *identifier;
struct expr *expr;
+ int refcnt;
extern void symbol_bind(struct scope *scope, const char *identifier,
struct expr *expr);
-extern int symbol_unbind(struct scope *scope, const char *identifier);
+extern int symbol_unbind(const struct scope *scope, const char *identifier);
extern struct symbol *symbol_lookup(const struct scope *scope,
const char *identifier);
+struct symbol *symbol_get(const struct scope *scope, const char *identifier);
enum table_flags {
TABLE_F_DORMANT = (1 << 0),