tests: extend native delinearize script
Florian Westphal
maintainerPATCH 1/1 tests: extend native delinearize script
Feed nft-generated ruleset to iptables-nft.
At this time, this will NOT pass. because dissector can handle
meta l4proto tcp ip saddr 1.2.3.4
but not
ip saddr 1.2.3.4 meta l4proto tcp
In the latter case, iptables-nft picks up the immediate value (6) as the ip address, because the first one (1.2.3.4) gets moved as PAYLOAD_PREV due to missing 'removal' of the CTX_PAYLOAD flag.
This is error prone, so lets rewrite the dissector to track each register separately and auto-clear state on writes.
--- .../nft-only/0010-iptables-nft-save.txt | 26 ++++++++++++ .../nft-only/0010-native-delinearize_0 | 21 +--------- .../testcases/nft-only/0010-nft-native.txt | 41 +++++++++++++++++++ 3 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 iptables/tests/shell/testcases/nft-only/0010-iptables-nft-save.txt create mode 100644 iptables/tests/shell/testcases/nft-only/0010-nft-native.txt
iptables/tests/shell/testcases/nft-only/0010-iptables-nft-save.txt new file +26 -0
@@ -0,0 +1,26 @@ +*filter +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +-A INPUT -s 1.2.3.4/32 -p tcp -m tcp --dport 23 -j ACCEPT +-A INPUT -s 1.2.3.0/24 -d 0.0.0.0/32 -p udp -m udp --dport 67:69 -j DROP +-A INPUT -s 1.0.0.0/8 -d 0.0.0.0/32 -p tcp -m tcp --sport 1024:65535 --dport 443 --tcp-flags SYN,ACK SYN -j ACCEPT +-A INPUT -p tcp -m tcp --dport 443 ! --tcp-flags SYN NONE -m comment --comment "checks if SYN bit is set" +-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -m comment --comment "same as iptables --syn" +-A INPUT -p tcp -m tcp --tcp-flags SYN SYN +-A INPUT -p tcp -m tcp ! --tcp-flags SYN,ACK SYN,ACK +-A INPUT -d 0.0.0.0/1 -m ttl --ttl-eq 1 -j DROP +-A INPUT -d 0.0.0.0/2 -m ttl --ttl-gt 2 -j ACCEPT +-A INPUT -d 0.0.0.0/3 -m ttl --ttl-lt 254 -j ACCEPT +-A INPUT -d 0.0.0.0/4 -m ttl ! --ttl-eq 255 -j DROP +-A INPUT -d 8.0.0.0/5 -p icmp -j ACCEPT +-A INPUT -d 8.0.0.0/6 -p icmp -j ACCEPT +-A INPUT -d 10.0.0.0/7 -p icmp -j ACCEPT +-A INPUT -m pkttype --pkt-type broadcast -j ACCEPT +-A INPUT -m pkttype ! --pkt-type unicast -j DROP +-A INPUT -p tcp +-A INPUT -d 0.0.0.0/1 -p udp +-A FORWARD -m limit --limit 10/day +-A FORWARD -p udp -m udp --dport 42 +-A FORWARD -i lo -o lo+ -j NFLOG --nflog-prefix "should use NFLOG" --nflog-group 1 --nflog-size 123 --nflog-threshold 42 +COMMIT
iptables/tests/shell/testcases/nft-only/0010-native-delinearize_0 +2 -19
@@ -5,22 +5,5 @@ nft -v >/dev/null || exit 0 set -e -nft -f - <<EOF -table ip filter { - chain FORWARD { - type filter hook forward priority filter; - limit rate 10/day counter - udp dport 42 counter - } -} -EOF - -EXPECT="*filter -:INPUT ACCEPT [0:0] -:FORWARD ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] --A FORWARD -m limit --limit 10/day --A FORWARD -p udp -m udp --dport 42 -COMMIT" - -diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables-save | grep -v '^#') +unshare -n bash -c "nft -f $(dirname $0)/0010-nft-native.txt; + diff -u -Z $(dirname $0)/0010-iptables-nft-save.txt <($XT_MULTI iptables-save | grep -v '^#')"
iptables/tests/shell/testcases/nft-only/0010-nft-native.txt new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.35.1
On Fri, Sep 23, 2022 at 02:17:25PM +0200, Florian Westphal wrote:
[...]
Quoted 19 lines
iptables/tests/shell/testcases/nft-only/0010-native-delinearize_0 +0
-11@@ -5,22 +5,5 @@ nft -v >/dev/null || exit 0 set -e -nft -f - <<EOF -table ip filter { - chain FORWARD { - type filter hook forward priority filter; - limit rate 10/day counter - udp dport 42 counter - } -} -EOF - -EXPECT="*filter
iptables/tests/shell/testcases/nft-only/0010-native-delinearize_0 nft -v >/dev/null || exit 0 · line 9
Quoted 10 lines
iptables/tests/shell/testcases/nft-only/0010-native-delinearize_0 +2
-8-:INPUT ACCEPT [0:0] -:FORWARD ACCEPT [0:0] -:OUTPUT ACCEPT [0:0] --A FORWARD -m limit --limit 10/day --A FORWARD -p udp -m udp --dport 42 -COMMIT" - -diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables-save | grep -v '^#') +unshare -n bash -c "nft -f $(dirname $0)/0010-nft-native.txt; + diff -u -Z $(dirname $0)/0010-iptables-nft-save.txt <($XT_MULTI iptables-save | grep -v '^#')"
run-test.sh calls unshare already. Apart from that: