diff mbox series

[iptables,v2,05/14] xtables: Drop nft_chain_list_find()

Message ID 20181213111607.5457-6-phil@nwl.cc
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series Separate rule cache per chain et al. | expand

Commit Message

Phil Sutter Dec. 13, 2018, 11:15 a.m. UTC
Replace the function by nftnl_chain_list_lookup_byname() as provided by
libnftnl.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 iptables/nft.c | 31 ++-----------------------------
 iptables/nft.h |  2 --
 2 files changed, 2 insertions(+), 31 deletions(-)
diff mbox series

Patch

diff --git a/iptables/nft.c b/iptables/nft.c
index 8c53dae7138ec..a440bb015386e 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -698,7 +698,7 @@  static void nft_chain_builtin_init(struct nft_handle *h,
 	/* Initialize built-in chains if they don't exist yet */
 	for (i=0; i < NF_INET_NUMHOOKS && table->chains[i].name != NULL; i++) {
 
-		c = nft_chain_list_find(list, table->chains[i].name);
+		c = nftnl_chain_list_lookup_byname(list, table->chains[i].name);
 		if (c != NULL)
 			continue;
 
@@ -1692,33 +1692,6 @@  err:
 	return ret == 0 ? 1 : 0;
 }
 
-struct nftnl_chain *
-nft_chain_list_find(struct nftnl_chain_list *list, const char *chain)
-{
-	struct nftnl_chain_list_iter *iter;
-	struct nftnl_chain *c;
-
-	iter = nftnl_chain_list_iter_create(list);
-	if (iter == NULL)
-		return NULL;
-
-	c = nftnl_chain_list_iter_next(iter);
-	while (c != NULL) {
-		const char *chain_name =
-			nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
-
-		if (strcmp(chain, chain_name) != 0)
-			goto next;
-
-		nftnl_chain_list_iter_destroy(iter);
-		return c;
-next:
-		c = nftnl_chain_list_iter_next(iter);
-	}
-	nftnl_chain_list_iter_destroy(iter);
-	return NULL;
-}
-
 static struct nftnl_chain *
 nft_chain_find(struct nft_handle *h, const char *table,
 	       const char *chain, bool need_rules)
@@ -1729,7 +1702,7 @@  nft_chain_find(struct nft_handle *h, const char *table,
 	if (list == NULL)
 		return NULL;
 
-	return nft_chain_list_find(list, chain);
+	return nftnl_chain_list_lookup_byname(list, chain);
 }
 
 bool nft_chain_exists(struct nft_handle *h,
diff --git a/iptables/nft.h b/iptables/nft.h
index af46afc789773..5cf3cd9315add 100644
--- a/iptables/nft.h
+++ b/iptables/nft.h
@@ -84,8 +84,6 @@  struct nftnl_chain;
 int nft_chain_set(struct nft_handle *h, const char *table, const char *chain, const char *policy, const struct xt_counters *counters);
 struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
 					    const char *table, bool need_rules);
-struct nftnl_chain *nft_chain_list_find(struct nftnl_chain_list *list,
-					const char *chain);
 int nft_chain_save(struct nft_handle *h, struct nftnl_chain_list *list);
 int nft_chain_user_add(struct nft_handle *h, const char *chain, const char *table);
 int nft_chain_user_del(struct nft_handle *h, const char *chain, const char *table, bool verbose);