xtables-restore: Fix verbose mode table flushing
Phil Sutter
reviewerPATCH 1/1 xtables-restore: Fix verbose mode table flushing
When called with --verbose mode, iptables-nft-restore did not print anything when flushing the table. Fix this by adding a "manual" mode to nft_cmd_table_flush(), turning it into a wrapper around '-F' and '-X' commands, which is exactly what iptables-legacy-restore does to flush a table. This though requires a real cache, so don't set NFT_CL_FAKE then.
Signed-off-by Phil Sutter <[email protected]>
--- iptables/nft-cmd.c | 7 +- iptables/nft-cmd.h | 2 +- iptables/nft-shared.h | 3 +- .../ipt-restore/0014-verbose-restore_0 | 76 +++++++++++++++++++ iptables/xtables-eb.c | 2 +- iptables/xtables-restore.c | 4 +- 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100755 iptables/tests/shell/testcases/ipt-restore/0014-verbose-restore_0
iptables/nft-cmd.c +6 -1
@@ -311,10 +311,15 @@ int nft_cmd_chain_set(struct nft_handle *h, const char *table,return 1 ; } -int nft_cmd_table_flush (struct nft_handle *h,const char *table) +int nft_cmd_table_flush (struct nft_handle *h,const char *table,bool verbose) {struct nft_cmd *cmd; +if (verbose) { +return nft_cmd_rule_flush (h,NULL , table, verbose) && +nft_cmd_chain_user_del (h,NULL , table, verbose); + } + cmd =nft_cmd_new (h,NFT_COMPAT_TABLE_FLUSH , table,NULL ,NULL ,-1 , false);if (!cmd)
iptables/nft-cmd.h +1 -1
@@ -65,7 +65,7 @@ int nft_cmd_chain_user_rename(struct nft_handle *h,const char *chain,int nft_cmd_rule_replace (struct nft_handle *h,const char *chain,const char *table,void *data,int rulenum,bool verbose); -int nft_cmd_table_flush (struct nft_handle *h,const char *table); +int nft_cmd_table_flush (struct nft_handle *h,const char *table,bool verbose);int nft_cmd_chain_restore (struct nft_handle *h,const char *chain,const char *table); int nft_cmd_rule_zero_counters(struct nft_handle *h, const char *chain,
iptables/nft-shared.h +2 -1
@@ -225,7 +225,8 @@ struct nft_xt_restore_cb {int (*chain_restore)(struct nft_handle *h,const char *chain,const char *table); -int (*table_flush)(struct nft_handle *h,const char *table); +int (*table_flush)(struct nft_handle *h,const char *table, +bool verbose);int (*do_command)(struct nft_handle *h,int argc,char *argv[],char **table,bool restore);
iptables/tests/shell/testcases/ipt-restore/0014-verbose-restore_0 new file +76 -0
76 lines not on this page · raw message
iptables/xtables-eb.c +1 -1
@@ -1155,7 +1155,7 @@ print_zero:/*case 7 :*/ /* atomic-init */ /*case 10:*/ /* atomic-save */ case 11 :/* init-table */ -nft_cmd_table_flush (h, *table); +nft_cmd_table_flush (h, *table, false);return 1 ;/* replace->command = c;
iptables/xtables-restore.c +2 -2
@@ -135,7 +135,7 @@ static void xtables_restore_parse_line(struct nft_handle *h,if (h->noflush ==0 ) {DEBUGP ("Cleaning all chains of table '%s'\n" , table);if (cb->table_flush) - cb->table_flush (h, table); + cb->table_flush (h, table, verbose); } ret =1 ;
@@ -260,7 +260,7 @@ void xtables_restore_parse(struct nft_handle *h,struct nft_xt_restore_state state = {};char buffer[10240 ] = {}; -if (!h->noflush) +if (!verbose && !h->noflush)nft_cache_level_set (h,NFT_CL_FAKE ,NULL ); line =0 ;
Signature · 1 line
2.25.1