]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests: iptables-test: Support variant deviation
authorPhil Sutter <phil@nwl.cc>
Fri, 4 Feb 2022 17:45:22 +0000 (18:45 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 10 Feb 2022 15:42:53 +0000 (16:42 +0100)
Some test results are not consistent between variants:

* CLUSTERIP is not supported with nft_compat, so all related tests fail
  with iptables-nft.
* iptables-legacy mandates TCPMSS be combined with SYN flag match,
  iptables-nft does not care. (Or precisely, xt_TCPMSS.ko can't validate
  match presence.)

Introduce an optional fourth test spec field to specify the variant it
applies to. Consequently, the opposite result is expected with the other
variant.

Signed-off-by: Phil Sutter <phil@nwl.cc>
extensions/libipt_CLUSTERIP.t
extensions/libxt_TCPMSS.t
iptables-test.py

index 5af555e005c1dc56f715b5bc3e5d8aa4dfcc683c..30b80167a622373d2d928fcc6c69d5e7de98b9e6 100644 (file)
@@ -1,4 +1,4 @@
 :INPUT
 -d 10.31.3.236/32 -i lo -j CLUSTERIP --new --hashmode sourceip --clustermac 01:AA:7B:47:F7:D7 --total-nodes 2 --local-node 0 --hash-init 1;=;FAIL
--d 10.31.3.236/32 -i lo -j CLUSTERIP --new --hashmode sourceip --clustermac 01:AA:7B:47:F7:D7 --total-nodes 2 --local-node 1 --hash-init 1;=;OK
--d 10.31.3.236/32 -i lo -j CLUSTERIP --new --hashmode sourceip --clustermac 01:AA:7B:47:F7:D7 --total-nodes 2 --local-node 2 --hash-init 1;=;OK
+-d 10.31.3.236/32 -i lo -j CLUSTERIP --new --hashmode sourceip --clustermac 01:AA:7B:47:F7:D7 --total-nodes 2 --local-node 1 --hash-init 1;=;OK;LEGACY
+-d 10.31.3.236/32 -i lo -j CLUSTERIP --new --hashmode sourceip --clustermac 01:AA:7B:47:F7:D7 --total-nodes 2 --local-node 2 --hash-init 1;=;OK;LEGACY
index 553a3452e4876778c17001eb59a360936b3a9e59..fbfbfcf88d81aec741d743c625dec752338db7f5 100644 (file)
@@ -1,6 +1,6 @@
 :FORWARD,OUTPUT,POSTROUTING
 *mangle
 -j TCPMSS;;FAIL
--p tcp -j TCPMSS --set-mss 42;;FAIL
+-p tcp -j TCPMSS --set-mss 42;;FAIL;LEGACY
 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --set-mss 42;=;OK
 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --clamp-mss-to-pmtu;=;OK
index 95fa11b1475ca6439a0a4850df0b92ea4eb69b59..b49afcab3c40cfca44f72d7a5fb1dbe46be837c3 100755 (executable)
@@ -182,6 +182,28 @@ def execute_cmd(cmd, filename, lineno):
     return ret
 
 
+def variant_res(res, variant):
+    '''
+    Adjust expected result with given variant
+
+    If expected result is scoped to a variant, the other one yields a different
+    result. Therefore map @res to itself if given variant is current, invert it
+    otherwise.
+
+    :param res: expected result from test spec ("OK" or "FAIL")
+    :param variant: variant @res is scoped to by test spec ("NFT" or "LEGACY")
+    '''
+    variant_executable = {
+            "NFT": "xtables-nft-multi",
+            "LEGACY": "xtables-legacy-multi"
+    }
+    res_inverse = { "OK": "FAIL", "FAIL": "OK" }
+
+    if variant_executable[variant] == EXECUTABLE:
+        return res
+    return res_inverse[res]
+
+
 def run_test_file(filename, netns):
     '''
     Runs a test file
@@ -275,6 +297,9 @@ def run_test_file(filename, netns):
                 rule_save = chain + " " + item[1]
 
             res = item[2].rstrip()
+            if len(item) > 3:
+                res = variant_res(res, item[3].rstrip())
+
             ret = run_test(iptables, rule, rule_save,
                            res, filename, lineno + 1, netns)