WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / router_multicast.sh
blob57e90c873a2cf4e6e326ed57b6410414a9dcb597
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # +------------------+
5 # | H1 (v$h1) |
6 # | 2001:db8:1::2/64 |
7 # | 198.51.100.2/28 |
8 # | $h1 + |
9 # +-------------|----+
10 # |
11 # +-------------|-------------------------------+
12 # | SW1 | |
13 # | $rp1 + |
14 # | 198.51.100.1/28 |
15 # | 2001:db8:1::1/64 |
16 # | |
17 # | 2001:db8:2::1/64 2001:db8:3::1/64 |
18 # | 198.51.100.17/28 198.51.100.33/28 |
19 # | $rp2 + $rp3 + |
20 # +--------------|--------------------------|---+
21 # | |
22 # | |
23 # +--------------|---+ +--------------|---+
24 # | H2 (v$h2) | | | H3 (v$h3) | |
25 # | $h2 + | | $h3 + |
26 # | 198.51.100.18/28 | | 198.51.100.34/28 |
27 # | 2001:db8:2::2/64 | | 2001:db8:3::2/64 |
28 # +------------------+ +------------------+
31 ALL_TESTS="mcast_v4 mcast_v6 rpf_v4 rpf_v6"
32 NUM_NETIFS=6
33 source lib.sh
34 source tc_common.sh
36 require_command $MCD
37 require_command $MC_CLI
38 table_name=selftests
40 h1_create()
42 simple_if_init $h1 198.51.100.2/28 2001:db8:1::2/64
44 ip route add 198.51.100.16/28 vrf v$h1 nexthop via 198.51.100.1
45 ip route add 198.51.100.32/28 vrf v$h1 nexthop via 198.51.100.1
47 ip route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::1
48 ip route add 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::1
50 tc qdisc add dev $h1 ingress
53 h1_destroy()
55 tc qdisc del dev $h1 ingress
57 ip route del 2001:db8:3::/64 vrf v$h1
58 ip route del 2001:db8:2::/64 vrf v$h1
60 ip route del 198.51.100.32/28 vrf v$h1
61 ip route del 198.51.100.16/28 vrf v$h1
63 simple_if_fini $h1 198.51.100.2/28 2001:db8:1::2/64
66 h2_create()
68 simple_if_init $h2 198.51.100.18/28 2001:db8:2::2/64
70 ip route add 198.51.100.0/28 vrf v$h2 nexthop via 198.51.100.17
71 ip route add 198.51.100.32/28 vrf v$h2 nexthop via 198.51.100.17
73 ip route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1
74 ip route add 2001:db8:3::/64 vrf v$h2 nexthop via 2001:db8:2::1
76 tc qdisc add dev $h2 ingress
79 h2_destroy()
81 tc qdisc del dev $h2 ingress
83 ip route del 2001:db8:3::/64 vrf v$h2
84 ip route del 2001:db8:1::/64 vrf v$h2
86 ip route del 198.51.100.32/28 vrf v$h2
87 ip route del 198.51.100.0/28 vrf v$h2
89 simple_if_fini $h2 198.51.100.18/28 2001:db8:2::2/64
92 h3_create()
94 simple_if_init $h3 198.51.100.34/28 2001:db8:3::2/64
96 ip route add 198.51.100.0/28 vrf v$h3 nexthop via 198.51.100.33
97 ip route add 198.51.100.16/28 vrf v$h3 nexthop via 198.51.100.33
99 ip route add 2001:db8:1::/64 vrf v$h3 nexthop via 2001:db8:3::1
100 ip route add 2001:db8:2::/64 vrf v$h3 nexthop via 2001:db8:3::1
102 tc qdisc add dev $h3 ingress
105 h3_destroy()
107 tc qdisc del dev $h3 ingress
109 ip route del 2001:db8:2::/64 vrf v$h3
110 ip route del 2001:db8:1::/64 vrf v$h3
112 ip route del 198.51.100.16/28 vrf v$h3
113 ip route del 198.51.100.0/28 vrf v$h3
115 simple_if_fini $h3 198.51.100.34/28 2001:db8:3::2/64
118 router_create()
120 ip link set dev $rp1 up
121 ip link set dev $rp2 up
122 ip link set dev $rp3 up
124 ip address add 198.51.100.1/28 dev $rp1
125 ip address add 198.51.100.17/28 dev $rp2
126 ip address add 198.51.100.33/28 dev $rp3
128 ip address add 2001:db8:1::1/64 dev $rp1
129 ip address add 2001:db8:2::1/64 dev $rp2
130 ip address add 2001:db8:3::1/64 dev $rp3
132 tc qdisc add dev $rp3 ingress
135 router_destroy()
137 tc qdisc del dev $rp3 ingress
139 ip address del 2001:db8:3::1/64 dev $rp3
140 ip address del 2001:db8:2::1/64 dev $rp2
141 ip address del 2001:db8:1::1/64 dev $rp1
143 ip address del 198.51.100.33/28 dev $rp3
144 ip address del 198.51.100.17/28 dev $rp2
145 ip address del 198.51.100.1/28 dev $rp1
147 ip link set dev $rp3 down
148 ip link set dev $rp2 down
149 ip link set dev $rp1 down
152 start_mcd()
154 SMCROUTEDIR="$(mktemp -d)"
156 for ((i = 1; i <= $NUM_NETIFS; ++i)); do
157 echo "phyint ${NETIFS[p$i]} enable" >> \
158 $SMCROUTEDIR/$table_name.conf
159 done
161 $MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
162 -P $SMCROUTEDIR/$table_name.pid
165 kill_mcd()
167 pkill $MCD
168 rm -rf $SMCROUTEDIR
171 setup_prepare()
173 h1=${NETIFS[p1]}
174 rp1=${NETIFS[p2]}
176 rp2=${NETIFS[p3]}
177 h2=${NETIFS[p4]}
179 rp3=${NETIFS[p5]}
180 h3=${NETIFS[p6]}
182 start_mcd
184 vrf_prepare
186 h1_create
187 h2_create
188 h3_create
190 router_create
192 forwarding_enable
195 cleanup()
197 pre_cleanup
199 forwarding_restore
201 router_destroy
203 h3_destroy
204 h2_destroy
205 h1_destroy
207 vrf_cleanup
209 kill_mcd
212 create_mcast_sg()
214 local if_name=$1; shift
215 local s_addr=$1; shift
216 local mcast=$1; shift
217 local dest_ifs=${@}
219 $MC_CLI -I $table_name add $if_name $s_addr $mcast $dest_ifs
222 delete_mcast_sg()
224 local if_name=$1; shift
225 local s_addr=$1; shift
226 local mcast=$1; shift
227 local dest_ifs=${@}
229 $MC_CLI -I $table_name remove $if_name $s_addr $mcast $dest_ifs
232 mcast_v4()
234 # Add two interfaces to an MC group, send a packet to the MC group and
235 # verify packets are received on both. Then delete the route and verify
236 # packets are no longer received.
238 RET=0
240 tc filter add dev $h2 ingress protocol ip pref 1 handle 122 flower \
241 dst_ip 225.1.2.3 action drop
242 tc filter add dev $h3 ingress protocol ip pref 1 handle 133 flower \
243 dst_ip 225.1.2.3 action drop
245 create_mcast_sg $rp1 198.51.100.2 225.1.2.3 $rp2 $rp3
247 # Send frames with the corresponding L2 destination address.
248 $MZ $h1 -c 5 -p 128 -t udp -a 00:11:22:33:44:55 -b 01:00:5e:01:02:03 \
249 -A 198.51.100.2 -B 225.1.2.3 -q
251 tc_check_packets "dev $h2 ingress" 122 5
252 check_err $? "Multicast not received on first host"
253 tc_check_packets "dev $h3 ingress" 133 5
254 check_err $? "Multicast not received on second host"
256 delete_mcast_sg $rp1 198.51.100.2 225.1.2.3 $rp2 $rp3
258 $MZ $h1 -c 5 -p 128 -t udp -a 00:11:22:33:44:55 -b 01:00:5e:01:02:03 \
259 -A 198.51.100.2 -B 225.1.2.3 -q
261 tc_check_packets "dev $h2 ingress" 122 5
262 check_err $? "Multicast received on host although deleted"
263 tc_check_packets "dev $h3 ingress" 133 5
264 check_err $? "Multicast received on second host although deleted"
266 tc filter del dev $h3 ingress protocol ip pref 1 handle 133 flower
267 tc filter del dev $h2 ingress protocol ip pref 1 handle 122 flower
269 log_test "mcast IPv4"
272 mcast_v6()
274 # Add two interfaces to an MC group, send a packet to the MC group and
275 # verify packets are received on both. Then delete the route and verify
276 # packets are no longer received.
278 RET=0
280 tc filter add dev $h2 ingress protocol ipv6 pref 1 handle 122 flower \
281 dst_ip ff0e::3 action drop
282 tc filter add dev $h3 ingress protocol ipv6 pref 1 handle 133 flower \
283 dst_ip ff0e::3 action drop
285 create_mcast_sg $rp1 2001:db8:1::2 ff0e::3 $rp2 $rp3
287 # Send frames with the corresponding L2 destination address.
288 $MZ $h1 -6 -c 5 -p 128 -t udp -a 00:11:22:33:44:55 \
289 -b 33:33:00:00:00:03 -A 2001:db8:1::2 -B ff0e::3 -q
291 tc_check_packets "dev $h2 ingress" 122 5
292 check_err $? "Multicast not received on first host"
293 tc_check_packets "dev $h3 ingress" 133 5
294 check_err $? "Multicast not received on second host"
296 delete_mcast_sg $rp1 2001:db8:1::2 ff0e::3 $rp2 $rp3
298 $MZ $h1 -6 -c 5 -p 128 -t udp -a 00:11:22:33:44:55 \
299 -b 33:33:00:00:00:03 -A 2001:db8:1::2 -B ff0e::3 -q
301 tc_check_packets "dev $h2 ingress" 122 5
302 check_err $? "Multicast received on first host although deleted"
303 tc_check_packets "dev $h3 ingress" 133 5
304 check_err $? "Multicast received on second host although deleted"
306 tc filter del dev $h3 ingress protocol ipv6 pref 1 handle 133 flower
307 tc filter del dev $h2 ingress protocol ipv6 pref 1 handle 122 flower
309 log_test "mcast IPv6"
312 rpf_v4()
314 # Add a multicast route from first router port to the other two. Send
315 # matching packets and test that both hosts receive them. Then, send
316 # the same packets via the third router port and test that they do not
317 # reach any host due to RPF check. A filter with 'skip_hw' is added to
318 # test that devices capable of multicast routing offload trap those
319 # packets. The filter is essentialy a NOP in other scenarios.
321 RET=0
323 tc filter add dev $h1 ingress protocol ip pref 1 handle 1 flower \
324 dst_ip 225.1.2.3 ip_proto udp dst_port 12345 action drop
325 tc filter add dev $h2 ingress protocol ip pref 1 handle 1 flower \
326 dst_ip 225.1.2.3 ip_proto udp dst_port 12345 action drop
327 tc filter add dev $h3 ingress protocol ip pref 1 handle 1 flower \
328 dst_ip 225.1.2.3 ip_proto udp dst_port 12345 action drop
329 tc filter add dev $rp3 ingress protocol ip pref 1 handle 1 flower \
330 skip_hw dst_ip 225.1.2.3 ip_proto udp dst_port 12345 action pass
332 create_mcast_sg $rp1 198.51.100.2 225.1.2.3 $rp2 $rp3
334 $MZ $h1 -c 5 -p 128 -t udp "ttl=10,sp=54321,dp=12345" \
335 -a 00:11:22:33:44:55 -b 01:00:5e:01:02:03 \
336 -A 198.51.100.2 -B 225.1.2.3 -q
338 tc_check_packets "dev $h2 ingress" 1 5
339 check_err $? "Multicast not received on first host"
340 tc_check_packets "dev $h3 ingress" 1 5
341 check_err $? "Multicast not received on second host"
343 $MZ $h3 -c 5 -p 128 -t udp "ttl=10,sp=54321,dp=12345" \
344 -a 00:11:22:33:44:55 -b 01:00:5e:01:02:03 \
345 -A 198.51.100.2 -B 225.1.2.3 -q
347 tc_check_packets "dev $h1 ingress" 1 0
348 check_err $? "Multicast received on first host when should not"
349 tc_check_packets "dev $h2 ingress" 1 5
350 check_err $? "Multicast received on second host when should not"
351 tc_check_packets "dev $rp3 ingress" 1 5
352 check_err $? "Packets not trapped due to RPF check"
354 delete_mcast_sg $rp1 198.51.100.2 225.1.2.3 $rp2 $rp3
356 tc filter del dev $rp3 ingress protocol ip pref 1 handle 1 flower
357 tc filter del dev $h3 ingress protocol ip pref 1 handle 1 flower
358 tc filter del dev $h2 ingress protocol ip pref 1 handle 1 flower
359 tc filter del dev $h1 ingress protocol ip pref 1 handle 1 flower
361 log_test "RPF IPv4"
364 rpf_v6()
366 RET=0
368 tc filter add dev $h1 ingress protocol ipv6 pref 1 handle 1 flower \
369 dst_ip ff0e::3 ip_proto udp dst_port 12345 action drop
370 tc filter add dev $h2 ingress protocol ipv6 pref 1 handle 1 flower \
371 dst_ip ff0e::3 ip_proto udp dst_port 12345 action drop
372 tc filter add dev $h3 ingress protocol ipv6 pref 1 handle 1 flower \
373 dst_ip ff0e::3 ip_proto udp dst_port 12345 action drop
374 tc filter add dev $rp3 ingress protocol ipv6 pref 1 handle 1 flower \
375 skip_hw dst_ip ff0e::3 ip_proto udp dst_port 12345 action pass
377 create_mcast_sg $rp1 2001:db8:1::2 ff0e::3 $rp2 $rp3
379 $MZ $h1 -6 -c 5 -p 128 -t udp "ttl=10,sp=54321,dp=12345" \
380 -a 00:11:22:33:44:55 -b 33:33:00:00:00:03 \
381 -A 2001:db8:1::2 -B ff0e::3 -q
383 tc_check_packets "dev $h2 ingress" 1 5
384 check_err $? "Multicast not received on first host"
385 tc_check_packets "dev $h3 ingress" 1 5
386 check_err $? "Multicast not received on second host"
388 $MZ $h3 -6 -c 5 -p 128 -t udp "ttl=10,sp=54321,dp=12345" \
389 -a 00:11:22:33:44:55 -b 33:33:00:00:00:03 \
390 -A 2001:db8:1::2 -B ff0e::3 -q
392 tc_check_packets "dev $h1 ingress" 1 0
393 check_err $? "Multicast received on first host when should not"
394 tc_check_packets "dev $h2 ingress" 1 5
395 check_err $? "Multicast received on second host when should not"
396 tc_check_packets "dev $rp3 ingress" 1 5
397 check_err $? "Packets not trapped due to RPF check"
399 delete_mcast_sg $rp1 2001:db8:1::2 ff0e::3 $rp2 $rp3
401 tc filter del dev $rp3 ingress protocol ipv6 pref 1 handle 1 flower
402 tc filter del dev $h3 ingress protocol ipv6 pref 1 handle 1 flower
403 tc filter del dev $h2 ingress protocol ipv6 pref 1 handle 1 flower
404 tc filter del dev $h1 ingress protocol ipv6 pref 1 handle 1 flower
406 log_test "RPF IPv6"
409 trap cleanup EXIT
411 setup_prepare
412 setup_wait
414 tests_run
416 exit $EXIT_STATUS