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 /ipn | |
| 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 'ipn')
| -rw-r--r-- | ipn/ipnlocal/local.go | 19 | ||||
| -rw-r--r-- | ipn/localapi/localapi.go | 14 |
2 files changed, 22 insertions, 11 deletions
diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 89b2562a9..6036d5000 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -254,14 +254,25 @@ func (b *LocalBackend) UpdateStatus(sb *ipnstate.StatusBuilder) { } } -// WhoIs reports the node and user who owns the node with the given IP. +// WhoIs reports the node and user who owns the node with the given IP:port. +// If the IP address is a Tailscale IP, the provided port may be 0. // If ok == true, n and u are valid. -func (b *LocalBackend) WhoIs(ip netaddr.IP) (n *tailcfg.Node, u tailcfg.UserProfile, ok bool) { +func (b *LocalBackend) WhoIs(ipp netaddr.IPPort) (n *tailcfg.Node, u tailcfg.UserProfile, ok bool) { b.mu.Lock() defer b.mu.Unlock() - n, ok = b.nodeByAddr[ip] + n, ok = b.nodeByAddr[ipp.IP] if !ok { - return nil, u, false + var ip netaddr.IP + if ipp.Port != 0 { + ip, ok = b.e.WhoIsIPPort(ipp) + } + if !ok { + return nil, u, false + } + n, ok = b.nodeByAddr[ip] + if !ok { + return nil, u, false + } } u, ok = b.netMap.UserProfiles[n.User] if !ok { diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index 7162a65ee..4e0dba3da 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -67,21 +67,21 @@ func (h *Handler) serveWhoIs(w http.ResponseWriter, r *http.Request) { return } b := h.b - var ip netaddr.IP - if v := r.FormValue("ip"); v != "" { + var ipp netaddr.IPPort + if v := r.FormValue("addr"); v != "" { var err error - ip, err = netaddr.ParseIP(r.FormValue("ip")) + ipp, err = netaddr.ParseIPPort(v) if err != nil { - http.Error(w, "invalid 'ip' parameter", 400) + http.Error(w, "invalid 'addr' parameter", 400) return } } else { - http.Error(w, "missing 'ip' parameter", 400) + http.Error(w, "missing 'addr' parameter", 400) return } - n, u, ok := b.WhoIs(ip) + n, u, ok := b.WhoIs(ipp) if !ok { - http.Error(w, "no match for IP", 404) + http.Error(w, "no match for IP:port", 404) return } res := &tailcfg.WhoIsResponse{ |
