1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# This test uses standard topology for testing gretap. See 5# ../../../net/forwarding/mirror_gre_topo_lib.sh for more details. 6# 7# Test offloading various features of offloading gretap mirrors specific to 8# mlxsw. 9 10lib_dir=$(dirname $0)/../../../net/forwarding 11 12NUM_NETIFS=6 13source $lib_dir/lib.sh 14source $lib_dir/mirror_lib.sh 15source $lib_dir/mirror_gre_lib.sh 16source $lib_dir/mirror_gre_topo_lib.sh 17 18setup_keyful() 19{ 20 tunnel_create gt6-key ip6gretap 2001:db8:3::1 2001:db8:3::2 \ 21 ttl 100 tos inherit allow-localremote \ 22 key 1234 23 24 tunnel_create h3-gt6-key ip6gretap 2001:db8:3::2 2001:db8:3::1 \ 25 key 1234 26 ip link set h3-gt6-key vrf v$h3 27 matchall_sink_create h3-gt6-key 28 29 ip address add dev $swp3 2001:db8:3::1/64 30 ip address add dev $h3 2001:db8:3::2/64 31} 32 33cleanup_keyful() 34{ 35 ip address del dev $h3 2001:db8:3::2/64 36 ip address del dev $swp3 2001:db8:3::1/64 37 38 tunnel_destroy h3-gt6-key 39 tunnel_destroy gt6-key 40} 41 42setup_soft() 43{ 44 # Set up a topology for testing underlay routes that point at an 45 # unsupported soft device. 46 47 tunnel_create gt6-soft ip6gretap 2001:db8:4::1 2001:db8:4::2 \ 48 ttl 100 tos inherit allow-localremote 49 50 tunnel_create h3-gt6-soft ip6gretap 2001:db8:4::2 2001:db8:4::1 51 ip link set h3-gt6-soft vrf v$h3 52 matchall_sink_create h3-gt6-soft 53 54 ip link add name v1 type veth peer name v2 55 ip link set dev v1 up 56 ip address add dev v1 2001:db8:4::1/64 57 58 ip link set dev v2 vrf v$h3 59 ip link set dev v2 up 60 ip address add dev v2 2001:db8:4::2/64 61} 62 63cleanup_soft() 64{ 65 ip link del dev v1 66 67 tunnel_destroy h3-gt6-soft 68 tunnel_destroy gt6-soft 69} 70 71setup_prepare() 72{ 73 h1=${NETIFS[p1]} 74 swp1=${NETIFS[p2]} 75 76 swp2=${NETIFS[p3]} 77 h2=${NETIFS[p4]} 78 79 swp3=${NETIFS[p5]} 80 h3=${NETIFS[p6]} 81 82 vrf_prepare 83 mirror_gre_topo_create 84 85 ip address add dev $swp3 2001:db8:2::1/64 86 ip address add dev $h3 2001:db8:2::2/64 87 88 ip address add dev $swp3 192.0.2.129/28 89 ip address add dev $h3 192.0.2.130/28 90 91 setup_keyful 92 setup_soft 93} 94 95cleanup() 96{ 97 pre_cleanup 98 99 cleanup_soft 100 cleanup_keyful 101 102 ip address del dev $h3 2001:db8:2::2/64 103 ip address del dev $swp3 2001:db8:2::1/64 104 105 ip address del dev $h3 192.0.2.130/28 106 ip address del dev $swp3 192.0.2.129/28 107 108 mirror_gre_topo_destroy 109 vrf_cleanup 110} 111 112test_span_gre_ttl_inherit() 113{ 114 local tundev=$1; shift 115 local type=$1; shift 116 local what=$1; shift 117 118 RET=0 119 120 ip link set dev $tundev type $type ttl inherit 121 mirror_install $swp1 ingress $tundev "matchall $tcflags" 122 fail_test_span_gre_dir $tundev ingress 123 124 ip link set dev $tundev type $type ttl 100 125 126 quick_test_span_gre_dir $tundev ingress 127 mirror_uninstall $swp1 ingress 128 129 log_test "$what: no offload on TTL of inherit ($tcflags)" 130} 131 132test_span_gre_tos_fixed() 133{ 134 local tundev=$1; shift 135 local type=$1; shift 136 local what=$1; shift 137 138 RET=0 139 140 ip link set dev $tundev type $type tos 0x10 141 mirror_install $swp1 ingress $tundev "matchall $tcflags" 142 fail_test_span_gre_dir $tundev ingress 143 144 ip link set dev $tundev type $type tos inherit 145 quick_test_span_gre_dir $tundev ingress 146 mirror_uninstall $swp1 ingress 147 148 log_test "$what: no offload on a fixed TOS ($tcflags)" 149} 150 151test_span_failable() 152{ 153 local should_fail=$1; shift 154 local tundev=$1; shift 155 local what=$1; shift 156 157 RET=0 158 159 mirror_install $swp1 ingress $tundev "matchall $tcflags" 160 if ((should_fail)); then 161 fail_test_span_gre_dir $tundev ingress 162 else 163 quick_test_span_gre_dir $tundev ingress 164 fi 165 mirror_uninstall $swp1 ingress 166 167 log_test "$what: should_fail=$should_fail ($tcflags)" 168} 169 170test_failable() 171{ 172 local should_fail=$1; shift 173 174 test_span_failable $should_fail gt6-key "mirror to keyful gretap" 175 test_span_failable $should_fail gt6-soft "mirror to gretap w/ soft underlay" 176} 177 178test_sw() 179{ 180 slow_path_trap_install $swp1 ingress 181 slow_path_trap_install $swp1 egress 182 183 test_failable 0 184 185 slow_path_trap_uninstall $swp1 egress 186 slow_path_trap_uninstall $swp1 ingress 187} 188 189test_hw() 190{ 191 test_failable 1 192 193 test_span_gre_tos_fixed gt4 gretap "mirror to gretap" 194 test_span_gre_tos_fixed gt6 ip6gretap "mirror to ip6gretap" 195 196 test_span_gre_ttl_inherit gt4 gretap "mirror to gretap" 197 test_span_gre_ttl_inherit gt6 ip6gretap "mirror to ip6gretap" 198} 199 200trap cleanup EXIT 201 202setup_prepare 203setup_wait 204 205if ! tc_offload_check; then 206 check_err 1 "Could not test offloaded functionality" 207 log_test "mlxsw-specific tests for mirror to gretap" 208 exit 209fi 210 211tcflags="skip_hw" 212test_sw 213 214tcflags="skip_sw" 215test_hw 216 217exit $EXIT_STATUS 218