mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
86e0f9b912
This moves NewContainsIPFunc from tsaddr to new ipset package. And wgengine/filter types gets split into wgengine/filter/filtertype, so netmap (and thus the CLI, etc) doesn't need to bring in ipset, bart, etc. Then add a test making sure the CLI deps don't regress. Updates #1278 Change-Id: Ia246d6d9502bbefbdeacc4aef1bed9c8b24f54d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package filter
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"tailscale.com/net/packet"
|
|
"tailscale.com/wgengine/filter/filtertype"
|
|
)
|
|
|
|
type matches []filtertype.Match
|
|
|
|
func (ms matches) match(q *packet.Parsed) bool {
|
|
for _, m := range ms {
|
|
if !slices.Contains(m.IPProto, q.IPProto) {
|
|
continue
|
|
}
|
|
if !m.SrcsContains(q.Src.Addr()) {
|
|
continue
|
|
}
|
|
for _, dst := range m.Dsts {
|
|
if !dst.Net.Contains(q.Dst.Addr()) {
|
|
continue
|
|
}
|
|
if !dst.Ports.Contains(q.Dst.Port()) {
|
|
continue
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (ms matches) matchIPsOnly(q *packet.Parsed) bool {
|
|
for _, m := range ms {
|
|
if !m.SrcsContains(q.Src.Addr()) {
|
|
continue
|
|
}
|
|
for _, dst := range m.Dsts {
|
|
if dst.Net.Contains(q.Dst.Addr()) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// matchProtoAndIPsOnlyIfAllPorts reports q matches any Match in ms where the
|
|
// Match if for the right IP Protocol and IP address, but ports are
|
|
// 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 !slices.Contains(m.IPProto, q.IPProto) {
|
|
continue
|
|
}
|
|
if !m.SrcsContains(q.Src.Addr()) {
|
|
continue
|
|
}
|
|
for _, dst := range m.Dsts {
|
|
if dst.Ports != filtertype.AllPorts {
|
|
continue
|
|
}
|
|
if dst.Net.Contains(q.Dst.Addr()) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|