mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-21 12:28:39 +00:00
wgengine/filter: use slices.Contains in another place
We keep finding these. Updates #cleanup Change-Id: Iabc049b0f8da07341011356f0ecd5315c33ff548 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
0a412eba40
commit
8b630c91bc
@ -6,6 +6,7 @@ package filter
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"tailscale.com/net/packet"
|
"tailscale.com/net/packet"
|
||||||
@ -100,7 +101,7 @@ type matches []Match
|
|||||||
|
|
||||||
func (ms matches) match(q *packet.Parsed) bool {
|
func (ms matches) match(q *packet.Parsed) bool {
|
||||||
for _, m := range ms {
|
for _, m := range ms {
|
||||||
if !protoInList(q.IPProto, m.IPProto) {
|
if !slices.Contains(m.IPProto, q.IPProto) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !ipInList(q.Src.Addr(), m.Srcs) {
|
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.
|
// ignored, as long as the match is for the entire uint16 port range.
|
||||||
func (ms matches) matchProtoAndIPsOnlyIfAllPorts(q *packet.Parsed) bool {
|
func (ms matches) matchProtoAndIPsOnlyIfAllPorts(q *packet.Parsed) bool {
|
||||||
for _, m := range ms {
|
for _, m := range ms {
|
||||||
if !protoInList(q.IPProto, m.IPProto) {
|
if !slices.Contains(m.IPProto, q.IPProto) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !ipInList(q.Src.Addr(), m.Srcs) {
|
if !ipInList(q.Src.Addr(), m.Srcs) {
|
||||||
@ -164,12 +165,3 @@ func ipInList(ip netip.Addr, netlist []netip.Prefix) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func protoInList(proto ipproto.Proto, valid []ipproto.Proto) bool {
|
|
||||||
for _, v := range valid {
|
|
||||||
if proto == v {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user