mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 06:07:34 +00:00
wgengine/filter: remove the Matches type.
It only served to obscure the underlying slice type without adding much value. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:

committed by
Dave Anderson

parent
b950bd60bf
commit
76d99cf01a
@@ -92,7 +92,7 @@ const (
|
||||
// NewAllowAll returns a packet filter that accepts everything to and
|
||||
// from localNets.
|
||||
func NewAllowAll(localNets []netaddr.IPPrefix, logf logger.Logf) *Filter {
|
||||
return New(Matches{Match{NetPortRangeAny, NetAny}}, localNets, nil, logf)
|
||||
return New([]Match{Match{NetPortRangeAny, NetAny}}, localNets, nil, logf)
|
||||
}
|
||||
|
||||
// NewAllowNone returns a packet filter that rejects everything.
|
||||
@@ -105,7 +105,7 @@ func NewAllowNone(logf logger.Logf) *Filter {
|
||||
// by matches. If shareStateWith is non-nil, the returned filter
|
||||
// shares state with the previous one, to enable changing rules at
|
||||
// runtime without breaking existing stateful flows.
|
||||
func New(matches Matches, localNets []netaddr.IPPrefix, shareStateWith *Filter, logf logger.Logf) *Filter {
|
||||
func New(matches []Match, localNets []netaddr.IPPrefix, shareStateWith *Filter, logf logger.Logf) *Filter {
|
||||
var state *filterState
|
||||
if shareStateWith != nil {
|
||||
state = shareStateWith.state
|
||||
|
@@ -97,7 +97,7 @@ func netports(netPorts ...string) (ret []NetPortRange) {
|
||||
return ret
|
||||
}
|
||||
|
||||
var matches = Matches{
|
||||
var matches = []Match{
|
||||
{Srcs: nets("8.1.1.1", "8.2.2.2"), Dsts: netports("1.2.3.4:22", "5.6.7.8:23-24")},
|
||||
{Srcs: nets("8.1.1.1", "8.2.2.2"), Dsts: netports("5.6.7.8:27-28")},
|
||||
{Srcs: nets("2.2.2.2"), Dsts: netports("8.1.1.1:22")},
|
||||
@@ -115,13 +115,13 @@ func newFilter(logf logger.Logf) *Filter {
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
for _, ent := range []Matches{Matches{matches[0]}, matches} {
|
||||
for _, ent := range [][]Match{[]Match{matches[0]}, matches} {
|
||||
b, err := json.Marshal(ent)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
|
||||
mm2 := Matches{}
|
||||
mm2 := []Match{}
|
||||
if err := json.Unmarshal(b, &mm2); err != nil {
|
||||
t.Fatalf("unmarshal: %v (%v)", err, string(b))
|
||||
}
|
||||
|
@@ -81,6 +81,3 @@ func (m Match) String() string {
|
||||
}
|
||||
return fmt.Sprintf("%v=>%v", ss, ds)
|
||||
}
|
||||
|
||||
// Matches is a list of packet matchers.
|
||||
type Matches []Match
|
||||
|
@@ -80,7 +80,7 @@ func (ms matches4) String() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func newMatches4(ms Matches) (ret matches4) {
|
||||
func newMatches4(ms []Match) (ret matches4) {
|
||||
for _, m := range ms {
|
||||
var m4 match4
|
||||
for _, src := range m.Srcs {
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
// MatchesFromFilterRules converts tailcfg FilterRules into Matches.
|
||||
// If an error is returned, the Matches result is still valid,
|
||||
// containing the rules that were successfully converted.
|
||||
func MatchesFromFilterRules(pf []tailcfg.FilterRule) (Matches, error) {
|
||||
func MatchesFromFilterRules(pf []tailcfg.FilterRule) ([]Match, error) {
|
||||
mm := make([]Match, 0, len(pf))
|
||||
var erracc error
|
||||
|
||||
|
@@ -98,7 +98,7 @@ func netports(netPorts ...string) (ret []filter.NetPortRange) {
|
||||
}
|
||||
|
||||
func setfilter(logf logger.Logf, tun *TUN) {
|
||||
matches := filter.Matches{
|
||||
matches := []filter.Match{
|
||||
{Srcs: nets("5.6.7.8"), Dsts: netports("1.2.3.4:89-90")},
|
||||
{Srcs: nets("1.2.3.4"), Dsts: netports("5.6.7.8:98")},
|
||||
}
|
||||
|
Reference in New Issue
Block a user