netmap

package
v1.102.1-sing-box-1.14... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package netmap contains the netmap.NetworkMap type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MagicDNSSuffixOfNodeName

func MagicDNSSuffixOfNodeName(nodeName string) string

MagicDNSSuffix returns the domain's MagicDNS suffix (even if MagicDNS isn't necessarily in use) of the provided Node.Name value.

It will neither start nor end with a period.

Types

type IPServiceMappings

type IPServiceMappings map[netip.Addr]tailcfg.ServiceName

IPServiceMappings maps IP addresses to service names. This is the inverse of tailcfg.ServiceIPMappings, and is used to inform track which service a VIP is associated with. This is set to b.ipVIPServiceMap every time the netmap is updated. This is used to reduce the cost for looking up the service name for the dst IP address in the netStack packet processing workflow.

This is of the form:

{
  "100.65.32.1": "svc:samba",
  "fd7a:115c:a1e0::1234": "svc:samba",
  "100.102.42.3": "svc:web",
  "fd7a:115c:a1e0::abcd": "svc:web",
}

type NetworkMap

type NetworkMap struct {
	Cached bool // whether this NetworkMap was loaded from disk cache (as opposed to live from network)

	SelfNode tailcfg.NodeView
	AllCaps  set.Set[tailcfg.NodeCapability] // set version of SelfNode.Capabilities + SelfNode.CapMap
	NodeKey  key.NodePublic

	MachineKey key.MachinePublic

	Peers []tailcfg.NodeView // sorted by Node.ID
	DNS   tailcfg.DNSConfig

	PacketFilter      []filtertype.Match
	PacketFilterRules views.Slice[tailcfg.FilterRule]
	SSHPolicy         *tailcfg.SSHPolicy // or nil, if not enabled/allowed

	// CollectServices reports whether this node's Tailnet has
	// requested that info about services be included in HostInfo.
	// If set, Hostinfo.ShieldsUp blocks services collection; that
	// takes precedence over this field.
	CollectServices bool

	// DERPMap is the last DERP server map received. It's reused
	// between updates and should not be modified.
	DERPMap *tailcfg.DERPMap

	// DisplayMessages are the list of health check problems for this
	// node from the perspective of the control plane.
	// If empty, there are no known problems from the control plane's
	// point of view, but the node might know about its own health
	// check problems.
	DisplayMessages map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage

	// TKAEnabled indicates whether the tailnet key authority should be
	// enabled, from the perspective of the control plane.
	TKAEnabled bool
	// TKAHead indicates the control plane's understanding of 'head' (the
	// hash of the latest update message to tick through TKA).
	TKAHead tka.AUMHash

	// Domain is the current Tailnet name.
	Domain string

	// DomainAuditLogID is an audit log ID provided by control and
	// only populated if the domain opts into data-plane audit logging.
	// If this is empty, then data-plane audit logging is disabled.
	DomainAuditLogID string

	// UserProfiles contains the profile information of UserIDs referenced
	// in SelfNode and Peers.
	UserProfiles map[tailcfg.UserID]tailcfg.UserProfileView
}

NetworkMap is the current state of the world.

The fields should all be considered read-only. They might alias parts of previous NetworkMap values.

func (*NetworkMap) AnyPeersAdvertiseRoutes

func (nm *NetworkMap) AnyPeersAdvertiseRoutes() bool

AnyPeersAdvertiseRoutes reports whether any peer is advertising non-exit node routes.

func (*NetworkMap) Concise

func (nm *NetworkMap) Concise() string

func (*NetworkMap) ConciseDiffFrom

func (b *NetworkMap) ConciseDiffFrom(a *NetworkMap) string

func (*NetworkMap) DomainName

func (nm *NetworkMap) DomainName() string

DomainName returns the name of the NetworkMap's current tailnet. If the map is nil, it returns an empty string.

func (*NetworkMap) GetAddresses

func (nm *NetworkMap) GetAddresses() views.Slice[netip.Prefix]

GetAddresses returns the self node's addresses, or the zero value if SelfNode is invalid.

func (*NetworkMap) GetIPVIPServiceMap

func (nm *NetworkMap) GetIPVIPServiceMap() IPServiceMappings

GetIPVIPServiceMap returns a map of VIP addresses to the service names that has the VIP address. The service names are with the prefix "svc:".

