tc_shblocks.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. ALL_TESTS="shared_block_test match_indev_test"
  4. NUM_NETIFS=4
  5. source tc_common.sh
  6. source lib.sh
  7. tcflags="skip_hw"
  8. h1_create()
  9. {
  10. simple_if_init $h1 192.0.2.1/24
  11. }
  12. h1_destroy()
  13. {
  14. simple_if_fini $h1 192.0.2.1/24
  15. }
  16. h2_create()
  17. {
  18. simple_if_init $h2 192.0.2.1/24
  19. }
  20. h2_destroy()
  21. {
  22. simple_if_fini $h2 192.0.2.1/24
  23. }
  24. switch_create()
  25. {
  26. simple_if_init $swp1 192.0.2.2/24
  27. tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
  28. simple_if_init $swp2 192.0.2.2/24
  29. tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
  30. }
  31. switch_destroy()
  32. {
  33. tc qdisc del dev $swp2 clsact
  34. simple_if_fini $swp2 192.0.2.2/24
  35. tc qdisc del dev $swp1 clsact
  36. simple_if_fini $swp1 192.0.2.2/24
  37. }
  38. shared_block_test()
  39. {
  40. RET=0
  41. tc filter add block 22 protocol ip pref 1 handle 101 flower \
  42. $tcflags dst_ip 192.0.2.2 action drop
  43. $MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
  44. -t ip -q
  45. tc_check_packets "block 22" 101 1
  46. check_err $? "Did not match first incoming packet on a block"
  47. $MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
  48. -t ip -q
  49. tc_check_packets "block 22" 101 2
  50. check_err $? "Did not match second incoming packet on a block"
  51. tc filter del block 22 protocol ip pref 1 handle 101 flower
  52. log_test "shared block ($tcflags)"
  53. }
  54. match_indev_test()
  55. {
  56. RET=0
  57. tc filter add block 22 protocol ip pref 1 handle 101 flower \
  58. $tcflags indev $swp1 dst_mac $swmac action drop
  59. tc filter add block 22 protocol ip pref 2 handle 102 flower \
  60. $tcflags indev $swp2 dst_mac $swmac action drop
  61. $MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
  62. -t ip -q
  63. tc_check_packets "block 22" 101 1
  64. check_err $? "Did not match first incoming packet on a block"
  65. $MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
  66. -t ip -q
  67. tc_check_packets "block 22" 102 1
  68. check_err $? "Did not match second incoming packet on a block"
  69. tc filter del block 22 protocol ip pref 1 handle 101 flower
  70. tc filter del block 22 protocol ip pref 2 handle 102 flower
  71. log_test "indev match ($tcflags)"
  72. }
  73. setup_prepare()
  74. {
  75. h1=${NETIFS[p1]}
  76. swp1=${NETIFS[p2]}
  77. swp2=${NETIFS[p3]}
  78. h2=${NETIFS[p4]}
  79. h1mac=$(mac_get $h1)
  80. h2mac=$(mac_get $h2)
  81. swmac=$(mac_get $swp1)
  82. swp2origmac=$(mac_get $swp2)
  83. ip link set $swp2 address $swmac
  84. vrf_prepare
  85. h1_create
  86. h2_create
  87. switch_create
  88. }
  89. cleanup()
  90. {
  91. pre_cleanup
  92. switch_destroy
  93. h2_destroy
  94. h1_destroy
  95. vrf_cleanup
  96. ip link set $swp2 address $swp2origmac
  97. }
  98. check_tc_shblock_support
  99. trap cleanup EXIT
  100. setup_prepare
  101. setup_wait
  102. tests_run
  103. tc_offload_check
  104. if [[ $? -ne 0 ]]; then
  105. log_info "Could not test offloaded functionality"
  106. else
  107. tcflags="skip_sw"
  108. tests_run
  109. fi
  110. exit $EXIT_STATUS