client, cmd/hello, ipn, wgengine: fix whois for netstack-forwarded connections

Updates #504

Updates #707

Signed-off-by: Naman Sood <mail@nsood.in>
This commit is contained in:
Naman Sood
2021-03-15 17:59:35 -04:00
parent 44ab0acbdb
commit 770aa71ffb
8 changed files with 108 additions and 28 deletions

View File

@@ -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")