Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Test for RIF MAC profiles resource. The test adds VLAN netdevices according to
0005 # the maximum number of RIF MAC profiles, sets each of them with a random
0006 # MAC address, and checks that eventually the number of occupied RIF MAC
0007 # profiles equals the maximum number of RIF MAC profiles.
0008 
0009 
0010 RIF_MAC_PROFILE_NUM_NETIFS=2
0011 
0012 rif_mac_profiles_create()
0013 {
0014         local count=$1; shift
0015         local should_fail=$1; shift
0016         local batch_file="$(mktemp)"
0017 
0018         for ((i = 1; i <= count; i++)); do
0019                 vlan=$(( i*10 ))
0020                 m=$(( i*11 ))
0021 
0022                 cat >> $batch_file <<-EOF
0023                         link add link $h1 name $h1.$vlan \
0024                                 address 00:$m:$m:$m:$m:$m type vlan id $vlan
0025                         address add 192.0.$m.1/24 dev $h1.$vlan
0026                 EOF
0027         done
0028 
0029         ip -b $batch_file &> /dev/null
0030         check_err_fail $should_fail $? "RIF creation"
0031 
0032         rm -f $batch_file
0033 }
0034 
0035 rif_mac_profile_test()
0036 {
0037         local count=$1; shift
0038         local should_fail=$1; shift
0039 
0040         rif_mac_profiles_create $count $should_fail
0041 
0042         occ=$(devlink -j resource show $DEVLINK_DEV \
0043               | jq '.[][][] | select(.name=="rif_mac_profiles") |.["occ"]')
0044 
0045         [[ $occ -eq $count ]]
0046         check_err_fail $should_fail $? "Attempt to use $count profiles (actual result $occ)"
0047 }
0048 
0049 rif_mac_profile_setup_prepare()
0050 {
0051         h1=${NETIFS[p1]}
0052         h2=${NETIFS[p2]}
0053 
0054         # Disable IPv6 on the two interfaces to avoid IPv6 link-local addresses
0055         # being generated and RIFs being created.
0056         sysctl_set net.ipv6.conf.$h1.disable_ipv6 1
0057         sysctl_set net.ipv6.conf.$h2.disable_ipv6 1
0058 
0059         ip link set $h1 up
0060         ip link set $h2 up
0061 }
0062 
0063 rif_mac_profile_cleanup()
0064 {
0065         pre_cleanup
0066 
0067         ip link set $h2 down
0068         ip link set $h1 down
0069 
0070         sysctl_restore net.ipv6.conf.$h2.disable_ipv6
0071         sysctl_restore net.ipv6.conf.$h1.disable_ipv6
0072 }