tc_shblocks.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. ALL_TESTS="shared_block_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. setup_prepare()
  55. {
  56. h1=${NETIFS[p1]}
  57. swp1=${NETIFS[p2]}
  58. swp2=${NETIFS[p3]}
  59. h2=${NETIFS[p4]}
  60. h1mac=$(mac_get $h1)
  61. h2mac=$(mac_get $h2)
  62. swmac=$(mac_get $swp1)
  63. swp2origmac=$(mac_get $swp2)
  64. ip link set $swp2 address $swmac
  65. vrf_prepare
  66. h1_create
  67. h2_create
  68. switch_create
  69. }
  70. cleanup()
  71. {
  72. pre_cleanup
  73. switch_destroy
  74. h2_destroy
  75. h1_destroy
  76. vrf_cleanup
  77. ip link set $swp2 address $swp2origmac
  78. }
  79. check_tc_shblock_support
  80. trap cleanup EXIT
  81. setup_prepare
  82. setup_wait
  83. tests_run
  84. tc_offload_check
  85. if [[ $? -ne 0 ]]; then
  86. log_info "Could not test offloaded functionality"
  87. else
  88. tcflags="skip_sw"
  89. tests_run
  90. fi
  91. exit $EXIT_STATUS