Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: net: add test for dst hint mechanism with directed broadcast addresses

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>

authored by

Oscar Maes and committed by
Jakub Kicinski
bd0d9e75 1b8c5fa0

+80
+1
tools/testing/selftests/net/Makefile
··· 117 117 TEST_PROGS += tfo_passive.sh 118 118 TEST_PROGS += broadcast_pmtu.sh 119 119 TEST_PROGS += ipv6_force_forwarding.sh 120 + TEST_PROGS += route_hint.sh 120 121 121 122 # YNL files, must be before "include ..lib.mk" 122 123 YNL_GEN_FILES := busy_poller netlink-dumps
+79
tools/testing/selftests/net/route_hint.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # This test ensures directed broadcast routes use dst hint mechanism 5 + 6 + source lib.sh 7 + 8 + CLIENT_IP4="192.168.0.1" 9 + SERVER_IP4="192.168.0.2" 10 + BROADCAST_ADDRESS="192.168.0.255" 11 + 12 + setup() { 13 + setup_ns CLIENT_NS SERVER_NS 14 + 15 + ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}" 16 + 17 + ip -net "${CLIENT_NS}" link set link0 up 18 + ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0 19 + 20 + ip -net "${SERVER_NS}" link set link1 up 21 + ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1 22 + 23 + ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off 24 + ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout" 25 + ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs" 26 + ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on 27 + } 28 + 29 + cleanup() { 30 + ip -net "${SERVER_NS}" link del link1 31 + cleanup_ns "${CLIENT_NS}" "${SERVER_NS}" 32 + } 33 + 34 + directed_bcast_hint_test() 35 + { 36 + local rc=0 37 + 38 + echo "Testing for directed broadcast route hint" 39 + 40 + orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd') 41 + ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \ 42 + -B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q 43 + sleep 1 44 + new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd') 45 + 46 + res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc) 47 + 48 + if [ "${res}" -lt 100 ]; then 49 + echo "[ OK ]" 50 + rc="${ksft_pass}" 51 + else 52 + echo "[FAIL] expected in_brd to be under 100, got ${res}" 53 + rc="${ksft_fail}" 54 + fi 55 + 56 + return "${rc}" 57 + } 58 + 59 + if [ ! -x "$(command -v mausezahn)" ]; then 60 + echo "SKIP: Could not run test without mausezahn tool" 61 + exit "${ksft_skip}" 62 + fi 63 + 64 + if [ ! -x "$(command -v jq)" ]; then 65 + echo "SKIP: Could not run test without jq tool" 66 + exit "${ksft_skip}" 67 + fi 68 + 69 + if [ ! -x "$(command -v bc)" ]; then 70 + echo "SKIP: Could not run test without bc tool" 71 + exit "${ksft_skip}" 72 + fi 73 + 74 + trap cleanup EXIT 75 + 76 + setup 77 + 78 + directed_bcast_hint_test 79 + exit $?