From 15d9ef481b13c40ef7b56f17635b47605839ec53 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 2 May 2025 16:29:44 +0200 Subject: [PATCH] policy/matcher: slices.ContainsFunc Signed-off-by: Kristoffer Dalby --- hscontrol/policy/matcher/matcher.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/hscontrol/policy/matcher/matcher.go b/hscontrol/policy/matcher/matcher.go index 1d4f09d2..ef29b171 100644 --- a/hscontrol/policy/matcher/matcher.go +++ b/hscontrol/policy/matcher/matcher.go @@ -3,6 +3,8 @@ package matcher import ( "net/netip" + "slices" + "github.com/juanfont/headscale/hscontrol/util" "go4.org/netipx" "tailscale.com/tailcfg" @@ -58,23 +60,11 @@ func MatchFromStrings(sources, destinations []string) Match { } func (m *Match) SrcsContainsIPs(ips ...netip.Addr) bool { - for _, ip := range ips { - if m.srcs.Contains(ip) { - return true - } - } - - return false + return slices.ContainsFunc(ips, m.srcs.Contains) } func (m *Match) DestsContainsIP(ips ...netip.Addr) bool { - for _, ip := range ips { - if m.dests.Contains(ip) { - return true - } - } - - return false + return slices.ContainsFunc(ips, m.dests.Contains) } func (m *Match) SrcsOverlapsPrefixes(prefixes ...netip.Prefix) bool {