Blame SOURCES/0030-nft-cache-Make-nft_rebuild_cache-respect-fake-cache.patch

87db66
From 2c183a2457d8640aaee3a98fc8fea70bf64d46f2 Mon Sep 17 00:00:00 2001
87db66
From: Phil Sutter <phil@nwl.cc>
87db66
Date: Sat, 29 Feb 2020 02:08:26 +0100
87db66
Subject: [PATCH] nft: cache: Make nft_rebuild_cache() respect fake cache
87db66
87db66
If transaction needed a refresh in nft_action(), restore with flush
87db66
would fetch a full cache instead of merely refreshing table list
87db66
contained in "fake" cache.
87db66
87db66
To fix this, nft_rebuild_cache() must distinguish between fake cache and
87db66
full rule cache. Therefore introduce NFT_CL_FAKE to be distinguished
87db66
from NFT_CL_RULES.
87db66
87db66
Signed-off-by: Phil Sutter <phil@nwl.cc>
87db66
(cherry picked from commit 40ad7793d1884f28767cf58c96e9d76ae0a18db1)
87db66
87db66
RHEL-only fix: Make nft_rebuild_cache() check 'level' instead of
87db66
'h->cache_level' as the latter may be reset by __nft_flush_cache().
87db66
87db66
Signed-off-by: Phil Sutter <psutter@redhat.com>
87db66
---
87db66
 iptables/nft-cache.c | 13 +++++++++----
87db66
 iptables/nft.h       |  3 ++-
87db66
 2 files changed, 11 insertions(+), 5 deletions(-)
87db66
87db66
diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
87db66
index bc6e7f7eaebfb..9623b463f0dd5 100644
87db66
--- a/iptables/nft-cache.c
87db66
+++ b/iptables/nft-cache.c
87db66
@@ -480,6 +480,7 @@ __nft_build_cache(struct nft_handle *h, enum nft_cache_level level,
87db66
 			break;
87db66
 		/* fall through */
87db66
 	case NFT_CL_RULES:
87db66
+	case NFT_CL_FAKE:
87db66
 		break;
87db66
 	}
87db66
 
87db66
@@ -516,7 +517,7 @@ void nft_fake_cache(struct nft_handle *h)
87db66
 
87db66
 		h->cache->table[type].chains = nftnl_chain_list_alloc();
87db66
 	}
87db66
-	h->cache_level = NFT_CL_RULES;
87db66
+	h->cache_level = NFT_CL_FAKE;
87db66
 	mnl_genid_get(h, &h->nft_genid);
87db66
 }
87db66
 
87db66
@@ -629,9 +630,13 @@ void nft_rebuild_cache(struct nft_handle *h)
87db66
 	if (h->cache_level)
87db66
 		__nft_flush_cache(h);
87db66
 
87db66
-	h->nft_genid = 0;
87db66
-	h->cache_level = NFT_CL_NONE;
87db66
-	__nft_build_cache(h, level, NULL, NULL, NULL);
87db66
+	if (level == NFT_CL_FAKE) {
87db66
+		nft_fake_cache(h);
87db66
+	} else {
87db66
+		h->nft_genid = 0;
87db66
+		h->cache_level = NFT_CL_NONE;
87db66
+		__nft_build_cache(h, level, NULL, NULL, NULL);
87db66
+	}
87db66
 }
87db66
 
87db66
 void nft_release_cache(struct nft_handle *h)
87db66
diff --git a/iptables/nft.h b/iptables/nft.h
87db66
index 5cf260a6d2cd3..2094b01455194 100644
87db66
--- a/iptables/nft.h
87db66
+++ b/iptables/nft.h
87db66
@@ -32,7 +32,8 @@ enum nft_cache_level {
87db66
 	NFT_CL_TABLES,
87db66
 	NFT_CL_CHAINS,
87db66
 	NFT_CL_SETS,
87db66
-	NFT_CL_RULES
87db66
+	NFT_CL_RULES,
87db66
+	NFT_CL_FAKE	/* must be last entry */
87db66
 };
87db66
 
87db66
 struct nft_cache {
87db66
-- 
87db66
2.28.0
87db66