func (*NetworkMap) GetMachineStatus

func (nm *NetworkMap) GetMachineStatus() tailcfg.MachineStatus

GetMachineStatus returns the MachineStatus of the local node.

func (*NetworkMap) GetVIPServiceIPMap

func (nm *NetworkMap) GetVIPServiceIPMap() tailcfg.ServiceIPMappings

GetVIPServiceIPMap returns a map of service names to the slice of VIP addresses that correspond to the service. The service names are with the prefix "svc:".

TODO(tailscale/corp##25997): cache the result of decoding the capmap so that we don't have to decode it multiple times after each netmap update.

func (*NetworkMap) HasCap

func (nm *NetworkMap) HasCap(c tailcfg.NodeCapability) bool

HasCap reports whether nm is non-nil and nm.AllCaps contains c.

func (*NetworkMap) JSON

func (nm *NetworkMap) JSON() string

func (*NetworkMap) MagicDNSSuffix

func (nm *NetworkMap) MagicDNSSuffix() string

MagicDNSSuffix returns the domain's MagicDNS suffix (even if MagicDNS isn't necessarily in use).

It will neither start nor end with a period.

func (*NetworkMap) PeerByTailscaleIP

func (nm *NetworkMap) PeerByTailscaleIP(ip netip.Addr) (peer tailcfg.NodeView, ok bool)

PeerByTailscaleIP returns a peer's Node based on its Tailscale IP.

If nm is nil or no peer is found, ok is false.

func (*NetworkMap) PeerIndexByNodeID

func (nm *NetworkMap) PeerIndexByNodeID(nodeID tailcfg.NodeID) int

PeerIndexByNodeID returns the index of the peer with the given nodeID in nm.Peers, or -1 if nm is nil or not found.

It assumes nm.Peers is sorted by Node.ID.

func (*NetworkMap) PeerWithStableID

func (nm *NetworkMap) PeerWithStableID(pid tailcfg.StableNodeID) (_ tailcfg.NodeView, ok bool)

PeerWithStableID finds and returns the peer associated to the inputted StableNodeID.

func (*NetworkMap) SelfKeyExpiry

func (nm *NetworkMap) SelfKeyExpiry() time.Time

SelfKeyExpiry returns nm.SelfNode.KeyExpiry, or the zero value if nil or nm.SelfNode is invalid.

func (*NetworkMap) SelfName

func (nm *NetworkMap) SelfName() string

SelfName returns nm.SelfNode.Name, or the empty string if nm is nil or nm.SelfNode is invalid.

func (*NetworkMap) SelfNodeOrZero

func (nm *NetworkMap) SelfNodeOrZero() tailcfg.NodeView

SelfNodeOrZero returns the self node, or a zero value if nm is nil.

func (*NetworkMap) Services

Services returns the Services visible (accessible) to this node, decoded from tailcfg.NodeAttrPrefixServices entries in the self node's CapMap. The returned map is keyed by tailcfg.ServiceDetails.Name, which is the canonical service name. It returns nil if nm is nil or SelfNode is invalid.

TODO(adrianosela): cache the result of decoding the capmap so we don't have to decode it multiple times after each netmap update.

func (*NetworkMap) String

func (nm *NetworkMap) String() string

func (*NetworkMap) TailnetDisplayName

func (nm *NetworkMap) TailnetDisplayName() string

TailnetDisplayName returns the admin-editable name contained in NodeAttrTailnetDisplayName. If the capability is not present it returns an empty string.

func (*NetworkMap) User

func (nm *NetworkMap) User() tailcfg.UserID

User returns nm.SelfNode.User if nm.SelfNode is non-nil, otherwise it returns 0.

func (*NetworkMap) VeryConcise

func (nm *NetworkMap) VeryConcise() string

type NodeMutation

type NodeMutation interface {
	NodeIDBeingMutated() tailcfg.NodeID
	Apply(*tailcfg.Node)
}

NodeMutation is the common interface for types that describe the change of a node's state.

func MutationsFromMapResponse

func MutationsFromMapResponse(res *tailcfg.MapResponse, now time.Time) (ret []NodeMutation, ok bool)

MutationsFromMapResponse returns all the discrete node mutations described by res. It returns ok=false if res contains any non-delta field as defined by mapResponseContainsNonPatchFields.

