19a0061b6Sopenharmony_ciFrom c70a33d219ccb43e6f59aa1b9bbab5dcb13f3443 Mon Sep 17 00:00:00 2001
29a0061b6Sopenharmony_ciFrom: Phil Sutter <phil@nwl.cc>
39a0061b6Sopenharmony_ciDate: Thu, 25 Aug 2022 11:53:04 +0200
49a0061b6Sopenharmony_ciSubject: [PATCH] xtables-restore: Extend failure error message
59a0061b6Sopenharmony_ci
69a0061b6Sopenharmony_ciIf a line causes zero 'ret' value and errno is set, call nft_strerror()
79a0061b6Sopenharmony_cifor a more detailed error message. While not perfect, it helps with
89a0061b6Sopenharmony_cidebugging ominous "line NN failed" messages pointing at COMMIT:
99a0061b6Sopenharmony_ci
109a0061b6Sopenharmony_ci| # iptables-nft-restore <<EOF
119a0061b6Sopenharmony_ci| *filter
129a0061b6Sopenharmony_ci| -A nonexist
139a0061b6Sopenharmony_ci| COMMIT
149a0061b6Sopenharmony_ci| EOF
159a0061b6Sopenharmony_ci| iptables-nft-restore: line 3 failed: No chain/target/match by that name.
169a0061b6Sopenharmony_ci
179a0061b6Sopenharmony_ciConflict: NA
189a0061b6Sopenharmony_ciReference: https://git.netfilter.org/iptables/commit?id=c70a33d219ccb43e6f59aa1b9bbab5dcb13f3443
199a0061b6Sopenharmony_ci
209a0061b6Sopenharmony_ciSigned-off-by: Phil Sutter <phil@nwl.cc>
219a0061b6Sopenharmony_ci---
229a0061b6Sopenharmony_ci iptables/xtables-restore.c | 5 ++++-
239a0061b6Sopenharmony_ci 1 file changed, 4 insertions(+), 1 deletion(-)
249a0061b6Sopenharmony_ci
259a0061b6Sopenharmony_cidiff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
269a0061b6Sopenharmony_ciindex abeaf76..5940e9a 100644
279a0061b6Sopenharmony_ci--- a/iptables/xtables-restore.c
289a0061b6Sopenharmony_ci+++ b/iptables/xtables-restore.c
299a0061b6Sopenharmony_ci@@ -247,8 +247,11 @@ static void xtables_restore_parse_line(struct nft_handle *h,
309a0061b6Sopenharmony_ci 	    (strcmp(p->tablename, state->curtable->name) != 0))
319a0061b6Sopenharmony_ci 		return;
329a0061b6Sopenharmony_ci 	if (!ret) {
339a0061b6Sopenharmony_ci-		fprintf(stderr, "%s: line %u failed\n",
349a0061b6Sopenharmony_ci+		fprintf(stderr, "%s: line %u failed",
359a0061b6Sopenharmony_ci 				xt_params->program_name, h->error.lineno);
369a0061b6Sopenharmony_ci+		if (errno)
379a0061b6Sopenharmony_ci+			fprintf(stderr,	": %s.", nft_strerror(errno));
389a0061b6Sopenharmony_ci+		fprintf(stderr, "\n");
399a0061b6Sopenharmony_ci 		exit(1);
409a0061b6Sopenharmony_ci 	}
419a0061b6Sopenharmony_ci }
429a0061b6Sopenharmony_ci-- 
439a0061b6Sopenharmony_ci2.33.0
449a0061b6Sopenharmony_ci
45