Blame SOURCES/0019-nft-Introduce-fetch_chain_cache.patch

1dc35b
From 0e72e49c0f220a9223de85574b878114bf8ceff3 Mon Sep 17 00:00:00 2001
8cce6c
From: Phil Sutter <phil@nwl.cc>
8cce6c
Date: Thu, 20 Dec 2018 16:09:10 +0100
8cce6c
Subject: [PATCH] nft: Introduce fetch_chain_cache()
8cce6c
8cce6c
Move chain cache population from nft_chain_list_get() into a dedicated
8cce6c
function.
8cce6c
8cce6c
Signed-off-by: Phil Sutter <phil@nwl.cc>
8cce6c
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8cce6c
(cherry picked from commit 8bae620abf9ac81794acca43d305ca74f15a13ff)
8cce6c
Signed-off-by: Phil Sutter <psutter@redhat.com>
8cce6c
---
8cce6c
 iptables/nft.c | 27 +++++++++++++++++----------
8cce6c
 1 file changed, 17 insertions(+), 10 deletions(-)
8cce6c
8cce6c
diff --git a/iptables/nft.c b/iptables/nft.c
8cce6c
index 469448f42cd6d..b425577798679 100644
8cce6c
--- a/iptables/nft.c
8cce6c
+++ b/iptables/nft.c
8cce6c
@@ -1295,20 +1295,12 @@ err:
8cce6c
 	return MNL_CB_OK;
8cce6c
 }
8cce6c
 
8cce6c
-struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
8cce6c
-					    const char *table)
8cce6c
+static int fetch_chain_cache(struct nft_handle *h)
8cce6c
 {
8cce6c
 	char buf[16536];
8cce6c
 	struct nlmsghdr *nlh;
8cce6c
-	const struct builtin_table *t;
8cce6c
 	int i, ret;
8cce6c
 
8cce6c
-	t = nft_table_builtin_find(h, table);
8cce6c
-	if (!t)
8cce6c
-		return NULL;
8cce6c
-
8cce6c
-	if (h->table[t->type].chain_cache)
8cce6c
-		return h->table[t->type].chain_cache;
8cce6c
 retry:
8cce6c
 	for (i = 0; i < NFT_TABLE_MAX; i++) {
8cce6c
 		enum nft_table_type type = h->tables[i].type;
8cce6c
@@ -1318,7 +1310,7 @@ retry:
8cce6c
 
8cce6c
 		h->table[type].chain_cache = nftnl_chain_list_alloc();
8cce6c
 		if (!h->table[type].chain_cache)
8cce6c
-			return NULL;
8cce6c
+			return -1;
8cce6c
 	}
8cce6c
 
8cce6c
 	nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETCHAIN, h->family,
8cce6c
@@ -1331,6 +1323,21 @@ retry:
8cce6c
 		goto retry;
8cce6c
 	}
8cce6c
 
8cce6c
+	return ret;
8cce6c
+}
8cce6c
+
8cce6c
+struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
8cce6c
+					    const char *table)
8cce6c
+{
8cce6c
+	const struct builtin_table *t;
8cce6c
+
8cce6c
+	t = nft_table_builtin_find(h, table);
8cce6c
+	if (!t)
8cce6c
+		return NULL;
8cce6c
+
8cce6c
+	if (!h->table[t->type].chain_cache)
8cce6c
+		fetch_chain_cache(h);
8cce6c
+
8cce6c
 	return h->table[t->type].chain_cache;
8cce6c
 }
8cce6c
 
8cce6c
-- 
1dc35b
2.21.0
8cce6c