This commit is contained in:
2026-02-19 10:07:43 +00:00
parent 007438e372
commit 6e637ecf77
1763 changed files with 60820 additions and 279516 deletions

View File

@@ -21,6 +21,7 @@ import (
"go4.org/mem"
"tailscale.com/envknob"
"tailscale.com/tailcfg"
"tailscale.com/types/lazy"
"tailscale.com/types/opt"
"tailscale.com/types/ptr"
"tailscale.com/util/cloudenv"
@@ -42,7 +43,7 @@ func RegisterHostinfoNewHook(f func(*tailcfg.Hostinfo)) {
// New returns a partially populated Hostinfo for the current host.
func New() *tailcfg.Hostinfo {
hostname, _ := os.Hostname()
hostname, _ := Hostname()
hostname = dnsname.FirstLabel(hostname)
hi := &tailcfg.Hostinfo{
IPNVersion: version.Long(),
@@ -497,5 +498,32 @@ func IsNATLabGuestVM() bool {
return false
}
// NAT Lab VMs have a unique MAC address prefix.
// See
const copyV86DeviceModel = "copy-v86"
var isV86Cache lazy.SyncValue[bool]
// IsInVM86 reports whether we're running in the copy/v86 wasm emulator,
// https://github.com/copy/v86/.
func IsInVM86() bool {
return isV86Cache.Get(func() bool {
return New().DeviceModel == copyV86DeviceModel
})
}
type hostnameQuery func() (string, error)
var hostnameFn atomic.Value // of func() (string, error)
// SetHostNameFn sets a custom function for querying the system hostname.
func SetHostnameFn(fn hostnameQuery) {
hostnameFn.Store(fn)
}
// Hostname returns the system hostname using the function
// set by SetHostNameFn. We will fallback to os.Hostname.
func Hostname() (string, error) {
if fn, ok := hostnameFn.Load().(hostnameQuery); ok && fn != nil {
return fn()
}
return os.Hostname()
}