|
|
8cce6c |
From 510fef3a3fe67feb3da2fb237784299c7f070d70 Mon Sep 17 00:00:00 2001
|
|
|
8cce6c |
From: Phil Sutter <phil@nwl.cc>
|
|
|
8cce6c |
Date: Thu, 20 Dec 2018 16:09:11 +0100
|
|
|
8cce6c |
Subject: [PATCH] nft: Move nft_rule_list_get() above nft_chain_list_get()
|
|
|
8cce6c |
|
|
|
8cce6c |
Later when introducing per chain rule caches, nft_rule_list_get() will
|
|
|
8cce6c |
be removed. But nftnl_rule_list_cb() which it uses will be reused to
|
|
|
8cce6c |
update each chain's rule cache from inside nftnl_chain_list_get(), so
|
|
|
8cce6c |
move both into position.
|
|
|
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 eb13831f1c41c0efa626ab85d4448fb8ce4c87a2)
|
|
|
8cce6c |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
8cce6c |
---
|
|
|
8cce6c |
iptables/nft.c | 110 ++++++++++++++++++++++++-------------------------
|
|
|
8cce6c |
1 file changed, 55 insertions(+), 55 deletions(-)
|
|
|
8cce6c |
|
|
|
8cce6c |
diff --git a/iptables/nft.c b/iptables/nft.c
|
|
|
8cce6c |
index b425577798679..1840561f2e531 100644
|
|
|
8cce6c |
--- a/iptables/nft.c
|
|
|
8cce6c |
+++ b/iptables/nft.c
|
|
|
8cce6c |
@@ -1326,61 +1326,6 @@ retry:
|
|
|
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 |
-static const char *policy_name[NF_ACCEPT+1] = {
|
|
|
8cce6c |
- [NF_DROP] = "DROP",
|
|
|
8cce6c |
- [NF_ACCEPT] = "ACCEPT",
|
|
|
8cce6c |
-};
|
|
|
8cce6c |
-
|
|
|
8cce6c |
-int nft_chain_save(struct nft_handle *h, struct nftnl_chain_list *list)
|
|
|
8cce6c |
-{
|
|
|
8cce6c |
- struct nftnl_chain_list_iter *iter;
|
|
|
8cce6c |
- struct nft_family_ops *ops;
|
|
|
8cce6c |
- struct nftnl_chain *c;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- ops = nft_family_ops_lookup(h->family);
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- iter = nftnl_chain_list_iter_create(list);
|
|
|
8cce6c |
- if (iter == NULL)
|
|
|
8cce6c |
- return 0;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- c = nftnl_chain_list_iter_next(iter);
|
|
|
8cce6c |
- while (c != NULL) {
|
|
|
8cce6c |
- const char *policy = NULL;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- if (nft_chain_builtin(c)) {
|
|
|
8cce6c |
- uint32_t pol = NF_ACCEPT;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- if (nftnl_chain_get(c, NFTNL_CHAIN_POLICY))
|
|
|
8cce6c |
- pol = nftnl_chain_get_u32(c, NFTNL_CHAIN_POLICY);
|
|
|
8cce6c |
- policy = policy_name[pol];
|
|
|
8cce6c |
- }
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- if (ops->save_chain)
|
|
|
8cce6c |
- ops->save_chain(c, policy);
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- c = nftnl_chain_list_iter_next(iter);
|
|
|
8cce6c |
- }
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- nftnl_chain_list_iter_destroy(iter);
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- return 1;
|
|
|
8cce6c |
-}
|
|
|
8cce6c |
-
|
|
|
8cce6c |
static int nftnl_rule_list_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
8cce6c |
{
|
|
|
8cce6c |
struct nftnl_rule *r;
|
|
|
8cce6c |
@@ -1437,6 +1382,61 @@ retry:
|
|
|
8cce6c |
return list;
|
|
|
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 |
+static const char *policy_name[NF_ACCEPT+1] = {
|
|
|
8cce6c |
+ [NF_DROP] = "DROP",
|
|
|
8cce6c |
+ [NF_ACCEPT] = "ACCEPT",
|
|
|
8cce6c |
+};
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+int nft_chain_save(struct nft_handle *h, struct nftnl_chain_list *list)
|
|
|
8cce6c |
+{
|
|
|
8cce6c |
+ struct nftnl_chain_list_iter *iter;
|
|
|
8cce6c |
+ struct nft_family_ops *ops;
|
|
|
8cce6c |
+ struct nftnl_chain *c;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ ops = nft_family_ops_lookup(h->family);
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ iter = nftnl_chain_list_iter_create(list);
|
|
|
8cce6c |
+ if (iter == NULL)
|
|
|
8cce6c |
+ return 0;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ c = nftnl_chain_list_iter_next(iter);
|
|
|
8cce6c |
+ while (c != NULL) {
|
|
|
8cce6c |
+ const char *policy = NULL;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ if (nft_chain_builtin(c)) {
|
|
|
8cce6c |
+ uint32_t pol = NF_ACCEPT;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ if (nftnl_chain_get(c, NFTNL_CHAIN_POLICY))
|
|
|
8cce6c |
+ pol = nftnl_chain_get_u32(c, NFTNL_CHAIN_POLICY);
|
|
|
8cce6c |
+ policy = policy_name[pol];
|
|
|
8cce6c |
+ }
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ if (ops->save_chain)
|
|
|
8cce6c |
+ ops->save_chain(c, policy);
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ c = nftnl_chain_list_iter_next(iter);
|
|
|
8cce6c |
+ }
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ nftnl_chain_list_iter_destroy(iter);
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ return 1;
|
|
|
8cce6c |
+}
|
|
|
8cce6c |
+
|
|
|
8cce6c |
int nft_rule_save(struct nft_handle *h, const char *table, unsigned int format)
|
|
|
8cce6c |
{
|
|
|
8cce6c |
struct nftnl_rule_list *list;
|
|
|
8cce6c |
--
|
|
|
8cce6c |
2.20.1
|
|
|
8cce6c |
|