staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / blackhole_routes.sh
blob5ba5bef44d5b17989dbc6ba22c081c33cce4421c
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test that blackhole routes are marked as offloaded and that packets hitting
5 # them are dropped by the ASIC and not by the kernel.
7 # +---------------------------------+
8 # | H1 (vrf) |
9 # | + $h1 |
10 # | | 192.0.2.1/24 |
11 # | | 2001:db8:1::1/64 |
12 # | | |
13 # | | default via 192.0.2.2 |
14 # | | default via 2001:db8:1::2 |
15 # +----|----------------------------+
16 # |
17 # +----|----------------------------------------------------------------------+
18 # | SW | |
19 # | + $rp1 |
20 # | 192.0.2.2/24 |
21 # | 2001:db8:1::2/64 |
22 # | |
23 # | 2001:db8:2::2/64 |
24 # | 198.51.100.2/24 |
25 # | + $rp2 |
26 # | | |
27 # +----|----------------------------------------------------------------------+
28 # |
29 # +----|----------------------------+
30 # | | default via 198.51.100.2 |
31 # | | default via 2001:db8:2::2 |
32 # | | |
33 # | | 2001:db8:2::1/64 |
34 # | | 198.51.100.1/24 |
35 # | + $h2 |
36 # | H2 (vrf) |
37 # +---------------------------------+
39 lib_dir=$(dirname $0)/../../../net/forwarding
41 ALL_TESTS="
42 ping_ipv4
43 ping_ipv6
44 blackhole_ipv4
45 blackhole_ipv6
47 NUM_NETIFS=4
48 source $lib_dir/tc_common.sh
49 source $lib_dir/lib.sh
51 h1_create()
53 simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
55 ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
56 ip -6 route add default vrf v$h1 nexthop via 2001:db8:1::2
59 h1_destroy()
61 ip -6 route del default vrf v$h1 nexthop via 2001:db8:1::2
62 ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
64 simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
67 h2_create()
69 simple_if_init $h2 198.51.100.1/24 2001:db8:2::1/64
71 ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
72 ip -6 route add default vrf v$h2 nexthop via 2001:db8:2::2
75 h2_destroy()
77 ip -6 route del default vrf v$h2 nexthop via 2001:db8:2::2
78 ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
80 simple_if_fini $h2 198.51.100.1/24 2001:db8:2::1/64
83 router_create()
85 ip link set dev $rp1 up
86 ip link set dev $rp2 up
88 tc qdisc add dev $rp1 clsact
90 __addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
91 __addr_add_del $rp2 add 198.51.100.2/24 2001:db8:2::2/64
94 router_destroy()
96 __addr_add_del $rp2 del 198.51.100.2/24 2001:db8:2::2/64
97 __addr_add_del $rp1 del 192.0.2.2/24 2001:db8:1::2/64
99 tc qdisc del dev $rp1 clsact
101 ip link set dev $rp2 down
102 ip link set dev $rp1 down
105 ping_ipv4()
107 ping_test $h1 198.51.100.1 ": h1->h2"
110 ping_ipv6()
112 ping6_test $h1 2001:db8:2::1 ": h1->h2"
115 blackhole_ipv4()
117 # Transmit packets from H1 to H2 and make sure they are dropped by the
118 # ASIC and not by the kernel
119 RET=0
121 ip -4 route add blackhole 198.51.100.0/30
122 tc filter add dev $rp1 ingress protocol ip pref 1 handle 101 flower \
123 skip_hw dst_ip 198.51.100.1 src_ip 192.0.2.1 ip_proto icmp \
124 action pass
126 ip -4 route show 198.51.100.0/30 | grep -q offload
127 check_err $? "route not marked as offloaded when should"
129 ping_do $h1 198.51.100.1
130 check_fail $? "ping passed when should not"
132 tc_check_packets "dev $rp1 ingress" 101 0
133 check_err $? "packets trapped and not dropped by ASIC"
135 log_test "IPv4 blackhole route"
137 tc filter del dev $rp1 ingress protocol ip pref 1 handle 101 flower
138 ip -4 route del blackhole 198.51.100.0/30
141 blackhole_ipv6()
143 RET=0
145 ip -6 route add blackhole 2001:db8:2::/120
146 tc filter add dev $rp1 ingress protocol ipv6 pref 1 handle 101 flower \
147 skip_hw dst_ip 2001:db8:2::1 src_ip 2001:db8:1::1 \
148 ip_proto icmpv6 action pass
150 ip -6 route show 2001:db8:2::/120 | grep -q offload
151 check_err $? "route not marked as offloaded when should"
153 ping6_do $h1 2001:db8:2::1
154 check_fail $? "ping passed when should not"
156 tc_check_packets "dev $rp1 ingress" 101 0
157 check_err $? "packets trapped and not dropped by ASIC"
159 log_test "IPv6 blackhole route"
161 tc filter del dev $rp1 ingress protocol ipv6 pref 1 handle 101 flower
162 ip -6 route del blackhole 2001:db8:2::/120
165 setup_prepare()
167 h1=${NETIFS[p1]}
168 rp1=${NETIFS[p2]}
170 rp2=${NETIFS[p3]}
171 h2=${NETIFS[p4]}
173 vrf_prepare
174 forwarding_enable
176 h1_create
177 h2_create
178 router_create
181 cleanup()
183 pre_cleanup
185 router_destroy
186 h2_destroy
187 h1_destroy
189 forwarding_restore
190 vrf_cleanup
193 trap cleanup EXIT
195 setup_prepare
196 setup_wait
198 tests_run
200 exit $EXIT_STATUS