diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index 167950d9c..c2e7dcaf4 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -12,7 +12,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa github.com/golang/groupcache/lru from tailscale.com/net/dnscache github.com/hdevalence/ed25519consensus from tailscale.com/tka L github.com/josharian/native from github.com/mdlayher/netlink+ - L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces+ + L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink github.com/klauspost/compress/flate from nhooyr.io/websocket L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+ @@ -85,14 +85,13 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa tailscale.com/util/lineread from tailscale.com/hostinfo+ tailscale.com/util/mak from tailscale.com/syncs+ tailscale.com/util/multierr from tailscale.com/health - tailscale.com/util/set from tailscale.com/health+ + tailscale.com/util/set from tailscale.com/health tailscale.com/util/singleflight from tailscale.com/net/dnscache tailscale.com/util/vizerror from tailscale.com/tsweb W 💣 tailscale.com/util/winutil from tailscale.com/hostinfo+ tailscale.com/version from tailscale.com/derp+ tailscale.com/version/distro from tailscale.com/hostinfo+ tailscale.com/wgengine/filter from tailscale.com/types/netmap - tailscale.com/wgengine/monitor from tailscale.com/net/sockstats golang.org/x/crypto/acme from golang.org/x/crypto/acme/autocert golang.org/x/crypto/acme/autocert from tailscale.com/cmd/derper golang.org/x/crypto/argon2 from tailscale.com/tka diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index f8147d646..e0db11c38 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -13,7 +13,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep github.com/google/uuid from tailscale.com/util/quarantine+ github.com/hdevalence/ed25519consensus from tailscale.com/tka L github.com/josharian/native from github.com/mdlayher/netlink+ - L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces+ + L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink github.com/kballard/go-shellquote from tailscale.com/cmd/tailscale/cli github.com/klauspost/compress/flate from nhooyr.io/websocket @@ -127,7 +127,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/version/distro from tailscale.com/cmd/tailscale/cli+ tailscale.com/wgengine/capture from tailscale.com/cmd/tailscale/cli tailscale.com/wgengine/filter from tailscale.com/types/netmap - tailscale.com/wgengine/monitor from tailscale.com/net/sockstats golang.org/x/crypto/argon2 from tailscale.com/tka golang.org/x/crypto/blake2b from golang.org/x/crypto/nacl/box+ golang.org/x/crypto/blake2s from tailscale.com/control/controlbase+ diff --git a/net/interfaces/interfaces.go b/net/interfaces/interfaces.go index d5a76c511..ba7756b1c 100644 --- a/net/interfaces/interfaces.go +++ b/net/interfaces/interfaces.go @@ -353,6 +353,12 @@ func (s *State) String() string { return sb.String() } +// ChangeFunc is a callback function (usually registered with +// wgengine/monitor's Mon) that's called when the network +// changed. The changed parameter is whether the network changed +// enough for State to have changed since the last callback. +type ChangeFunc func(changed bool, state *State) + // An InterfaceFilter indicates whether EqualFiltered should use i when deciding whether two States are equal. // ips are all the IPPrefixes associated with i. type InterfaceFilter func(i Interface, ips []netip.Prefix) bool diff --git a/net/sockstats/sockstats.go b/net/sockstats/sockstats.go index 28055d201..e8e1ff735 100644 --- a/net/sockstats/sockstats.go +++ b/net/sockstats/sockstats.go @@ -11,7 +11,7 @@ package sockstats import ( "context" - "tailscale.com/wgengine/monitor" + "tailscale.com/net/interfaces" ) type SockStats struct { @@ -34,6 +34,13 @@ func Get() *SockStats { return get() } -func SetLinkMonitor(lm *monitor.Mon) { +// LinkMonitor is the interface for the parts of wgengine/mointor's Mon that we +// need, to avoid the dependency. +type LinkMonitor interface { + InterfaceState() *interfaces.State + RegisterChangeCallback(interfaces.ChangeFunc) (unregister func()) +} + +func SetLinkMonitor(lm LinkMonitor) { setLinkMonitor(lm) } diff --git a/net/sockstats/sockstats_noop.go b/net/sockstats/sockstats_noop.go index 913f62d4d..518c73443 100644 --- a/net/sockstats/sockstats_noop.go +++ b/net/sockstats/sockstats_noop.go @@ -7,8 +7,6 @@ package sockstats import ( "context" - - "tailscale.com/wgengine/monitor" ) func withSockStats(ctx context.Context, label string) context.Context { @@ -19,5 +17,5 @@ func get() *SockStats { return nil } -func setLinkMonitor(lm *monitor.Mon) { +func setLinkMonitor(lm LinkMonitor) { } diff --git a/net/sockstats/sockstats_tsgo.go b/net/sockstats/sockstats_tsgo.go index 58a737d1c..ab28c78a6 100644 --- a/net/sockstats/sockstats_tsgo.go +++ b/net/sockstats/sockstats_tsgo.go @@ -13,7 +13,6 @@ import ( "sync/atomic" "tailscale.com/net/interfaces" - "tailscale.com/wgengine/monitor" ) type sockStatCounters struct { @@ -113,7 +112,7 @@ func get() *SockStats { return r } -func setLinkMonitor(lm *monitor.Mon) { +func setLinkMonitor(lm LinkMonitor) { sockStats.mu.Lock() defer sockStats.mu.Unlock() diff --git a/wgengine/monitor/monitor.go b/wgengine/monitor/monitor.go index 52bb0bc1c..fc318d358 100644 --- a/wgengine/monitor/monitor.go +++ b/wgengine/monitor/monitor.go @@ -48,12 +48,6 @@ type osMon interface { IsInterestingInterface(iface string) bool } -// ChangeFunc is a callback function that's called when the network -// changed. The changed parameter is whether the network changed -// enough for interfaces.State to have changed since the last -// callback. -type ChangeFunc func(changed bool, state *interfaces.State) - // Mon represents a monitoring instance. type Mon struct { logf logger.Logf @@ -62,7 +56,7 @@ type Mon struct { stop chan struct{} // closed on Stop mu sync.Mutex // guards all following fields - cbs set.HandleSet[ChangeFunc] + cbs set.HandleSet[interfaces.ChangeFunc] ruleDelCB set.HandleSet[RuleDeleteCallback] ifState *interfaces.State gwValid bool // whether gw and gwSelfIP are valid @@ -139,7 +133,7 @@ func (m *Mon) GatewayAndSelfIP() (gw, myIP netip.Addr, ok bool) { // RegisterChangeCallback adds callback to the set of parties to be // notified (in their own goroutine) when the network state changes. // To remove this callback, call unregister (or close the monitor). -func (m *Mon) RegisterChangeCallback(callback ChangeFunc) (unregister func()) { +func (m *Mon) RegisterChangeCallback(callback interfaces.ChangeFunc) (unregister func()) { m.mu.Lock() defer m.mu.Unlock() handle := m.cbs.Add(callback)