|
|
029dc7 |
From 1ad5112b216c46fdf799fa7c8fbf6508f0f4afc9 Mon Sep 17 00:00:00 2001
|
|
|
029dc7 |
From: Phil Sutter <phil@nwl.cc>
|
|
|
029dc7 |
Date: Sun, 30 Dec 2018 20:06:09 +0100
|
|
|
029dc7 |
Subject: [PATCH] nft: Simplify flush_chain_cache()
|
|
|
029dc7 |
|
|
|
029dc7 |
With all the checks for 'tablename' being non-NULL, this code was rather
|
|
|
029dc7 |
stupid and really hard to read. And the fix is indeed quite simple: If a
|
|
|
029dc7 |
table name was given, use nft_table_builtin_find() and just flush its
|
|
|
029dc7 |
chain cache. Otherwise iterate over all builtin tables without any
|
|
|
029dc7 |
conditionals for 'tablename'.
|
|
|
029dc7 |
|
|
|
029dc7 |
Fixes: d4b0d248cc057 ("nft: Reduce indenting level in flush_chain_cache()")
|
|
|
029dc7 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
029dc7 |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
029dc7 |
(cherry picked from commit 4441b7da7995ed87741164ef39e99f1065eb9637)
|
|
|
029dc7 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
029dc7 |
---
|
|
|
029dc7 |
iptables/nft.c | 24 +++++++++++-------------
|
|
|
029dc7 |
1 file changed, 11 insertions(+), 13 deletions(-)
|
|
|
029dc7 |
|
|
|
029dc7 |
diff --git a/iptables/nft.c b/iptables/nft.c
|
|
|
029dc7 |
index 25e538b7e35d7..dafb879ebd6f0 100644
|
|
|
029dc7 |
--- a/iptables/nft.c
|
|
|
029dc7 |
+++ b/iptables/nft.c
|
|
|
029dc7 |
@@ -793,27 +793,25 @@ static int __flush_chain_cache(struct nftnl_chain *c, void *data)
|
|
|
029dc7 |
|
|
|
029dc7 |
static void flush_chain_cache(struct nft_handle *h, const char *tablename)
|
|
|
029dc7 |
{
|
|
|
029dc7 |
+ const struct builtin_table *table;
|
|
|
029dc7 |
int i;
|
|
|
029dc7 |
|
|
|
029dc7 |
+ if (tablename) {
|
|
|
029dc7 |
+ table = nft_table_builtin_find(h, tablename);
|
|
|
029dc7 |
+ if (!table || !h->table[table->type].chain_cache)
|
|
|
029dc7 |
+ return;
|
|
|
029dc7 |
+ nftnl_chain_list_foreach(h->table[table->type].chain_cache,
|
|
|
029dc7 |
+ __flush_chain_cache, NULL);
|
|
|
029dc7 |
+ return;
|
|
|
029dc7 |
+ }
|
|
|
029dc7 |
+
|
|
|
029dc7 |
for (i = 0; i < NFT_TABLE_MAX; i++) {
|
|
|
029dc7 |
if (h->tables[i].name == NULL)
|
|
|
029dc7 |
continue;
|
|
|
029dc7 |
|
|
|
029dc7 |
- if (tablename && strcmp(h->tables[i].name, tablename))
|
|
|
029dc7 |
+ if (!h->table[i].chain_cache)
|
|
|
029dc7 |
continue;
|
|
|
029dc7 |
|
|
|
029dc7 |
- if (!h->table[i].chain_cache) {
|
|
|
029dc7 |
- if (tablename)
|
|
|
029dc7 |
- return;
|
|
|
029dc7 |
- continue;
|
|
|
029dc7 |
- }
|
|
|
029dc7 |
-
|
|
|
029dc7 |
- if (tablename) {
|
|
|
029dc7 |
- nftnl_chain_list_foreach(h->table[i].chain_cache,
|
|
|
029dc7 |
- __flush_chain_cache, NULL);
|
|
|
029dc7 |
- return;
|
|
|
029dc7 |
- }
|
|
|
029dc7 |
-
|
|
|
029dc7 |
nftnl_chain_list_free(h->table[i].chain_cache);
|
|
|
029dc7 |
h->table[i].chain_cache = NULL;
|
|
|
029dc7 |
}
|
|
|
029dc7 |
--
|
|
|
029dc7 |
2.21.0
|
|
|
029dc7 |
|