Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / router_nh.sh
blob92904b01eae97f88aab08e1a8756c929791c229e
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # +-------------------------+ +-------------------------+
5 # | H1 | | H2 |
6 # | $h1 + | | $h2 + |
7 # | 192.0.2.2/24 | | | 198.51.100.2/24 | |
8 # | 2001:db8:1::2/64 | | | 2001:db8:2::2/64 | |
9 # +-------------------|-----+ +-------------------|-----+
10 # | |
11 # +-------------------|----------------------------|-----+
12 # | R1 | | |
13 # | $rp1 + $rp2 + |
14 # | 192.0.2.1/24 198.51.100.1/24 |
15 # | 2001:db8:1::1/64 2001:db8:2::1/64 |
16 # +------------------------------------------------------+
18 ALL_TESTS="
19 ping_ipv4
20 ping_ipv6
23 NUM_NETIFS=4
24 source lib.sh
25 source tc_common.sh
27 h1_create()
29 vrf_create "vrf-h1"
30 ip link set dev $h1 master vrf-h1
32 ip link set dev vrf-h1 up
33 ip link set dev $h1 up
35 ip address add 192.0.2.2/24 dev $h1
36 ip address add 2001:db8:1::2/64 dev $h1
38 ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
39 ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
42 h1_destroy()
44 ip route del 2001:db8:2::/64 vrf vrf-h1
45 ip route del 198.51.100.0/24 vrf vrf-h1
47 ip address del 2001:db8:1::2/64 dev $h1
48 ip address del 192.0.2.2/24 dev $h1
50 ip link set dev $h1 down
51 vrf_destroy "vrf-h1"
54 h2_create()
56 vrf_create "vrf-h2"
57 ip link set dev $h2 master vrf-h2
59 ip link set dev vrf-h2 up
60 ip link set dev $h2 up
62 ip address add 198.51.100.2/24 dev $h2
63 ip address add 2001:db8:2::2/64 dev $h2
65 ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
66 ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
69 h2_destroy()
71 ip route del 2001:db8:1::/64 vrf vrf-h2
72 ip route del 192.0.2.0/24 vrf vrf-h2
74 ip address del 2001:db8:2::2/64 dev $h2
75 ip address del 198.51.100.2/24 dev $h2
77 ip link set dev $h2 down
78 vrf_destroy "vrf-h2"
81 router_create()
83 ip link set dev $rp1 up
84 ip link set dev $rp2 up
86 tc qdisc add dev $rp2 clsact
88 ip address add 192.0.2.1/24 dev $rp1
89 ip address add 2001:db8:1::1/64 dev $rp1
91 ip address add 198.51.100.1/24 dev $rp2
92 ip address add 2001:db8:2::1/64 dev $rp2
95 router_destroy()
97 ip address del 2001:db8:2::1/64 dev $rp2
98 ip address del 198.51.100.1/24 dev $rp2
100 ip address del 2001:db8:1::1/64 dev $rp1
101 ip address del 192.0.2.1/24 dev $rp1
103 tc qdisc del dev $rp2 clsact
105 ip link set dev $rp2 down
106 ip link set dev $rp1 down
109 routing_nh_obj()
111 # Create the nexthops as AF_INET6, so that IPv4 and IPv6 routes could
112 # use them.
113 ip -6 nexthop add id 101 dev $rp1
114 ip -6 nexthop add id 102 dev $rp2
116 ip route replace 192.0.2.0/24 nhid 101
117 ip route replace 2001:db8:1::/64 nhid 101
118 ip route replace 198.51.100.0/24 nhid 102
119 ip route replace 2001:db8:2::/64 nhid 102
122 setup_prepare()
124 h1=${NETIFS[p1]}
125 rp1=${NETIFS[p2]}
127 rp2=${NETIFS[p3]}
128 h2=${NETIFS[p4]}
130 rp1mac=$(mac_get $rp1)
132 vrf_prepare
134 h1_create
135 h2_create
137 router_create
139 forwarding_enable
142 cleanup()
144 pre_cleanup
146 forwarding_restore
148 router_destroy
150 h2_destroy
151 h1_destroy
153 vrf_cleanup
156 ping_ipv4()
158 ping_test $h1 198.51.100.2
161 ping_ipv6()
163 ping6_test $h1 2001:db8:2::2
166 trap cleanup EXIT
168 setup_prepare
169 setup_wait
170 routing_nh_obj
172 tests_run
174 exit $EXIT_STATUS