all: move network monitoring from wgengine/monitor to net/netmon

We're using it in more and more places, and it's not really specific to
our use of Wireguard (and does more just link/interface monitoring).

Also removes the separate interface we had for it in sockstats -- it's
a small enough package (we already pull in all of its dependencies
via other paths) that it's not worth the extra complexity.

Updates #7621
Updates #7850

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
Mihai Parparita
2023-04-18 14:26:58 -07:00
committed by Mihai Parparita
parent 3ede3aafe4
commit 4722f7e322
51 changed files with 266 additions and 270 deletions

View File

@@ -42,6 +42,7 @@ import (
"tailscale.com/logtail"
"tailscale.com/logtail/filch"
"tailscale.com/net/memnet"
"tailscale.com/net/netmon"
"tailscale.com/net/proxymux"
"tailscale.com/net/socks5"
"tailscale.com/net/tsdial"
@@ -51,7 +52,6 @@ import (
"tailscale.com/types/nettype"
"tailscale.com/util/mak"
"tailscale.com/wgengine"
"tailscale.com/wgengine/monitor"
"tailscale.com/wgengine/netstack"
)
@@ -106,7 +106,7 @@ type Server struct {
initErr error
lb *ipnlocal.LocalBackend
netstack *netstack.Impl
linkMon *monitor.Mon
netMon *netmon.Monitor
rootPath string // the state directory
hostname string
shutdownCtx context.Context
@@ -356,8 +356,8 @@ func (s *Server) Close() error {
if s.lb != nil {
s.lb.Shutdown()
}
if s.linkMon != nil {
s.linkMon.Close()
if s.netMon != nil {
s.netMon.Close()
}
if s.dialer != nil {
s.dialer.Close()
@@ -476,17 +476,17 @@ func (s *Server) start() (reterr error) {
return err
}
s.linkMon, err = monitor.New(logf)
s.netMon, err = netmon.New(logf)
if err != nil {
return err
}
closePool.add(s.linkMon)
closePool.add(s.netMon)
s.dialer = &tsdial.Dialer{Logf: logf} // mutated below (before used)
eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
ListenPort: 0,
LinkMonitor: s.linkMon,
Dialer: s.dialer,
ListenPort: 0,
NetMon: s.netMon,
Dialer: s.dialer,
})
if err != nil {
return err