From 340105fa8004503135d5792a64b8972b6a7bfdc0 Mon Sep 17 00:00:00 2001 From: "Pablo M. Bermudo Garay" Date: Fri, 31 Mar 2017 14:34:38 +0200 Subject: tests: add regression tests for xtables-translate This test suite is intended to detect regressions in the translation infrastructure. The script checks if ip[6]tables-translate produces the expected output, otherwise it prints the wrong translation and the expected one. ** Arguments --all # Show also passed tests [test] # Run only the specified test file ** Test files structure Test files are located under extensions directory. Every file contains tests about specific extension translations. A test file name must end with ".txlate". Inside the files, every single test is defined by two consecutive lines: ip[6]tables-translate command and expected result. One blank line is left between tests by convention. e.g. $ cat extensions/libxt_cpu.txlate iptables-translate -A INPUT -p tcp --dport 80 -m cpu --cpu 0 -j ACCEPT nft add rule ip filter INPUT tcp dport 80 cpu 0 counter accept iptables-translate -A INPUT -p tcp --dport 80 -m cpu ! --cpu 1 -j ACCEPT nft add rule ip filter INPUT tcp dport 80 cpu != 1 counter accept Signed-off-by: Pablo M. Bermudo Garay Signed-off-by: Pablo Neira Ayuso --- extensions/libxt_conntrack.txlate | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 extensions/libxt_conntrack.txlate (limited to 'extensions/libxt_conntrack.txlate') diff --git a/extensions/libxt_conntrack.txlate b/extensions/libxt_conntrack.txlate new file mode 100644 index 00000000..e35d5ce8 --- /dev/null +++ b/extensions/libxt_conntrack.txlate @@ -0,0 +1,41 @@ +iptables-translate -t filter -A INPUT -m conntrack --ctstate NEW,RELATED -j ACCEPT +nft add rule ip filter INPUT ct state new,related counter accept + +ip6tables-translate -t filter -A INPUT -m conntrack ! --ctstate NEW,RELATED -j ACCEPT +nft add rule ip6 filter INPUT ct state != new,related counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctproto UDP -j ACCEPT +nft add rule ip filter INPUT ct original protocol 17 counter accept + +iptables-translate -t filter -A INPUT -m conntrack ! --ctproto UDP -j ACCEPT +nft add rule ip filter INPUT ct original protocol != 17 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctorigsrc 10.100.2.131 -j ACCEPT +nft add rule ip filter INPUT ct original saddr 10.100.2.131 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctorigsrc 10.100.0.0/255.255.0.0 -j ACCEPT +nft add rule ip filter INPUT ct original saddr 10.100.0.0/16 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctorigdst 10.100.2.131 -j ACCEPT +nft add rule ip filter INPUT ct original daddr 10.100.2.131 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctreplsrc 10.100.2.131 -j ACCEPT +nft add rule ip filter INPUT ct reply saddr 10.100.2.131 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctrepldst 10.100.2.131 -j ACCEPT +nft add rule ip filter INPUT ct reply daddr 10.100.2.131 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctproto tcp --ctorigsrcport 443:444 -j ACCEPT +nft add rule ip filter INPUT ct original protocol 6 ct original proto-src 443-444 counter accept + +iptables-translate -t filter -A INPUT -m conntrack ! --ctstatus CONFIRMED -j ACCEPT +nft add rule ip filter INPUT ct status != confirmed counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctexpire 3 -j ACCEPT +nft add rule ip filter INPUT ct expiration 3 counter accept + +iptables-translate -t filter -A INPUT -m conntrack --ctdir ORIGINAL -j ACCEPT +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 -- cgit v1.2.3