The following snippet fails if user chain FOO exists, but it should not fail: iptables-compat -F iptables-compat -N FOO iptables-compat-save > foo iptables-compat-restore < foo Reported-by: Florian Westphal <fw@xxxxxxxxx> Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- iptables/nft-shared.h | 2 +- iptables/nft.c | 25 +++++++++++++++++++++++++ iptables/nft.h | 1 + iptables/xtables-restore.c | 6 +++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/iptables/nft-shared.h b/iptables/nft-shared.h index e13a1a8563c3..1520d613b528 100644 --- a/iptables/nft-shared.h +++ b/iptables/nft-shared.h @@ -255,7 +255,7 @@ struct nft_xt_restore_cb { int (*chain_user_add)(struct nft_handle *h, const char *chain, const char *table); - int (*rule_flush)(struct nft_handle *h, const char *chain, const char *table); + int (*table_flush)(struct nft_handle *h, const char *table); int (*do_command)(struct nft_handle *h, int argc, char *argv[], char **table, bool restore); diff --git a/iptables/nft.c b/iptables/nft.c index e60923d6ecbf..5858e01e52ac 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -262,6 +262,7 @@ enum obj_update_type { NFT_COMPAT_RULE_REPLACE, NFT_COMPAT_RULE_DELETE, NFT_COMPAT_RULE_FLUSH, + NFT_COMPAT_TABLE_FLUSH, }; enum obj_action { @@ -1283,6 +1284,25 @@ next: return 1; } +int nft_table_flush(struct nft_handle *h, const char *table) +{ + struct nftnl_table *r; + int ret = 0; + + nft_fn = nft_table_flush; + + r = nftnl_table_alloc(); + if (r == NULL) + goto err; + + nftnl_table_set_str(r, NFTNL_TABLE_NAME, table); + + batch_table_add(h, NFT_COMPAT_TABLE_FLUSH, r); +err: + /* the core expects 1 for success and 0 for error */ + return ret == 0 ? 1 : 0; +} + static void __nft_rule_flush(struct nft_handle *h, const char *table, const char *chain) { @@ -2294,6 +2314,11 @@ static int nft_action(struct nft_handle *h, int action) nft_compat_rule_batch_add(h, NFT_MSG_DELRULE, 0, seq++, n->rule); break; + case NFT_COMPAT_TABLE_FLUSH: + nft_compat_table_batch_add(h, NFT_MSG_DELTABLE, + 0, + seq++, n->table); + break; } h->obj_list_num--; diff --git a/iptables/nft.h b/iptables/nft.h index aaf3cbe0c0e3..2d5c37e5b502 100644 --- a/iptables/nft.h +++ b/iptables/nft.h @@ -58,6 +58,7 @@ struct nftnl_chain_list; int nft_for_each_table(struct nft_handle *h, int (*func)(struct nft_handle *h, const char *tablename, bool counters), bool counters); bool nft_table_find(struct nft_handle *h, const char *tablename); int nft_table_purge_chains(struct nft_handle *h, const char *table, struct nftnl_chain_list *list); +int nft_table_flush(struct nft_handle *h, const char *table); /* * Operations with chains. diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c index fc39ad9c4fa5..3de496f85387 100644 --- a/iptables/xtables-restore.c +++ b/iptables/xtables-restore.c @@ -191,7 +191,7 @@ struct nft_xt_restore_cb restore_cb = { .commit = nft_commit, .abort = nft_abort, .chains_purge = nft_table_purge_chains, - .rule_flush = nft_rule_flush, + .table_flush = nft_table_flush, .chain_del = chain_delete, .do_command = do_commandx, .chain_set = nft_chain_set, @@ -270,8 +270,8 @@ void xtables_restore_parse(struct nft_handle *h, if (noflush == 0) { DEBUGP("Cleaning all chains of table '%s'\n", table); - if (cb->rule_flush) - cb->rule_flush(h, NULL, table); + if (cb->table_flush) + cb->table_flush(h, table); } ret = 1; -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html