]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables: fix the wrong appending of jump verdict after the comment. v1.6.1
authorShyam Saini <mayhs11saini@gmail.com>
Thu, 26 Jan 2017 09:19:50 +0000 (14:49 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 26 Jan 2017 16:11:58 +0000 (17:11 +0100)
Fix wrong appending of jump verdict after the comment

For example:
$ iptables-translate -A INPUT -p tcp -m tcp --sport http -s  192.168.0.0/16 -d 192.168.0.0/16 -j LONGNACCEPT -m comment --comment "foobar"
nft add rule ip filter INPUT ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter comment \"foobar\"jump LONGNACCEPT

Note that even without comment with double-quotes (i.e. --comment
"foobar"), it will add quotes:

$ iptables-translate -A FORWARD -p tcp -m tcp --sport http -s 192.168.0.0/16 -d 192.168.0.0/16 -j DROP -m comment --comment singlecomment
nft add rule ip filter FORWARD ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter comment \"singlecomment\"drop

Attempting to apply the translated/generated rule will result to:

$ nft add rule ip filter INPUT ip saddr 192.168.0.0/16 ip daddr  192.168.0.0/16 tcp sport 80 counter comment \"foobar\"jump LONGNACCEPT
<cmdline>:1:111-114: Error: syntax error, unexpected jump, expecting endof file or newline or semicolon
add rule ip filter INPUT ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter comment "foobar"jump LONGNACCEPT

After this patch
$ iptables-translate -A INPUT -p tcp -m tcp --sport http -s 192.168.0.0/16 -d 192.168.0.0/16 -j LONGNACCEPT -m comment --comment "foobar"
nft add rule ip filter INPUT ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter jump LONGNACCEPT comment \"foobar\"
which is correct translation

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Reviewed-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft-ipv4.c
iptables/nft-ipv6.c

index 52b1bed2a9ebc22f4d841e9ea0146f10126917f0..e5947a7c1e1f6a1fa41eb043c393e048dbb5f691 100644 (file)
@@ -489,12 +489,11 @@ static int nft_ipv4_xlate(const void *data, struct xt_xlate *xl)
 
        /* Always add counters per rule, as in iptables */
        xt_xlate_add(xl, "counter ");
+       ret = xlate_action(cs, !!(cs->fw.ip.flags & IPT_F_GOTO), xl);
 
        comment = xt_xlate_get_comment(xl);
        if (comment)
-               xt_xlate_add(xl, "comment %s", comment);
-
-       ret = xlate_action(cs, !!(cs->fw.ip.flags & IPT_F_GOTO), xl);
+               xt_xlate_add(xl, " comment %s", comment);
 
        return ret;
 }
index c475b8e9513ee86c61d5535286266275160bcb7a..9cf4058f58b862881f32a4a73be7d2a61247561f 100644 (file)
@@ -438,12 +438,11 @@ static int nft_ipv6_xlate(const void *data, struct xt_xlate *xl)
 
        /* Always add counters per rule, as in iptables */
        xt_xlate_add(xl, "counter ");
+       ret = xlate_action(cs, !!(cs->fw6.ipv6.flags & IP6T_F_GOTO), xl);
 
        comment = xt_xlate_get_comment(xl);
        if (comment)
-               xt_xlate_add(xl, "comment %s", comment);
-
-       ret = xlate_action(cs, !!(cs->fw6.ipv6.flags & IP6T_F_GOTO), xl);
+               xt_xlate_add(xl, " comment %s", comment);
 
        return ret;
 }