1 # SPDX-License-Identifier: GPL-2.0
3 # Test offloading a number of mirrors-to-gretap. The test creates a number of
4 # tunnels. Then it adds one flower mirror for each of the tunnels, matching a
5 # given host IP. Then it generates traffic at each of the host IPs and checks
6 # that the traffic has been mirrored at the appropriate tunnel.
8 # +--------------------------+ +--------------------------+
11 # | | 2001:db8:1:X::1/64 | | 2001:db8:1:X::2/64 | |
12 # +-----|--------------------+ +--------------------|-----+
14 # +-----|-------------------------------------------------------------|-----+
15 # | SW o--> mirrors | |
16 # | +---|-------------------------------------------------------------|---+ |
17 # | | + $swp1 BR $swp2 + | |
18 # | +---------------------------------------------------------------------+ |
20 # | + $swp3 + gt6-<X> (ip6gretap) |
21 # | | 2001:db8:2:X::1/64 : loc=2001:db8:2:X::1 |
22 # | | : rem=2001:db8:2:X::2 |
26 # +-----|--------------------------------:----------------------------------+
28 # +-----|--------------------------------:----------------------------------+
29 # | H3 + $h3 + h3-gt6-<X> (ip6gretap) |
30 # | 2001:db8:2:X::2/64 loc=2001:db8:2:X::2 |
31 # | rem=2001:db8:2:X::1 |
35 # +-------------------------------------------------------------------------+
37 source ..
/..
/..
/..
/net
/forwarding
/mirror_lib.sh
41 mirror_gre_ipv6_addr
()
46 printf "2001:db8:%x:%x" $net $num
49 mirror_gre_tunnels_create
()
52 local should_fail
=$1; shift
54 MIRROR_GRE_BATCH_FILE
="$(mktemp)"
55 for ((i
=0; i
< count
; ++i
)); do
56 local match_dip
=$
(mirror_gre_ipv6_addr
1 $i)::2
60 ((mirror_gre_tunnels
++))
62 ip address add dev
$h1 $
(mirror_gre_ipv6_addr
1 $i)::1/64
63 ip address add dev
$h2 $
(mirror_gre_ipv6_addr
1 $i)::2/64
65 ip address add dev
$swp3 $
(mirror_gre_ipv6_addr
2 $i)::1/64
66 ip address add dev
$h3 $
(mirror_gre_ipv6_addr
2 $i)::2/64
68 tunnel_create
$tun ip6gretap \
69 $
(mirror_gre_ipv6_addr
2 $i)::1 \
70 $
(mirror_gre_ipv6_addr
2 $i)::2 \
71 ttl
100 tos inherit allow-localremote
73 tunnel_create
$htun ip6gretap \
74 $
(mirror_gre_ipv6_addr
2 $i)::2 \
75 $
(mirror_gre_ipv6_addr
2 $i)::1
76 ip link
set $htun vrf v
$h3
77 matchall_sink_create
$htun
79 cat >> $MIRROR_GRE_BATCH_FILE <<-EOF
80 filter add dev $swp1 ingress pref 1000 \
82 flower $tcflags dst_ip $match_dip \
83 action mirred egress mirror dev $tun
87 tc
-b $MIRROR_GRE_BATCH_FILE
88 check_err_fail
$should_fail $?
"Mirror rule insertion"
91 mirror_gre_tunnels_destroy
()
95 for ((i
=0; i
< count
; ++i
)); do
99 ip address del dev
$h3 $
(mirror_gre_ipv6_addr
2 $i)::2/64
100 ip address del dev
$swp3 $
(mirror_gre_ipv6_addr
2 $i)::1/64
102 ip address del dev
$h2 $
(mirror_gre_ipv6_addr
1 $i)::2/64
103 ip address del dev
$h1 $
(mirror_gre_ipv6_addr
1 $i)::1/64
112 local count
=$1; shift
113 local should_fail
=$1; shift
115 mirror_gre_tunnels_create
$count $should_fail
116 if ((should_fail
)); then
122 for ((i
= 0; i
< count
; ++i
)); do
123 local dip
=$
(mirror_gre_ipv6_addr
1 $i)::2
127 icmp6_capture_install
$htun
128 mirror_test v
$h1 "" $dip $htun 100 10
129 icmp6_capture_uninstall
$htun
135 local count
=$1; shift
136 local should_fail
=$1; shift
138 if ! tc_offload_check
$TC_FLOWER_NUM_NETIFS; then
139 check_err
1 "Could not test offloaded functionality"
144 __mirror_gre_test
$count $should_fail
147 mirror_gre_setup_prepare
()
166 ip link add name br1
type bridge vlan_filtering
1
167 ip link
set dev br1 up
169 ip link
set dev
$swp1 master br1
170 ip link
set dev
$swp1 up
171 tc qdisc add dev
$swp1 clsact
173 ip link
set dev
$swp2 master br1
174 ip link
set dev
$swp2 up
176 ip link
set dev
$swp3 up
181 mirror_gre_tunnels_destroy
$mirror_gre_tunnels
183 ip link
set dev
$swp3 down
185 ip link
set dev
$swp2 down
187 tc qdisc del dev
$swp1 clsact
188 ip link
set dev
$swp1 down