]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: libxt_conntrack: provide translation for DNAT and SNAT --ctstate
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Jul 2020 11:04:34 +0000 (13:04 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 24 Jul 2020 11:21:41 +0000 (13:21 +0200)
iptables-translate -t filter -A INPUT -m conntrack --ctstate DNAT -j ACCEPT
nft add rule ip filter INPUT ct status dnat counter accept

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
extensions/libxt_conntrack.c
extensions/libxt_conntrack.txlate

index 6f3503933e6648170676f4c1be4ac32e8184ddf9..7734509c9af84d17b197956dcdf2eca4b77b3b5f 100644 (file)
@@ -1249,11 +1249,19 @@ static int _conntrack3_mt_xlate(struct xt_xlate *xl,
        }
 
        if (sinfo->match_flags & XT_CONNTRACK_STATE) {
-               xt_xlate_add(xl, "%sct state %s", space,
-                            sinfo->invert_flags & XT_CONNTRACK_STATE ?
-                            "!= " : "");
-               state_xlate_print(xl, sinfo->state_mask);
-               space = " ";
+               if ((sinfo->state_mask & XT_CONNTRACK_STATE_SNAT) ||
+                   (sinfo->state_mask & XT_CONNTRACK_STATE_DNAT)) {
+                       xt_xlate_add(xl, "%sct status %s%s", space,
+                                    sinfo->invert_flags & XT_CONNTRACK_STATUS ? "!=" : "",
+                                    sinfo->state_mask & XT_CONNTRACK_STATE_SNAT ? "snat" : "dnat");
+                       space = " ";
+               } else {
+                       xt_xlate_add(xl, "%sct state %s", space,
+                                    sinfo->invert_flags & XT_CONNTRACK_STATE ?
+                                    "!= " : "");
+                       state_xlate_print(xl, sinfo->state_mask);
+                       space = " ";
+               }
        }
 
        if (sinfo->match_flags & XT_CONNTRACK_STATUS) {
index 8a3d0181c71efadaf916b391e4f09539acc59244..d374f8a035f00b23f382c02c27de4c759e4cf1ff 100644 (file)
@@ -42,3 +42,10 @@ nft add rule ip filter INPUT ct direction original counter accept
 
 iptables-translate -t filter -A INPUT -m conntrack --ctstate NEW --ctproto tcp --ctorigsrc 192.168.0.1 --ctorigdst 192.168.0.1 --ctreplsrc 192.168.0.1 --ctrepldst 192.168.0.1 --ctorigsrcport 12 --ctorigdstport 14 --ctreplsrcport 16 --ctrepldstport 18 --ctexpire 10 --ctstatus SEEN_REPLY --ctdir ORIGINAL -j ACCEPT
 nft add rule ip filter INPUT ct direction original ct original protocol 6 ct state new ct status seen-reply ct expiration 10 ct original saddr 192.168.0.1 ct original daddr 192.168.0.1 ct reply saddr 192.168.0.1 ct reply daddr 192.168.0.1 ct original proto-src 12 ct original proto-dst 14 ct reply proto-src 16 ct reply proto-dst 18 counter accept
+
+iptables-translate -t filter -A INPUT -m conntrack --ctstate SNAT -j ACCEPT
+nft add rule ip filter INPUT ct status snat counter accept
+
+iptables-translate -t filter -A INPUT -m conntrack --ctstate DNAT -j ACCEPT
+nft add rule ip filter INPUT ct status dnat counter accept
+