staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / one_armed_router.sh
blobf02d83e945767c9d9f626f503534fc1fdd060e3a
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test a "one-armed router" [1] scenario. Packets forwarded between H1 and H2
5 # should be forwarded by the ASIC, but also trapped so that ICMP redirect
6 # packets could be potentially generated.
8 # 1. https://en.wikipedia.org/wiki/One-armed_router
10 # +---------------------------------+
11 # | H1 (vrf) |
12 # | + $h1 |
13 # | | 192.0.2.1/24 |
14 # | | 2001:db8:1::1/64 |
15 # | | |
16 # | | default via 192.0.2.2 |
17 # | | default via 2001:db8:1::2 |
18 # +----|----------------------------+
19 # |
20 # +----|----------------------------------------------------------------------+
21 # | SW | |
22 # | +--|--------------------------------------------------------------------+ |
23 # | | + $swp1 BR0 (802.1d) | |
24 # | | | |
25 # | | 192.0.2.2/24 | |
26 # | | 2001:db8:1::2/64 | |
27 # | | 198.51.100.2/24 | |
28 # | | 2001:db8:2::2/64 | |
29 # | | | |
30 # | | + $swp2 | |
31 # | +--|--------------------------------------------------------------------+ |
32 # | | |
33 # +----|----------------------------------------------------------------------+
34 # |
35 # +----|----------------------------+
36 # | | default via 198.51.100.2 |
37 # | | default via 2001:db8:2::2 |
38 # | | |
39 # | | 2001:db8:2::1/64 |
40 # | | 198.51.100.1/24 |
41 # | + $h2 |
42 # | H2 (vrf) |
43 # +---------------------------------+
45 lib_dir=$(dirname $0)/../../../net/forwarding
47 ALL_TESTS="ping_ipv4 ping_ipv6 fwd_mark_ipv4 fwd_mark_ipv6"
48 NUM_NETIFS=4
49 source $lib_dir/tc_common.sh
50 source $lib_dir/lib.sh
52 h1_create()
54 simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
56 ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
57 ip -6 route add default vrf v$h1 nexthop via 2001:db8:1::2
60 h1_destroy()
62 ip -6 route del default vrf v$h1 nexthop via 2001:db8:1::2
63 ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
65 simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
68 h2_create()
70 simple_if_init $h2 198.51.100.1/24 2001:db8:2::1/64
72 ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
73 ip -6 route add default vrf v$h2 nexthop via 2001:db8:2::2
76 h2_destroy()
78 ip -6 route del default vrf v$h2 nexthop via 2001:db8:2::2
79 ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
81 simple_if_fini $h2 198.51.100.1/24 2001:db8:2::1/64
84 switch_create()
86 ip link add name br0 type bridge mcast_snooping 0
87 ip link set dev br0 up
89 ip link set dev $swp1 master br0
90 ip link set dev $swp1 up
91 ip link set dev $swp2 master br0
92 ip link set dev $swp2 up
94 tc qdisc add dev $swp1 clsact
95 tc qdisc add dev $swp2 clsact
97 __addr_add_del br0 add 192.0.2.2/24 2001:db8:1::2/64
98 __addr_add_del br0 add 198.51.100.2/24 2001:db8:2::2/64
101 switch_destroy()
103 __addr_add_del br0 del 198.51.100.2/24 2001:db8:2::2/64
104 __addr_add_del br0 del 192.0.2.2/24 2001:db8:1::2/64
106 tc qdisc del dev $swp2 clsact
107 tc qdisc del dev $swp1 clsact
109 ip link set dev $swp2 down
110 ip link set dev $swp2 nomaster
111 ip link set dev $swp1 down
112 ip link set dev $swp1 nomaster
114 ip link set dev br0 down
115 ip link del dev br0
118 ping_ipv4()
120 ping_test $h1 198.51.100.1 ": h1->h2"
123 ping_ipv6()
125 ping6_test $h1 2001:db8:2::1 ": h1->h2"
128 fwd_mark_ipv4()
130 # Transmit packets from H1 to H2 and make sure they are trapped at
131 # swp1 due to loopback error, but only forwarded by the ASIC through
132 # swp2
134 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
135 skip_hw dst_ip 198.51.100.1 ip_proto udp dst_port 52768 \
136 action pass
138 tc filter add dev $swp2 egress protocol ip pref 1 handle 101 flower \
139 skip_hw dst_ip 198.51.100.1 ip_proto udp dst_port 52768 \
140 action pass
142 tc filter add dev $swp2 egress protocol ip pref 2 handle 102 flower \
143 skip_sw dst_ip 198.51.100.1 ip_proto udp dst_port 52768 \
144 action pass
146 ip vrf exec v$h1 $MZ $h1 -c 10 -d 100msec -p 64 -A 192.0.2.1 \
147 -B 198.51.100.1 -t udp dp=52768,sp=42768 -q
149 RET=0
151 tc_check_packets "dev $swp1 ingress" 101 10
152 check_err $?
154 log_test "fwd mark: trapping IPv4 packets due to LBERROR"
156 RET=0
158 tc_check_packets "dev $swp2 egress" 101 0
159 check_err $?
161 log_test "fwd mark: forwarding IPv4 packets in software"
163 RET=0
165 tc_check_packets "dev $swp2 egress" 102 10
166 check_err $?
168 log_test "fwd mark: forwarding IPv4 packets in hardware"
170 tc filter del dev $swp2 egress protocol ip pref 2 handle 102 flower
171 tc filter del dev $swp2 egress protocol ip pref 1 handle 101 flower
172 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
175 fwd_mark_ipv6()
177 tc filter add dev $swp1 ingress protocol ipv6 pref 1 handle 101 flower \
178 skip_hw dst_ip 2001:db8:2::1 ip_proto udp dst_port 52768 \
179 action pass
181 tc filter add dev $swp2 egress protocol ipv6 pref 1 handle 101 flower \
182 skip_hw dst_ip 2001:db8:2::1 ip_proto udp dst_port 52768 \
183 action pass
185 tc filter add dev $swp2 egress protocol ipv6 pref 2 handle 102 flower \
186 skip_sw dst_ip 2001:db8:2::1 ip_proto udp dst_port 52768 \
187 action pass
189 ip vrf exec v$h1 $MZ $h1 -6 -c 10 -d 100msec -p 64 -A 2001:db8:1::1 \
190 -B 2001:db8:2::1 -t udp dp=52768,sp=42768 -q
192 RET=0
194 tc_check_packets "dev $swp1 ingress" 101 10
195 check_err $?
197 log_test "fwd mark: trapping IPv6 packets due to LBERROR"
199 RET=0
201 tc_check_packets "dev $swp2 egress" 101 0
202 check_err $?
204 log_test "fwd mark: forwarding IPv6 packets in software"
206 RET=0
208 tc_check_packets "dev $swp2 egress" 102 10
209 check_err $?
211 log_test "fwd mark: forwarding IPv6 packets in hardware"
213 tc filter del dev $swp2 egress protocol ipv6 pref 2 handle 102 flower
214 tc filter del dev $swp2 egress protocol ipv6 pref 1 handle 101 flower
215 tc filter del dev $swp1 ingress protocol ipv6 pref 1 handle 101 flower
218 setup_prepare()
220 h1=${NETIFS[p1]}
221 swp1=${NETIFS[p2]}
223 swp2=${NETIFS[p3]}
224 h2=${NETIFS[p4]}
226 vrf_prepare
227 forwarding_enable
229 sysctl_set net.ipv4.conf.all.accept_redirects 0
230 sysctl_set net.ipv6.conf.all.accept_redirects 0
232 h1_create
233 h2_create
234 switch_create
237 cleanup()
239 pre_cleanup
241 switch_destroy
242 h2_destroy
243 h1_destroy
245 sysctl_restore net.ipv6.conf.all.accept_redirects
246 sysctl_restore net.ipv4.conf.all.accept_redirects
248 forwarding_restore
249 vrf_cleanup
252 trap cleanup EXIT
254 setup_prepare
255 setup_wait
257 tests_run
259 exit $EXIT_STATUS