loopback.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Kselftest framework requirement - SKIP code is 4.
  4. ksft_skip=4
  5. ALL_TESTS="loopback_test"
  6. NUM_NETIFS=2
  7. lib_dir=$(dirname "$0")
  8. source "$lib_dir"/../../../net/forwarding/tc_common.sh
  9. source "$lib_dir"/../../../net/forwarding/lib.sh
  10. h1_create()
  11. {
  12. simple_if_init $h1 192.0.2.1/24
  13. tc qdisc add dev $h1 clsact
  14. }
  15. h1_destroy()
  16. {
  17. tc qdisc del dev $h1 clsact
  18. simple_if_fini $h1 192.0.2.1/24
  19. }
  20. h2_create()
  21. {
  22. simple_if_init $h2
  23. }
  24. h2_destroy()
  25. {
  26. simple_if_fini $h2
  27. }
  28. loopback_test()
  29. {
  30. RET=0
  31. tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \
  32. skip_hw arp_op reply arp_tip 192.0.2.1 action drop
  33. $MZ $h1 -c 1 -t arp -q
  34. tc_check_packets "dev $h1 ingress" 101 1
  35. check_fail $? "Matched on a filter without loopback setup"
  36. ethtool -K $h1 loopback on
  37. check_err $? "Failed to enable loopback"
  38. setup_wait_dev $h1
  39. $MZ $h1 -c 1 -t arp -q
  40. tc_check_packets "dev $h1 ingress" 101 1
  41. check_err $? "Did not match on filter with loopback"
  42. ethtool -K $h1 loopback off
  43. check_err $? "Failed to disable loopback"
  44. $MZ $h1 -c 1 -t arp -q
  45. tc_check_packets "dev $h1 ingress" 101 2
  46. check_fail $? "Matched on a filter after loopback was removed"
  47. tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower
  48. log_test "loopback"
  49. }
  50. setup_prepare()
  51. {
  52. h1=${NETIFS[p1]}
  53. h2=${NETIFS[p2]}
  54. vrf_prepare
  55. h1_create
  56. h2_create
  57. if ethtool -k $h1 | grep loopback | grep -q fixed; then
  58. log_test "SKIP: dev $h1 does not support loopback feature"
  59. exit $ksft_skip
  60. fi
  61. }
  62. cleanup()
  63. {
  64. pre_cleanup
  65. h2_destroy
  66. h1_destroy
  67. vrf_cleanup
  68. }
  69. trap cleanup EXIT
  70. setup_prepare
  71. setup_wait
  72. tests_run
  73. exit $EXIT_STATUS