xref: /linux/tools/testing/selftests/net/route_hint.sh (revision a7ddedc84c59a645ef970b992f7cda5bffc70cc0)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test ensures directed broadcast routes use dst hint mechanism
5
6source lib.sh
7
8CLIENT_IP4="192.168.0.1"
9SERVER_IP4="192.168.0.2"
10BROADCAST_ADDRESS="192.168.0.255"
11
12setup() {
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
29cleanup() {
30	ip -net "${SERVER_NS}" link del link1
31	cleanup_ns "${CLIENT_NS}" "${SERVER_NS}"
32}
33
34directed_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
59if [ ! -x "$(command -v mausezahn)" ]; then
60	echo "SKIP: Could not run test without mausezahn tool"
61	exit "${ksft_skip}"
62fi
63
64if [ ! -x "$(command -v jq)" ]; then
65	echo "SKIP: Could not run test without jq tool"
66	exit "${ksft_skip}"
67fi
68
69if [ ! -x "$(command -v bc)" ]; then
70	echo "SKIP: Could not run test without bc tool"
71	exit "${ksft_skip}"
72fi
73
74trap cleanup EXIT
75
76setup
77
78directed_bcast_hint_test
79exit $?
80