2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS
="standalone vlan_unaware_bridge vlan_aware_bridge test_vlan \
5 vlan_over_vlan_unaware_bridged_port vlan_over_vlan_aware_bridged_port \
6 vlan_over_vlan_unaware_bridge vlan_over_vlan_aware_bridge"
16 H1_IPV6
="2001:db8:1::1"
17 H2_IPV6
="2001:db8:1::2"
19 BRIDGE_ADDR
="00:00:de:ad:be:ee"
20 MACVLAN_ADDR
="00:00:de:ad:be:ef"
21 UNKNOWN_UC_ADDR1
="de:ad:be:ef:ee:03"
22 UNKNOWN_UC_ADDR2
="de:ad:be:ef:ee:04"
23 UNKNOWN_UC_ADDR3
="de:ad:be:ef:ee:05"
24 JOINED_IPV4_MC_ADDR
="225.1.2.3"
25 UNKNOWN_IPV4_MC_ADDR1
="225.1.2.4"
26 UNKNOWN_IPV4_MC_ADDR2
="225.1.2.5"
27 UNKNOWN_IPV4_MC_ADDR3
="225.1.2.6"
28 JOINED_IPV6_MC_ADDR
="ff2e::0102:0304"
29 UNKNOWN_IPV6_MC_ADDR1
="ff2e::0102:0305"
30 UNKNOWN_IPV6_MC_ADDR2
="ff2e::0102:0306"
31 UNKNOWN_IPV6_MC_ADDR3
="ff2e::0102:0307"
33 JOINED_MACV4_MC_ADDR
="01:00:5e:01:02:03"
34 UNKNOWN_MACV4_MC_ADDR1
="01:00:5e:01:02:04"
35 UNKNOWN_MACV4_MC_ADDR2
="01:00:5e:01:02:05"
36 UNKNOWN_MACV4_MC_ADDR3
="01:00:5e:01:02:06"
37 JOINED_MACV6_MC_ADDR
="33:33:01:02:03:04"
38 UNKNOWN_MACV6_MC_ADDR1
="33:33:01:02:03:05"
39 UNKNOWN_MACV6_MC_ADDR2
="33:33:01:02:03:06"
40 UNKNOWN_MACV6_MC_ADDR3
="33:33:01:02:03:07"
43 01:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 00 02 \
44 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \
45 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \
46 00 00 00 00 00 00 00 00 00 00"
47 PTP_1588_L2_FOLLOW_UP
=" \
48 01:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 08 02 \
49 00 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
50 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \
51 00 00 66 83 c5 f1 17 97 ed f0"
52 PTP_1588_L2_PDELAY_REQ
=" \
53 01:80:c2:00:00:0e 00:00:de:ad:be:ef 88:f7 02 02 \
54 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
55 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 06 05 7f \
56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
58 PTP_1588_IPV4_SYNC
=" \
59 01:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \
60 00 48 0a 9a 40 00 01 11 cb 88 c0 00 02 01 e0 00 \
61 01 81 01 3f 01 3f 00 34 a3 c8 00 02 00 2c 00 00 \
62 02 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
63 63 ff fe cf 17 0e 00 01 00 00 00 00 00 00 00 00 \
65 PTP_1588_IPV4_FOLLOW_UP
="
66 01:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \
67 00 48 0a 9b 40 00 01 11 cb 87 c0 00 02 01 e0 00 \
68 01 81 01 40 01 40 00 34 a3 c8 08 02 00 2c 00 00 \
69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
70 63 ff fe cf 17 0e 00 01 00 00 02 00 00 00 66 83 \
72 PTP_1588_IPV4_PDELAY_REQ
=" \
73 01:00:5e:00:00:6b 00:00:de:ad:be:ef 08:00 45 00 \
74 00 52 35 a9 40 00 01 11 a1 85 c0 00 02 01 e0 00 \
75 00 6b 01 3f 01 3f 00 3e a2 bc 02 02 00 36 00 00 \
76 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
77 63 ff fe cf 17 0e 00 01 00 01 05 7f 00 00 00 00 \
78 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
79 PTP_1588_IPV6_SYNC
=" \
80 33:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 06 \
81 7c 2f 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \
82 00 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \
83 00 00 00 00 01 81 01 3f 01 3f 00 36 2e 92 00 02 \
84 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \
85 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \
86 00 00 00 00 00 00 00 00 00 00 00 00"
87 PTP_1588_IPV6_FOLLOW_UP
=" \
88 33:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 0a \
89 00 bc 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \
90 00 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \
91 00 00 00 00 01 81 01 40 01 40 00 36 2e 92 08 02 \
92 00 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
93 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \
94 00 00 66 83 c6 2a 32 09 bd 74 00 00"
95 PTP_1588_IPV6_PDELAY_REQ
=" \
96 33:33:00:00:00:6b 00:00:de:ad:be:ef 86:dd 60 0c \
97 5c fd 00 40 11 01 fe 80 00 00 00 00 00 00 3c 37 \
98 63 ff fe cf 17 0e ff 02 00 00 00 00 00 00 00 00 \
99 00 00 00 00 00 6b 01 3f 01 3f 00 40 b4 54 02 02 \
100 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
101 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 01 05 7f \
102 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
105 # Disable promisc to ensure we don't receive unknown MAC DA packets
106 export TCPDUMP_EXTRA_FLAGS
="-pl"
113 local if_name
=$1; shift
114 local pkt
="$1"; shift
115 local smac
=$
(mac_get
$if_name)
117 pkt
="${pkt/00:00:de:ad:be:ef/$smac}"
119 $MZ -q $if_name "$pkt"
127 ip neigh add
$H2_IPV4 lladdr
$dmac dev
$if_name
128 ping_do
$if_name $H2_IPV4
129 ip neigh del
$H2_IPV4 dev
$if_name
134 local if_name
=$1; shift
136 local pattern
=$1; shift
137 local should_receive
=$1; shift
138 local test_name
="$1"; shift
141 [ $should_receive = true
] && should_fail
=0 || should_fail
=1
144 tcpdump_show
$if_name |
grep -q "$pattern"
146 check_err_fail
"$should_fail" "$?" "reception"
148 log_test
"$test_name: $type"
154 local vrf_name
=$
(master_name_get
$if_name)
156 ip route add
225.100.1.0/24 dev
$if_name vrf
$vrf_name
157 ip
-6 route add ff2e
::/64 dev
$if_name vrf
$vrf_name
163 local vrf_name
=$
(master_name_get
$if_name)
165 ip route del
225.100.1.0/24 dev
$if_name vrf
$vrf_name
166 ip
-6 route del ff2e
::/64 dev
$if_name vrf
$vrf_name
171 local send_if_name
=$1; shift
172 local rcv_if_name
=$1; shift
173 local skip_ptp
=$1; shift
174 local no_unicast_flt
=$1; shift
175 local test_name
="$1"; shift
176 local smac
=$
(mac_get
$send_if_name)
177 local rcv_dmac
=$
(mac_get
$rcv_if_name)
180 tcpdump_start
$rcv_if_name
182 mc_route_prepare
$send_if_name
183 mc_route_prepare
$rcv_if_name
185 send_uc_ipv4
$send_if_name $rcv_dmac
186 send_uc_ipv4
$send_if_name $MACVLAN_ADDR
187 send_uc_ipv4
$send_if_name $UNKNOWN_UC_ADDR1
189 ip link
set dev
$rcv_if_name promisc on
190 send_uc_ipv4
$send_if_name $UNKNOWN_UC_ADDR2
191 mc_send
$send_if_name $UNKNOWN_IPV4_MC_ADDR2
192 mc_send
$send_if_name $UNKNOWN_IPV6_MC_ADDR2
193 ip link
set dev
$rcv_if_name promisc off
195 mc_join
$rcv_if_name $JOINED_IPV4_MC_ADDR
196 mc_send
$send_if_name $JOINED_IPV4_MC_ADDR
199 mc_join
$rcv_if_name $JOINED_IPV6_MC_ADDR
200 mc_send
$send_if_name $JOINED_IPV6_MC_ADDR
203 mc_send
$send_if_name $UNKNOWN_IPV4_MC_ADDR1
204 mc_send
$send_if_name $UNKNOWN_IPV6_MC_ADDR1
206 ip link
set dev
$rcv_if_name allmulticast on
207 send_uc_ipv4
$send_if_name $UNKNOWN_UC_ADDR3
208 mc_send
$send_if_name $UNKNOWN_IPV4_MC_ADDR3
209 mc_send
$send_if_name $UNKNOWN_IPV6_MC_ADDR3
210 ip link
set dev
$rcv_if_name allmulticast off
212 mc_route_destroy
$rcv_if_name
213 mc_route_destroy
$send_if_name
215 if [ $skip_ptp = false
]; then
216 ip maddress add
01:1b
:19:00:00:00 dev
$rcv_if_name
217 send_raw
$send_if_name "$PTP_1588_L2_SYNC"
218 send_raw
$send_if_name "$PTP_1588_L2_FOLLOW_UP"
219 ip maddress del
01:1b
:19:00:00:00 dev
$rcv_if_name
221 ip maddress add
01:80:c2
:00:00:0e dev
$rcv_if_name
222 send_raw
$send_if_name "$PTP_1588_L2_PDELAY_REQ"
223 ip maddress del
01:80:c2
:00:00:0e dev
$rcv_if_name
225 mc_join
$rcv_if_name 224.0.1.129
226 send_raw
$send_if_name "$PTP_1588_IPV4_SYNC"
227 send_raw
$send_if_name "$PTP_1588_IPV4_FOLLOW_UP"
230 mc_join
$rcv_if_name 224.0.0.107
231 send_raw
$send_if_name "$PTP_1588_IPV4_PDELAY_REQ"
234 mc_join
$rcv_if_name ff0e
::181
235 send_raw
$send_if_name "$PTP_1588_IPV6_SYNC"
236 send_raw
$send_if_name "$PTP_1588_IPV6_FOLLOW_UP"
239 mc_join
$rcv_if_name ff02
::6b
240 send_raw
$send_if_name "$PTP_1588_IPV6_PDELAY_REQ"
246 tcpdump_stop
$rcv_if_name
248 check_rcv
$rcv_if_name "Unicast IPv4 to primary MAC address" \
249 "$smac > $rcv_dmac, ethertype IPv4 (0x0800)" \
252 check_rcv
$rcv_if_name "Unicast IPv4 to macvlan MAC address" \
253 "$smac > $MACVLAN_ADDR, ethertype IPv4 (0x0800)" \
256 [ $no_unicast_flt = true
] && should_receive
=true || should_receive
=false
257 check_rcv
$rcv_if_name "Unicast IPv4 to unknown MAC address" \
258 "$smac > $UNKNOWN_UC_ADDR1, ethertype IPv4 (0x0800)" \
259 $should_receive "$test_name"
261 check_rcv
$rcv_if_name "Unicast IPv4 to unknown MAC address, promisc" \
262 "$smac > $UNKNOWN_UC_ADDR2, ethertype IPv4 (0x0800)" \
265 [ $no_unicast_flt = true
] && should_receive
=true || should_receive
=false
266 check_rcv
$rcv_if_name \
267 "Unicast IPv4 to unknown MAC address, allmulti" \
268 "$smac > $UNKNOWN_UC_ADDR3, ethertype IPv4 (0x0800)" \
269 $should_receive "$test_name"
271 check_rcv
$rcv_if_name "Multicast IPv4 to joined group" \
272 "$smac > $JOINED_MACV4_MC_ADDR, ethertype IPv4 (0x0800)" \
276 check_rcv
$rcv_if_name \
277 "Multicast IPv4 to unknown group" \
278 "$smac > $UNKNOWN_MACV4_MC_ADDR1, ethertype IPv4 (0x0800)" \
281 check_rcv
$rcv_if_name "Multicast IPv4 to unknown group, promisc" \
282 "$smac > $UNKNOWN_MACV4_MC_ADDR2, ethertype IPv4 (0x0800)" \
285 check_rcv
$rcv_if_name "Multicast IPv4 to unknown group, allmulti" \
286 "$smac > $UNKNOWN_MACV4_MC_ADDR3, ethertype IPv4 (0x0800)" \
289 check_rcv
$rcv_if_name "Multicast IPv6 to joined group" \
290 "$smac > $JOINED_MACV6_MC_ADDR, ethertype IPv6 (0x86dd)" \
294 check_rcv
$rcv_if_name "Multicast IPv6 to unknown group" \
295 "$smac > $UNKNOWN_MACV6_MC_ADDR1, ethertype IPv6 (0x86dd)" \
298 check_rcv
$rcv_if_name "Multicast IPv6 to unknown group, promisc" \
299 "$smac > $UNKNOWN_MACV6_MC_ADDR2, ethertype IPv6 (0x86dd)" \
302 check_rcv
$rcv_if_name "Multicast IPv6 to unknown group, allmulti" \
303 "$smac > $UNKNOWN_MACV6_MC_ADDR3, ethertype IPv6 (0x86dd)" \
306 if [ $skip_ptp = false
]; then
307 check_rcv
$rcv_if_name "1588v2 over L2 transport, Sync" \
308 "ethertype PTP (0x88f7).* PTPv2.* msg type : sync msg" \
311 check_rcv
$rcv_if_name "1588v2 over L2 transport, Follow-Up" \
312 "ethertype PTP (0x88f7).* PTPv2.* msg type : follow up msg" \
315 check_rcv
$rcv_if_name "1588v2 over L2 transport, Peer Delay Request" \
316 "ethertype PTP (0x88f7).* PTPv2.* msg type : peer delay req msg" \
319 check_rcv
$rcv_if_name "1588v2 over IPv4, Sync" \
320 "ethertype IPv4 (0x0800).* PTPv2.* msg type : sync msg" \
323 check_rcv
$rcv_if_name "1588v2 over IPv4, Follow-Up" \
324 "ethertype IPv4 (0x0800).* PTPv2.* msg type : follow up msg" \
327 check_rcv
$rcv_if_name "1588v2 over IPv4, Peer Delay Request" \
328 "ethertype IPv4 (0x0800).* PTPv2.* msg type : peer delay req msg" \
331 check_rcv
$rcv_if_name "1588v2 over IPv6, Sync" \
332 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : sync msg" \
335 check_rcv
$rcv_if_name "1588v2 over IPv6, Follow-Up" \
336 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : follow up msg" \
339 check_rcv
$rcv_if_name "1588v2 over IPv6, Peer Delay Request" \
340 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : peer delay req msg" \
344 tcpdump_cleanup
$rcv_if_name
349 simple_if_init
$h1 $H1_IPV4/24 $H1_IPV6/64
354 simple_if_fini
$h1 $H1_IPV4/24 $H1_IPV6/64
359 simple_if_init
$h2 $H2_IPV4/24 $H2_IPV6/64
364 simple_if_fini
$h2 $H2_IPV4/24 $H2_IPV6/64
370 vlan_create
$h1 100 v
$h1 $H1_IPV4/24 $H1_IPV6/64
382 vlan_create
$h2 100 v
$h2 $H2_IPV4/24 $H2_IPV6/64
393 local vlan_filtering
=$1
395 ip link add br0
type bridge vlan_filtering
$vlan_filtering
396 ip link
set br0 address
$BRIDGE_ADDR
399 ip link
set $h2 master br0
412 ip link add link
$lower name macvlan0
type macvlan mode private
413 ip link
set macvlan0 address
$MACVLAN_ADDR
414 ip link
set macvlan0 up
424 local no_unicast_flt
=true
427 if [ $
(has_unicast_flt
$h2) = yes ]; then
435 run_test
$h1 $h2 $skip_ptp $no_unicast_flt "$h2"
444 local no_unicast_flt
=true
445 local vlan_filtering
=$1
449 bridge_create
$vlan_filtering
450 simple_if_init br0
$H2_IPV4/24 $H2_IPV6/64
453 run_test
$h1 br0
$skip_ptp $no_unicast_flt \
454 "vlan_filtering=$vlan_filtering bridge"
457 simple_if_fini br0
$H2_IPV4/24 $H2_IPV6/64
462 vlan_unaware_bridge
()
474 local no_unicast_flt
=true
477 if [ $
(has_unicast_flt
$h2) = yes ]; then
483 macvlan_create
$h2.100
485 run_test
$h1.100
$h2.100
$skip_ptp $no_unicast_flt "VLAN upper"
492 vlan_over_bridged_port
()
494 local no_unicast_flt
=true
495 local vlan_filtering
=$1
498 # br_manage_promisc() will not force a single vlan_filtering port to
499 # promiscuous mode, so we should still expect unicast filtering to take
500 # place if the device can do it.
501 if [ $
(has_unicast_flt
$h2) = yes ] && [ $vlan_filtering = 1 ]; then
507 bridge_create
$vlan_filtering
508 macvlan_create
$h2.100
510 run_test
$h1.100
$h2.100
$skip_ptp $no_unicast_flt \
511 "VLAN over vlan_filtering=$vlan_filtering bridged port"
519 vlan_over_vlan_unaware_bridged_port
()
521 vlan_over_bridged_port
0
524 vlan_over_vlan_aware_bridged_port
()
526 vlan_over_bridged_port
1
531 local no_unicast_flt
=true
532 local vlan_filtering
=$1
536 bridge_create
$vlan_filtering
538 vlan_create br0
100 vbr0
$H2_IPV4/24 $H2_IPV6/64
539 macvlan_create br0.100
541 if [ $vlan_filtering = 1 ]; then
542 bridge vlan add dev
$h2 vid
100 master
543 bridge vlan add dev br0 vid
100 self
546 run_test
$h1.100 br0.100
$skip_ptp $no_unicast_flt \
547 "VLAN over vlan_filtering=$vlan_filtering bridge"
549 if [ $vlan_filtering = 1 ]; then
550 bridge vlan del dev br0 vid
100 self
551 bridge vlan del dev
$h2 vid
100 master
561 vlan_over_vlan_unaware_bridge
()
566 vlan_over_vlan_aware_bridge
()
584 # setup_wait() needs this