tailcfg,types/netmap: expose visible services node attr

This commit is contained in:
Adriano Sela Aviles 2026-04-03 00:46:35 -07:00
parent eaa5d9df4b
commit 99b3073ab6
No known key found for this signature in database
GPG Key ID: 28128631BCCBB1BB
2 changed files with 39 additions and 0 deletions

View File

@ -2694,6 +2694,14 @@ const (
// (replace conflicting keys).
NodeAttrServiceHost NodeCapability = "service-host"
// NodeAttrVisibleServiceDetails carries the full details of VIP services
// that are visible (accessible) to this node, including their names,
// assigned IP addresses, and port requirements. This is sent to consuming
// client nodes so they can discover services without relying solely on DNS
// resolution. There is exactly one value for this key in [NodeCapMap], of
// type []*[ServiceDetail].
NodeAttrVisibleServiceDetails NodeCapability = "visible-service-details"
// NodeAttrMaxKeyDuration represents the MaxKeyDuration setting on the
// tailnet. The value of this key in [NodeCapMap] will be only one entry of
// type float64 representing the duration in seconds. This cap will be
@ -3318,6 +3326,20 @@ const LBHeader = "Ts-Lb"
// this client is hosting can be ignored.
type ServiceIPMappings map[ServiceName][]netip.Addr
// ServiceDetail describes a VIP service visible to or hosted by a node. It is
// used as the element type of the []*[ServiceDetail] value sent via
// [NodeAttrVisibleServiceDetails].
type ServiceDetail struct {
// Name is the name of the service, of the form "svc:dns-label".
Name ServiceName
// Addrs are the IP addresses (IPv4 and IPv6) assigned to this service.
Addrs []netip.Addr `json:",omitempty"`
// Ports are the protocol/port combinations the service accepts.
Ports []ProtoPortRange `json:",omitempty"`
}
// ClientAuditAction represents an auditable action that a client can report to the
// control plane. These actions must correspond to the supported actions
// in the control plane.

View File

@ -120,6 +120,23 @@ func (nm *NetworkMap) GetVIPServiceIPMap() tailcfg.ServiceIPMappings {
return ipMaps[0]
}
// GetVisibleServiceDetails returns the list of VIP services that are visible
// (accessible) to this node, including their names, IP addresses, and ports.
// Returns nil if no visible service details are present.
func (nm *NetworkMap) GetVisibleServiceDetails() []*tailcfg.ServiceDetail {
if nm == nil {
return nil
}
if !nm.SelfNode.Valid() {
return nil
}
details, err := tailcfg.UnmarshalNodeCapViewJSON[[]*tailcfg.ServiceDetail](nm.SelfNode.CapMap(), tailcfg.NodeAttrVisibleServiceDetails)
if len(details) != 1 || err != nil {
return nil
}
return details[0]
}
// GetIPVIPServiceMap returns a map of VIP addresses to the service
// names that has the VIP address. The service names are with the
// prefix "svc:".