|
|
8cce6c |
From f13c1474a2f70d7d3cb5f3f5be8a4cceebb324a0 Mon Sep 17 00:00:00 2001
|
|
|
8cce6c |
From: Phil Sutter <phil@nwl.cc>
|
|
|
8cce6c |
Date: Sun, 30 Dec 2018 20:06:08 +0100
|
|
|
8cce6c |
Subject: [PATCH] nft: Simplify nft_is_chain_compatible()
|
|
|
8cce6c |
|
|
|
8cce6c |
Make use of nft_{table,chain}_builtin_find() instead of open-coding the
|
|
|
8cce6c |
list traversal. Since code is pretty obvious now, drop the comments
|
|
|
8cce6c |
added earlier.
|
|
|
8cce6c |
|
|
|
8cce6c |
Fixes: e774b15299c27 ("nft: Review is_*_compatible() routines")
|
|
|
8cce6c |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
8cce6c |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
8cce6c |
(cherry picked from commit fae77a24634365b18687a5f09357dbf4aaee2bc0)
|
|
|
8cce6c |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
8cce6c |
---
|
|
|
8cce6c |
iptables/nft.c | 34 +++++++++-------------------------
|
|
|
8cce6c |
1 file changed, 9 insertions(+), 25 deletions(-)
|
|
|
8cce6c |
|
|
|
8cce6c |
diff --git a/iptables/nft.c b/iptables/nft.c
|
|
|
8cce6c |
index 1fd3837f2d334..25e538b7e35d7 100644
|
|
|
8cce6c |
--- a/iptables/nft.c
|
|
|
8cce6c |
+++ b/iptables/nft.c
|
|
|
8cce6c |
@@ -3077,11 +3077,12 @@ static int nft_is_rule_compatible(struct nftnl_rule *rule, void *data)
|
|
|
8cce6c |
|
|
|
8cce6c |
static int nft_is_chain_compatible(struct nftnl_chain *c, void *data)
|
|
|
8cce6c |
{
|
|
|
8cce6c |
- const struct builtin_chain *chains = NULL, *chain = NULL;
|
|
|
8cce6c |
- const char *table, *name, *type;
|
|
|
8cce6c |
+ const struct builtin_table *table;
|
|
|
8cce6c |
+ const struct builtin_chain *chain;
|
|
|
8cce6c |
+ const char *tname, *cname, *type;
|
|
|
8cce6c |
struct nft_handle *h = data;
|
|
|
8cce6c |
enum nf_inet_hooks hook;
|
|
|
8cce6c |
- int i, prio;
|
|
|
8cce6c |
+ int prio;
|
|
|
8cce6c |
|
|
|
8cce6c |
if (nftnl_rule_foreach(c, nft_is_rule_compatible, NULL))
|
|
|
8cce6c |
return -1;
|
|
|
8cce6c |
@@ -3089,33 +3090,16 @@ static int nft_is_chain_compatible(struct nftnl_chain *c, void *data)
|
|
|
8cce6c |
if (!nft_chain_builtin(c))
|
|
|
8cce6c |
return 0;
|
|
|
8cce6c |
|
|
|
8cce6c |
- /* find chain's table in builtin tables */
|
|
|
8cce6c |
- table = nftnl_chain_get_str(c, NFTNL_CHAIN_TABLE);
|
|
|
8cce6c |
- for (i = 0; i < NFT_TABLE_MAX; i++) {
|
|
|
8cce6c |
- const char *cur_table = h->tables[i].name;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- if (!cur_table || strcmp(cur_table, table))
|
|
|
8cce6c |
- continue;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- chains = h->tables[i].chains;
|
|
|
8cce6c |
- break;
|
|
|
8cce6c |
- }
|
|
|
8cce6c |
- if (!chains)
|
|
|
8cce6c |
+ tname = nftnl_chain_get_str(c, NFTNL_CHAIN_TABLE);
|
|
|
8cce6c |
+ table = nft_table_builtin_find(h, tname);
|
|
|
8cce6c |
+ if (!table)
|
|
|
8cce6c |
return -1;
|
|
|
8cce6c |
|
|
|
8cce6c |
- /* find chain in builtin chain list */
|
|
|
8cce6c |
- name = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
|
|
|
8cce6c |
- for (i = 0; i < NF_INET_NUMHOOKS && chains[i].name; i++) {
|
|
|
8cce6c |
- if (strcmp(name, chains[i].name))
|
|
|
8cce6c |
- continue;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- chain = &chains[i];
|
|
|
8cce6c |
- break;
|
|
|
8cce6c |
- }
|
|
|
8cce6c |
+ cname = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
|
|
|
8cce6c |
+ chain = nft_chain_builtin_find(table, cname);
|
|
|
8cce6c |
if (!chain)
|
|
|
8cce6c |
return -1;
|
|
|
8cce6c |
|
|
|
8cce6c |
- /* compare properties */
|
|
|
8cce6c |
type = nftnl_chain_get_str(c, NFTNL_CHAIN_TYPE);
|
|
|
8cce6c |
prio = nftnl_chain_get_u32(c, NFTNL_CHAIN_PRIO);
|
|
|
8cce6c |
hook = nftnl_chain_get_u32(c, NFTNL_CHAIN_HOOKNUM);
|
|
|
8cce6c |
--
|
|
|
8cce6c |
2.20.1
|
|
|
8cce6c |
|