1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 # Kselftest framework requirement - SKIP code 4 # Kselftest framework requirement - SKIP code is 4. 5 ksft_skip=4 5 ksft_skip=4 6 6 7 ALL_TESTS="loopback_test" 7 ALL_TESTS="loopback_test" 8 NUM_NETIFS=2 8 NUM_NETIFS=2 9 lib_dir=$(dirname "$0") 9 lib_dir=$(dirname "$0") 10 source "$lib_dir"/../../../net/forwarding/tc_c 10 source "$lib_dir"/../../../net/forwarding/tc_common.sh 11 source "$lib_dir"/../../../net/forwarding/lib. 11 source "$lib_dir"/../../../net/forwarding/lib.sh 12 12 13 h1_create() 13 h1_create() 14 { 14 { 15 simple_if_init $h1 192.0.2.1/24 15 simple_if_init $h1 192.0.2.1/24 16 tc qdisc add dev $h1 clsact 16 tc qdisc add dev $h1 clsact 17 } 17 } 18 18 19 h1_destroy() 19 h1_destroy() 20 { 20 { 21 tc qdisc del dev $h1 clsact 21 tc qdisc del dev $h1 clsact 22 simple_if_fini $h1 192.0.2.1/24 22 simple_if_fini $h1 192.0.2.1/24 23 } 23 } 24 24 25 h2_create() 25 h2_create() 26 { 26 { 27 simple_if_init $h2 27 simple_if_init $h2 28 } 28 } 29 29 30 h2_destroy() 30 h2_destroy() 31 { 31 { 32 simple_if_fini $h2 32 simple_if_fini $h2 33 } 33 } 34 34 35 loopback_test() 35 loopback_test() 36 { 36 { 37 RET=0 37 RET=0 38 38 39 tc filter add dev $h1 ingress protocol 39 tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \ 40 skip_hw arp_op reply arp_tip 1 40 skip_hw arp_op reply arp_tip 192.0.2.1 action drop 41 41 42 $MZ $h1 -c 1 -t arp -q 42 $MZ $h1 -c 1 -t arp -q 43 43 44 tc_check_packets "dev $h1 ingress" 101 44 tc_check_packets "dev $h1 ingress" 101 1 45 check_fail $? "Matched on a filter wit 45 check_fail $? "Matched on a filter without loopback setup" 46 46 47 ethtool -K $h1 loopback on 47 ethtool -K $h1 loopback on 48 check_err $? "Failed to enable loopbac 48 check_err $? "Failed to enable loopback" 49 49 50 setup_wait_dev $h1 50 setup_wait_dev $h1 51 51 52 $MZ $h1 -c 1 -t arp -q 52 $MZ $h1 -c 1 -t arp -q 53 53 54 tc_check_packets "dev $h1 ingress" 101 54 tc_check_packets "dev $h1 ingress" 101 1 55 check_err $? "Did not match on filter 55 check_err $? "Did not match on filter with loopback" 56 56 57 ethtool -K $h1 loopback off 57 ethtool -K $h1 loopback off 58 check_err $? "Failed to disable loopba 58 check_err $? "Failed to disable loopback" 59 59 60 $MZ $h1 -c 1 -t arp -q 60 $MZ $h1 -c 1 -t arp -q 61 61 62 tc_check_packets "dev $h1 ingress" 101 62 tc_check_packets "dev $h1 ingress" 101 2 63 check_fail $? "Matched on a filter aft 63 check_fail $? "Matched on a filter after loopback was removed" 64 64 65 tc filter del dev $h1 ingress protocol 65 tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower 66 66 67 log_test "loopback" 67 log_test "loopback" 68 } 68 } 69 69 70 setup_prepare() 70 setup_prepare() 71 { 71 { 72 h1=${NETIFS[p1]} 72 h1=${NETIFS[p1]} 73 h2=${NETIFS[p2]} 73 h2=${NETIFS[p2]} 74 74 75 vrf_prepare 75 vrf_prepare 76 76 77 h1_create 77 h1_create 78 h2_create 78 h2_create 79 79 80 if ethtool -k $h1 | grep loopback | gr 80 if ethtool -k $h1 | grep loopback | grep -q fixed; then 81 log_test "SKIP: dev $h1 does n 81 log_test "SKIP: dev $h1 does not support loopback feature" 82 exit $ksft_skip 82 exit $ksft_skip 83 fi 83 fi 84 } 84 } 85 85 86 cleanup() 86 cleanup() 87 { 87 { 88 pre_cleanup 88 pre_cleanup 89 89 90 h2_destroy 90 h2_destroy 91 h1_destroy 91 h1_destroy 92 92 93 vrf_cleanup 93 vrf_cleanup 94 } 94 } 95 95 96 trap cleanup EXIT 96 trap cleanup EXIT 97 97 98 setup_prepare 98 setup_prepare 99 setup_wait 99 setup_wait 100 100 101 tests_run 101 tests_run 102 102 103 exit $EXIT_STATUS 103 exit $EXIT_STATUS
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.