summaryrefslogtreecommitdiffstats
path: root/iptables/nft-shared.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2022-11-23 14:44:22 +0100
committerFlorian Westphal <fw@strlen.de>2022-11-23 15:05:12 +0100
commit83241d3f173dd57c3fdc347490213776a070fa40 (patch)
tree585c10b01325e714857fb6e99406ddf6fa70c345 /iptables/nft-shared.c
parent25883ce88bfba087ef142cb909d59dbbc1818b32 (diff)
iptables-nft: exit nonzero when iptables-save cannot decode all expressions
We always return 0, even if we printed some error message half-way. Increment an error counter whenever an error message was printed so that the chain-loop can exit with an error if this counter is nonzero. Another effect is that iptables-save will no longer print the COMMIT line anmore. Reported-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de> Acked-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/nft-shared.c')
-rw-r--r--iptables/nft-shared.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
index 97512e3f..63d25198 100644
--- a/iptables/nft-shared.c
+++ b/iptables/nft-shared.c
@@ -1199,7 +1199,7 @@ static void nft_parse_range(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
}
}
-void nft_rule_to_iptables_command_state(struct nft_handle *h,
+bool nft_rule_to_iptables_command_state(struct nft_handle *h,
const struct nftnl_rule *r,
struct iptables_command_state *cs)
{
@@ -1210,10 +1210,11 @@ void nft_rule_to_iptables_command_state(struct nft_handle *h,
.h = h,
.table = nftnl_rule_get_str(r, NFTNL_RULE_TABLE),
};
+ bool ret = true;
iter = nftnl_expr_iter_create(r);
if (iter == NULL)
- return;
+ return false;
ctx.iter = iter;
expr = nftnl_expr_iter_next(iter);
@@ -1249,6 +1250,7 @@ void nft_rule_to_iptables_command_state(struct nft_handle *h,
if (ctx.errmsg) {
fprintf(stderr, "%s", ctx.errmsg);
ctx.errmsg = NULL;
+ ret = false;
}
expr = nftnl_expr_iter_next(iter);
@@ -1270,7 +1272,7 @@ void nft_rule_to_iptables_command_state(struct nft_handle *h,
match = xtables_find_match("comment", XTF_TRY_LOAD,
&cs->matches);
if (match == NULL)
- return;
+ return false;
size = XT_ALIGN(sizeof(struct xt_entry_match))
+ match->size;
@@ -1287,6 +1289,8 @@ void nft_rule_to_iptables_command_state(struct nft_handle *h,
if (!cs->jumpto)
cs->jumpto = "";
+
+ return ret;
}
void nft_clear_iptables_command_state(struct iptables_command_state *cs)