2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="standalone two_bridges one_bridge_two_pvids"
16 H1_IPV6="2001:db8:1::1"
17 H2_IPV6="2001:db8:1::2"
19 IPV4_ALLNODES="224.0.0.1"
20 IPV6_ALLNODES="ff02::1"
21 MACV4_ALLNODES="01:00:5e:00:00:01"
22 MACV6_ALLNODES="33:33:00:00:00:01"
23 NON_IP_MC="01:02:03:04:05:06"
24 NON_IP_PKT="00:04 48:45:4c:4f"
25 BC="ff:ff:ff:ff:ff:ff"
27 # The full 4K VLAN space is too much to check, so strategically pick some
28 # values which should provide reasonable coverage
29 vids=(0 1 2 5 10 20 50 100 200 500 1000 1000 2000 4000 4094)
37 $MZ -q $if_name "$dmac $smac $NON_IP_PKT"
45 ip neigh add $H2_IPV4 lladdr $dmac dev $if_name
46 ping_do $if_name $H2_IPV4
47 ip neigh del $H2_IPV4 dev $if_name
54 ping_do $if_name $IPV4_ALLNODES "-I $if_name"
62 ip -6 neigh add $H2_IPV6 lladdr $dmac dev $if_name
63 ping6_do $if_name $H2_IPV6
64 ip -6 neigh del $H2_IPV6 dev $if_name
71 ping6_do $if_name $IPV6_ALLNODES%$if_name
83 tcpdump_show $if_name | grep -q "$pattern"
85 check_err_fail "$should_fail" "$?" "reception"
93 local smac=$(mac_get $h1)
94 local dmac=$(mac_get $h2)
95 local h1_ipv6_lladdr=$(ipv6_lladdr_get $h1)
98 echo "$test_name: Sending packets"
102 send_non_ip $h1 $smac $dmac
103 send_non_ip $h1 $smac $NON_IP_MC
104 send_non_ip $h1 $smac $BC
105 send_uc_ipv4 $h1 $dmac
107 send_uc_ipv6 $h1 $dmac
110 for vid in "${vids[@]}"; do
112 simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/64
114 send_non_ip $h1.$vid $smac $dmac
115 send_non_ip $h1.$vid $smac $NON_IP_MC
116 send_non_ip $h1.$vid $smac $BC
117 send_uc_ipv4 $h1.$vid $dmac
118 send_mc_ipv4 $h1.$vid
119 send_uc_ipv6 $h1.$vid $dmac
120 send_mc_ipv6 $h1.$vid
122 simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/64
123 vlan_destroy $h1 $vid
128 echo "$test_name: Checking which packets were received"
132 check_rcv $h2 "$test_name: Unicast non-IP untagged" \
133 "$smac > $dmac, 802.3, length 4:"
135 check_rcv $h2 "$test_name: Multicast non-IP untagged" \
136 "$smac > $NON_IP_MC, 802.3, length 4:"
138 check_rcv $h2 "$test_name: Broadcast non-IP untagged" \
139 "$smac > $BC, 802.3, length 4:"
141 check_rcv $h2 "$test_name: Unicast IPv4 untagged" \
142 "$smac > $dmac, ethertype IPv4 (0x0800)"
144 check_rcv $h2 "$test_name: Multicast IPv4 untagged" \
145 "$smac > $MACV4_ALLNODES, ethertype IPv4 (0x0800).*: $H1_IPV4 > $IPV4_ALLNODES"
147 check_rcv $h2 "$test_name: Unicast IPv6 untagged" \
148 "$smac > $dmac, ethertype IPv6 (0x86dd).*8: $H1_IPV6 > $H2_IPV6"
150 check_rcv $h2 "$test_name: Multicast IPv6 untagged" \
151 "$smac > $MACV6_ALLNODES, ethertype IPv6 (0x86dd).*: $h1_ipv6_lladdr > $IPV6_ALLNODES"
153 for vid in "${vids[@]}"; do
154 check_rcv $h2 "$test_name: Unicast non-IP VID $vid" \
155 "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
157 check_rcv $h2 "$test_name: Multicast non-IP VID $vid" \
158 "$smac > $NON_IP_MC, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
160 check_rcv $h2 "$test_name: Broadcast non-IP VID $vid" \
161 "$smac > $BC, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
163 check_rcv $h2 "$test_name: Unicast IPv4 VID $vid" \
164 "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv4 (0x0800), $H1_IPV4 > $H2_IPV4"
166 check_rcv $h2 "$test_name: Multicast IPv4 VID $vid" \
167 "$smac > $MACV4_ALLNODES, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv4 (0x0800), $H1_IPV4 > $IPV4_ALLNODES"
169 check_rcv $h2 "$test_name: Unicast IPv6 VID $vid" \
170 "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv6 (0x86dd), $H1_IPV6 > $H2_IPV6"
172 check_rcv $h2 "$test_name: Multicast IPv6 VID $vid" \
173 "$smac > $MACV6_ALLNODES, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv6 (0x86dd), $h1_ipv6_lladdr > $IPV6_ALLNODES"
181 run_test "Standalone switch ports"
186 ip link add br0 type bridge && ip link set br0 up
187 ip link add br1 type bridge && ip link set br1 up
188 ip link set $swp1 master br0
189 ip link set $swp2 master br1
191 run_test "Switch ports in different bridges"
197 one_bridge_two_pvids()
199 ip link add br0 type bridge vlan_filtering 1 vlan_default_pvid 0
201 ip link set $swp1 master br0
202 ip link set $swp2 master br0
204 bridge vlan add dev $swp1 vid 1 pvid untagged
205 bridge vlan add dev $swp2 vid 2 pvid untagged
207 run_test "Switch ports in VLAN-aware bridge with different PVIDs"
214 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
219 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
224 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
229 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
236 ip link set dev $swp2 down
237 ip link set dev $swp1 down
251 # we call simple_if_init from the test itself, but setup_wait expects
252 # that we call it from here, and waits until the interfaces are up
253 ip link set dev $swp1 up
254 ip link set dev $swp2 up