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

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