Blame SOURCES/0005-tests-add-tests-ipset-to-nftables.patch

74da1b
From 55554de816520471e11f39b99468d5777ae57937 Mon Sep 17 00:00:00 2001
74da1b
From: Pablo Neira Ayuso <pablo@netfilter.org>
74da1b
Date: Fri, 25 Jun 2021 22:30:43 +0200
74da1b
Subject: [PATCH] tests: add tests ipset to nftables
74da1b
74da1b
This test checks that the translation from ipset to nftables is correct.
74da1b
74da1b
term$ cd tests/xlate
74da1b
term$ ./runtest.sh
74da1b
74da1b
in case that the translation is not correct, it shows the diff with expected
74da1b
translation output.
74da1b
74da1b
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
74da1b
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
74da1b
(cherry picked from commit 7587d1c4b5465f3b5315536b439b63a5ffe0311d)
74da1b
---
74da1b
 tests/xlate/runtest.sh  | 29 +++++++++++++++++++++
74da1b
 tests/xlate/xlate.t     | 55 ++++++++++++++++++++++++++++++++++++++++
74da1b
 tests/xlate/xlate.t.nft | 56 +++++++++++++++++++++++++++++++++++++++++
74da1b
 3 files changed, 140 insertions(+)
74da1b
 create mode 100755 tests/xlate/runtest.sh
74da1b
 create mode 100644 tests/xlate/xlate.t
74da1b
 create mode 100644 tests/xlate/xlate.t.nft
