mirror_gre.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This test uses standard topology for testing gretap. See
  4. # mirror_gre_topo_lib.sh for more details.
  5. #
  6. # Test for "tc action mirred egress mirror" when the device to mirror to is a
  7. # gretap or ip6gretap netdevice. Expect that the packets come out encapsulated,
  8. # and another gretap / ip6gretap netdevice is then capable of decapsulating the
  9. # traffic. Test that the payload is what is expected (ICMP ping request or
  10. # reply, depending on test).
  11. ALL_TESTS="
  12. test_gretap
  13. test_ip6gretap
  14. test_gretap_mac
  15. test_ip6gretap_mac
  16. test_two_spans
  17. "
  18. NUM_NETIFS=6
  19. source lib.sh
  20. source mirror_lib.sh
  21. source mirror_gre_lib.sh
  22. source mirror_gre_topo_lib.sh
  23. setup_prepare()
  24. {
  25. h1=${NETIFS[p1]}
  26. swp1=${NETIFS[p2]}
  27. swp2=${NETIFS[p3]}
  28. h2=${NETIFS[p4]}
  29. swp3=${NETIFS[p5]}
  30. h3=${NETIFS[p6]}
  31. vrf_prepare
  32. mirror_gre_topo_create
  33. ip address add dev $swp3 192.0.2.129/28
  34. ip address add dev $h3 192.0.2.130/28
  35. ip address add dev $swp3 2001:db8:2::1/64
  36. ip address add dev $h3 2001:db8:2::2/64
  37. }
  38. cleanup()
  39. {
  40. pre_cleanup
  41. ip address del dev $h3 2001:db8:2::2/64
  42. ip address del dev $swp3 2001:db8:2::1/64
  43. ip address del dev $h3 192.0.2.130/28
  44. ip address del dev $swp3 192.0.2.129/28
  45. mirror_gre_topo_destroy
  46. vrf_cleanup
  47. }
  48. test_span_gre_mac()
  49. {
  50. local tundev=$1; shift
  51. local direction=$1; shift
  52. local prot=$1; shift
  53. local what=$1; shift
  54. local swp3mac=$(mac_get $swp3)
  55. local h3mac=$(mac_get $h3)
  56. RET=0
  57. mirror_install $swp1 $direction $tundev "matchall $tcflags"
  58. tc filter add dev $h3 ingress pref 77 prot $prot \
  59. flower ip_proto 0x2f src_mac $swp3mac dst_mac $h3mac \
  60. action pass
  61. mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
  62. tc filter del dev $h3 ingress pref 77
  63. mirror_uninstall $swp1 $direction
  64. log_test "$direction $what: envelope MAC ($tcflags)"
  65. }
  66. test_two_spans()
  67. {
  68. RET=0
  69. mirror_install $swp1 ingress gt4 "matchall $tcflags"
  70. mirror_install $swp1 egress gt6 "matchall $tcflags"
  71. quick_test_span_gre_dir gt4 ingress
  72. quick_test_span_gre_dir gt6 egress
  73. mirror_uninstall $swp1 ingress
  74. fail_test_span_gre_dir gt4 ingress
  75. quick_test_span_gre_dir gt6 egress
  76. mirror_install $swp1 ingress gt4 "matchall $tcflags"
  77. mirror_uninstall $swp1 egress
  78. quick_test_span_gre_dir gt4 ingress
  79. fail_test_span_gre_dir gt6 egress
  80. mirror_uninstall $swp1 ingress
  81. log_test "two simultaneously configured mirrors ($tcflags)"
  82. }
  83. test_gretap()
  84. {
  85. full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
  86. full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
  87. }
  88. test_ip6gretap()
  89. {
  90. full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
  91. full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
  92. }
  93. test_gretap_mac()
  94. {
  95. test_span_gre_mac gt4 ingress ip "mirror to gretap"
  96. test_span_gre_mac gt4 egress ip "mirror to gretap"
  97. }
  98. test_ip6gretap_mac()
  99. {
  100. test_span_gre_mac gt6 ingress ipv6 "mirror to ip6gretap"
  101. test_span_gre_mac gt6 egress ipv6 "mirror to ip6gretap"
  102. }
  103. test_all()
  104. {
  105. slow_path_trap_install $swp1 ingress
  106. slow_path_trap_install $swp1 egress
  107. tests_run
  108. slow_path_trap_uninstall $swp1 egress
  109. slow_path_trap_uninstall $swp1 ingress
  110. }
  111. trap cleanup EXIT
  112. setup_prepare
  113. setup_wait
  114. tcflags="skip_hw"
  115. test_all
  116. if ! tc_offload_check; then
  117. echo "WARN: Could not test offloaded functionality"
  118. else
  119. tcflags="skip_sw"
  120. test_all
  121. fi
  122. exit $EXIT_STATUS