cmd/tailscale, ipn/ipnlocal: add "peerapi" ping type

For debugging when stuff like #4750 isn't working.

RELNOTE=tailscale ping -peerapi

Change-Id: I9c52c90fb046e3ab7d2b121387073319fbf27b99
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-05-27 21:34:36 -07:00
committed by Brad Fitzpatrick
parent 575aacb1e2
commit 4d85cf586b
5 changed files with 86 additions and 0 deletions

View File

@@ -72,6 +72,24 @@ type NetworkMap struct {
UserProfiles map[tailcfg.UserID]tailcfg.UserProfile
}
// PeerByTailscaleIP returns a peer's Node based on its Tailscale IP.
//
// If nm is nil or no peer is found, ok is false.
func (nm *NetworkMap) PeerByTailscaleIP(ip netaddr.IP) (peer *tailcfg.Node, ok bool) {
// TODO(bradfitz):
if nm == nil {
return nil, false
}
for _, n := range nm.Peers {
for _, a := range n.Addresses {
if a.IP() == ip {
return n, true
}
}
}
return nil, false
}
// MagicDNSSuffix returns the domain's MagicDNS suffix (even if
// MagicDNS isn't necessarily in use).
//