diff options
| author | Naman Sood <mail@nsood.in> | 2021-03-15 17:59:35 -0400 |
|---|---|---|
| committer | Naman Sood <mail@nsood.in> | 2021-03-15 18:14:09 -0400 |
| commit | 770aa71ffbfbb01f7c8bfc65ce5e0505c783efde (patch) | |
| tree | 32356706a18c3b5604b2f7c6785c4c57f7591266 /cmd | |
| parent | 44ab0acbdbd8b79af74ea1f8187c4d782ce38635 (diff) | |
| download | tailscale-770aa71ffbfbb01f7c8bfc65ce5e0505c783efde.tar.xz tailscale-770aa71ffbfbb01f7c8bfc65ce5e0505c783efde.zip | |
client, cmd/hello, ipn, wgengine: fix whois for netstack-forwarded connections
Updates #504
Updates #707
Signed-off-by: Naman Sood <mail@nsood.in>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hello/hello.go | 22 |
1 files changed, 19 insertions, 3 deletions
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") |
