Преглед изворни кода

wgengine/filter: use slices.Contains in another place

We keep finding these.

Updates #cleanup

Change-Id: Iabc049b0f8da07341011356f0ecd5315c33ff548
Signed-off-by: Brad Fitzpatrick <[email protected]>
Brad Fitzpatrick пре 2 година
родитељ
комит
8b630c91bc
1 измењених фајлова са 3 додато и 11 уклоњено
  1. 3 11
      wgengine/filter/match.go

+ 3 - 11
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
-}