18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Test operations that we expect to report extended ack.
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_cilib_dir=$(dirname $0)/../../../net/forwarding
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciALL_TESTS="
98c2ecf20Sopenharmony_ci	netdev_pre_up_test
108c2ecf20Sopenharmony_ci	vxlan_vlan_add_test
118c2ecf20Sopenharmony_ci	vxlan_bridge_create_test
128c2ecf20Sopenharmony_ci	bridge_create_test
138c2ecf20Sopenharmony_ci"
148c2ecf20Sopenharmony_ciNUM_NETIFS=2
158c2ecf20Sopenharmony_cisource $lib_dir/lib.sh
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cisetup_prepare()
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	swp1=${NETIFS[p1]}
208c2ecf20Sopenharmony_ci	swp2=${NETIFS[p2]}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	ip link set dev $swp1 up
238c2ecf20Sopenharmony_ci	ip link set dev $swp2 up
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cicleanup()
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	pre_cleanup
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	ip link set dev $swp2 down
318c2ecf20Sopenharmony_ci	ip link set dev $swp1 down
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cinetdev_pre_up_test()
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	RET=0
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	ip link add name br1 up type bridge vlan_filtering 0 mcast_snooping 0
398c2ecf20Sopenharmony_ci	ip link add name vx1 up type vxlan id 1000 \
408c2ecf20Sopenharmony_ci		local 192.0.2.17 remote 192.0.2.18 \
418c2ecf20Sopenharmony_ci		dstport 4789 nolearning noudpcsum tos inherit ttl 100
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	ip link set dev vx1 master br1
448c2ecf20Sopenharmony_ci	check_err $?
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	ip link set dev $swp1 master br1
478c2ecf20Sopenharmony_ci	check_err $?
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	ip link add name br2 up type bridge vlan_filtering 0 mcast_snooping 0
508c2ecf20Sopenharmony_ci	ip link add name vx2 up type vxlan id 2000 \
518c2ecf20Sopenharmony_ci		local 192.0.2.17 remote 192.0.2.18 \
528c2ecf20Sopenharmony_ci		dstport 4789 nolearning noudpcsum tos inherit ttl 100
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	ip link set dev vx2 master br2
558c2ecf20Sopenharmony_ci	check_err $?
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	ip link set dev $swp2 master br2
588c2ecf20Sopenharmony_ci	check_err $?
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	# Unsupported configuration: mlxsw demands that all offloaded VXLAN
618c2ecf20Sopenharmony_ci	# devices have the same TTL.
628c2ecf20Sopenharmony_ci	ip link set dev vx2 down
638c2ecf20Sopenharmony_ci	ip link set dev vx2 type vxlan ttl 200
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	ip link set dev vx2 up &>/dev/null
668c2ecf20Sopenharmony_ci	check_fail $?
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	ip link set dev vx2 up 2>&1 >/dev/null | grep -q mlxsw_spectrum
698c2ecf20Sopenharmony_ci	check_err $?
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	log_test "extack - NETDEV_PRE_UP"
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	ip link del dev vx2
748c2ecf20Sopenharmony_ci	ip link del dev br2
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	ip link del dev vx1
778c2ecf20Sopenharmony_ci	ip link del dev br1
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_civxlan_vlan_add_test()
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	RET=0
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	ip link add name br1 up type bridge vlan_filtering 1 mcast_snooping 0
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	# Unsupported configuration: mlxsw demands VXLAN with "noudpcsum".
878c2ecf20Sopenharmony_ci	ip link add name vx1 up type vxlan id 1000 \
888c2ecf20Sopenharmony_ci		local 192.0.2.17 remote 192.0.2.18 \
898c2ecf20Sopenharmony_ci		dstport 4789 tos inherit ttl 100
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	ip link set dev vx1 master br1
928c2ecf20Sopenharmony_ci	check_err $?
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	bridge vlan add dev vx1 vid 1
958c2ecf20Sopenharmony_ci	check_err $?
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	ip link set dev $swp1 master br1
988c2ecf20Sopenharmony_ci	check_err $?
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	bridge vlan add dev vx1 vid 1 pvid untagged 2>&1 >/dev/null \
1018c2ecf20Sopenharmony_ci		| grep -q mlxsw_spectrum
1028c2ecf20Sopenharmony_ci	check_err $?
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	log_test "extack - map VLAN at VXLAN device"
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	ip link del dev vx1
1078c2ecf20Sopenharmony_ci	ip link del dev br1
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_civxlan_bridge_create_test()
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	RET=0
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	# Unsupported configuration: mlxsw demands VXLAN with "noudpcsum".
1158c2ecf20Sopenharmony_ci	ip link add name vx1 up type vxlan id 1000 \
1168c2ecf20Sopenharmony_ci		local 192.0.2.17 remote 192.0.2.18 \
1178c2ecf20Sopenharmony_ci		dstport 4789 tos inherit ttl 100
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	# Test with VLAN-aware bridge.
1208c2ecf20Sopenharmony_ci	ip link add name br1 up type bridge vlan_filtering 1 mcast_snooping 0
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	ip link set dev vx1 master br1
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	ip link set dev $swp1 master br1 2>&1 > /dev/null \
1258c2ecf20Sopenharmony_ci		| grep -q mlxsw_spectrum
1268c2ecf20Sopenharmony_ci	check_err $?
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	# Test with VLAN-unaware bridge.
1298c2ecf20Sopenharmony_ci	ip link set dev br1 type bridge vlan_filtering 0
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	ip link set dev $swp1 master br1 2>&1 > /dev/null \
1328c2ecf20Sopenharmony_ci		| grep -q mlxsw_spectrum
1338c2ecf20Sopenharmony_ci	check_err $?
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	log_test "extack - bridge creation with VXLAN"
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	ip link del dev br1
1388c2ecf20Sopenharmony_ci	ip link del dev vx1
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cibridge_create_test()
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	RET=0
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	ip link add name br1 up type bridge vlan_filtering 1
1468c2ecf20Sopenharmony_ci	ip link add name br2 up type bridge vlan_filtering 1
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	ip link set dev $swp1 master br1
1498c2ecf20Sopenharmony_ci	check_err $?
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	# Only one VLAN-aware bridge is supported, so this should fail with
1528c2ecf20Sopenharmony_ci	# an extack.
1538c2ecf20Sopenharmony_ci	ip link set dev $swp2 master br2 2>&1 > /dev/null \
1548c2ecf20Sopenharmony_ci		| grep -q mlxsw_spectrum
1558c2ecf20Sopenharmony_ci	check_err $?
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	log_test "extack - multiple VLAN-aware bridges creation"
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	ip link del dev br2
1608c2ecf20Sopenharmony_ci	ip link del dev br1
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_citrap cleanup EXIT
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cisetup_prepare
1668c2ecf20Sopenharmony_cisetup_wait
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_citests_run
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciexit $EXIT_STATUS
171