laurenceman / rpms / iptables

Forked from rpms/iptables 5 years ago
Clone

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

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