Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # This test uses standard topology for testing gretap. See
0005 # mirror_gre_topo_lib.sh for more details.
0006 #
0007 # Test for "tc action mirred egress mirror" when the device to mirror to is a
0008 # gretap or ip6gretap netdevice. Expect that the packets come out encapsulated,
0009 # and another gretap / ip6gretap netdevice is then capable of decapsulating the
0010 # traffic. Test that the payload is what is expected (ICMP ping request or
0011 # reply, depending on test).
0012 
0013 ALL_TESTS="
0014         test_gretap
0015         test_ip6gretap
0016         test_gretap_mac
0017         test_ip6gretap_mac
0018         test_two_spans
0019 "
0020 
0021 NUM_NETIFS=6
0022 source lib.sh
0023 source mirror_lib.sh
0024 source mirror_gre_lib.sh
0025 source mirror_gre_topo_lib.sh
0026 
0027 setup_prepare()
0028 {
0029         h1=${NETIFS[p1]}
0030         swp1=${NETIFS[p2]}
0031 
0032         swp2=${NETIFS[p3]}
0033         h2=${NETIFS[p4]}
0034 
0035         swp3=${NETIFS[p5]}
0036         h3=${NETIFS[p6]}
0037 
0038         vrf_prepare
0039         mirror_gre_topo_create
0040 
0041         ip address add dev $swp3 192.0.2.129/28
0042         ip address add dev $h3 192.0.2.130/28
0043 
0044         ip address add dev $swp3 2001:db8:2::1/64
0045         ip address add dev $h3 2001:db8:2::2/64
0046 }
0047 
0048 cleanup()
0049 {
0050         pre_cleanup
0051 
0052         ip address del dev $h3 2001:db8:2::2/64
0053         ip address del dev $swp3 2001:db8:2::1/64
0054 
0055         ip address del dev $h3 192.0.2.130/28
0056         ip address del dev $swp3 192.0.2.129/28
0057 
0058         mirror_gre_topo_destroy
0059         vrf_cleanup
0060 }
0061 
0062 test_span_gre_mac()
0063 {
0064         local tundev=$1; shift
0065         local direction=$1; shift
0066         local what=$1; shift
0067 
0068         case "$direction" in
0069         ingress) local src_mac=$(mac_get $h1); local dst_mac=$(mac_get $h2)
0070                 ;;
0071         egress) local src_mac=$(mac_get $h2); local dst_mac=$(mac_get $h1)
0072                 ;;
0073         esac
0074 
0075         RET=0
0076 
0077         mirror_install $swp1 $direction $tundev "matchall $tcflags"
0078         icmp_capture_install h3-${tundev} "src_mac $src_mac dst_mac $dst_mac"
0079 
0080         mirror_test v$h1 192.0.2.1 192.0.2.2 h3-${tundev} 100 10
0081 
0082         icmp_capture_uninstall h3-${tundev}
0083         mirror_uninstall $swp1 $direction
0084 
0085         log_test "$direction $what: envelope MAC ($tcflags)"
0086 }
0087 
0088 test_two_spans()
0089 {
0090         RET=0
0091 
0092         mirror_install $swp1 ingress gt4 "matchall $tcflags"
0093         mirror_install $swp1 egress gt6 "matchall $tcflags"
0094         quick_test_span_gre_dir gt4 ingress
0095         quick_test_span_gre_dir gt6 egress
0096 
0097         mirror_uninstall $swp1 ingress
0098         fail_test_span_gre_dir gt4 ingress
0099         quick_test_span_gre_dir gt6 egress
0100 
0101         mirror_install $swp1 ingress gt4 "matchall $tcflags"
0102         mirror_uninstall $swp1 egress
0103         quick_test_span_gre_dir gt4 ingress
0104         fail_test_span_gre_dir gt6 egress
0105 
0106         mirror_uninstall $swp1 ingress
0107         log_test "two simultaneously configured mirrors ($tcflags)"
0108 }
0109 
0110 test_gretap()
0111 {
0112         full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
0113         full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
0114 }
0115 
0116 test_ip6gretap()
0117 {
0118         full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
0119         full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
0120 }
0121 
0122 test_gretap_mac()
0123 {
0124         test_span_gre_mac gt4 ingress "mirror to gretap"
0125         test_span_gre_mac gt4 egress "mirror to gretap"
0126 }
0127 
0128 test_ip6gretap_mac()
0129 {
0130         test_span_gre_mac gt6 ingress "mirror to ip6gretap"
0131         test_span_gre_mac gt6 egress "mirror to ip6gretap"
0132 }
0133 
0134 test_all()
0135 {
0136         slow_path_trap_install $swp1 ingress
0137         slow_path_trap_install $swp1 egress
0138 
0139         tests_run
0140 
0141         slow_path_trap_uninstall $swp1 egress
0142         slow_path_trap_uninstall $swp1 ingress
0143 }
0144 
0145 trap cleanup EXIT
0146 
0147 setup_prepare
0148 setup_wait
0149 
0150 tcflags="skip_hw"
0151 test_all
0152 
0153 if ! tc_offload_check; then
0154         echo "WARN: Could not test offloaded functionality"
0155 else
0156         tcflags="skip_sw"
0157         test_all
0158 fi
0159 
0160 exit $EXIT_STATUS