1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="
5	ping_ipv4
6	ping_ipv6
7"
8NUM_NETIFS=4
9source lib.sh
10
11h1_create()
12{
13	simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
14	ip -4 route add 192.0.2.128/28 vrf v$h1 nexthop via 192.0.2.2
15	ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
16}
17
18h1_destroy()
19{
20	ip -6 route del 2001:db8:2::/64 vrf v$h1
21	ip -4 route del 192.0.2.128/28 vrf v$h1
22	simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
23}
24
25h2_create()
26{
27	simple_if_init $h2 192.0.2.130/28 2001:db8:2::2/64
28	ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.129
29	ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
30}
31
32h2_destroy()
33{
34	ip -6 route del 2001:db8:1::/64 vrf v$h2
35	ip -4 route del 192.0.2.0/28 vrf v$h2
36	simple_if_fini $h2 192.0.2.130/28 2001:db8:2::2/64
37}
38
39router_create()
40{
41	ip link add name br1 address $(mac_get $swp1) \
42		type bridge vlan_filtering 1
43	ip link set dev br1 up
44
45	ip link set dev $swp1 master br1
46	ip link set dev $swp1 up
47	__addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64
48
49	ip link set dev $swp2 up
50	__addr_add_del $swp2 add 192.0.2.129/28 2001:db8:2::1/64
51}
52
53router_destroy()
54{
55	__addr_add_del $swp2 del 192.0.2.129/28 2001:db8:2::1/64
56	ip link set dev $swp2 down
57
58	__addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64
59	ip link set dev $swp1 down
60	ip link set dev $swp1 nomaster
61
62	ip link del dev br1
63}
64
65setup_prepare()
66{
67	h1=${NETIFS[p1]}
68	swp1=${NETIFS[p2]}
69
70	swp2=${NETIFS[p3]}
71	h2=${NETIFS[p4]}
72
73	vrf_prepare
74
75	h1_create
76	h2_create
77
78	router_create
79
80	forwarding_enable
81}
82
83cleanup()
84{
85	pre_cleanup
86
87	forwarding_restore
88
89	router_destroy
90
91	h2_destroy
92	h1_destroy
93
94	vrf_cleanup
95}
96
97ping_ipv4()
98{
99	ping_test $h1 192.0.2.130
100}
101
102ping_ipv6()
103{
104	ping6_test $h1 2001:db8:2::2
105}
106
107trap cleanup EXIT
108
109setup_prepare
110setup_wait
111
112tests_run
113
114exit $EXIT_STATUS
115