From 7055f870f8360bca2ead39c41f2538467fee7f7b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 15 Apr 2021 17:08:24 -0700 Subject: [PATCH] control/controlclient: only use a single DNS label as the hostname. Fixes #971 Signed-off-by: David Anderson --- control/controlclient/direct.go | 2 ++ util/dnsname/dnsname.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 880fc04bc..13efeca21 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -46,6 +46,7 @@ import ( "tailscale.com/types/opt" "tailscale.com/types/persist" "tailscale.com/types/wgkey" + "tailscale.com/util/dnsname" "tailscale.com/util/systemd" "tailscale.com/version" "tailscale.com/wgengine/filter" @@ -179,6 +180,7 @@ var osVersion func() string // non-nil on some platforms func NewHostinfo() *tailcfg.Hostinfo { hostname, _ := os.Hostname() + hostname = dnsname.FirstLabel(hostname) var osv string if osVersion != nil { osv = osVersion() diff --git a/util/dnsname/dnsname.go b/util/dnsname/dnsname.go index 4a0cf8eaa..56ee0baea 100644 --- a/util/dnsname/dnsname.go +++ b/util/dnsname/dnsname.go @@ -223,6 +223,14 @@ func NumLabels(hostname string) int { return strings.Count(hostname, ".") } +// FirstLabel returns the first DNS label of hostname. +func FirstLabel(hostname string) string { + if i := strings.IndexByte(hostname, '.'); i != -1 { + return hostname[:i] + } + return hostname +} + var separators = map[byte]bool{ ' ': true, '.': true,