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)
| 438 | // selfNodeAddresses return the Tailscale IPv4 and IPv6 addresses for the self node. |
| 439 | // st is expected to be a status with peers included. |
| 440 | func (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. |
no test coverage detected