Test case for: 91a79b792204 ("netfilter: nf_reject: don't leak dst refcount for loopback packets") and db99b2f2b3e2 ("netfilter: nf_reject: don't reply to icmp error messages") Signed-off-by: Florian Westphal --- .../testcases/packetpath/reject_loopback | 223 ++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100755 tests/shell/testcases/packetpath/reject_loopback diff --git a/tests/shell/testcases/packetpath/reject_loopback b/tests/shell/testcases/packetpath/reject_loopback new file mode 100755 index 000000000000..d199b1275f3f --- /dev/null +++ b/tests/shell/testcases/packetpath/reject_loopback @@ -0,0 +1,223 @@ +#!/bin/bash + +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_socat) + +# Tests reject functionality for both IPv4 and IPv6 with TCP and ICMP traffic on +# the loopback interface. +# +# - check reject works, i.e. ping and connect fail +# - check we don't reply to tcp resets with another tcp reset +# - check we don't reply to icmp error with another icmp error + +ret=0 +port=14512 + +ip link set lo up + +load_ruleset_netdev() +{ +echo load netdev test ruleset +$NFT -f -< /dev/null + maybe_error $? "$err_wanted" "ping 127.0.0.1" + + socat -u STDIN TCP-CONNECT:127.0.0.1:$port,connect-timeout=1 < /dev/null 2>/dev/null + maybe_error $? "$err_wanted" "connect 127.0.0.1" + + ping -W 1 -q -c 1 ::1 > /dev/null + maybe_error $? "$err_wanted" "connect 127.0.0.1" + + socat -u STDIN TCP-CONNECT:[::1]:$port,connect-timeout=1 < /dev/null 2>/dev/null + maybe_error $? "$err_wanted" "connect ::1" +} + +# Start socat listeners in background +timeout 10 socat TCP-LISTEN:$port,bind=127.0.0.1,reuseaddr PIPE & +SOCAT_PID4=$! + +timeout 10 socat TCP6-LISTEN:$port,bind=::1,reuseaddr PIPE & +SOCAT_PID6=$! + +# Give listeners time to start +sleep 1 + +# empty ruleset +test_all 0 + +load_ruleset_inet +test_all 1 +$NFT delete table inet t + +load_ruleset_netdev +test_all 1 +$NFT delete table netdev t + +load_ruleset_inet_loop +test_all 1 +check_counters inet +$NFT delete table inet t + +load_ruleset_netdev_loop +test_all 1 +check_counters netdev +$NFT delete table netdev t + +# Clean up listeners +kill $SOCAT_PID4 $SOCAT_PID6 2>/dev/null + +echo "Exiting with $ret" +exit $ret -- 2.49.1