2 # SPDX-License-Identifier: GPL-2.0
19 require_command
$MC_CLI
25 ip link
set dev
$h1 master vrf-h1
27 ip link
set dev vrf-h1 up
28 ip link
set dev
$h1 up
30 ip address add
192.0.2.2/24 dev
$h1
31 ip address add
2001:db8
:1::2/64 dev
$h1
33 ip route add
198.51.100.0/24 vrf vrf-h1 nexthop via
192.0.2.1
34 ip route add
2001:db8
:2::/64 vrf vrf-h1 nexthop via
2001:db8
:1::1
39 ip route del
2001:db8
:2::/64 vrf vrf-h1
40 ip route del
198.51.100.0/24 vrf vrf-h1
42 ip address del
2001:db8
:1::2/64 dev
$h1
43 ip address del
192.0.2.2/24 dev
$h1
45 ip link
set dev
$h1 down
52 ip link
set dev
$h2 master vrf-h2
54 ip link
set dev vrf-h2 up
55 ip link
set dev
$h2 up
57 ip address add
198.51.100.2/24 dev
$h2
58 ip address add
2001:db8
:2::2/64 dev
$h2
60 ip route add
192.0.2.0/24 vrf vrf-h2 nexthop via
198.51.100.1
61 ip route add
2001:db8
:1::/64 vrf vrf-h2 nexthop via
2001:db8
:2::1
66 ip route del
2001:db8
:1::/64 vrf vrf-h2
67 ip route del
192.0.2.0/24 vrf vrf-h2
69 ip address del
2001:db8
:2::2/64 dev
$h2
70 ip address del
198.51.100.2/24 dev
$h2
72 ip link
set dev
$h2 down
78 ip link
set dev
$rp1 up
79 ip link
set dev
$rp2 up
81 tc qdisc add dev
$rp2 clsact
83 ip address add
192.0.2.1/24 dev
$rp1
84 ip address add
2001:db8
:1::1/64 dev
$rp1
86 ip address add
198.51.100.1/24 dev
$rp2
87 ip address add
2001:db8
:2::1/64 dev
$rp2
92 ip address del
2001:db8
:2::1/64 dev
$rp2
93 ip address del
198.51.100.1/24 dev
$rp2
95 ip address del
2001:db8
:1::1/64 dev
$rp1
96 ip address del
192.0.2.1/24 dev
$rp1
98 tc qdisc del dev
$rp2 clsact
100 ip link
set dev
$rp2 down
101 ip link
set dev
$rp1 down
106 SMCROUTEDIR
="$(mktemp -d)"
108 for ((i
= 1; i
<= $NUM_NETIFS; ++i
)); do
109 echo "phyint ${NETIFS[p$i]} enable" >> \
110 $SMCROUTEDIR/$table_name.conf
113 $MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
114 -P $SMCROUTEDIR/$table_name.pid
131 rp1mac
=$
(mac_get
$rp1)
163 ping_test
$h1 198.51.100.2
168 ping6_test
$h1 2001:db8
:2::2
175 # Disable rpfilter to prevent packets to be dropped because of it.
176 sysctl_set net.ipv4.conf.all.rp_filter
0
177 sysctl_set net.ipv4.conf.
$rp1.rp_filter
0
179 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
180 flower src_ip
240.0.0.1 ip_proto udp action pass
182 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
183 -A 240.0.0.1 -b $rp1mac -B 198.51.100.2 -q
185 tc_check_packets
"dev $rp2 egress" 101 5
186 check_err $?
"Packets were dropped"
188 log_test
"Source IP in class E"
190 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower
191 sysctl_restore net.ipv4.conf.
$rp1.rp_filter
192 sysctl_restore net.ipv4.conf.all.rp_filter
197 local if_name
=$1; shift
198 local s_addr
=$1; shift
199 local mcast
=$1; shift
202 $MC_CLI -I $table_name add
$if_name $s_addr $mcast $dest_ifs
207 local if_name
=$1; shift
208 local s_addr
=$1; shift
209 local mcast
=$1; shift
212 $MC_CLI -I $table_name remove
$if_name $s_addr $mcast $dest_ifs
218 local proto
=$1; shift
221 local flags
=${1:-""}; shift
222 local dmac
=01:02:03:04:05:06
226 tc filter add dev
$rp2 egress protocol
$proto pref
1 handle
101 \
227 flower dst_ip
$dip action pass
229 create_mcast_sg
$rp1 $sip $dip $rp2
231 $MZ $flags $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec
-b $dmac \
234 tc_check_packets
"dev $rp2 egress" 101 5
235 check_err $?
"Packets were dropped"
237 log_test
"Multicast MAC mismatch: $desc"
239 delete_mcast_sg
$rp1 $sip $dip $rp2
240 tc filter del dev
$rp2 egress protocol
$proto pref
1 handle
101 flower
245 __mc_mac_mismatch
"IPv4" "ip" 192.0.2.2 225.1.2.3
246 __mc_mac_mismatch
"IPv6" "ipv6" 2001:db8
:1::2 ff0e
::3 "-6"
253 # Disable rpfilter to prevent packets to be dropped because of it.
254 sysctl_set net.ipv4.conf.all.rp_filter
0
255 sysctl_set net.ipv4.conf.
$rp1.rp_filter
0
257 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
258 flower src_ip
198.51.100.2 action pass
260 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
261 -A 198.51.100.2 -b $rp1mac -B 198.51.100.2 -q
263 tc_check_packets
"dev $rp2 egress" 101 5
264 check_err $?
"Packets were dropped"
266 log_test
"Source IP is equal to destination IP: IPv4"
268 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower
269 sysctl_restore net.ipv4.conf.
$rp1.rp_filter
270 sysctl_restore net.ipv4.conf.all.rp_filter
277 tc filter add dev
$rp2 egress protocol ipv6 pref
1 handle
101 \
278 flower src_ip
2001:db8
:2::2 action pass
280 $MZ -6 $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec \
281 -A 2001:db8
:2::2 -b $rp1mac -B 2001:db8
:2::2 -q
283 tc_check_packets
"dev $rp2 egress" 101 5
284 check_err $?
"Packets were dropped"
286 log_test
"Source IP is equal to destination IP: IPv6"
288 tc filter del dev
$rp2 egress protocol ipv6 pref
1 handle
101 flower
291 ipv4_dip_link_local
()
293 local dip
=169.254.1.1
297 tc filter add dev
$rp2 egress protocol ip pref
1 handle
101 \
298 flower dst_ip
$dip action pass
300 ip neigh add
169.254.1.1 lladdr
00:11:22:33:44:55 dev
$rp2
301 ip route add
169.254.1.0/24 dev
$rp2
303 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 5 -d 1msec
-b $rp1mac -B $dip -q
305 tc_check_packets
"dev $rp2 egress" 101 5
306 check_err $?
"Packets were dropped"
308 log_test
"IPv4 destination IP is link-local"
310 ip route del
169.254.1.0/24 dev
$rp2
311 ip neigh del
169.254.1.1 lladdr
00:11:22:33:44:55 dev
$rp2
312 tc filter del dev
$rp2 egress protocol ip pref
1 handle
101 flower