1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4ALL_TESTS="loopback_test" 5NUM_NETIFS=2 6source tc_common.sh 7source lib.sh 8 9h1_create() 10{ 11 simple_if_init $h1 192.0.2.1/24 12 tc qdisc add dev $h1 clsact 13} 14 15h1_destroy() 16{ 17 tc qdisc del dev $h1 clsact 18 simple_if_fini $h1 192.0.2.1/24 19} 20 21h2_create() 22{ 23 simple_if_init $h2 24} 25 26h2_destroy() 27{ 28 simple_if_fini $h2 29} 30 31loopback_test() 32{ 33 RET=0 34 35 tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \ 36 skip_hw arp_op reply arp_tip 192.0.2.1 action drop 37 38 $MZ $h1 -c 1 -t arp -q 39 40 tc_check_packets "dev $h1 ingress" 101 1 41 check_fail $? "Matched on a filter without loopback setup" 42 43 ethtool -K $h1 loopback on 44 check_err $? "Failed to enable loopback" 45 46 setup_wait_dev $h1 47 48 $MZ $h1 -c 1 -t arp -q 49 50 tc_check_packets "dev $h1 ingress" 101 1 51 check_err $? "Did not match on filter with loopback" 52 53 ethtool -K $h1 loopback off 54 check_err $? "Failed to disable loopback" 55 56 $MZ $h1 -c 1 -t arp -q 57 58 tc_check_packets "dev $h1 ingress" 101 2 59 check_fail $? "Matched on a filter after loopback was removed" 60 61 tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower 62 63 log_test "loopback" 64} 65 66setup_prepare() 67{ 68 h1=${NETIFS[p1]} 69 h2=${NETIFS[p2]} 70 71 vrf_prepare 72 73 h1_create 74 h2_create 75} 76 77cleanup() 78{ 79 pre_cleanup 80 81 h2_destroy 82 h1_destroy 83 84 vrf_cleanup 85} 86 87trap cleanup EXIT 88 89setup_prepare 90setup_wait 91 92tests_run 93 94exit $EXIT_STATUS 95