net/interfaces: remove mutating methods, add EqualFiltered instead

Now callers (wgengine/monitor) don't need to mutate the state to remove
boring interfaces before calling State.Equal. Instead, the methods
to remove boring interfaces from the State are removed, as is
the reflect-using Equal method itself, and in their place is
a new EqualFiltered method that takes a func predicate to match
interfaces to compare.

And then the FilterInteresting predicate is added for use
with EqualFiltered to do the job that that wgengine/monitor
previously wanted.

Now wgengine/monitor can keep the full interface state around,
including the "boring" interfaces, which we'll need for peerapi on
macOS/iOS to bind to the interface index of the utunN device.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-03-26 09:09:12 -07:00
parent 5a62aa8047
commit 7f174e84e6
3 changed files with 77 additions and 49 deletions

View File

@@ -101,12 +101,7 @@ func (m *Mon) InterfaceState() *interfaces.State {
}
func (m *Mon) interfaceStateUncached() (*interfaces.State, error) {
s, err := interfaces.GetState()
if s != nil {
s.RemoveTailscaleInterfaces()
s.RemoveUninterestingInterfacesAndAddresses()
}
return s, err
return interfaces.GetState()
}
// GatewayAndSelfIP returns the current network's default gateway, and
@@ -233,7 +228,7 @@ func (m *Mon) debounce() {
} else {
m.mu.Lock()
oldState := m.ifState
changed := !curState.Equal(oldState)
changed := !curState.EqualFiltered(oldState, interfaces.FilterInteresting)
if changed {
m.gwValid = false
m.ifState = curState