Skip to content

Commit 47898d7

Browse files
oscar-maesNipaLocal
authored andcommitted
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> Signed-off-by: NipaLocal <nipa@local>
1 parent ed0f611 commit 47898d7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# This test ensures directed broadcast routes use dst hint mechanism
5+
6+
CLIENT_NS=$(mktemp -u client-XXXXXXXX)
7+
CLIENT_IP4="192.168.0.1"
8+
9+
SERVER_NS=$(mktemp -u server-XXXXXXXX)
10+
SERVER_IP4="192.168.0.2"
11+
12+
BROADCAST_ADDRESS="192.168.0.255"
13+
14+
setup() {
15+
ip netns add "${CLIENT_NS}"
16+
ip netns add "${SERVER_NS}"
17+
18+
ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
19+
20+
ip -net "${CLIENT_NS}" link set link0 up
21+
ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
22+
23+
ip -net "${SERVER_NS}" link set link1 up
24+
ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
25+
26+
ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
27+
ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
28+
ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
29+
ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
30+
}
31+
32+
cleanup() {
33+
ip -net "${SERVER_NS}" link del link1
34+
ip netns del "${CLIENT_NS}"
35+
ip netns del "${SERVER_NS}"
36+
}
37+
38+
directed_bcast_hint_test()
39+
{
40+
echo "Testing for directed broadcast route hint"
41+
42+
orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
43+
ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
44+
-B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
45+
sleep 1
46+
new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
47+
48+
res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
49+
50+
[ "${res}" -lt 100 ]
51+
}
52+
53+
trap cleanup EXIT
54+
55+
setup
56+
57+
directed_bcast_hint_test
58+
exit $?

0 commit comments

Comments
 (0)