]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-translate: Return non-zero if translation fails
authorPhil Sutter <phil@nwl.cc>
Tue, 10 Mar 2026 16:22:52 +0000 (17:22 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 13 Mar 2026 11:35:14 +0000 (12:35 +0100)
Untranslated parts in output are easily overlooked and also don't disrupt
piping into nft (which is a bad idea to begin with), so make a little
noise if things go sideways:

| # iptables-translate -A FORWARD -m recent --set
| nft # -A FORWARD -m recent --set
| Translation not (fully) implemented

| # cat /tmp/input.ipt
| *filter
| -A FORWARD -s 1.2.3.4
| -A FORWARD -m recent --set
| COMMIT
| # iptables-restore-translate -f /tmp/input.ipt
| # Translated by iptables-restore-translate v1.8.13 on Tue Mar 10 17:29:17 2026
| add table ip filter
| add rule ip filter FORWARD ip saddr 1.2.3.4 counter
| # -t filter -A FORWARD -m recent --set
| iptables-translate-restore: line 3 failed

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
iptables/xtables-translate.c

index 3d8617f05b120fa56291f060415f62e3a4c0e54a..74cc8efffc0eb05ef31301288bc3d39dfeb3b88d 100644 (file)
@@ -297,8 +297,8 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[],
 
        switch (p.command) {
        case CMD_APPEND:
-               ret = 1;
-               if (!xlate(h, &p, &cs, &args, true, nft_rule_xlate_add))
+               ret = xlate(h, &p, &cs, &args, true, nft_rule_xlate_add);
+               if (!ret)
                        print_ipt_cmd(argc, argv);
                break;
        case CMD_DELETE:
@@ -310,8 +310,8 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[],
        case CMD_REPLACE:
                break;
        case CMD_INSERT:
-               ret = 1;
-               if (!xlate(h, &p, &cs, &args, false, nft_rule_xlate_add))
+               ret = xlate(h, &p, &cs, &args, false, nft_rule_xlate_add);
+               if (!ret)
                        print_ipt_cmd(argc, argv);
                break;
        case CMD_FLUSH:
@@ -558,7 +558,7 @@ static int xtables_xlate_main(int family, const char *progname, int argc,
 
        ret = do_command_xlate(&h, argc, argv, &table, false);
        if (!ret)
-               fprintf(stderr, "Translation not implemented\n");
+               fprintf(stderr, "Translation not (fully) implemented\n");
 
        nft_fini(&h);
        xtables_fini();