74da1b
74da1b
diff --git a/tests/xlate/runtest.sh b/tests/xlate/runtest.sh
74da1b
new file mode 100755
74da1b
index 0000000000000..a2a02c05d7573
74da1b
--- /dev/null
74da1b
+++ b/tests/xlate/runtest.sh
74da1b
@@ -0,0 +1,29 @@
74da1b
+#!/bin/bash
74da1b
+
74da1b
+DIFF=$(which diff)
74da1b
+if [ ! -x "$DIFF" ] ; then
74da1b
+	echo "ERROR: missing diff"
74da1b
+	exit 1
74da1b
+fi
74da1b
+
74da1b
+IPSET_XLATE=$(which ipset-translate)
74da1b
+if [ ! -x "$IPSET_XLATE" ] ; then
74da1b
+	echo "ERROR: ipset-translate is not installed yet"
74da1b
+	exit 1
74da1b
+fi
74da1b
+
74da1b
+TMP=$(mktemp)
74da1b
+ipset-translate restore < xlate.t &> $TMP
74da1b
+if [ $? -ne 0 ]
74da1b
+then
74da1b
+	cat $TMP
74da1b
+	echo -e "[\033[0;31mERROR\033[0m] failed to run ipset-translate"
74da1b
+	exit 1
74da1b
+fi
74da1b
+${DIFF} -u xlate.t.nft $TMP
74da1b
+if [ $? -eq 0 ]
74da1b
+then
74da1b
+	echo -e "[\033[0;32mOK\033[0m] tests are fine!"
74da1b
+else
74da1b
+	echo -e "[\033[0;31mERROR\033[0m] unexpected ipset to nftables translation"
74da1b
+fi
74da1b
diff --git a/tests/xlate/xlate.t b/tests/xlate/xlate.t
74da1b
new file mode 100644
74da1b
index 0000000000000..b1e7d288e2a98
74da1b
--- /dev/null
74da1b
+++ b/tests/xlate/xlate.t
74da1b
@@ -0,0 +1,55 @@
74da1b
+create hip1 hash:ip
74da1b
+add hip1 192.168.10.2
74da1b
+add hip1 192.168.10.3
74da1b
+create hip2 hash:ip hashsize 128 bucketsize 255 timeout 4
74da1b
+add hip2 192.168.10.3
74da1b
+add hip2 192.168.10.4 timeout 10
74da1b
+create hip3 hash:ip counters
74da1b
+add hip3 192.168.10.3 packets 5 bytes 3456
74da1b
+create hip4 hash:ip netmask 24
74da1b
+add hip4 192.168.10.0
74da1b
+create hip5 hash:ip maxelem 24
74da1b
+add hip5 192.168.10.0
74da1b
+create hip6 hash:ip comment
74da1b
+add hip5 192.168.10.1
74da1b
+add hip5 192.168.10.2 comment "this is a comment"
74da1b
+create ipp1 hash:ip,port
74da1b
+add ipp1 192.168.10.1,0
74da1b
+add ipp1 192.168.10.2,5
74da1b
+create ipp2 hash:ip,port timeout 4
74da1b
+add ipp2 192.168.10.1,0 timeout 12
74da1b
+add ipp2 192.168.10.2,5
74da1b
+create ipp3 hash:ip,port counters
74da1b
+add ipp3 192.168.10.3,20 packets 5 bytes 3456
74da1b
+create ipp4 hash:ip,port timeout 4 counters
74da1b
+add ipp4 192.168.10.3,20 packets 5 bytes 3456
74da1b
+create bip1 bitmap:ip range 2.0.0.1-2.1.0.1 timeout 5
74da1b
+create bip2 bitmap:ip range 10.0.0.0/8 netmask 24 timeout 5
74da1b
+add bip2 10.10.10.0
74da1b
+add bip2 10.10.20.0 timeout 12
74da1b
+create net1 hash:net
74da1b
+add net1 192.168.10.0/24
74da1b
+create net2 hash:net,net
74da1b
+add net2 192.168.10.0/24,192.168.20.0/24
74da1b
+create hm1 hash:mac
74da1b
+add hm1 aa:bb:cc:dd:ee:ff
74da1b
+create him1 hash:ip,mac
74da1b
+add him1 1.1.1.1,aa:bb:cc:dd:ee:ff
74da1b
+create ni1 hash:net,iface
74da1b
+add ni1 1.1.1.0/24,eth0
74da1b
+create nip1 hash:net,port
74da1b
+add nip1 1.1.1.0/24,22
74da1b
+create npn1 hash:net,port,net
74da1b
+add npn1 1.1.1.0/24,22,2.2.2.0/24
74da1b
+create nn1 hash:net,net
74da1b
+add nn1 1.1.1.0/24,2.2.2.0/24
74da1b
+create ipn1 hash:ip,port,net
74da1b
+add ipn1 1.1.1.1,22,2.2.2.0/24
74da1b
+create ipi1 hash:ip,port,ip
74da1b
+add ipi1 1.1.1.1,22,2.2.2.2
74da1b
+create im1 hash:ip,mark
74da1b
+add im1 1.1.1.1,0x123456
74da1b
+create bp1 bitmap:port range 1-1024
74da1b
+add bp1 22
74da1b
+create bim1 bitmap:ip,mac range 1.1.1.0/24
74da1b
+add bim1 1.1.1.1,aa:bb:cc:dd:ee:ff
74da1b
diff --git a/tests/xlate/xlate.t.nft b/tests/xlate/xlate.t.nft
74da1b
new file mode 100644
74da1b
index 0000000000000..96eba3b0175ea
74da1b
--- /dev/null
74da1b
+++ b/tests/xlate/xlate.t.nft
74da1b
@@ -0,0 +1,56 @@
74da1b
+add table inet global
74da1b
+add set inet global hip1 { type ipv4_addr; }
74da1b
+add element inet global hip1 { 192.168.10.2 }
74da1b
+add element inet global hip1 { 192.168.10.3 }
74da1b
+add set inet global hip2 { type ipv4_addr; timeout 4s; }
74da1b
+add element inet global hip2 { 192.168.10.3 }
74da1b
+add element inet global hip2 { 192.168.10.4 timeout 10s }
74da1b
+add set inet global hip3 { type ipv4_addr; counter; }
74da1b
+add element inet global hip3 { 192.168.10.3 counter packets 5 bytes 3456 }
74da1b
+add set inet global hip4 { type ipv4_addr; flags interval; }
74da1b
+add element inet global hip4 { 192.168.10.0/24 }
74da1b
+add set inet global hip5 { type ipv4_addr; size 24; }
74da1b
+add element inet global hip5 { 192.168.10.0 }
74da1b
+add set inet global hip6 { type ipv4_addr; }
74da1b
+add element inet global hip5 { 192.168.10.1 }
74da1b
+add element inet global hip5 { 192.168.10.2 comment "this is a comment" }
74da1b
+add set inet global ipp1 { type ipv4_addr . inet_proto . inet_service; }
74da1b
+add element inet global ipp1 { 192.168.10.1 . tcp . 0 }
74da1b
+add element inet global ipp1 { 192.168.10.2 . tcp . 5 }
74da1b
+add set inet global ipp2 { type ipv4_addr . inet_proto . inet_service; timeout 4s; }
74da1b
+add element inet global ipp2 { 192.168.10.1 . tcp . 0 timeout 12s }
74da1b
+add element inet global ipp2 { 192.168.10.2 . tcp . 5 }
74da1b
+add set inet global ipp3 { type ipv4_addr . inet_proto . inet_service; counter; }
74da1b
+add element inet global ipp3 { 192.168.10.3 . tcp . 20 counter packets 5 bytes 3456 }
74da1b
+add set inet global ipp4 { type ipv4_addr . inet_proto . inet_service; counter; timeout 4s; }
74da1b
+add element inet global ipp4 { 192.168.10.3 . tcp . 20 counter packets 5 bytes 3456 }
74da1b
+add set inet global bip1 { type ipv4_addr; timeout 5s; }
74da1b
+add set inet global bip2 { type ipv4_addr; timeout 5s; flags interval; }
74da1b
+add element inet global bip2 { 10.10.10.0/24 }
74da1b
+add element inet global bip2 { 10.10.20.0/24 timeout 12s }
74da1b
+add set inet global net1 { type ipv4_addr; flags interval; }
74da1b
+add element inet global net1 { 192.168.10.0/24 }
74da1b
+add set inet global net2 { type ipv4_addr . ipv4_addr; flags interval; }
74da1b
+add element inet global net2 { 192.168.10.0/24 . 192.168.20.0/24 }
74da1b
+add set inet global hm1 { type ether_addr; }
74da1b
+add element inet global hm1 { aa:bb:cc:dd:ee:ff }
74da1b
+add set inet global him1 { type ipv4_addr . ether_addr; }
74da1b
+add element inet global him1 { 1.1.1.1 . aa:bb:cc:dd:ee:ff }
74da1b
+add set inet global ni1 { type ipv4_addr . ifname; flags interval; }
74da1b
+add element inet global ni1 { 1.1.1.0/24 . eth0 }
74da1b
+add set inet global nip1 { type ipv4_addr . inet_proto . inet_service; flags interval; }
74da1b
+add element inet global nip1 { 1.1.1.0/24 . tcp . 22 }
74da1b
+add set inet global npn1 { type ipv4_addr . inet_proto . inet_service . ipv4_addr; flags interval; }
74da1b
+add element inet global npn1 { 1.1.1.0/24 . tcp . 22 . 2.2.2.0/24 }
74da1b
+add set inet global nn1 { type ipv4_addr . ipv4_addr; flags interval; }
74da1b
+add element inet global nn1 { 1.1.1.0/24 . 2.2.2.0/24 }
74da1b
+add set inet global ipn1 { type ipv4_addr . inet_proto . inet_service . ipv4_addr; flags interval; }
74da1b
+add element inet global ipn1 { 1.1.1.1 . tcp . 22 . 2.2.2.0/24 }
74da1b
+add set inet global ipi1 { type ipv4_addr . inet_proto . inet_service . ipv4_addr; }
74da1b
+add element inet global ipi1 { 1.1.1.1 . tcp . 22 . 2.2.2.2 }
74da1b
+add set inet global im1 { type ipv4_addr . mark; }
74da1b
+add element inet global im1 { 1.1.1.1 . 0x00123456 }
74da1b
+add set inet global bp1 { type inet_service; }
74da1b
+add element inet global bp1 { 22 }
74da1b
+add set inet global bim1 { type ipv4_addr . ether_addr; }
74da1b
+add element inet global bim1 { 1.1.1.1 . aa:bb:cc:dd:ee:ff }
74da1b
-- 
74da1b
2.38.0
74da1b