wgengine: handle nil netmaps when assigning isSubnetRouter.

Fixes tailscale/coral#51

Signed-off-by: Maisem Ali <maisem@tailscale.com>
(cherry picked from commit 07f48a7bfeb7ceb249ce3ee90fc04ea616ef0b4c)
This commit is contained in:
Maisem Ali 2022-03-16 09:46:19 -07:00 committed by Denton Gentry
parent c8fb4f8c79
commit 80b31f3893

View File

@ -118,6 +118,7 @@ type userspaceEngine struct {
lastEngineSigFull deephash.Sum // of full wireguard config lastEngineSigFull deephash.Sum // of full wireguard config
lastEngineSigTrim deephash.Sum // of trimmed wireguard config lastEngineSigTrim deephash.Sum // of trimmed wireguard config
lastDNSConfig *dns.Config lastDNSConfig *dns.Config
lastIsSubnetRouter bool // was the node a primary subnet router in the last run.
recvActivityAt map[key.NodePublic]mono.Time recvActivityAt map[key.NodePublic]mono.Time
trimmedNodes map[key.NodePublic]bool // set of node keys of peers currently excluded from wireguard config trimmedNodes map[key.NodePublic]bool // set of node keys of peers currently excluded from wireguard config
sentActivityAt map[netaddr.IP]*mono.Time // value is accessed atomically sentActivityAt map[netaddr.IP]*mono.Time // value is accessed atomically
@ -125,8 +126,6 @@ type userspaceEngine struct {
statusBufioReader *bufio.Reader // reusable for UAPI statusBufioReader *bufio.Reader // reusable for UAPI
lastStatusPollTime mono.Time // last time we polled the engine status lastStatusPollTime mono.Time // last time we polled the engine status
lastIsSubnetRouter bool // was the node a primary subnet router in the last run.
mu sync.Mutex // guards following; see lock order comment below mu sync.Mutex // guards following; see lock order comment below
netMap *netmap.NetworkMap // or nil netMap *netmap.NetworkMap // or nil
closing bool // Close was called (even if we're still closing) closing bool // Close was called (even if we're still closing)
@ -854,6 +853,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
e.peerSequence = append(e.peerSequence, p.PublicKey) e.peerSequence = append(e.peerSequence, p.PublicKey)
peerSet[p.PublicKey] = struct{}{} peerSet[p.PublicKey] = struct{}{}
} }
nm := e.netMap
e.mu.Unlock() e.mu.Unlock()
listenPort := e.confListenPort listenPort := e.confListenPort
@ -862,8 +862,8 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
} }
isSubnetRouter := false isSubnetRouter := false
if e.birdClient != nil { if e.birdClient != nil && nm != nil && nm.SelfNode != nil {
isSubnetRouter = hasOverlap(e.netMap.SelfNode.PrimaryRoutes, e.netMap.Hostinfo.RoutableIPs) isSubnetRouter = hasOverlap(nm.SelfNode.PrimaryRoutes, nm.Hostinfo.RoutableIPs)
} }
isSubnetRouterChanged := isSubnetRouter != e.lastIsSubnetRouter isSubnetRouterChanged := isSubnetRouter != e.lastIsSubnetRouter