From 8343b243e7350fbbfd943b0e149deac6d4cb1009 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Fri, 30 Sep 2022 14:15:17 -0700 Subject: [PATCH] all: consistently initialize Logf when creating tsdial.Dialers Most visible when using tsnet.Server, but could have resulted in dropped messages in a few other places too. Fixes #5743 Signed-off-by: Mihai Parparita --- cmd/tailscaled/tailscaled.go | 3 +-- cmd/tailscaled/tailscaled_windows.go | 2 +- cmd/tsconnect/wasm/wasm_js.go | 2 +- ipn/ipnlocal/local.go | 2 +- net/dns/manager.go | 2 +- tsnet/tsnet.go | 2 +- wgengine/userspace.go | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 97785530c..5878b3590 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -375,8 +375,7 @@ func run() error { socksListener, httpProxyListener := mustStartProxyListeners(args.socksAddr, args.httpProxyAddr) - dialer := new(tsdial.Dialer) // mutated below (before used) - dialer.Logf = logf + dialer := &tsdial.Dialer{Logf: logf} // mutated below (before used) e, useNetstack, err := createEngine(logf, linkMon, dialer) if err != nil { return fmt.Errorf("createEngine: %w", err) diff --git a/cmd/tailscaled/tailscaled_windows.go b/cmd/tailscaled/tailscaled_windows.go index bcb6fbfd0..35f7623ce 100644 --- a/cmd/tailscaled/tailscaled_windows.go +++ b/cmd/tailscaled/tailscaled_windows.go @@ -266,7 +266,7 @@ func startIPNServer(ctx context.Context, logid string) error { if err != nil { return fmt.Errorf("monitor: %w", err) } - dialer := new(tsdial.Dialer) + dialer := &tsdial.Dialer{Logf: logf} getEngineRaw := func() (wgengine.Engine, *netstack.Impl, error) { dev, devName, err := tstun.New(logf, "Tailscale") diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index 731d6d994..b62485ce8 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -96,7 +96,7 @@ func newIPN(jsConfig js.Value) map[string]any { logtail := logtail.NewLogger(c, log.Printf) logf := logtail.Logf - dialer := new(tsdial.Dialer) + dialer := &tsdial.Dialer{Logf: logf} eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{ Dialer: dialer, }) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 3040452e3..f0436615e 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -214,7 +214,7 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, diale logf.JSON(1, "Hostinfo", hi) envknob.LogCurrent(logf) if dialer == nil { - dialer = new(tsdial.Dialer) + dialer = &tsdial.Dialer{Logf: logf} } osshare.SetFileSharingEnabled(false, logf) diff --git a/net/dns/manager.go b/net/dns/manager.go index 711c04852..c766fd65c 100644 --- a/net/dns/manager.go +++ b/net/dns/manager.go @@ -540,7 +540,7 @@ func Cleanup(logf logger.Logf, interfaceName string) { logf("creating dns cleanup: %v", err) return } - dns := NewManager(logf, oscfg, nil, new(tsdial.Dialer), nil) + dns := NewManager(logf, oscfg, nil, &tsdial.Dialer{Logf: logf}, nil) if err := dns.Down(); err != nil { logf("dns down: %v", err) } diff --git a/tsnet/tsnet.go b/tsnet/tsnet.go index 006a9c586..cdd30225b 100644 --- a/tsnet/tsnet.go +++ b/tsnet/tsnet.go @@ -271,7 +271,7 @@ func (s *Server) start() (reterr error) { } closePool.add(s.linkMon) - s.dialer = new(tsdial.Dialer) // mutated below (before used) + s.dialer = &tsdial.Dialer{Logf: logf} // mutated below (before used) eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{ ListenPort: 0, LinkMonitor: s.linkMon, diff --git a/wgengine/userspace.go b/wgengine/userspace.go index ece0a200d..e6c876360 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -282,7 +282,7 @@ func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error) conf.DNS = d } if conf.Dialer == nil { - conf.Dialer = new(tsdial.Dialer) + conf.Dialer = &tsdial.Dialer{Logf: logf} } var tsTUNDev *tstun.Wrapper