]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
libnftables: Introduce nft_ctx_flush_cache()
authorPhil Sutter <phil@nwl.cc>
Mon, 23 Oct 2017 15:33:17 +0000 (17:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Oct 2017 13:23:55 +0000 (15:23 +0200)
This allows an application to explicitly flush caches associated with a
given nft context, as seen in cli_complete().

Note that this is a bit inconsistent in that it releases the global
interface cache, but nft_ctx_free() does the same so at least it's not a
regression.

Note that there is no need for explicit cache update routine since cache
is populated during command execution depending on whether it is needed
or not.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/nftables/nftables.h
src/cli.c
src/libnftables.c

index 44d3e95d399e6bb8943be1141f7a54aa0c945501..1207f10cd2457de023de19de7c009eb83392621a 100644 (file)
@@ -51,6 +51,7 @@ enum nftables_exit_codes {
 struct nft_ctx *nft_ctx_new(uint32_t flags);
 void nft_ctx_free(struct nft_ctx *ctx);
 FILE *nft_ctx_set_output(struct nft_ctx *ctx, FILE *fp);
+void nft_ctx_flush_cache(struct nft_ctx *ctx);
 
 int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen);
 int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename);
index cadc3af6e80345e720aeaff8c0b1e4a924fa282d..3174cfed05a7d3fa2c59f6cd678522bac6871743 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -140,8 +140,7 @@ static void cli_complete(char *line)
        nft_run(cli_nft, cli_nf_sock, scanner, state, &msgs);
        erec_print_list(&cli_nft->output, &msgs, cli_nft->debug_mask);
        xfree(line);
-       cache_release(&cli_nft->cache);
-       iface_cache_release();
+       nft_ctx_flush_cache(cli_nft);
 }
 
 static char **cli_completion(const char *text, int start, int end)
index 9bc51dd894d0909a550994aee9632b5ee1663cc1..d34e52759e947e149ad3e5ccfc9a63aa75dd4419 100644 (file)
@@ -147,13 +147,18 @@ struct nft_ctx *nft_ctx_new(uint32_t flags)
        return ctx;
 }
 
+void nft_ctx_flush_cache(struct nft_ctx *ctx)
+{
+       iface_cache_release();
+       cache_release(&ctx->cache);
+}
+
 void nft_ctx_free(struct nft_ctx *ctx)
 {
        if (ctx->nf_sock)
                netlink_close_sock(ctx->nf_sock);
 
-       iface_cache_release();
-       cache_release(&ctx->cache);
+       nft_ctx_flush_cache(ctx);
        xfree(ctx);
        nft_exit();
 }