MCPcopy Index your code
hub / github.com/tailscale/tailscale / selfNodeAddresses

Method selfNodeAddresses

client/web/web.go:440–466  ·  view source on GitHub ↗

selfNodeAddresses return the Tailscale IPv4 and IPv6 addresses for the self node. st is expected to be a status with peers included.

(r *http.Request, st *ipnstate.Status)

Source from the content-addressed store, hash-verified

438// selfNodeAddresses return the Tailscale IPv4 and IPv6 addresses for the self node.
439// st is expected to be a status with peers included.
440func (s *Server) selfNodeAddresses(r *http.Request, st *ipnstate.Status) (ipv4, ipv6 netip.Addr) {
441 for _, ip := range st.Self.TailscaleIPs {
442 if ip.Is4() {
443 ipv4 = ip
444 } else if ip.Is6() {
445 ipv6 = ip
446 }
447 if ipv4.IsValid() && ipv6.IsValid() {
448 break // found both IPs
449 }
450 }
451 if whois, err := s.lc.WhoIs(r.Context(), r.RemoteAddr); err == nil {
452 // The source peer connecting to this node may know it by a different
453 // IP than the node knows itself as. Specifically, this may be the case
454 // if the peer is coming from a different tailnet (sharee node), as IPs
455 // are specific to each tailnet.
456 // Here, we check if the source peer knows the node by a different IP,
457 // and return the peer's version if so.
458 if knownIPv4 := whois.Node.SelfNodeV4MasqAddrForThisPeer; knownIPv4 != nil {
459 ipv4 = *knownIPv4
460 }
461 if knownIPv6 := whois.Node.SelfNodeV6MasqAddrForThisPeer; knownIPv6 != nil {
462 ipv6 = *knownIPv6
463 }
464 }
465 return ipv4, ipv6
466}
467
468// authorizeRequest reports whether the request from the web client
469// is authorized to be completed.

Callers 2

requireTailscaleIPMethod · 0.95
serveGetNodeDataMethod · 0.95

Calls 3

WhoIsMethod · 0.65
ContextMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected