Blame SOURCES/0030-nft-Simplify-flush_chain_cache.patch

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