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

@@ -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 {

View File

@@ -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{