xref: /linux/tools/testing/selftests/net/nsh_gso.sh (revision f16d85cd3de9d0c761b74155b4cbe2f20d3dcf80)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Check software GSO of NSH packets: a TCP GSO packet behind a few NSH
5# headers is segmented, and a deep stack of NSH headers is dropped
6# instead of recursing in nsh_gso_segment() for each of them.
7
8source lib.sh
9
10NR_SEGS=4
11ret=0
12
13cleanup()
14{
15	cleanup_ns $ns1
16}
17
18tx_packets()
19{
20	ip netns exec $ns1 cat /sys/class/net/dummy0/statistics/tx_packets
21}
22
23# $1: number of NSH headers, $2: expected number of transmitted packets
24check_nsh_gso()
25{
26	local depth=$1
27	local expected=$2
28	local before
29	local sent
30
31	before=$(tx_packets)
32	ip netns exec $ns1 ./nsh_gso dummy0 $depth
33	sent=$(($(tx_packets) - before))
34
35	if [ $sent -eq $expected ]; then
36		echo "PASS: $depth NSH headers: $sent packets sent"
37	else
38		echo "FAIL: $depth NSH headers: $sent packets sent, expected $expected"
39		ret=1
40	fi
41}
42
43modprobe -q nsh
44nsh_loaded=$?
45
46trap cleanup EXIT
47setup_ns ns1 || exit $ksft_skip
48
49ip -netns $ns1 link add dummy0 type dummy
50ip -netns $ns1 link set dummy0 up
51# No IPv6 autoconf traffic on the device, to get stable counters.
52ip netns exec $ns1 sysctl -qw net.ipv6.conf.dummy0.disable_ipv6=1
53# Force software segmentation in validate_xmit_skb().
54ip netns exec $ns1 ethtool -K dummy0 tso off >/dev/null || exit $ksft_skip
55
56before=$(tx_packets)
57ip netns exec $ns1 ./nsh_gso dummy0 1
58if [ $(($(tx_packets) - before)) -eq 0 ] && [ $nsh_loaded -ne 0 ]; then
59	echo "SKIP: NSH GSO not available"
60	exit $ksft_skip
61fi
62
63check_nsh_gso 1 $NR_SEGS
64# The recursion limit is shared with the inner IPv4 header.
65check_nsh_gso 4 $NR_SEGS
66check_nsh_gso 5 0
67check_nsh_gso 64 0
68# The largest stack that fits in a 64KB header.
69check_nsh_gso 8000 0
70
71exit $ret
72