207 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# +---------------------+ +---------------------+5# | H1 | | H2 |6# | + $h1 | | $h2 + |7# | | 192.0.2.1/28 | | 192.0.2.2/28 | |8# +-----|---------------+ +---------------|-----+9# | |10# +-----|-------------------------------------------------------------|-----+11# | SW o--> mirror | |12# | +---|-------------------------------------------------------------|---+ |13# | | + $swp1 BR $swp2 + | |14# | +---------------------------------------------------------------------+ |15# | |16# | +---------------------------------------------------------------------+ |17# | | OL + gt6 (ip6gretap) + gt4 (gretap) | |18# | | : loc=2001:db8:2::1 : loc=192.0.2.129 | |19# | | : rem=2001:db8:2::2 : rem=192.0.2.130 | |20# | | : ttl=100 : ttl=100 | |21# | | : tos=inherit : tos=inherit | |22# | +-------------------------:--|-------------------:--|-----------------+ |23# | : | : | |24# | +-------------------------:--|-------------------:--|-----------------+ |25# | | UL : |,---------------------' | |26# | | + $swp3 : || : | |27# | | | 192.0.2.129/28 : vv : | |28# | | | 2001:db8:2::1/64 : + ul (dummy) : | |29# | +---|---------------------:----------------------:--------------------+ |30# +-----|---------------------:----------------------:----------------------+31# | : :32# +-----|---------------------:----------------------:----------------------+33# | H3 + $h3 + h3-gt6 (ip6gretap) + h3-gt4 (gretap) |34# | 192.0.2.130/28 loc=2001:db8:2::2 loc=192.0.2.130 |35# | 2001:db8:2::2/64 rem=2001:db8:2::1 rem=192.0.2.129 |36# | ttl=100 ttl=100 |37# | tos=inherit tos=inherit |38# | |39# +-------------------------------------------------------------------------+40#41# This tests mirroring to gretap and ip6gretap configured in an overlay /42# underlay manner, i.e. with a bound dummy device that marks underlay VRF where43# the encapsulated packed should be routed.44 45ALL_TESTS="46 test_gretap47 test_ip6gretap48"49 50NUM_NETIFS=651source lib.sh52source mirror_lib.sh53source mirror_gre_lib.sh54 55h1_create()56{57 simple_if_init $h1 192.0.2.1/2858}59 60h1_destroy()61{62 simple_if_fini $h1 192.0.2.1/2863}64 65h2_create()66{67 simple_if_init $h2 192.0.2.2/2868}69 70h2_destroy()71{72 simple_if_fini $h2 192.0.2.2/2873}74 75h3_create()76{77 simple_if_init $h3 192.0.2.130/28 2001:db8:2::2/6478 79 tunnel_create h3-gt4 gretap 192.0.2.130 192.0.2.12980 ip link set h3-gt4 vrf v$h381 matchall_sink_create h3-gt482 83 tunnel_create h3-gt6 ip6gretap 2001:db8:2::2 2001:db8:2::184 ip link set h3-gt6 vrf v$h385 matchall_sink_create h3-gt686}87 88h3_destroy()89{90 tunnel_destroy h3-gt691 tunnel_destroy h3-gt492 93 simple_if_fini $h3 192.0.2.130/28 2001:db8:2::2/6494}95 96switch_create()97{98 # Bridge between H1 and H2.99 100 ip link add name br1 type bridge vlan_filtering 1101 ip link set dev br1 addrgenmode none102 ip link set dev br1 up103 104 ip link set dev $swp1 master br1105 ip link set dev $swp1 up106 107 ip link set dev $swp2 master br1108 ip link set dev $swp2 up109 110 tc qdisc add dev $swp1 clsact111 112 # Underlay.113 114 simple_if_init $swp3 192.0.2.129/28 2001:db8:2::1/64115 116 ip link add name ul type dummy117 ip link set dev ul master v$swp3118 ip link set dev ul up119 120 # Overlay.121 122 vrf_create vrf-ol123 ip link set dev vrf-ol up124 125 tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \126 ttl 100 tos inherit dev ul127 ip link set dev gt4 master vrf-ol128 ip link set dev gt4 up129 130 tunnel_create gt6 ip6gretap 2001:db8:2::1 2001:db8:2::2 \131 ttl 100 tos inherit dev ul allow-localremote132 ip link set dev gt6 master vrf-ol133 ip link set dev gt6 up134}135 136switch_destroy()137{138 vrf_destroy vrf-ol139 140 tunnel_destroy gt6141 tunnel_destroy gt4142 143 simple_if_fini $swp3 192.0.2.129/28 2001:db8:2::1/64144 145 ip link del dev ul146 147 tc qdisc del dev $swp1 clsact148 149 ip link set dev $swp1 down150 ip link set dev $swp2 down151 ip link del dev br1152}153 154setup_prepare()155{156 h1=${NETIFS[p1]}157 swp1=${NETIFS[p2]}158 159 swp2=${NETIFS[p3]}160 h2=${NETIFS[p4]}161 162 swp3=${NETIFS[p5]}163 h3=${NETIFS[p6]}164 165 vrf_prepare166 167 h1_create168 h2_create169 h3_create170 171 switch_create172}173 174cleanup()175{176 pre_cleanup177 178 switch_destroy179 180 h3_destroy181 h2_destroy182 h1_destroy183 184 vrf_cleanup185}186 187test_gretap()188{189 full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap w/ UL"190 full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap w/ UL"191}192 193test_ip6gretap()194{195 full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap w/ UL"196 full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap w/ UL"197}198 199trap cleanup EXIT200 201setup_prepare202setup_wait203 204tests_run205 206exit $EXIT_STATUS207