1
0

mirror_gre.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 what=$1; shift
  53. case "$direction" in
  54. ingress) local src_mac=$(mac_get $h1); local dst_mac=$(mac_get $h2)
  55. ;;
  56. egress) local src_mac=$(mac_get $h2); local dst_mac=$(mac_get $h1)
  57. ;;
  58. esac
  59. RET=0
  60. mirror_install $swp1 $direction $tundev "matchall $tcflags"
  61. icmp_capture_install h3-${tundev} "src_mac $src_mac dst_mac $dst_mac"
  62. mirror_test v$h1 192.0.2.1 192.0.2.2 h3-${tundev} 100 10
  63. icmp_capture_uninstall h3-${tundev}
  64. mirror_uninstall $swp1 $direction
  65. log_test "$direction $what: envelope MAC ($tcflags)"
  66. }
  67. test_two_spans()
  68. {
  69. RET=0
  70. mirror_install $swp1 ingress gt4 "matchall $tcflags"
  71. mirror_install $swp1 egress gt6 "matchall $tcflags"
  72. quick_test_span_gre_dir gt4 ingress
  73. quick_test_span_gre_dir gt6 egress
  74. mirror_uninstall $swp1 ingress
  75. fail_test_span_gre_dir gt4 ingress
  76. quick_test_span_gre_dir gt6 egress
  77. mirror_install $swp1 ingress gt4 "matchall $tcflags"
  78. mirror_uninstall $swp1 egress
  79. quick_test_span_gre_dir gt4 ingress
  80. fail_test_span_gre_dir gt6 egress
  81. mirror_uninstall $swp1 ingress
  82. log_test "two simultaneously configured mirrors ($tcflags)"
  83. }
  84. test_gretap()
  85. {
  86. full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
  87. full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
  88. }
  89. test_ip6gretap()
  90. {
  91. full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
  92. full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
  93. }
  94. test_gretap_mac()
  95. {
  96. test_span_gre_mac gt4 ingress "mirror to gretap"
  97. test_span_gre_mac gt4 egress "mirror to gretap"
  98. }
  99. test_ip6gretap_mac()
  100. {
  101. test_span_gre_mac gt6 ingress "mirror to ip6gretap"
  102. test_span_gre_mac gt6 egress "mirror to ip6gretap"
  103. }
  104. test_all()
  105. {
  106. slow_path_trap_install $swp1 ingress
  107. slow_path_trap_install $swp1 egress
  108. tests_run
  109. slow_path_trap_uninstall $swp1 egress
  110. slow_path_trap_uninstall $swp1 ingress
  111. }
  112. trap cleanup EXIT
  113. setup_prepare
  114. setup_wait
  115. tcflags="skip_hw"
  116. test_all
  117. if ! tc_offload_check; then
  118. echo "WARN: Could not test offloaded functionality"
  119. else
  120. tcflags="skip_sw"
  121. test_all
  122. fi
  123. exit $EXIT_STATUS