Upserts and removes (from res.PeersChanged / res.PeersRemoved) are emitted as NodeMutationUpsert / NodeMutationRemove entries. A PeersChanged entry can be either a new peer or a full replacement for an existing peer that couldn't be represented as PeerChangedPatch. Callers must type-switch to handle those alongside field mutations.

func NodeMutationsFromPatch

func NodeMutationsFromPatch(p *tailcfg.PeerChange) (_ []NodeMutation, ok bool)

NodeMutationsFromPatch returns the NodeMutations that p describes. If p describes something not yet supported by a specific NodeMutation type, it returns (nil, false).

type NodeMutationDERPHome

type NodeMutationDERPHome struct {
	DERPRegion int
	// contains filtered or unexported fields
}

NodeMutationDERPHome is a NodeMutation that says a node has changed its DERP home region.

func (NodeMutationDERPHome) Apply

func (m NodeMutationDERPHome) Apply(n *tailcfg.Node)

func (NodeMutationDERPHome) NodeIDBeingMutated

func (m NodeMutationDERPHome) NodeIDBeingMutated() tailcfg.NodeID

type NodeMutationEndpoints

type NodeMutationEndpoints struct {
	Endpoints []netip.AddrPort
	// contains filtered or unexported fields
}

NodeMutationEndpoints is a NodeMutation that says a node's endpoints have changed.

func (NodeMutationEndpoints) Apply

func (m NodeMutationEndpoints) Apply(n *tailcfg.Node)

func (NodeMutationEndpoints) NodeIDBeingMutated

func (m NodeMutationEndpoints) NodeIDBeingMutated() tailcfg.NodeID

type NodeMutationLastSeen

type NodeMutationLastSeen struct {
	LastSeen time.Time
	// contains filtered or unexported fields
}

NodeMutationLastSeen is a NodeMutation that says a node's LastSeen value should be set to the current time.

func (NodeMutationLastSeen) Apply

func (m NodeMutationLastSeen) Apply(n *tailcfg.Node)

func (NodeMutationLastSeen) NodeIDBeingMutated

func (m NodeMutationLastSeen) NodeIDBeingMutated() tailcfg.NodeID

type NodeMutationOnline

type NodeMutationOnline struct {
	Online bool
	// contains filtered or unexported fields
}

NodeMutationOnline is a NodeMutation that says a node is now online or offline.

func (NodeMutationOnline) Apply

func (m NodeMutationOnline) Apply(n *tailcfg.Node)

func (NodeMutationOnline) NodeIDBeingMutated

func (m NodeMutationOnline) NodeIDBeingMutated() tailcfg.NodeID

type NodeMutationRemove

type NodeMutationRemove struct {
	// contains filtered or unexported fields
}

NodeMutationRemove is a NodeMutation that says a peer has been removed. Apply is a no-op: consumers of NodeMutationRemove must type-switch to handle removes by deleting the node from their peer map.

func MakeNodeMutationRemove

func MakeNodeMutationRemove(nodeID tailcfg.NodeID) NodeMutationRemove

MakeNodeMutationRemove returns a NodeMutationRemove that targets nodeID. It is the constructor for NodeMutationRemove for callers outside this package, since the embedded ID field is unexported.

func (NodeMutationRemove) Apply

func (m NodeMutationRemove) Apply(*tailcfg.Node)

func (NodeMutationRemove) NodeIDBeingMutated

func (m NodeMutationRemove) NodeIDBeingMutated() tailcfg.NodeID

type NodeMutationUpsert

type NodeMutationUpsert struct {
	Node tailcfg.NodeView
}

NodeMutationUpsert is a NodeMutation that says a peer's full Node value should be inserted or replaced.

Apply is a no-op: consumers of NodeMutationUpsert must type-switch to handle upserts by storing Node in their peer map.

func (NodeMutationUpsert) Apply

func (m NodeMutationUpsert) Apply(*tailcfg.Node)

func (NodeMutationUpsert) NodeIDBeingMutated

func (m NodeMutationUpsert) NodeIDBeingMutated() tailcfg.NodeID

type WGConfigFlags

type WGConfigFlags int

WGConfigFlags is a bitmask of flags to control the behavior of the wireguard configuration generation done by NetMap.WGCfg.

const (
	AllowSubnetRoutes WGConfigFlags
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL