From 332325e3c3fab4c25bb5f387f9663205f63748dc Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 30 Oct 2019 21:45:39 +0100 Subject: libnftables: Store top_scope in struct nft_ctx Allow for interactive sessions to make use of defines. Since parser is initialized for each line, top scope defines didn't persist although they are actually useful for stuff like: | # nft -i | define goodports = { 22, 23, 80, 443 } | add rule inet t c tcp dport $goodports accept | add rule inet t c tcp sport $goodports accept While being at it, introduce scope_alloc() and scope_free(). Signed-off-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- src/rule.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 552b3c6b..4abc13c9 100644 --- a/src/rule.c +++ b/src/rule.c @@ -645,6 +645,15 @@ struct rule *rule_lookup_by_index(const struct chain *chain, uint64_t index) return NULL; } +struct scope *scope_alloc(void) +{ + struct scope *scope = xzalloc(sizeof(struct scope)); + + init_list_head(&scope->symbols); + + return scope; +} + struct scope *scope_init(struct scope *scope, const struct scope *parent) { scope->parent = parent; @@ -664,6 +673,12 @@ void scope_release(const struct scope *scope) } } +void scope_free(struct scope *scope) +{ + scope_release(scope); + xfree(scope); +} + void symbol_bind(struct scope *scope, const char *identifier, struct expr *expr) { struct symbol *sym; -- cgit v1.2.3