From: Hangbin Liu <[email protected]>

The PSP test installs policy and route state, but relies on global
cleanup to tear it down. That can leave flavor-specific state around
when later tests are added to the same script.

Add cleanup_end_flv_psp() and run it at the end of
host_srv6_end_flv_psp_tests().

The host proxies are needed by all PSP testing. So move it to common
setup() and no need to delete.

Signed-off-by: Hangbin Liu <[email protected]>
---
 .../testing/selftests/net/srv6_end_flavors_test.sh | 70 ++++++++++++++++++++--
 1 file changed, 66 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/srv6_end_flavors_test.sh 
b/tools/testing/selftests/net/srv6_end_flavors_test.sh
index 56a1c5f865a7..52731983b4cc 100755
--- a/tools/testing/selftests/net/srv6_end_flavors_test.sh
+++ b/tools/testing/selftests/net/srv6_end_flavors_test.sh
@@ -564,10 +564,6 @@ __setup_rt_policy()
                add "${IPv6_HS_NETWORK}::${dst}" \
                encap seg6 mode inline segs "${policy}" \
                dev "${DUMMY_DEVNAME}"
-
-       ip -netns "${in_nsname}" -6 neigh \
-               add proxy "${IPv6_HS_NETWORK}::${dst}" \
-               dev "${RT2HS_DEVNAME}"
 }
 
 # see __setup_rt_policy
@@ -576,6 +572,56 @@ setup_rt_policy_ipv6()
        __setup_rt_policy "$1" "$2" "$3"
 }
 
+cleanup_rt_policy_ipv6()
+{
+       local dst="$1"
+       local encap_rt="$2"
+       local policy_rts="$3"
+       local in_nsname
+       local rt_nsname
+       local function
+       local fullsid
+       local op_type
+       local node
+       local n
+
+       in_nsname="$(get_rtname "${encap_rt}")"
+
+       for n in ${policy_rts}; do
+               node="$(__get_srv6_rtcfg_id "${n}")"
+               op_type="$(__get_srv6_rtcfg_op "${n}")"
+               rt_nsname="$(get_rtname "${node}")"
+
+               case "${op_type}" in
+               "noflv")
+                       function="${END_FUNC}"
+                       ;;
+
+               "psp")
+                       function="${END_PSP_FUNC}"
+                       ;;
+
+               *)
+                       break
+                       ;;
+               esac
+
+               fullsid="${LOCATOR_SERVICE}:${node}::${function}"
+
+               # Remove SRv6 Endpoint behavior for the selected router
+               if ip -netns "${rt_nsname}" -6 route get "${fullsid}" 
&>/dev/null; then
+                       ip -netns "${rt_nsname}" -6 route \
+                               del "${fullsid}" \
+                               table "${LOCALSID_TABLE_ID}" \
+                               dev "${DUMMY_DEVNAME}"
+               fi
+       done
+
+       # Remove SRv6 policy for incoming traffic sent by connected hosts
+       ip -netns "${in_nsname}" -6 route \
+               del "${IPv6_HS_NETWORK}::${dst}" dev "${DUMMY_DEVNAME}"
+}
+
 setup_hs()
 {
        local hs="$1"
@@ -645,6 +691,14 @@ setup()
        setup_rt_local_sids 3 "1 2 4"
        setup_rt_local_sids 4 "1 2 3"
 
+       # setup proxy on route entries for hosts
+       ip -netns "$(get_rtname 1)" -6 neigh add \
+               proxy "${IPv6_HS_NETWORK}::2" \
+               dev "${RT2HS_DEVNAME}"
+       ip -netns "$(get_rtname 2)" -6 neigh add \
+               proxy "${IPv6_HS_NETWORK}::1" \
+               dev "${RT2HS_DEVNAME}"
+
        # testing environment was set up successfully
        SETUP_ERR=0
 }
@@ -669,6 +723,12 @@ setup_end_flv_psp()
        setup_rt_policy_ipv6 1 2 "1:psp"
 }
 
+cleanup_end_flv_psp()
+{
+       cleanup_rt_policy_ipv6 2 1 "3:noflv 4:psp 2:psp"
+       cleanup_rt_policy_ipv6 1 2 "1:psp"
+}
+
 check_rt_connectivity()
 {
        local rtsrc="$1"
@@ -771,6 +831,8 @@ host_srv6_end_flv_psp_tests()
 
        check_and_log_hs_connectivity 1 2
        check_and_log_hs_connectivity 2 1
+
+       cleanup_end_flv_psp
 }
 
 test_iproute2_supp_or_ksft_skip()

-- 
2.55.0


Reply via email to