netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Eric Leblond <eric@regit.org>,
	netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: [nft PATCH v2 2/4] libnftables: Introduce nft_ctx_flush_cache()
Date: Mon, 23 Oct 2017 17:33:17 +0200	[thread overview]
Message-ID: <20171023153319.13415-3-phil@nwl.cc> (raw)
In-Reply-To: <20171023153319.13415-1-phil@nwl.cc>

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>
---
 include/nftables/nftables.h | 1 +
 src/cli.c                   | 3 +--
 src/libnftables.c           | 9 +++++++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/nftables/nftables.h b/include/nftables/nftables.h
index 44d3e95d399e6..1207f10cd2457 100644
--- a/include/nftables/nftables.h
+++ b/include/nftables/nftables.h
@@ -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);
diff --git a/src/cli.c b/src/cli.c
index cadc3af6e8034..3174cfed05a7d 100644
--- 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)
diff --git a/src/libnftables.c b/src/libnftables.c
index 9bc51dd894d09..d34e52759e947 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -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();
 }
-- 
2.13.1


  parent reply	other threads:[~2017-10-23 15:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 15:33 [nft PATCH v2 0/4] libnftables preparations Phil Sutter
2017-10-23 15:33 ` [nft PATCH v2 1/4] libnftables: Move library stuff out of main.c Phil Sutter
2017-10-24 15:48   ` Pablo Neira Ayuso
2017-10-24 16:42     ` Phil Sutter
2017-11-09 13:25     ` [nft PATCH] libnftables: Unexport enum nftables_exit_codes Phil Sutter
2017-11-09 19:27       ` Phil Sutter
2017-11-10 11:27         ` [nft PATCH v2] " Phil Sutter
2017-11-13 12:31           ` Pablo Neira Ayuso
2017-11-13 12:38             ` Phil Sutter
2017-11-13 14:08               ` [nft PATCH v3] " Phil Sutter
2017-11-16 13:33                 ` Pablo Neira Ayuso
2017-11-16 13:48                   ` Phil Sutter
2017-11-13 13:49             ` [nft PATCH v2] " Phil Sutter
2017-11-13 13:53               ` Pablo Neira Ayuso
2017-11-13 14:04                 ` Phil Sutter
2017-10-23 15:33 ` Phil Sutter [this message]
2017-10-24 15:52   ` [nft PATCH v2 2/4] libnftables: Introduce nft_ctx_flush_cache() Pablo Neira Ayuso
2017-10-24 17:40     ` Phil Sutter
2017-10-25  9:25       ` Pablo Neira Ayuso
2017-10-25 11:40         ` [nft PATCH] libnftables: Get rid of explicit cache flushes Phil Sutter
2017-10-26 18:15           ` Pablo Neira Ayuso
2017-10-23 15:33 ` [nft PATCH v2 3/4] cli: Use nft_run_cmd_from_buffer() Phil Sutter
2017-10-23 15:33 ` [nft PATCH v2 4/4] libnftables: Introduce getters and setters for everything Phil Sutter
2017-10-24 15:20 ` [nft PATCH v2 0/4] libnftables preparations Pablo Neira Ayuso
2017-10-24 16:29   ` Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171023153319.13415-3-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=eric@regit.org \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).