From 8b630c91bc44e731406cd51a5055bd2273b84772 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 11 Oct 2023 14:00:50 -0700 Subject: [PATCH] wgengine/filter: use slices.Contains in another place We keep finding these. Updates #cleanup Change-Id: Iabc049b0f8da07341011356f0ecd5315c33ff548 Signed-off-by: Brad Fitzpatrick --- wgengine/filter/match.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/wgengine/filter/match.go b/wgengine/filter/match.go index 2d6f71d19..b0ebfbb41 100644 --- a/wgengine/filter/match.go +++ b/wgengine/filter/match.go @@ -6,6 +6,7 @@ package filter import ( "fmt" "net/netip" + "slices" "strings" "tailscale.com/net/packet" @@ -100,7 +101,7 @@ type matches []Match func (ms matches) match(q *packet.Parsed) bool { for _, m := range ms { - if !protoInList(q.IPProto, m.IPProto) { + if !slices.Contains(m.IPProto, q.IPProto) { continue } if !ipInList(q.Src.Addr(), m.Srcs) { @@ -138,7 +139,7 @@ func (ms matches) matchIPsOnly(q *packet.Parsed) bool { // ignored, as long as the match is for the entire uint16 port range. func (ms matches) matchProtoAndIPsOnlyIfAllPorts(q *packet.Parsed) bool { for _, m := range ms { - if !protoInList(q.IPProto, m.IPProto) { + if !slices.Contains(m.IPProto, q.IPProto) { continue } if !ipInList(q.Src.Addr(), m.Srcs) { @@ -164,12 +165,3 @@ func ipInList(ip netip.Addr, netlist []netip.Prefix) bool { } return false } - -func protoInList(proto ipproto.Proto, valid []ipproto.Proto) bool { - for _, v := range valid { - if proto == v { - return true - } - } - return false -}