2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking drop monitor functionality.
7 # Kselftest framework requirement - SKIP code is 4.
10 # all tests in this script. Can be overridden with -t option
18 DEVLINK="devlink -N ns1"
19 NS_EXEC="ip netns exec ns1"
20 NETDEVSIM_PATH=/sys/bus/netdevsim/
22 DEV=netdevsim${DEV_ADDR}
23 DEVLINK_DEV=netdevsim/${DEV}
31 if [ ${rc} -eq ${expected} ]; then
32 printf " TEST: %-60s [ OK ]\n" "${msg}"
33 nsuccess=$((nsuccess+1))
37 printf " TEST: %-60s [FAIL]\n" "${msg}"
43 modprobe netdevsim &> /dev/null
47 $IP link add dummy10 up type dummy
49 $NS_EXEC echo "$DEV_ADDR 1" > ${NETDEVSIM_PATH}/new_device
51 local netdev=$($NS_EXEC ls ${NETDEVSIM_PATH}/devices/${DEV}/net/)
52 $IP link set dev $netdev up
59 $NS_EXEC echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
66 echo "Software drops test"
70 local dir=$(mktemp -d)
72 $TC qdisc add dev dummy10 clsact
73 $TC filter add dev dummy10 egress pref 1 handle 101 proto ip \
74 flower dst_ip 192.0.2.10 action drop
76 $NS_EXEC mausezahn dummy10 -a 00:11:22:33:44:55 -b 00:aa:bb:cc:dd:ee \
77 -A 192.0.2.1 -B 192.0.2.10 -t udp sp=12345,dp=54321 -c 0 -q \
79 timeout 5 dwdump -o sw -w ${dir}/packets.pcap
80 (( $(tshark -r ${dir}/packets.pcap \
81 -Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) != 0))
82 log_test $? 0 "Capturing active software drops"
84 rm ${dir}/packets.pcap
86 { kill %% && wait %%; } 2>/dev/null
87 timeout 5 dwdump -o sw -w ${dir}/packets.pcap
88 (( $(tshark -r ${dir}/packets.pcap \
89 -Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) == 0))
90 log_test $? 0 "Capturing inactive software drops"
100 echo "Hardware drops test"
104 local dir=$(mktemp -d)
106 $DEVLINK trap set $DEVLINK_DEV trap blackhole_route action trap
107 timeout 5 dwdump -o hw -w ${dir}/packets.pcap
108 (( $(tshark -r ${dir}/packets.pcap \
109 -Y 'net_dm.hw_trap_name== blackhole_route' 2> /dev/null \
111 log_test $? 0 "Capturing active hardware drops"
113 rm ${dir}/packets.pcap
115 $DEVLINK trap set $DEVLINK_DEV trap blackhole_route action drop
116 timeout 5 dwdump -o hw -w ${dir}/packets.pcap
117 (( $(tshark -r ${dir}/packets.pcap \
118 -Y 'net_dm.hw_trap_name== blackhole_route' 2> /dev/null \
120 log_test $? 0 "Capturing inactive hardware drops"
127 ################################################################################
135 -t <test> Test(s) to run (default: all)
140 ################################################################################
143 while getopts ":t:h" opt; do
151 if [ "$(id -u)" -ne 0 ];then
152 echo "SKIP: Need root privileges"
156 if [ ! -x "$(command -v ip)" ]; then
157 echo "SKIP: Could not run test without ip tool"
161 if [ ! -x "$(command -v devlink)" ]; then
162 echo "SKIP: Could not run test without devlink tool"
166 if [ ! -x "$(command -v tshark)" ]; then
167 echo "SKIP: Could not run test without tshark tool"
171 if [ ! -x "$(command -v dwdump)" ]; then
172 echo "SKIP: Could not run test without dwdump tool"
176 if [ ! -x "$(command -v udevadm)" ]; then
177 echo "SKIP: Could not run test without udevadm tool"
181 if [ ! -x "$(command -v timeout)" ]; then
182 echo "SKIP: Could not run test without timeout tool"
186 if [ ! -x "$(command -v mausezahn)" ]; then
187 echo "SKIP: Could not run test without mausezahn tool"
191 tshark -G fields 2> /dev/null | grep -q net_dm
192 if [ $? -ne 0 ]; then
193 echo "SKIP: tshark too old, missing net_dm dissector"
203 sw_drops|sw) sw_drops_test;;
204 hw_drops|hw) hw_drops_test;;
206 help) echo "Test names: $TESTS"; exit 0;;
210 if [ "$TESTS" != "none" ]; then
211 printf "\nTests passed: %3d\n" ${nsuccess}
212 printf "Tests failed: %3d\n" ${nfail}