You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package filter
|
|
|
|
import (
|
|
"tailscale.com/net/packet"
|
|
"tailscale.com/types/views"
|
|
"tailscale.com/wgengine/filter/filtertype"
|
|
)
|
|
|
|
type matches []filtertype.Match
|
|
|
|
func (ms matches) match(q *packet.Parsed) bool {
|
|
for _, m := range ms {
|
|
if !views.SliceContains(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 !views.SliceContains(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
|
|
}
|
|
|