Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Kselftest framework requirement - SKIP code is 4.
0005 ksft_skip=4
0006 
0007 ALL_TESTS="loopback_test"
0008 NUM_NETIFS=2
0009 source tc_common.sh
0010 source lib.sh
0011 
0012 h1_create()
0013 {
0014         simple_if_init $h1 192.0.2.1/24
0015         tc qdisc add dev $h1 clsact
0016 }
0017 
0018 h1_destroy()
0019 {
0020         tc qdisc del dev $h1 clsact
0021         simple_if_fini $h1 192.0.2.1/24
0022 }
0023 
0024 h2_create()
0025 {
0026         simple_if_init $h2
0027 }
0028 
0029 h2_destroy()
0030 {
0031         simple_if_fini $h2
0032 }
0033 
0034 loopback_test()
0035 {
0036         RET=0
0037 
0038         tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \
0039                 skip_hw arp_op reply arp_tip 192.0.2.1 action drop
0040 
0041         $MZ $h1 -c 1 -t arp -q
0042 
0043         tc_check_packets "dev $h1 ingress" 101 1
0044         check_fail $? "Matched on a filter without loopback setup"
0045 
0046         ethtool -K $h1 loopback on
0047         check_err $? "Failed to enable loopback"
0048 
0049         setup_wait_dev $h1
0050 
0051         $MZ $h1 -c 1 -t arp -q
0052 
0053         tc_check_packets "dev $h1 ingress" 101 1
0054         check_err $? "Did not match on filter with loopback"
0055 
0056         ethtool -K $h1 loopback off
0057         check_err $? "Failed to disable loopback"
0058 
0059         $MZ $h1 -c 1 -t arp -q
0060 
0061         tc_check_packets "dev $h1 ingress" 101 2
0062         check_fail $? "Matched on a filter after loopback was removed"
0063 
0064         tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower
0065 
0066         log_test "loopback"
0067 }
0068 
0069 setup_prepare()
0070 {
0071         h1=${NETIFS[p1]}
0072         h2=${NETIFS[p2]}
0073 
0074         vrf_prepare
0075 
0076         h1_create
0077         h2_create
0078 
0079         if ethtool -k $h1 | grep loopback | grep -q fixed; then
0080                 log_test "SKIP: dev $h1 does not support loopback feature"
0081                 exit $ksft_skip
0082         fi
0083 }
0084 
0085 cleanup()
0086 {
0087         pre_cleanup
0088 
0089         h2_destroy
0090         h1_destroy
0091 
0092         vrf_cleanup
0093 }
0094 
0095 trap cleanup EXIT
0096 
0097 setup_prepare
0098 setup_wait
0099 
0100 tests_run
0101 
0102 exit $EXIT_STATUS