From 562e996996992a486021423da978387e0ebcd294 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Wed, 24 Feb 2021 23:45:27 +0100 Subject: [PATCH] Fixed crash when NetInfo is nil --- machine.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/machine.go b/machine.go index a81a9be8..648478ad 100644 --- a/machine.go +++ b/machine.go @@ -95,6 +95,13 @@ func (m Machine) toNode() (*tailcfg.Node, error) { } } + var derp string + if hostinfo.NetInfo != nil { + derp = fmt.Sprintf("127.3.3.40:%d", hostinfo.NetInfo.PreferredDERP) + } else { + derp = "127.3.3.40:0" // Zero means disconnected or unknown. + } + n := tailcfg.Node{ ID: tailcfg.NodeID(m.ID), // this is the actual ID StableID: tailcfg.StableNodeID(strconv.FormatUint(m.ID, 10)), // in headscale, unlike tailcontrol server, IDs are permantent @@ -107,7 +114,7 @@ func (m Machine) toNode() (*tailcfg.Node, error) { Addresses: addrs, AllowedIPs: allowedIPs, Endpoints: endpoints, - DERP: fmt.Sprintf("127.3.3.40:%d", hostinfo.NetInfo.PreferredDERP), + DERP: derp, Hostinfo: hostinfo, Created: m.CreatedAt,