Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 lib_dir=$(dirname $0)/../../../net/forwarding
0005 
0006 ALL_TESTS="
0007         rif_mac_profile_edit_test
0008 "
0009 NUM_NETIFS=2
0010 source $lib_dir/lib.sh
0011 source $lib_dir/devlink_lib.sh
0012 
0013 setup_prepare()
0014 {
0015         h1=${NETIFS[p1]}
0016         h2=${NETIFS[p2]}
0017 
0018         # Disable IPv6 on the two interfaces to avoid IPv6 link-local addresses
0019         # being generated and RIFs being created
0020         sysctl_set net.ipv6.conf.$h1.disable_ipv6 1
0021         sysctl_set net.ipv6.conf.$h2.disable_ipv6 1
0022 
0023         ip link set $h1 up
0024         ip link set $h2 up
0025 }
0026 
0027 cleanup()
0028 {
0029         pre_cleanup
0030 
0031         ip link set $h2 down
0032         ip link set $h1 down
0033 
0034         sysctl_restore net.ipv6.conf.$h2.disable_ipv6
0035         sysctl_restore net.ipv6.conf.$h1.disable_ipv6
0036 
0037         # Reload in order to clean all the RIFs and RIF MAC profiles created
0038         devlink_reload
0039 }
0040 
0041 create_max_rif_mac_profiles()
0042 {
0043         local count=$1; shift
0044         local batch_file="$(mktemp)"
0045 
0046         for ((i = 1; i <= count; i++)); do
0047                 vlan=$(( i*10 ))
0048                 m=$(( i*11 ))
0049 
0050                 cat >> $batch_file <<-EOF
0051                         link add link $h1 name $h1.$vlan \
0052                                 address 00:$m:$m:$m:$m:$m type vlan id $vlan
0053                         address add 192.0.$m.1/24 dev $h1.$vlan
0054                 EOF
0055         done
0056 
0057         ip -b $batch_file &> /dev/null
0058         rm -f $batch_file
0059 }
0060 
0061 rif_mac_profile_replacement_test()
0062 {
0063         local h1_10_mac=$(mac_get $h1.10)
0064 
0065         RET=0
0066 
0067         ip link set $h1.10 address 00:12:34:56:78:99
0068         check_err $?
0069 
0070         log_test "RIF MAC profile replacement"
0071 
0072         ip link set $h1.10 address $h1_10_mac
0073 }
0074 
0075 rif_mac_profile_consolidation_test()
0076 {
0077         local count=$1; shift
0078         local h1_20_mac
0079 
0080         RET=0
0081 
0082         if [[ $count -eq 1 ]]; then
0083                 return
0084         fi
0085 
0086         h1_20_mac=$(mac_get $h1.20)
0087 
0088         # Set the MAC of $h1.20 to that of $h1.10 and confirm that they are
0089         # using the same MAC profile.
0090         ip link set $h1.20 address 00:11:11:11:11:11
0091         check_err $?
0092 
0093         occ=$(devlink -j resource show $DEVLINK_DEV \
0094               | jq '.[][][] | select(.name=="rif_mac_profiles") |.["occ"]')
0095 
0096         [[ $occ -eq $((count - 1)) ]]
0097         check_err $? "MAC profile occupancy did not decrease"
0098 
0099         log_test "RIF MAC profile consolidation"
0100 
0101         ip link set $h1.20 address $h1_20_mac
0102 }
0103 
0104 rif_mac_profile_shared_replacement_test()
0105 {
0106         local count=$1; shift
0107         local i=$((count + 1))
0108         local vlan=$(( i*10 ))
0109         local m=11
0110 
0111         RET=0
0112 
0113         # Create a VLAN netdevice that has the same MAC as the first one.
0114         ip link add link $h1 name $h1.$vlan address 00:$m:$m:$m:$m:$m \
0115                 type vlan id $vlan
0116         ip address add 192.0.$m.1/24 dev $h1.$vlan
0117 
0118         # MAC replacement should fail because all the MAC profiles are in use
0119         # and the profile is shared between multiple RIFs
0120         m=$(( i*11 ))
0121         ip link set $h1.$vlan address 00:$m:$m:$m:$m:$m &> /dev/null
0122         check_fail $?
0123 
0124         log_test "RIF MAC profile shared replacement"
0125 
0126         ip link del dev $h1.$vlan
0127 }
0128 
0129 rif_mac_profile_edit_test()
0130 {
0131         local count=$(devlink_resource_size_get rif_mac_profiles)
0132 
0133         create_max_rif_mac_profiles $count
0134 
0135         rif_mac_profile_replacement_test
0136         rif_mac_profile_consolidation_test $count
0137         rif_mac_profile_shared_replacement_test $count
0138 }
0139 
0140 trap cleanup EXIT
0141 
0142 setup_prepare
0143 setup_wait
0144 
0145 tests_run
0146 
0147 exit $EXIT_STATUS