2 # SPDX-License-Identifier: GPL-2.0
11 # +-------------|-------------------------------+
15 # | 2001:db8:1::1/64 |
17 # | 2001:db8:2::1/64 2001:db8:3::1/64 |
18 # | 198.51.100.17/28 198.51.100.33/28 |
20 # +--------------|--------------------------|---+
23 # +--------------|---+ +--------------|---+
24 # | H2 (v$h2) | | | H3 (v$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"
37 require_command
$MC_CLI
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
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
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
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
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
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
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
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
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
161 $MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
162 -P $SMCROUTEDIR/$table_name.pid
214 local if_name
=$1; shift
215 local s_addr
=$1; shift
216 local mcast
=$1; shift
219 $MC_CLI -I $table_name add
$if_name $s_addr $mcast $dest_ifs
224 local if_name
=$1; shift
225 local s_addr
=$1; shift
226 local mcast
=$1; shift
229 $MC_CLI -I $table_name remove
$if_name $s_addr $mcast $dest_ifs
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.
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"
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.
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"
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.
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
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