0001
0002
0003
0004 ALL_TESTS="shared_block_test match_indev_test"
0005 NUM_NETIFS=4
0006 source tc_common.sh
0007 source lib.sh
0008
0009 tcflags="skip_hw"
0010
0011 h1_create()
0012 {
0013 simple_if_init $h1 192.0.2.1/24
0014 }
0015
0016 h1_destroy()
0017 {
0018 simple_if_fini $h1 192.0.2.1/24
0019 }
0020
0021 h2_create()
0022 {
0023 simple_if_init $h2 192.0.2.1/24
0024 }
0025
0026 h2_destroy()
0027 {
0028 simple_if_fini $h2 192.0.2.1/24
0029 }
0030
0031 switch_create()
0032 {
0033 simple_if_init $swp1 192.0.2.2/24
0034 tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
0035
0036 simple_if_init $swp2 192.0.2.2/24
0037 tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
0038 }
0039
0040 switch_destroy()
0041 {
0042 tc qdisc del dev $swp2 clsact
0043 simple_if_fini $swp2 192.0.2.2/24
0044
0045 tc qdisc del dev $swp1 clsact
0046 simple_if_fini $swp1 192.0.2.2/24
0047 }
0048
0049 shared_block_test()
0050 {
0051 RET=0
0052
0053 tc filter add block 22 protocol ip pref 1 handle 101 flower \
0054 $tcflags dst_ip 192.0.2.2 action drop
0055
0056 $MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
0057 -t ip -q
0058
0059 tc_check_packets "block 22" 101 1
0060 check_err $? "Did not match first incoming packet on a block"
0061
0062 $MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
0063 -t ip -q
0064
0065 tc_check_packets "block 22" 101 2
0066 check_err $? "Did not match second incoming packet on a block"
0067
0068 tc filter del block 22 protocol ip pref 1 handle 101 flower
0069
0070 log_test "shared block ($tcflags)"
0071 }
0072
0073 match_indev_test()
0074 {
0075 RET=0
0076
0077 tc filter add block 22 protocol ip pref 1 handle 101 flower \
0078 $tcflags indev $swp1 dst_mac $swmac action drop
0079 tc filter add block 22 protocol ip pref 2 handle 102 flower \
0080 $tcflags indev $swp2 dst_mac $swmac action drop
0081
0082 $MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
0083 -t ip -q
0084
0085 tc_check_packets "block 22" 101 1
0086 check_err $? "Did not match first incoming packet on a block"
0087
0088 $MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
0089 -t ip -q
0090
0091 tc_check_packets "block 22" 102 1
0092 check_err $? "Did not match second incoming packet on a block"
0093
0094 tc filter del block 22 protocol ip pref 1 handle 101 flower
0095 tc filter del block 22 protocol ip pref 2 handle 102 flower
0096
0097 log_test "indev match ($tcflags)"
0098 }
0099
0100 setup_prepare()
0101 {
0102 h1=${NETIFS[p1]}
0103 swp1=${NETIFS[p2]}
0104
0105 swp2=${NETIFS[p3]}
0106 h2=${NETIFS[p4]}
0107
0108 h1mac=$(mac_get $h1)
0109 h2mac=$(mac_get $h2)
0110
0111 swmac=$(mac_get $swp1)
0112 swp2origmac=$(mac_get $swp2)
0113 ip link set $swp2 address $swmac
0114
0115 vrf_prepare
0116
0117 h1_create
0118 h2_create
0119 switch_create
0120 }
0121
0122 cleanup()
0123 {
0124 pre_cleanup
0125
0126 switch_destroy
0127 h2_destroy
0128 h1_destroy
0129
0130 vrf_cleanup
0131
0132 ip link set $swp2 address $swp2origmac
0133 }
0134
0135 check_tc_shblock_support
0136
0137 trap cleanup EXIT
0138
0139 setup_prepare
0140 setup_wait
0141
0142 tests_run
0143
0144 tc_offload_check
0145 if [[ $? -ne 0 ]]; then
0146 log_info "Could not test offloaded functionality"
0147 else
0148 tcflags="skip_sw"
0149 tests_run
0150 fi
0151
0152 exit $EXIT_STATUS