mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-10 10:41:32 +09:00
3aece65014
PR tailscale/tailscale#20646 changed the representation of DERP region
IDs from plain ints to a tailcfg.DERPRegionID type. This patch
requires that version of the tailscale.com library and updates our
code to also use the new type.
Updates: tailscale/tailscale#20165
(cherry picked from commit 79695ab51b)
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
// Package state provides pure functions for processing [tailcfg.MapRequest] data.
|
|
// These functions are extracted from [State.UpdateNodeFromMapRequest] to improve
|
|
// testability and maintainability.
|
|
|
|
package state
|
|
|
|
import (
|
|
"github.com/juanfont/headscale/hscontrol/types"
|
|
"github.com/rs/zerolog/log"
|
|
"tailscale.com/tailcfg"
|
|
)
|
|
|
|
// netInfoFromMapRequest determines the correct [tailcfg.NetInfo] to use.
|
|
// Returns the [tailcfg.NetInfo] that should be used for this request.
|
|
func netInfoFromMapRequest(
|
|
nodeID types.NodeID,
|
|
currentHostinfo *tailcfg.Hostinfo,
|
|
reqHostinfo *tailcfg.Hostinfo,
|
|
) *tailcfg.NetInfo {
|
|
// If request has [tailcfg.NetInfo], use it
|
|
if reqHostinfo != nil && reqHostinfo.NetInfo != nil {
|
|
return reqHostinfo.NetInfo
|
|
}
|
|
|
|
// Otherwise, use current [tailcfg.NetInfo] if available
|
|
if currentHostinfo != nil && currentHostinfo.NetInfo != nil {
|
|
log.Debug().
|
|
Caller().
|
|
Uint64("node.id", nodeID.Uint64()).
|
|
Int64("preferredDERP", currentHostinfo.NetInfo.PreferredDERP.Int64()).
|
|
Msg("using NetInfo from previous Hostinfo in MapRequest")
|
|
|
|
return currentHostinfo.NetInfo
|
|
}
|
|
|
|
// No [tailcfg.NetInfo] available anywhere - log for debugging
|
|
var hostname string
|
|
if reqHostinfo != nil {
|
|
hostname = reqHostinfo.Hostname
|
|
} else if currentHostinfo != nil {
|
|
hostname = currentHostinfo.Hostname
|
|
}
|
|
|
|
log.Debug().
|
|
Caller().
|
|
Uint64("node.id", nodeID.Uint64()).
|
|
Str("node.hostname", hostname).
|
|
Msg("node sent update but has no NetInfo in request or database")
|
|
|
|
return nil
|
|
}
|