From b9fb8ac70244f6b391118a9b180699e65533e7b0 Mon Sep 17 00:00:00 2001 From: Chenyang Gao Date: Sat, 6 May 2023 14:04:37 +0800 Subject: [PATCH] fix sys.Set(router) issue will crash the daemon in some OSs Signed-off-by: Chenyang Gao in commit 6e96744, the tsd system type has been added. Which will cause the daemon will crash on some OSs (Windows, darwin and so on). The root cause is that on those OSs, handleSubnetsInNetstack() will return true and set the conf.Router with a wrapper. Later in NewUserspaceEngine() it will do subsystem set and found that early set router mismatch to current value, then panic. --- cmd/tailscaled/tailscaled.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 0d46cdb0f..95193f1e7 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -649,7 +649,6 @@ func tryEngine(logf logger.Logf, sys *tsd.System, name string) (onlyNetstack boo dev.Close() return false, fmt.Errorf("creating router: %w", err) } - sys.Set(r) d, err := dns.NewOSConfigurator(logf, devName) if err != nil { @@ -663,6 +662,7 @@ func tryEngine(logf logger.Logf, sys *tsd.System, name string) (onlyNetstack boo conf.Router = netstack.NewSubnetRouterWrapper(conf.Router) netstackSubnetRouter = true } + sys.Set(conf.Router) } e, err := wgengine.NewUserspaceEngine(logf, conf) if err != nil {