2 # SPDX-License-Identifier: GPL-2.0
4 # +--------------------+ +----------------------+
8 # | 192.0.2.2/24 | | | | 198.51.100.2/24 |
9 # | 2001:db8:1::2/64 | | | | 2001:db8:2::2/64 |
11 # +------------------|-+ +-|--------------------+
13 # +------------------|-------------------------|--------------------+
17 # | 192.0.2.1/24 198.51.100.1/24 |
18 # | 2001:db8:1::1/64 2001:db8:2::1/64 |
20 # +-----------------------------------------------------------------+
37 require_command
$MC_CLI
43 ip link
set dev
$h1 master vrf-h1
45 ip link
set dev vrf-h1 up
46 ip link
set dev
$h1 up
48 ip address add
192.0.2.2/24 dev
$h1
49 ip address add
2001:db8
:1::2/64 dev
$h1
51 ip route add
198.51.100.0/24 vrf vrf-h1 nexthop via
192.0.2.1
52 ip route add
2001:db8
:2::/64 vrf vrf-h1 nexthop via
2001:db8
:1::1
57 ip route del
2001:db8
:2::/64 vrf vrf-h1
58 ip route del
198.51.100.0/24 vrf vrf-h1
60 ip address del
2001:db8
:1::2/64 dev
$h1
61 ip address del
192.0.2.2/24 dev
$h1
63 ip link
set dev
$h1 down
70 ip link
set dev
$h2 master vrf-h2
72 ip link
set dev vrf-h2 up
73 ip link
set dev
$h2 up
75 ip address add
198.51.100.2/24 dev
$h2
76 ip address add
2001:db8
:2::2/64 dev
$h2
78 ip route add
192.0.2.0/24 vrf vrf-h2 nexthop via
198.51.100.1
79 ip route add
2001:db8
:1::/64 vrf vrf-h2 nexthop via
2001:db8
:2::1
84 ip route del
2001:db8
:1::/64 vrf vrf-h2
85 ip route del
192.0.2.0/24 vrf vrf-h2
87 ip address del
2001:db8
:2::2/64 dev
$h2
88 ip address del
198.51.100.2/24 dev
$h2
90 ip link
set dev
$h2 down
96 ip link
set dev
$rp1 up
97 ip link
set dev
$rp2 up
99 tc qdisc add dev
$rp2 clsact
101 ip address add
192.0.2.1/24 dev
$rp1
102 ip address add
2001:db8
:1::1/64 dev
$rp1
104 ip address add
198.51.100.1/24 dev
$rp2
105 ip address add
2001:db8
:2::1/64 dev
$rp2
110 ip address del
2001:db8
:2::1/64 dev
$rp2
111 ip address del
198.51.100.1/24 dev
$rp2
113 ip address del
2001:db8
:1::1/64 dev
$rp1
114 ip address del
192.0.2.1/24 dev
$rp1
116 tc qdisc del dev
$rp2 clsact
118 ip link
set dev
$rp2 down
119 ip link
set dev
$rp1 down
124 SMCROUTEDIR
="$(mktemp -d)"
126 for ((i
= 1; i
<= $NUM_NETIFS; ++i
)); do
127 echo "phyint ${NETIFS[p$i]} enable" >> \
128 $SMCROUTEDIR/$table_name.conf
131 $MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
132 -P $SMCROUTEDIR/$table_name.pid
149 rp1mac
=$
(mac_get
$rp1)
181 ping_test
$h1 198.51.100.2
186 ping6_test
$h1 2001:db8
:2::2
193 # Disable rpfilter to prevent packets to be dropped because of it.
194 sysctl_set net.ipv4.conf.all.rp_filter
0
195 sysctl_set net.ipv4.conf.
$rp1.rp_filter
0
197 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
198 flower src_ip
240.0.0.1 ip_proto udp action pass
200 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
201 -A 240.0.0.1 -b $rp1mac -B 198.51.100.2 -q
203 tc_check_packets
"dev $rp2 egress" 101 5
204 check_err $?
"Packets were dropped"
206 log_test
"Source IP in class E"
208 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower
209 sysctl_restore net.ipv4.conf.
$rp1.rp_filter
210 sysctl_restore net.ipv4.conf.all.rp_filter
215 local if_name
=$1; shift
216 local s_addr
=$1; shift
217 local mcast
=$1; shift
220 $MC_CLI -I $table_name add
$if_name $s_addr $mcast $dest_ifs
225 local if_name
=$1; shift
226 local s_addr
=$1; shift
227 local mcast
=$1; shift
230 $MC_CLI -I $table_name remove
$if_name $s_addr $mcast $dest_ifs
236 local proto
=$1; shift
239 local flags
=${1:-""}; shift
240 local dmac
=01:02:03:04:05:06
244 tc filter add dev
$rp2 egress protocol
$proto pref
1 handle
101 \
245 flower dst_ip
$dip action pass
247 create_mcast_sg
$rp1 $sip $dip $rp2
249 $MZ $flags $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec
-b $dmac \
252 tc_check_packets
"dev $rp2 egress" 101 5
253 check_err $?
"Packets were dropped"
255 log_test
"Multicast MAC mismatch: $desc"
257 delete_mcast_sg
$rp1 $sip $dip $rp2
258 tc filter del dev
$rp2 egress protocol
$proto pref
1 handle
101 flower
263 __mc_mac_mismatch
"IPv4" "ip" 192.0.2.2 225.1.2.3
264 __mc_mac_mismatch
"IPv6" "ipv6" 2001:db8
:1::2 ff0e
::3 "-6"
271 # Disable rpfilter to prevent packets to be dropped because of it.
272 sysctl_set net.ipv4.conf.all.rp_filter
0
273 sysctl_set net.ipv4.conf.
$rp1.rp_filter
0
275 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
276 flower src_ip
198.51.100.2 action pass
278 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
279 -A 198.51.100.2 -b $rp1mac -B 198.51.100.2 -q
281 tc_check_packets
"dev $rp2 egress" 101 5
282 check_err $?
"Packets were dropped"
284 log_test
"Source IP is equal to destination IP: IPv4"
286 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower
287 sysctl_restore net.ipv4.conf.
$rp1.rp_filter
288 sysctl_restore net.ipv4.conf.all.rp_filter
295 tc filter add dev
$rp2 egress protocol ipv6 pref
1 handle
101 \
296 flower src_ip
2001:db8
:2::2 action pass
298 $MZ -6 $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
299 -A 2001:db8
:2::2 -b $rp1mac -B 2001:db8
:2::2 -q
301 tc_check_packets
"dev $rp2 egress" 101 5
302 check_err $?
"Packets were dropped"
304 log_test
"Source IP is equal to destination IP: IPv6"
306 tc filter del dev
$rp2 egress protocol ipv6 pref
1 handle
101 flower
309 ipv4_dip_link_local
()
311 local dip
=169.254.1.1
315 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
316 flower dst_ip
$dip action pass
318 ip neigh add
169.254.1.1 lladdr
00:11:22:33:44:55 dev
$rp2
319 ip route add
169.254.1.0/24 dev
$rp2
321 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec
-b $rp1mac -B $dip -q
323 tc_check_packets
"dev $rp2 egress" 101 5
324 check_err $?
"Packets were dropped"
326 log_test
"IPv4 destination IP is link-local"
328 ip route del
169.254.1.0/24 dev
$rp2
329 ip neigh del
169.254.1.1 lladdr
00:11:22:33:44:55 dev
$rp2
330 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower