mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-16 18:08:40 +00:00
ipn/ipnstate: add ExitNodeStatus to share the exit node if it is in use, the IP, ID and whether its online. (#4761)
- Updates #4619 Signed-off-by: nyghtowl <warrick@tailscale.com>
This commit is contained in:
parent
6246fa32f0
commit
3a182d5dd6
@ -425,6 +425,20 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func
|
||||
s.CurrentTailnet.MagicDNSSuffix = b.netMap.MagicDNSSuffix()
|
||||
s.CurrentTailnet.MagicDNSEnabled = b.netMap.DNS.Proxied
|
||||
s.CurrentTailnet.Name = b.netMap.Domain
|
||||
if b.prefs != nil && !b.prefs.ExitNodeID.IsZero() {
|
||||
if exitPeer, ok := b.netMap.PeerWithStableID(b.prefs.ExitNodeID); ok {
|
||||
var online = false
|
||||
if exitPeer.Online != nil {
|
||||
online = *exitPeer.Online
|
||||
}
|
||||
s.ExitNodeStatus = &ipnstate.ExitNodeStatus{
|
||||
ID: b.prefs.ExitNodeID,
|
||||
Online: online,
|
||||
TailscaleIPs: exitPeer.Addresses,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
sb.MutateSelfStatus(func(ss *ipnstate.PeerStatus) {
|
||||
|
@ -38,6 +38,10 @@ type Status struct {
|
||||
TailscaleIPs []netaddr.IP // Tailscale IP(s) assigned to this node
|
||||
Self *PeerStatus
|
||||
|
||||
// ExitNodeStatus describes the current exit node.
|
||||
// If nil, an exit node is not in use.
|
||||
ExitNodeStatus *ExitNodeStatus `json:"ExitNodeStatus,omitempty"`
|
||||
|
||||
// Health contains health check problems.
|
||||
// Empty means everything is good. (or at least that no known
|
||||
// problems are detected)
|
||||
@ -81,6 +85,18 @@ type TailnetStatus struct {
|
||||
MagicDNSEnabled bool
|
||||
}
|
||||
|
||||
// ExitNodeStatus describes the current exit node.
|
||||
type ExitNodeStatus struct {
|
||||
// ID is the exit node's ID.
|
||||
ID tailcfg.StableNodeID
|
||||
|
||||
// Online is whether the exit node is alive.
|
||||
Online bool
|
||||
|
||||
// TailscaleIPs are the exit node's IP addresses assigned to the node.
|
||||
TailscaleIPs []netaddr.IPPrefix
|
||||
}
|
||||
|
||||
func (s *Status) Peers() []key.NodePublic {
|
||||
kk := make([]key.NodePublic, 0, len(s.Peer))
|
||||
for k := range s.Peer {
|
||||
|
@ -122,6 +122,16 @@ func (nm *NetworkMap) VeryConcise() string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// PeerWithStableID finds and returns the peer associated to the inputted StableNodeID.
|
||||
func (nm *NetworkMap) PeerWithStableID(pid tailcfg.StableNodeID) (_ *tailcfg.Node, ok bool) {
|
||||
for _, p := range nm.Peers {
|
||||
if p.StableID == pid {
|
||||
return p, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// printConciseHeader prints a concise header line representing nm to buf.
|
||||
//
|
||||
// If this function is changed to access different fields of nm, keep
|
||||
|
Loading…
x
Reference in New Issue
Block a user