1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# This test uses standard topology for testing gretap. See 5# mirror_gre_topo_lib.sh for more details. 6# 7# Test how mirrors to gretap and ip6gretap react to changes to relevant 8# configuration. 9 10ALL_TESTS=" 11 test_ttl 12 test_tun_up 13 test_egress_up 14 test_remote_ip 15 test_tun_del 16 test_route_del 17" 18 19NUM_NETIFS=6 20source lib.sh 21source mirror_lib.sh 22source mirror_gre_lib.sh 23source mirror_gre_topo_lib.sh 24 25setup_prepare() 26{ 27 h1=${NETIFS[p1]} 28 swp1=${NETIFS[p2]} 29 30 swp2=${NETIFS[p3]} 31 h2=${NETIFS[p4]} 32 33 swp3=${NETIFS[p5]} 34 h3=${NETIFS[p6]} 35 36 vrf_prepare 37 mirror_gre_topo_create 38 39 # This test downs $swp3, which deletes the configured IPv6 address 40 # unless this sysctl is set. 41 sysctl_set net.ipv6.conf.$swp3.keep_addr_on_down 1 42 43 ip address add dev $swp3 192.0.2.129/28 44 ip address add dev $h3 192.0.2.130/28 45 46 ip address add dev $swp3 2001:db8:2::1/64 47 ip address add dev $h3 2001:db8:2::2/64 48} 49 50cleanup() 51{ 52 pre_cleanup 53 54 ip address del dev $h3 2001:db8:2::2/64 55 ip address del dev $swp3 2001:db8:2::1/64 56 57 ip address del dev $h3 192.0.2.130/28 58 ip address del dev $swp3 192.0.2.129/28 59 60 sysctl_restore net.ipv6.conf.$swp3.keep_addr_on_down 61 62 mirror_gre_topo_destroy 63 vrf_cleanup 64} 65 66test_span_gre_ttl() 67{ 68 local tundev=$1; shift 69 local type=$1; shift 70 local prot=$1; shift 71 local what=$1; shift 72 73 RET=0 74 75 mirror_install $swp1 ingress $tundev \ 76 "prot ip flower $tcflags ip_prot icmp" 77 tc filter add dev $h3 ingress pref 77 prot $prot \ 78 flower skip_hw ip_ttl 50 action pass 79 80 mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 0 81 82 ip link set dev $tundev type $type ttl 50 83 sleep 2 84 mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10 85 86 ip link set dev $tundev type $type ttl 100 87 tc filter del dev $h3 ingress pref 77 88 mirror_uninstall $swp1 ingress 89 90 log_test "$what: TTL change ($tcflags)" 91} 92 93test_span_gre_tun_up() 94{ 95 local tundev=$1; shift 96 local what=$1; shift 97 98 RET=0 99 100 ip link set dev $tundev down 101 mirror_install $swp1 ingress $tundev "matchall $tcflags" 102 fail_test_span_gre_dir $tundev ingress 103 104 ip link set dev $tundev up 105 106 quick_test_span_gre_dir $tundev ingress 107 mirror_uninstall $swp1 ingress 108 109 log_test "$what: tunnel down/up ($tcflags)" 110} 111 112test_span_gre_egress_up() 113{ 114 local tundev=$1; shift 115 local remote_ip=$1; shift 116 local what=$1; shift 117 118 RET=0 119 120 ip link set dev $swp3 down 121 mirror_install $swp1 ingress $tundev "matchall $tcflags" 122 fail_test_span_gre_dir $tundev ingress 123 124 # After setting the device up, wait for neighbor to get resolved so that 125 # we can expect mirroring to work. 126 ip link set dev $swp3 up 127 setup_wait_dev $swp3 128 ping -c 1 -I $swp3 $remote_ip &>/dev/null 129 130 quick_test_span_gre_dir $tundev ingress 131 mirror_uninstall $swp1 ingress 132 133 log_test "$what: egress down/up ($tcflags)" 134} 135 136test_span_gre_remote_ip() 137{ 138 local tundev=$1; shift 139 local type=$1; shift 140 local correct_ip=$1; shift 141 local wrong_ip=$1; shift 142 local what=$1; shift 143 144 RET=0 145 146 ip link set dev $tundev type $type remote $wrong_ip 147 mirror_install $swp1 ingress $tundev "matchall $tcflags" 148 fail_test_span_gre_dir $tundev ingress 149 150 ip link set dev $tundev type $type remote $correct_ip 151 quick_test_span_gre_dir $tundev ingress 152 mirror_uninstall $swp1 ingress 153 154 log_test "$what: remote address change ($tcflags)" 155} 156 157test_span_gre_tun_del() 158{ 159 local tundev=$1; shift 160 local type=$1; shift 161 local flags=$1; shift 162 local local_ip=$1; shift 163 local remote_ip=$1; shift 164 local what=$1; shift 165 166 RET=0 167 168 mirror_install $swp1 ingress $tundev "matchall $tcflags" 169 quick_test_span_gre_dir $tundev ingress 170 ip link del dev $tundev 171 fail_test_span_gre_dir $tundev ingress 172 173 tunnel_create $tundev $type $local_ip $remote_ip \ 174 ttl 100 tos inherit $flags 175 176 # Recreating the tunnel doesn't reestablish mirroring, so reinstall it 177 # and verify it works for the follow-up tests. 178 mirror_uninstall $swp1 ingress 179 mirror_install $swp1 ingress $tundev "matchall $tcflags" 180 quick_test_span_gre_dir $tundev ingress 181 mirror_uninstall $swp1 ingress 182 183 log_test "$what: tunnel deleted ($tcflags)" 184} 185 186test_span_gre_route_del() 187{ 188 local tundev=$1; shift 189 local edev=$1; shift 190 local route=$1; shift 191 local what=$1; shift 192 193 RET=0 194 195 mirror_install $swp1 ingress $tundev "matchall $tcflags" 196 quick_test_span_gre_dir $tundev ingress 197 198 ip route del $route dev $edev 199 fail_test_span_gre_dir $tundev ingress 200 201 ip route add $route dev $edev 202 quick_test_span_gre_dir $tundev ingress 203 204 mirror_uninstall $swp1 ingress 205 206 log_test "$what: underlay route removal ($tcflags)" 207} 208 209test_ttl() 210{ 211 test_span_gre_ttl gt4 gretap ip "mirror to gretap" 212 test_span_gre_ttl gt6 ip6gretap ipv6 "mirror to ip6gretap" 213} 214 215test_tun_up() 216{ 217 test_span_gre_tun_up gt4 "mirror to gretap" 218 test_span_gre_tun_up gt6 "mirror to ip6gretap" 219} 220 221test_egress_up() 222{ 223 test_span_gre_egress_up gt4 192.0.2.130 "mirror to gretap" 224 test_span_gre_egress_up gt6 2001:db8:2::2 "mirror to ip6gretap" 225} 226 227test_remote_ip() 228{ 229 test_span_gre_remote_ip gt4 gretap 192.0.2.130 192.0.2.132 "mirror to gretap" 230 test_span_gre_remote_ip gt6 ip6gretap 2001:db8:2::2 2001:db8:2::4 "mirror to ip6gretap" 231} 232 233test_tun_del() 234{ 235 test_span_gre_tun_del gt4 gretap "" \ 236 192.0.2.129 192.0.2.130 "mirror to gretap" 237 test_span_gre_tun_del gt6 ip6gretap allow-localremote \ 238 2001:db8:2::1 2001:db8:2::2 "mirror to ip6gretap" 239} 240 241test_route_del() 242{ 243 test_span_gre_route_del gt4 $swp3 192.0.2.128/28 "mirror to gretap" 244 test_span_gre_route_del gt6 $swp3 2001:db8:2::/64 "mirror to ip6gretap" 245} 246 247test_all() 248{ 249 slow_path_trap_install $swp1 ingress 250 slow_path_trap_install $swp1 egress 251 252 tests_run 253 254 slow_path_trap_uninstall $swp1 egress 255 slow_path_trap_uninstall $swp1 ingress 256} 257 258trap cleanup EXIT 259 260setup_prepare 261setup_wait 262 263tcflags="skip_hw" 264test_all 265 266if ! tc_offload_check; then 267 echo "WARN: Could not test offloaded functionality" 268else 269 tcflags="skip_sw" 270 test_all 271fi 272 273exit $EXIT_STATUS 274