1 # SPDX-License-Identifier: GPL-2.0
4 # Handles creation and destruction of IP-in-IP or GRE tunnels over the given
5 # topology. Supports both flat and hierarchical models.
8 # Overlay and underlay share the same VRF.
9 # SW1 uses default VRF so tunnel has no bound dev.
10 # SW2 uses non-default VRF tunnel has a bound dev.
11 # +--------------------------------+
14 # | 198.51.100.1/24 | |
15 # | 2001:db8:1::1/64 | |
16 # +-------------------------|------+
18 # +-------------------------|-------------------+
22 # | 2001:db8:1::2/64 |
25 # | loc=2001:db8:3::1 |
26 # | rem=2001:db8:3::2 --. |
29 # | .--------------------- |
32 # | + $ul1.111 (vlan) |
33 # | | 2001:db8:10::1/64 |
37 # | VRF default + $ul1 |
38 # +---------------------|-----------------------+
40 # +---------------------|-----------------------+
46 # | + $ul2.111 (vlan) |
47 # | ^ 2001:db8:10::2/64 |
50 # | '----------------------. |
51 # | + g2a (ip6gre) | |
52 # | loc=2001:db8:3::2 | |
53 # | rem=2001:db8:3::1 --' |
57 # | | 203.0.113.2/24 |
58 # | VRF v$ol2 | 2001:db8:2::2/64 |
59 # +---------------------|-----------------------+
60 # +---------------------|----------+
64 # | 2001:db8:2::1/64 |
65 # +--------------------------------+
68 # The tunnel is bound to a device in a different VRF
70 # +--------------------------------+
73 # | 198.51.100.1/24 | |
74 # | 2001:db8:1::1/64 | |
75 # +-------------------------|------+
77 # +-------------------------|-------------------+
79 # | +-----------------------|-----------------+ |
81 # | | 198.51.100.2/24 | |
82 # | | 2001:db8:1::2/64 | |
84 # | | + g1a (ip6gre) | |
85 # | | loc=2001:db8:3::1 | |
86 # | | rem=2001:db8:3::2 | |
90 # | +--------------------|--------------------+ |
92 # | +--------------------|--------------------+ |
97 # | | 2001:db8:3::1/64 | |
98 # | | .-----------' | |
101 # | | + $ul1.111 (vlan) | |
102 # | | | 2001:db8:10::1/64 | |
104 # | | \__________ | |
107 # | +---------------------|-------------------+ |
108 # +-----------------------|---------------------+
110 # +-----------------------|---------------------+
112 # | +---------------------|-------------------+ |
117 # | | | $ul2.111 (vlan) | |
118 # | | + 2001:db8:10::2/64 | |
123 # | | 2001:db8:3::2/64 | |
127 # | | VRF v$ul2 | | |
128 # | +---------------------|-------------------+ |
130 # | +---------------------|-------------------+ |
131 # | | VRF v$ol2 | | |
134 # | | g2a (ip6gre) + | |
135 # | | loc=2001:db8:3::2 | |
136 # | | rem=2001:db8:3::1 | |
137 # | | tos=inherit | |
140 # | | 203.0.113.2/24 | | |
141 # | | 2001:db8:2::2/64 | | |
142 # | +---------------------|-------------------+ |
143 # +-----------------------|---------------------+
145 # +-----------------------|--------+
149 # | 2001:db8:2::1/64 |
150 # +--------------------------------+
157 simple_if_init
$h1 198.51.100.1/24 2001:db8
:1::1/64
158 ip route add vrf v
$h1 203.0.113.0/24 via
198.51.100.2
159 ip
-6 route add vrf v
$h1 2001:db8
:2::/64 via
2001:db8
:1::2
164 ip
-6 route del vrf v
$h1 2001:db8
:2::/64 via
2001:db8
:1::2
165 ip route del vrf v
$h1 203.0.113.0/24 via
198.51.100.2
166 simple_if_fini
$h1 198.51.100.1/24 2001:db8
:1::1/64
171 simple_if_init
$h2 203.0.113.1/24 2001:db8
:2::1/64
172 ip route add vrf v
$h2 198.51.100.0/24 via
203.0.113.2
173 ip
-6 route add vrf v
$h2 2001:db8
:1::/64 via
2001:db8
:2::2
178 ip
-6 route del vrf v
$h2 2001:db8
:1::/64 via
2001:db8
:2::2
179 ip route del vrf v
$h2 198.51.100.0/24 via
203.0.113.2
180 simple_if_fini
$h2 203.0.113.1/24 2001:db8
:2::1/64
188 ip link
set dev
$ol1 up
189 __addr_add_del
$ol1 add
198.51.100.2/24 2001:db8
:1::2/64
191 ip link
set dev
$ul1 up
192 vlan_create
$ul1 111 "" 2001:db8
:10::1/64
194 tunnel_create g1a ip6gre
2001:db8
:3::1 2001:db8
:3::2 tos inherit \
196 ip link
set dev g1a up
197 __addr_add_del g1a add
"2001:db8:3::1/128"
199 ip
-6 route add
2001:db8
:3::2/128 via
2001:db8
:10::2
200 ip route add
203.0.113.0/24 dev g1a
201 ip
-6 route add
2001:db8
:2::/64 dev g1a
209 ip
-6 route del
2001:db8
:2::/64
210 ip route del
203.0.113.0/24
211 ip
-6 route del
2001:db8
:3::2/128 via
2001:db8
:10::2
213 __simple_if_fini g1a
2001:db8
:3::1/128
216 vlan_destroy
$ul1 111
217 __simple_if_fini
$ul1
218 __simple_if_fini
$ol1 198.51.100.2/24 2001:db8
:1::2/64
226 simple_if_init
$ol2 203.0.113.2/24 2001:db8
:2::2/64
227 __simple_if_init
$ul2 v
$ol2
228 vlan_create
$ul2 111 v
$ol2 2001:db8
:10::2/64
230 tunnel_create g2a ip6gre
2001:db8
:3::2 2001:db8
:3::1 tos inherit \
231 ttl inherit dev v
$ol2 "$@"
232 __simple_if_init g2a v
$ol2 2001:db8
:3::2/128
234 # Replace neighbor to avoid 1 dropped packet due to "unresolved neigh"
235 ip neigh replace dev
$ol2 203.0.113.1 lladdr $
(mac_get
$h2)
236 ip
-6 neigh replace dev
$ol2 2001:db8
:2::1 lladdr $
(mac_get
$h2)
238 ip
-6 route add vrf v
$ol2 2001:db8
:3::1/128 via
2001:db8
:10::1
239 ip route add vrf v
$ol2 198.51.100.0/24 dev g2a
240 ip
-6 route add vrf v
$ol2 2001:db8
:1::/64 dev g2a
248 ip
-6 route del vrf v
$ol2 2001:db8
:2::/64
249 ip route del vrf v
$ol2 198.51.100.0/24
250 ip
-6 route del vrf v
$ol2 2001:db8
:3::1/128 via
2001:db8
:10::1
252 __simple_if_fini g2a
2001:db8
:3::2/128
255 vlan_destroy
$ul2 111
256 __simple_if_fini
$ul2
257 simple_if_fini
$ol2 203.0.113.2/24 2001:db8
:2::2/64
260 sw1_hierarchical_create
()
265 simple_if_init
$ol1 198.51.100.2/24 2001:db8
:1::2/64
267 ip link add name dummy1
type dummy
268 __simple_if_init dummy1 v
$ul1 2001:db8
:3::1/64
270 vlan_create
$ul1 111 v
$ul1 2001:db8
:10::1/64
271 tunnel_create g1a ip6gre
2001:db8
:3::1 2001:db8
:3::2 tos inherit \
272 ttl inherit dev dummy1
"$@"
273 ip link
set dev g1a master v
$ol1
275 ip
-6 route add vrf v
$ul1 2001:db8
:3::2/128 via
2001:db8
:10::2
276 ip route add vrf v
$ol1 203.0.113.0/24 dev g1a
277 ip
-6 route add vrf v
$ol1 2001:db8
:2::/64 dev g1a
280 sw1_hierarchical_destroy
()
285 ip
-6 route del vrf v
$ol1 2001:db8
:2::/64
286 ip route del vrf v
$ol1 203.0.113.0/24
287 ip
-6 route del vrf v
$ul1 2001:db8
:3::2/128
290 vlan_destroy
$ul1 111
292 __simple_if_fini dummy1
2001:db8
:3::1/64
293 ip link del dev dummy1
296 simple_if_fini
$ol1 198.51.100.2/24 2001:db8
:1::2/64
299 sw2_hierarchical_create
()
304 simple_if_init
$ol2 203.0.113.2/24 2001:db8
:2::2/64
307 ip link add name dummy2
type dummy
308 __simple_if_init dummy2 v
$ul2 2001:db8
:3::2/64
310 vlan_create
$ul2 111 v
$ul2 2001:db8
:10::2/64
311 tunnel_create g2a ip6gre
2001:db8
:3::2 2001:db8
:3::1 tos inherit \
312 ttl inherit dev dummy2
"$@"
313 ip link
set dev g2a master v
$ol2
315 # Replace neighbor to avoid 1 dropped packet due to "unresolved neigh"
316 ip neigh replace dev
$ol2 203.0.113.1 lladdr $
(mac_get
$h2)
317 ip
-6 neigh replace dev
$ol2 2001:db8
:2::1 lladdr $
(mac_get
$h2)
319 ip
-6 route add vrf v
$ul2 2001:db8
:3::1/128 via
2001:db8
:10::1
320 ip route add vrf v
$ol2 198.51.100.0/24 dev g2a
321 ip
-6 route add vrf v
$ol2 2001:db8
:1::/64 dev g2a
324 sw2_hierarchical_destroy
()
329 ip
-6 route del vrf v
$ol2 2001:db8
:2::/64
330 ip route del vrf v
$ol2 198.51.100.0/24
331 ip
-6 route del vrf v
$ul2 2001:db8
:3::1/128
334 vlan_destroy
$ul2 111
336 __simple_if_fini dummy2
2001:db8
:3::2/64
337 ip link del dev dummy2
340 simple_if_fini
$ol2 203.0.113.2/24 2001:db8
:2::2/64
343 test_traffic_ip4ip6
()
348 ol1mac
=$
(mac_get
$ol1)
350 tc qdisc add dev
$ul1 clsact
351 tc filter add dev
$ul1 egress proto all pref
1 handle
101 \
352 flower
$TC_FLAG action pass
354 tc qdisc add dev
$ol2 clsact
355 tc filter add dev
$ol2 egress protocol ipv4 pref
1 handle
101 \
356 flower
$TC_FLAG dst_ip
203.0.113.1 action pass
358 $MZ $h1 -c 1000 -p 64 -a $h1mac -b $ol1mac -A 198.51.100.1 \
359 -B 203.0.113.1 -t ip
-q -d $MZ_DELAY
361 # Check ports after encap and after decap.
362 tc_check_at_least_x_packets
"dev $ul1 egress" 101 1000
363 check_err $?
"Packets did not go through $ul1, tc_flag = $TC_FLAG"
365 tc_check_at_least_x_packets
"dev $ol2 egress" 101 1000
366 check_err $?
"Packets did not go through $ol2, tc_flag = $TC_FLAG"
370 tc filter del dev
$ol2 egress protocol ipv4 pref
1 handle
101 flower
371 tc qdisc del dev
$ol2 clsact
372 tc filter del dev
$ul1 egress proto all pref
1 handle
101 flower
373 tc qdisc del dev
$ul1 clsact
376 test_traffic_ip6ip6
()
381 ol1mac
=$
(mac_get
$ol1)
383 tc qdisc add dev
$ul1 clsact
384 tc filter add dev
$ul1 egress proto all pref
1 handle
101 \
385 flower
$TC_FLAG action pass
387 tc qdisc add dev
$ol2 clsact
388 tc filter add dev
$ol2 egress protocol ipv6 pref
1 handle
101 \
389 flower
$TC_FLAG dst_ip
2001:db8
:2::1 action pass
391 $MZ -6 $h1 -c 1000 -p 64 -a $h1mac -b $ol1mac -A 2001:db8
:1::1 \
392 -B 2001:db8
:2::1 -t ip
-q -d $MZ_DELAY
394 # Check ports after encap and after decap.
395 tc_check_at_least_x_packets
"dev $ul1 egress" 101 1000
396 check_err $?
"Packets did not go through $ul1, tc_flag = $TC_FLAG"
398 tc_check_at_least_x_packets
"dev $ol2 egress" 101 1000
399 check_err $?
"Packets did not go through $ol2, tc_flag = $TC_FLAG"
403 tc filter del dev
$ol2 egress protocol ipv6 pref
1 handle
101 flower
404 tc qdisc del dev
$ol2 clsact
405 tc filter del dev
$ul1 egress proto all pref
1 handle
101 flower
406 tc qdisc del dev
$ul1 clsact
413 ip link
set mtu
$mtu dev
$h1
414 ip link
set mtu
$mtu dev
$ol1
415 ip link
set mtu
$mtu dev g1a
416 ip link
set mtu
$mtu dev
$ul1
417 ip link
set mtu
$mtu dev
$ul1.111
418 ip link
set mtu
$mtu dev
$h2
419 ip link
set mtu
$mtu dev
$ol2
420 ip link
set mtu
$mtu dev g2a
421 ip link
set mtu
$mtu dev
$ul2
422 ip link
set mtu
$mtu dev
$ul2.111
429 ping6_do
$h1 2001:db8
:2::1 "-s 1800 -w 3"
430 check_fail $?
"ping GRE IPv6 should not pass with packet size 1800"
435 ping6_do
$h1 2001:db8
:2::1 "-s 1800 -w 3"
437 log_test
"ping GRE IPv6, packet size 1800 after MTU change"
440 topo_flat_remote_change
()
447 ip link
set dev g1a
type ip6gre
local $new1 remote
$new2
448 __addr_add_del g1a add
"$new1/128"
449 __addr_add_del g1a del
"$old1/128"
450 ip
-6 route add
$new2/128 via
2001:db8
:10::2
451 ip
-6 route del
$old2/128
453 ip link
set dev g2a
type ip6gre
local $new2 remote
$new1
454 __addr_add_del g2a add
"$new2/128"
455 __addr_add_del g2a del
"$old2/128"
456 ip
-6 route add vrf v
$ol2 $new1/128 via
2001:db8
:10::1
457 ip
-6 route del vrf v
$ol2 $old1/128
462 local old1
=2001:db8
:3::1
463 local new1
=2001:db8
:3::10
464 local old2
=2001:db8
:3::2
465 local new2
=2001:db8
:3::20
467 topo_flat_remote_change
$old1 $new1 $old2 $new2
470 flat_remote_restore
()
472 local old1
=2001:db8
:3::10
473 local new1
=2001:db8
:3::1
474 local old2
=2001:db8
:3::20
475 local new2
=2001:db8
:3::2
477 topo_flat_remote_change
$old1 $new1 $old2 $new2
480 topo_hier_remote_change
()
487 __addr_add_del dummy1 del
"$old1/64"
488 __addr_add_del dummy1 add
"$new1/64"
489 ip link
set dev g1a
type ip6gre
local $new1 remote
$new2
490 ip
-6 route add vrf v
$ul1 $new2/128 via
2001:db8
:10::2
491 ip
-6 route del vrf v
$ul1 $old2/128
493 __addr_add_del dummy2 del
"$old2/64"
494 __addr_add_del dummy2 add
"$new2/64"
495 ip link
set dev g2a
type ip6gre
local $new2 remote
$new1
496 ip
-6 route add vrf v
$ul2 $new1/128 via
2001:db8
:10::1
497 ip
-6 route del vrf v
$ul2 $old1/128
502 local old1
=2001:db8
:3::1
503 local new1
=2001:db8
:3::10
504 local old2
=2001:db8
:3::2
505 local new2
=2001:db8
:3::20
507 topo_hier_remote_change
$old1 $new1 $old2 $new2
510 hier_remote_restore
()
512 local old1
=2001:db8
:3::10
513 local new1
=2001:db8
:3::1
514 local old2
=2001:db8
:3::20
515 local new2
=2001:db8
:3::2
517 topo_hier_remote_change
$old1 $new1 $old2 $new2