tc_chains.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. ALL_TESTS="unreachable_chain_test gact_goto_chain_test"
  4. NUM_NETIFS=2
  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.2/24
  19. tc qdisc add dev $h2 clsact
  20. }
  21. h2_destroy()
  22. {
  23. tc qdisc del dev $h2 clsact
  24. simple_if_fini $h2 192.0.2.2/24
  25. }
  26. unreachable_chain_test()
  27. {
  28. RET=0
  29. tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
  30. flower $tcflags dst_mac $h2mac action drop
  31. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  32. -t ip -q
  33. tc_check_packets "dev $h2 ingress" 1101 1
  34. check_fail $? "matched on filter in unreachable chain"
  35. tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
  36. flower
  37. log_test "unreachable chain ($tcflags)"
  38. }
  39. gact_goto_chain_test()
  40. {
  41. RET=0
  42. tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
  43. flower $tcflags dst_mac $h2mac action drop
  44. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  45. $tcflags dst_mac $h2mac action drop
  46. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  47. $tcflags dst_mac $h2mac action goto chain 1
  48. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  49. -t ip -q
  50. tc_check_packets "dev $h2 ingress" 102 1
  51. check_fail $? "Matched on a wrong filter"
  52. tc_check_packets "dev $h2 ingress" 101 1
  53. check_err $? "Did not match on correct filter with goto chain action"
  54. tc_check_packets "dev $h2 ingress" 1101 1
  55. check_err $? "Did not match on correct filter in chain 1"
  56. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  57. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  58. tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
  59. flower
  60. log_test "gact goto chain ($tcflags)"
  61. }
  62. setup_prepare()
  63. {
  64. h1=${NETIFS[p1]}
  65. h2=${NETIFS[p2]}
  66. h1mac=$(mac_get $h1)
  67. h2mac=$(mac_get $h2)
  68. vrf_prepare
  69. h1_create
  70. h2_create
  71. }
  72. cleanup()
  73. {
  74. pre_cleanup
  75. h2_destroy
  76. h1_destroy
  77. vrf_cleanup
  78. }
  79. trap cleanup EXIT
  80. setup_prepare
  81. setup_wait
  82. tests_run
  83. tc_offload_check
  84. if [[ $? -ne 0 ]]; then
  85. log_info "Could not test offloaded functionality"
  86. else
  87. tcflags="skip_sw"
  88. tests_run
  89. fi
  90. exit $EXIT_STATUS