summaryrefslogtreecommitdiffstats
path: root/iptables/nft.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-09-25 11:29:59 +0200
committerPhil Sutter <phil@nwl.cc>2019-09-30 08:14:55 +0200
commit2a459ebc0ee53a57a92631fa07f6bf2b4f3fbc8c (patch)
treee78f5e8800509e44c8dfe204214f73297574ca59 /iptables/nft.c
parent3e450a6cc2325f4481dc86f074774dcdfd4947c3 (diff)
xtables-restore: Minimize caching when flushing
Unless --noflush was given, xtables-restore merely needs the list of tables to decide whether to delete it or not. Introduce nft_fake_cache() function which populates table list, initializes chain lists (so nft_chain_list_get() returns an empty list instead of NULL) and sets 'have_cache' to turn any later calls to nft_build_cache() into nops. If --noflush was given, call nft_build_cache() just once instead of for each table line in input. Signed-off-by: Phil Sutter <phil@nwl.cc> Acked-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/nft.c')
-rw-r--r--iptables/nft.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/iptables/nft.c b/iptables/nft.c
index fde1b2a3..a2f36b7e 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1611,6 +1611,23 @@ retry:
h->nft_genid = genid_start;
}
+void nft_fake_cache(struct nft_handle *h)
+{
+ int i;
+
+ fetch_table_cache(h);
+ for (i = 0; i < NFT_TABLE_MAX; i++) {
+ enum nft_table_type type = h->tables[i].type;
+
+ if (!h->tables[i].name)
+ continue;
+
+ h->cache->table[type].chains = nftnl_chain_list_alloc();
+ }
+ h->have_cache = true;
+ mnl_genid_get(h, &h->nft_genid);
+}
+
void nft_build_cache(struct nft_handle *h)
{
if (!h->have_cache)