summaryrefslogtreecommitdiffstats
path: root/iptables
diff options
context:
space:
mode:
Diffstat (limited to 'iptables')
-rw-r--r--iptables/nft-cache.c22
-rw-r--r--iptables/nft-cache.h3
-rw-r--r--iptables/nft.c32
3 files changed, 39 insertions, 18 deletions
diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
index 64dcda57..c55970d0 100644
--- a/iptables/nft-cache.c
+++ b/iptables/nft-cache.c
@@ -384,7 +384,7 @@ static void __nft_flush_cache(struct nft_handle *h)
}
}
-static int __flush_rule_cache(struct nftnl_rule *r, void *data)
+static int ____flush_rule_cache(struct nftnl_rule *r, void *data)
{
nftnl_rule_list_del(r);
nftnl_rule_free(r);
@@ -392,9 +392,25 @@ static int __flush_rule_cache(struct nftnl_rule *r, void *data)
return 0;
}
-void flush_rule_cache(struct nftnl_chain *c)
+static int __flush_rule_cache(struct nftnl_chain *c, void *data)
{
- nftnl_rule_foreach(c, __flush_rule_cache, NULL);
+ return nftnl_rule_foreach(c, ____flush_rule_cache, NULL);
+}
+
+int flush_rule_cache(struct nft_handle *h, const char *table,
+ struct nftnl_chain *c)
+{
+ const struct builtin_table *t;
+
+ if (c)
+ return __flush_rule_cache(c, NULL);
+
+ t = nft_table_builtin_find(h, table);
+ if (!t || !h->cache->table[t->type].chains)
+ return 0;
+
+ return nftnl_chain_list_foreach(h->cache->table[t->type].chains,
+ __flush_rule_cache, NULL);
}
static int __flush_chain_cache(struct nftnl_chain *c, void *data)
diff --git a/iptables/nft-cache.h b/iptables/nft-cache.h
index 793a85f4..cb7a7688 100644
--- a/iptables/nft-cache.h
+++ b/iptables/nft-cache.h
@@ -8,7 +8,8 @@ void nft_build_cache(struct nft_handle *h, struct nftnl_chain *c);
void nft_rebuild_cache(struct nft_handle *h);
void nft_release_cache(struct nft_handle *h);
void flush_chain_cache(struct nft_handle *h, const char *tablename);
-void flush_rule_cache(struct nftnl_chain *c);
+int flush_rule_cache(struct nft_handle *h, const char *table,
+ struct nftnl_chain *c);
struct nftnl_chain_list *
nft_chain_list_get(struct nft_handle *h, const char *table, const char *chain);
diff --git a/iptables/nft.c b/iptables/nft.c
index 12cc423c..89b1c7a8 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1437,7 +1437,7 @@ __nft_rule_flush(struct nft_handle *h, const char *table,
struct obj_update *obj;
struct nftnl_rule *r;
- if (verbose)
+ if (verbose && chain)
fprintf(stdout, "Flushing chain `%s'\n", chain);
r = nftnl_rule_alloc();
@@ -1445,7 +1445,8 @@ __nft_rule_flush(struct nft_handle *h, const char *table,
return;
nftnl_rule_set_str(r, NFTNL_RULE_TABLE, table);
- nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, chain);
+ if (chain)
+ nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, chain);
obj = batch_rule_add(h, NFT_COMPAT_RULE_FLUSH, r);
if (!obj) {
@@ -1459,19 +1460,21 @@ __nft_rule_flush(struct nft_handle *h, const char *table,
int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
bool verbose)
{
- int ret = 0;
- struct nftnl_chain_list *list;
struct nftnl_chain_list_iter *iter;
- struct nftnl_chain *c;
+ struct nftnl_chain_list *list;
+ struct nftnl_chain *c = NULL;
+ int ret = 0;
nft_xt_builtin_init(h, table);
nft_fn = nft_rule_flush;
- list = nft_chain_list_get(h, table, chain);
- if (list == NULL) {
- ret = 1;
- goto err;
+ if (chain || verbose) {
+ list = nft_chain_list_get(h, table, chain);
+ if (list == NULL) {
+ ret = 1;
+ goto err;
+ }
}
if (chain) {
@@ -1480,9 +1483,11 @@ int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
errno = ENOENT;
return 0;
}
+ }
+ if (chain || !verbose) {
__nft_rule_flush(h, table, chain, verbose, false);
- flush_rule_cache(c);
+ flush_rule_cache(h, table, c);
return 1;
}
@@ -1494,11 +1499,10 @@ int nft_rule_flush(struct nft_handle *h, const char *chain, const char *table,
c = nftnl_chain_list_iter_next(iter);
while (c != NULL) {
- const char *chain_name =
- nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
+ chain = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
- __nft_rule_flush(h, table, chain_name, verbose, false);
- flush_rule_cache(c);
+ __nft_rule_flush(h, table, chain, verbose, false);
+ flush_rule_cache(h, table, c);
c = nftnl_chain_list_iter_next(iter);
}
nftnl_chain_list_iter_destroy(iter);