From 770aa71ffbfbb01f7c8bfc65ce5e0505c783efde Mon Sep 17 00:00:00 2001 From: Naman Sood Date: Mon, 15 Mar 2021 17:59:35 -0400 Subject: client, cmd/hello, ipn, wgengine: fix whois for netstack-forwarded connections Updates #504 Updates #707 Signed-off-by: Naman Sood --- cmd/hello/hello.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/hello/hello.go b/cmd/hello/hello.go index fc7343150..1c14fb71b 100644 --- a/cmd/hello/hello.go +++ b/cmd/hello/hello.go @@ -13,12 +13,12 @@ import ( "html/template" "io/ioutil" "log" - "net" "net/http" "os" "strings" "tailscale.com/client/tailscale" + "tailscale.com/tailcfg" ) var ( @@ -107,6 +107,23 @@ type tmplData struct { IP string // "100.2.3.4" } +func tailscaleIP(who *tailcfg.WhoIsResponse) string { + if who == nil { + return "" + } + for _, nodeIP := range who.Node.Addresses { + if nodeIP.IP.Is4() && nodeIP.IsSingleIP() { + return nodeIP.IP.String() + } + } + for _, nodeIP := range who.Node.Addresses { + if nodeIP.IsSingleIP() { + return nodeIP.IP.String() + } + } + return "" +} + func root(w http.ResponseWriter, r *http.Request) { if r.TLS == nil && *httpsAddr != "" { host := r.Host @@ -146,14 +163,13 @@ func root(w http.ResponseWriter, r *http.Request) { return } } else { - ip, _, _ := net.SplitHostPort(r.RemoteAddr) data = tmplData{ DisplayName: who.UserProfile.DisplayName, LoginName: who.UserProfile.LoginName, ProfilePicURL: who.UserProfile.ProfilePicURL, MachineName: firstLabel(who.Node.ComputedName), MachineOS: who.Node.Hostinfo.OS, - IP: ip, + IP: tailscaleIP(who), } } w.Header().Set("Content-Type", "text/html; charset=utf-8") -- cgit v1.3-3-g829e