]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests: net: add test for dst hint mechanism with directed broadcast addresses
authorOscar Maes <oscmaes92@gmail.com>
Tue, 19 Aug 2025 17:46:42 +0000 (19:46 +0200)
committerJakub Kicinski <kuba@kernel.org>
Mon, 25 Aug 2025 23:07:16 +0000 (16:07 -0700)
Add a test for ensuring that the dst hint mechanism is used for
directed broadcast addresses.

This test relies on mausezahn for sending directed broadcast packets.
Additionally, a high GRO flush timeout is set to ensure that packets
will be received as lists.

The test determines if the hint mechanism was used by checking
the in_brd statistic using lnstat.

Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
Link: https://patch.msgid.link/20250819174642.5148-3-oscmaes92@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/route_hint.sh [new file with mode: 0755]

index b31a71f2b37295973ca5aec14dd540146f2d7570..eef0b8f8a7b06597a42b3535d13e521502a7acb5 100644 (file)
@@ -117,6 +117,7 @@ TEST_GEN_FILES += tfo
 TEST_PROGS += tfo_passive.sh
 TEST_PROGS += broadcast_pmtu.sh
 TEST_PROGS += ipv6_force_forwarding.sh
+TEST_PROGS += route_hint.sh
 
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := busy_poller netlink-dumps
diff --git a/tools/testing/selftests/net/route_hint.sh b/tools/testing/selftests/net/route_hint.sh
new file mode 100755 (executable)
index 0000000..2db01ec
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# This test ensures directed broadcast routes use dst hint mechanism
+
+source lib.sh
+
+CLIENT_IP4="192.168.0.1"
+SERVER_IP4="192.168.0.2"
+BROADCAST_ADDRESS="192.168.0.255"
+
+setup() {
+       setup_ns CLIENT_NS SERVER_NS
+
+       ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
+
+       ip -net "${CLIENT_NS}" link set link0 up
+       ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
+
+       ip -net "${SERVER_NS}" link set link1 up
+       ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
+
+       ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
+       ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
+       ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
+       ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
+}
+
+cleanup() {
+       ip -net "${SERVER_NS}" link del link1
+       cleanup_ns "${CLIENT_NS}" "${SERVER_NS}"
+}
+
+directed_bcast_hint_test()
+{
+       local rc=0
+
+       echo "Testing for directed broadcast route hint"
+
+       orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
+       ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
+               -B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
+       sleep 1
+       new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
+
+       res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
+
+       if [ "${res}" -lt 100 ]; then
+               echo "[ OK ]"
+               rc="${ksft_pass}"
+       else
+               echo "[FAIL] expected in_brd to be under 100, got ${res}"
+               rc="${ksft_fail}"
+       fi
+
+       return "${rc}"
+}
+
+if [ ! -x "$(command -v mausezahn)" ]; then
+       echo "SKIP: Could not run test without mausezahn tool"
+       exit "${ksft_skip}"
+fi
+
+if [ ! -x "$(command -v jq)" ]; then
+       echo "SKIP: Could not run test without jq tool"
+       exit "${ksft_skip}"
+fi
+
+if [ ! -x "$(command -v bc)" ]; then
+       echo "SKIP: Could not run test without bc tool"
+       exit "${ksft_skip}"
+fi
+
+trap cleanup EXIT
+
+setup
+
+directed_bcast_hint_test
+exit $?