1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Testing For IPv4 and IPv6 BIG TCP. 5# TOPO: CLIENT_NS (link0)<--->(link1) ROUTER_NS (link2)<--->(link3) SERVER_NS 6 7CLIENT_NS=$(mktemp -u client-XXXXXXXX) 8CLIENT_IP4="198.51.100.1" 9CLIENT_IP6="2001:db8:1::1" 10 11SERVER_NS=$(mktemp -u server-XXXXXXXX) 12SERVER_IP4="203.0.113.1" 13SERVER_IP6="2001:db8:2::1" 14 15ROUTER_NS=$(mktemp -u router-XXXXXXXX) 16SERVER_GW4="203.0.113.2" 17CLIENT_GW4="198.51.100.2" 18SERVER_GW6="2001:db8:2::2" 19CLIENT_GW6="2001:db8:1::2" 20 21MAX_SIZE=128000 22CHK_SIZE=65535 23 24# Kselftest framework requirement - SKIP code is 4. 25ksft_skip=4 26 27setup() { 28 ip netns add $CLIENT_NS 29 ip netns add $SERVER_NS 30 ip netns add $ROUTER_NS 31 ip -net $ROUTER_NS link add link1 type veth peer name link0 netns $CLIENT_NS 32 ip -net $ROUTER_NS link add link2 type veth peer name link3 netns $SERVER_NS 33 34 ip -net $CLIENT_NS link set link0 up 35 ip -net $CLIENT_NS link set link0 mtu 1442 36 ip -net $CLIENT_NS addr add $CLIENT_IP4/24 dev link0 37 ip -net $CLIENT_NS addr add $CLIENT_IP6/64 dev link0 nodad 38 ip -net $CLIENT_NS route add $SERVER_IP4 dev link0 via $CLIENT_GW4 39 ip -net $CLIENT_NS route add $SERVER_IP6 dev link0 via $CLIENT_GW6 40 ip -net $CLIENT_NS link set dev link0 \ 41 gro_ipv4_max_size $MAX_SIZE gso_ipv4_max_size $MAX_SIZE 42 ip -net $CLIENT_NS link set dev link0 \ 43 gro_max_size $MAX_SIZE gso_max_size $MAX_SIZE 44 ip net exec $CLIENT_NS sysctl -wq net.ipv4.tcp_window_scaling=10 45 46 ip -net $ROUTER_NS link set link1 up 47 ip -net $ROUTER_NS link set link2 up 48 ip -net $ROUTER_NS addr add $CLIENT_GW4/24 dev link1 49 ip -net $ROUTER_NS addr add $CLIENT_GW6/64 dev link1 nodad 50 ip -net $ROUTER_NS addr add $SERVER_GW4/24 dev link2 51 ip -net $ROUTER_NS addr add $SERVER_GW6/64 dev link2 nodad 52 ip -net $ROUTER_NS link set dev link1 \ 53 gro_ipv4_max_size $MAX_SIZE gso_ipv4_max_size $MAX_SIZE 54 ip -net $ROUTER_NS link set dev link2 \ 55 gro_ipv4_max_size $MAX_SIZE gso_ipv4_max_size $MAX_SIZE 56 ip -net $ROUTER_NS link set dev link1 \ 57 gro_max_size $MAX_SIZE gso_max_size $MAX_SIZE 58 ip -net $ROUTER_NS link set dev link2 \ 59 gro_max_size $MAX_SIZE gso_max_size $MAX_SIZE 60 # test for nf_ct_skb_network_trim in nf_conntrack_ovs used by TC ct action. 61 ip net exec $ROUTER_NS tc qdisc add dev link1 ingress 62 ip net exec $ROUTER_NS tc filter add dev link1 ingress \ 63 proto ip flower ip_proto tcp action ct 64 ip net exec $ROUTER_NS tc filter add dev link1 ingress \ 65 proto ipv6 flower ip_proto tcp action ct 66 ip net exec $ROUTER_NS sysctl -wq net.ipv4.ip_forward=1 67 ip net exec $ROUTER_NS sysctl -wq net.ipv6.conf.all.forwarding=1 68 69 ip -net $SERVER_NS link set link3 up 70 ip -net $SERVER_NS addr add $SERVER_IP4/24 dev link3 71 ip -net $SERVER_NS addr add $SERVER_IP6/64 dev link3 nodad 72 ip -net $SERVER_NS route add $CLIENT_IP4 dev link3 via $SERVER_GW4 73 ip -net $SERVER_NS route add $CLIENT_IP6 dev link3 via $SERVER_GW6 74 ip -net $SERVER_NS link set dev link3 \ 75 gro_ipv4_max_size $MAX_SIZE gso_ipv4_max_size $MAX_SIZE 76 ip -net $SERVER_NS link set dev link3 \ 77 gro_max_size $MAX_SIZE gso_max_size $MAX_SIZE 78 ip net exec $SERVER_NS sysctl -wq net.ipv4.tcp_window_scaling=10 79 ip net exec $SERVER_NS netserver 2>&1 >/dev/null 80} 81 82cleanup() { 83 ip net exec $SERVER_NS pkill netserver 84 ip -net $ROUTER_NS link del link1 85 ip -net $ROUTER_NS link del link2 86 ip netns del "$CLIENT_NS" 87 ip netns del "$SERVER_NS" 88 ip netns del "$ROUTER_NS" 89} 90 91start_counter() { 92 local ipt="iptables" 93 local iface=$1 94 local netns=$2 95 96 [ "$NF" = "6" ] && ipt="ip6tables" 97 ip net exec $netns $ipt -t raw -A PREROUTING -i $iface \ 98 -m length ! --length 0:$CHK_SIZE -j ACCEPT 99} 100 101check_counter() { 102 local ipt="iptables" 103 local iface=$1 104 local netns=$2 105 106 [ "$NF" = "6" ] && ipt="ip6tables" 107 test `ip net exec $netns $ipt -t raw -L -v |grep $iface | awk '{print $1}'` != "0" 108} 109 110stop_counter() { 111 local ipt="iptables" 112 local iface=$1 113 local netns=$2 114 115 [ "$NF" = "6" ] && ipt="ip6tables" 116 ip net exec $netns $ipt -t raw -D PREROUTING -i $iface \ 117 -m length ! --length 0:$CHK_SIZE -j ACCEPT 118} 119 120do_netperf() { 121 local serip=$SERVER_IP4 122 local netns=$1 123 124 [ "$NF" = "6" ] && serip=$SERVER_IP6 125 ip net exec $netns netperf -$NF -t TCP_STREAM -H $serip 2>&1 >/dev/null 126} 127 128do_test() { 129 local cli_tso=$1 130 local gw_gro=$2 131 local gw_tso=$3 132 local ser_gro=$4 133 local ret="PASS" 134 135 ip net exec $CLIENT_NS ethtool -K link0 tso $cli_tso 136 ip net exec $ROUTER_NS ethtool -K link1 gro $gw_gro 137 ip net exec $ROUTER_NS ethtool -K link2 tso $gw_tso 138 ip net exec $SERVER_NS ethtool -K link3 gro $ser_gro 139 140 start_counter link1 $ROUTER_NS 141 start_counter link3 $SERVER_NS 142 do_netperf $CLIENT_NS 143 144 if check_counter link1 $ROUTER_NS; then 145 check_counter link3 $SERVER_NS || ret="FAIL_on_link3" 146 else 147 ret="FAIL_on_link1" 148 fi 149 150 stop_counter link1 $ROUTER_NS 151 stop_counter link3 $SERVER_NS 152 printf "%-9s %-8s %-8s %-8s: [%s]\n" \ 153 $cli_tso $gw_gro $gw_tso $ser_gro $ret 154 test $ret = "PASS" 155} 156 157testup() { 158 echo "CLI GSO | GW GRO | GW GSO | SER GRO" && \ 159 do_test "on" "on" "on" "on" && \ 160 do_test "on" "off" "on" "off" && \ 161 do_test "off" "on" "on" "on" && \ 162 do_test "on" "on" "off" "on" && \ 163 do_test "off" "on" "off" "on" 164} 165 166if ! netperf -V &> /dev/null; then 167 echo "SKIP: Could not run test without netperf tool" 168 exit $ksft_skip 169fi 170 171if ! ip link help 2>&1 | grep gso_ipv4_max_size &> /dev/null; then 172 echo "SKIP: Could not run test without gso/gro_ipv4_max_size supported in ip-link" 173 exit $ksft_skip 174fi 175 176trap cleanup EXIT 177setup && echo "Testing for BIG TCP:" && \ 178NF=4 testup && echo "***v4 Tests Done***" && \ 179NF=6 testup && echo "***v6 Tests Done***" 180exit $? 181