diff options
author | Phil Sutter <phil@nwl.cc> | 2019-10-30 21:45:39 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2019-11-07 12:46:16 +0100 |
commit | 332325e3c3fab4c25bb5f387f9663205f63748dc (patch) | |
tree | b9e616a69a3b87829c4f6531a6677119d9af6275 /src/libnftables.c | |
parent | 856c78d4fdc73ac746ef1473f08d78cf2ebcbc4c (diff) |
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 <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/libnftables.c')
-rw-r--r-- | src/libnftables.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libnftables.c b/src/libnftables.c index e2037243..cd2fcf2f 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -155,6 +155,7 @@ struct nft_ctx *nft_ctx_new(uint32_t flags) nft_ctx_add_include_path(ctx, DEFAULT_INCLUDE_PATH); ctx->parser_max_errors = 10; init_list_head(&ctx->cache.list); + ctx->top_scope = scope_alloc(); ctx->flags = flags; ctx->output.output_fp = stdout; ctx->output.error_fp = stderr; @@ -292,6 +293,7 @@ void nft_ctx_free(struct nft_ctx *ctx) iface_cache_release(); cache_release(&ctx->cache); nft_ctx_clear_include_paths(ctx); + scope_free(ctx->top_scope); xfree(ctx->state); nft_exit(ctx); xfree(ctx); @@ -368,7 +370,7 @@ static int nft_parse_bison_buffer(struct nft_ctx *nft, const char *buf, { int ret; - parser_init(nft, nft->state, msgs, cmds); + parser_init(nft, nft->state, msgs, cmds, nft->top_scope); nft->scanner = scanner_init(nft->state); scanner_push_buffer(nft->scanner, &indesc_cmdline, buf); @@ -384,7 +386,7 @@ static int nft_parse_bison_filename(struct nft_ctx *nft, const char *filename, { int ret; - parser_init(nft, nft->state, msgs, cmds); + parser_init(nft, nft->state, msgs, cmds, nft->top_scope); nft->scanner = scanner_init(nft->state); if (scanner_read_file(nft, filename, &internal_location) < 0) return -1; |