From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH xtables-nft 3/6] xtables: add and use nft_build_cache
Date: Tue, 23 Apr 2019 15:16:22 +0200 [thread overview]
Message-ID: <20190423131625.23377-4-fw@strlen.de> (raw)
In-Reply-To: <20190423131625.23377-1-fw@strlen.de>
Will be used with the "generation id" infrastructure.
When we're told that the commit failed because someone else made
changes, we can use this to re-initialize the cache and then
revalidate the transaction list (e.g. to detect that we now have
to flush the user-defined chain 'foo' that we wanted to create, but
was added just now by someone else).
Signed-off-by: Florian Westphal <fw@strlen.de>
---
iptables/nft.c | 28 +++++++++++++++++++++++-----
iptables/nft.h | 2 ++
iptables/xtables-restore.c | 5 +----
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/iptables/nft.c b/iptables/nft.c
index 1cef7a13c90d..4c9ce1a29383 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1486,6 +1486,28 @@ static int fetch_rule_cache(struct nft_handle *h)
return 0;
}
+static void __nft_build_cache(struct nft_handle *h)
+{
+ fetch_chain_cache(h);
+ fetch_rule_cache(h);
+ h->have_cache = true;
+}
+
+
+void nft_build_cache(struct nft_handle *h)
+{
+ if (!h->have_cache)
+ __nft_build_cache(h);
+}
+
+void nft_rebuild_cache(struct nft_handle *h)
+{
+ if (!h->have_cache)
+ flush_chain_cache(h, NULL);
+
+ __nft_build_cache(h);
+}
+
struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
const char *table)
{
@@ -1495,11 +1517,7 @@ struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
if (!t)
return NULL;
- if (!h->have_cache) {
- fetch_chain_cache(h);
- fetch_rule_cache(h);
- h->have_cache = true;
- }
+ nft_build_cache(h);
return h->table[t->type].chain_cache;
}
diff --git a/iptables/nft.h b/iptables/nft.h
index d428287b46ff..97c28b356a46 100644
--- a/iptables/nft.h
+++ b/iptables/nft.h
@@ -63,6 +63,8 @@ int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
void *data);
int nft_init(struct nft_handle *h, const struct builtin_table *t);
void nft_fini(struct nft_handle *h);
+void nft_build_cache(struct nft_handle *h);
+void nft_rebuild_cache(struct nft_handle *h);
/*
* Operations with tables.
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index b12ab6a60b3a..a6a331d39868 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -145,10 +145,7 @@ void xtables_restore_parse(struct nft_handle *h,
if (p->tablename && (strcmp(p->tablename, table) != 0))
continue;
- /* Fixme: Needed to init chain cache.
- * Should create explicit function to do this.
- */
- nft_chain_list_get(h, table);
+ nft_build_cache(h);
if (h->noflush == 0) {
DEBUGP("Cleaning all chains of table '%s'\n",
--
2.21.0
next prev parent reply other threads:[~2019-04-23 13:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-23 13:16 [PATCH xtables-nft 0/6] handle parallel restore case Florian Westphal
2019-04-23 13:16 ` [PATCH xtables-nft 1/6] xtables: unify user chain add/flush for " Florian Westphal
2019-04-23 13:16 ` [PATCH xtables-nft 2/6] xtables: add skip flag to objects Florian Westphal
2019-04-23 13:16 ` Florian Westphal [this message]
2019-04-23 13:16 ` [PATCH xtables-nft 4/6] xtables: add and set "implict" flag on transaction objects Florian Westphal
2019-04-23 13:16 ` [PATCH xtables-nft 5/6] xtables: handle concurrent ruleset modifications Florian Westphal
2019-04-23 13:16 ` [PATCH xtables-nft 6/6] tests: add test script for race-free restore Florian Westphal
2019-04-26 17:05 ` [PATCH xtables-nft 0/6] handle parallel restore case Pablo Neira Ayuso
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=20190423131625.23377-4-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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).