1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# Test for "tc action mirred egress mirror" when the underlay route points at a 5# team device. 6# 7# +----------------------+ +----------------------+ 8# | H1 | | H2 | 9# | + $h1.333 | | $h1.555 + | 10# | | 192.0.2.1/28 | | 192.0.2.18/28 | | 11# +----|-----------------+ +----------------|-----+ 12# | $h1 | 13# +---------------------------------+------------------------------+ 14# | 15# +--------------------------------------|------------------------------------+ 16# | SW o---> mirror | 17# | | | 18# | +----------------------------------+------------------------------+ | 19# | | $swp1 | | 20# | + $swp1.333 $swp1.555 + | 21# | 192.0.2.2/28 192.0.2.17/28 | 22# | | 23# | | 24# | + gt4 (gretap) ,-> + lag1 (team) | 25# | loc=192.0.2.129 | | 192.0.2.129/28 | 26# | rem=192.0.2.130 --' | | 27# | ttl=100 | | 28# | tos=inherit | | 29# | _____________________|______________________ | 30# | / \ | 31# | / \ | 32# | + $swp3 + $swp4 | 33# +---|------------------------------------------------|----------------------+ 34# | | 35# +---|------------------------------------------------|----------------------+ 36# | + $h3 + $h4 H3 | 37# | \ / | 38# | \____________________________________________/ | 39# | | | 40# | + lag2 (team) ------> + gt4-dst (gretap) | 41# | 192.0.2.130/28 loc=192.0.2.130 | 42# | rem=192.0.2.129 | 43# | ttl=100 | 44# | tos=inherit | 45# | | 46# | | 47# | | 48# | | 49# +---------------------------------------------------------------------------+ 50 51ALL_TESTS=" 52 test_mirror_gretap_first 53 test_mirror_gretap_second 54" 55 56REQUIRE_TEAMD="yes" 57NUM_NETIFS=6 58source lib.sh 59source mirror_lib.sh 60 61vlan_host_create() 62{ 63 local if_name=$1; shift 64 local vid=$1; shift 65 local vrf_name=$1; shift 66 local ips=("${@}") 67 68 vrf_create $vrf_name 69 ip link set dev $vrf_name up 70 vlan_create $if_name $vid $vrf_name "${ips[@]}" 71} 72 73vlan_host_destroy() 74{ 75 local if_name=$1; shift 76 local vid=$1; shift 77 local vrf_name=$1; shift 78 79 vlan_destroy $if_name $vid 80 ip link set dev $vrf_name down 81 vrf_destroy $vrf_name 82} 83 84h1_create() 85{ 86 vlan_host_create $h1 333 vrf-h1 192.0.2.1/28 87 ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2 88} 89 90h1_destroy() 91{ 92 ip -4 route del 192.0.2.16/28 vrf vrf-h1 93 vlan_host_destroy $h1 333 vrf-h1 94} 95 96h2_create() 97{ 98 vlan_host_create $h1 555 vrf-h2 192.0.2.18/28 99 ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17 100} 101 102h2_destroy() 103{ 104 ip -4 route del 192.0.2.0/28 vrf vrf-h2 105 vlan_host_destroy $h1 555 vrf-h2 106} 107 108h3_create_team() 109{ 110 team_create lag2 lacp $h3 $h4 111 __simple_if_init lag2 vrf-h3 192.0.2.130/32 112 ip -4 route add vrf vrf-h3 192.0.2.129/32 dev lag2 113} 114 115h3_destroy_team() 116{ 117 ip -4 route del vrf vrf-h3 192.0.2.129/32 dev lag2 118 __simple_if_fini lag2 192.0.2.130/32 119 team_destroy lag2 120 121 ip link set dev $h3 down 122 ip link set dev $h4 down 123} 124 125h3_create() 126{ 127 vrf_create vrf-h3 128 ip link set dev vrf-h3 up 129 h3_create_team 130 131 tunnel_create gt4-dst gretap 192.0.2.130 192.0.2.129 \ 132 ttl 100 tos inherit 133 ip link set dev gt4-dst master vrf-h3 134 tc qdisc add dev gt4-dst clsact 135} 136 137h3_destroy() 138{ 139 tc qdisc del dev gt4-dst clsact 140 ip link set dev gt4-dst nomaster 141 tunnel_destroy gt4-dst 142 143 h3_destroy_team 144 ip link set dev vrf-h3 down 145 vrf_destroy vrf-h3 146} 147 148switch_create() 149{ 150 ip link set dev $swp1 up 151 tc qdisc add dev $swp1 clsact 152 vlan_create $swp1 333 "" 192.0.2.2/28 153 vlan_create $swp1 555 "" 192.0.2.17/28 154 155 tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \ 156 ttl 100 tos inherit 157 158 ip link set dev $swp3 up 159 ip link set dev $swp4 up 160 team_create lag1 lacp $swp3 $swp4 161 __addr_add_del lag1 add 192.0.2.129/32 162 ip -4 route add 192.0.2.130/32 dev lag1 163} 164 165switch_destroy() 166{ 167 ip -4 route del 192.0.2.130/32 dev lag1 168 __addr_add_del lag1 del 192.0.2.129/32 169 team_destroy lag1 170 171 ip link set dev $swp4 down 172 ip link set dev $swp3 down 173 174 tunnel_destroy gt4 175 176 vlan_destroy $swp1 555 177 vlan_destroy $swp1 333 178 tc qdisc del dev $swp1 clsact 179 ip link set dev $swp1 down 180} 181 182setup_prepare() 183{ 184 h1=${NETIFS[p1]} 185 swp1=${NETIFS[p2]} 186 187 swp3=${NETIFS[p3]} 188 h3=${NETIFS[p4]} 189 190 swp4=${NETIFS[p5]} 191 h4=${NETIFS[p6]} 192 193 vrf_prepare 194 195 ip link set dev $h1 up 196 h1_create 197 h2_create 198 h3_create 199 switch_create 200} 201 202cleanup() 203{ 204 pre_cleanup 205 206 switch_destroy 207 h3_destroy 208 h2_destroy 209 h1_destroy 210 ip link set dev $h1 down 211 212 vrf_cleanup 213} 214 215test_lag_slave() 216{ 217 local up_dev=$1; shift 218 local down_dev=$1; shift 219 local what=$1; shift 220 221 RET=0 222 223 mirror_install $swp1 ingress gt4 \ 224 "proto 802.1q flower vlan_id 333" 225 vlan_capture_install gt4-dst "vlan_ethtype ipv4 ip_proto icmp type 8" 226 227 # Move $down_dev away from the team. That will prompt change in 228 # txability of the connected device, without changing its upness. The 229 # driver should notice the txability change and move the traffic to the 230 # other slave. 231 ip link set dev $down_dev nomaster 232 sleep 2 233 mirror_test vrf-h1 192.0.2.1 192.0.2.18 gt4-dst 100 10 234 235 # Test lack of connectivity when neither slave is txable. 236 ip link set dev $up_dev nomaster 237 sleep 2 238 mirror_test vrf-h1 192.0.2.1 192.0.2.18 gt4-dst 100 0 239 240 vlan_capture_uninstall gt4-dst 241 mirror_uninstall $swp1 ingress 242 243 # Recreate H3's team device, because mlxsw, which this test is 244 # predominantly mean to test, requires a bottom-up construction and 245 # doesn't allow enslavement to a device that already has an upper. 246 h3_destroy_team 247 h3_create_team 248 # Wait for ${h,swp}{3,4}. 249 setup_wait 250 251 log_test "$what" 252} 253 254test_mirror_gretap_first() 255{ 256 test_lag_slave $h3 $h4 "mirror to gretap: LAG first slave" 257} 258 259test_mirror_gretap_second() 260{ 261 test_lag_slave $h4 $h3 "mirror to gretap: LAG second slave" 262} 263 264trap cleanup EXIT 265 266setup_prepare 267setup_wait 268 269tests_run 270 271exit $EXIT_STATUS 272