From a3b8a21385577378eddf64585d4600f5435166c9 Mon Sep 17 00:00:00 2001 From: Hakan Sariman Date: Sat, 8 Mar 2025 12:26:53 +0300 Subject: [PATCH] Refactor CheckRoutes to return resource IDs for matching source and destination addresses --- client/internal/peer/status.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/internal/peer/status.go b/client/internal/peer/status.go index e59874ae2..512034dc6 100644 --- a/client/internal/peer/status.go +++ b/client/internal/peer/status.go @@ -367,10 +367,8 @@ func (d *Status) RemovePeerStateRoute(peer string, route string) error { return nil } -// CheckRoutes checks for both the source and destination IP addresses in the local peer routes first, -// and then in the remote peers' routes. It returns the IP address of the matching peer (as a string) -// for source and destination. If a match is found in local peer routes, the local peer IP is returned; -// otherwise, the remote peer IP is returned. If no match is found, an empty string is returned for that IP. +// CheckRoutes checks if the source and destination addresses are within the same route +// and returns the resource ID of the route that contains the addresses func (d *Status) CheckRoutes(src, dst netip.Addr, direction nftypes.Direction) (srcResId string, dstResId string) { d.mux.Lock() d.resIdMux.Lock() @@ -383,6 +381,10 @@ func (d *Status) CheckRoutes(src, dst netip.Addr, direction nftypes.Direction) ( } else if route.Contains(dst) { dstResId = resId } + + if srcResId != "" && dstResId != "" { + break + } } return