Documentation
¶
Overview ¶
Package conn25 registers the conn25 feature and implements its associated ipnext.Extension. conn25 will be an app connector like feature that routes traffic for configured domains via connector devices and avoids the "too many routes" pitfall of app connector. It is currently (2026-02-04) some peer API routes for clients to tell connectors about their desired routing.
Index ¶
- Constants
- Variables
- type ClientFlowRef
- type Conn25
- type Conn25Datapath
- type ConnectorTransitIPRequest
- type ConnectorTransitIPResponse
- type FlowData
- type FlowTable
- type FlowTableOption
- type Origin
- type PacketAction
- type TransitIPRequest
- type TransitIPResponse
- type TransitIPResponseCode
- type TupleAndAction
Constants ¶
const ( // OK indicates that the mapping was created as requested. OK TransitIPResponseCode = 0 // OtherFailure indicates that the mapping failed for a reason that does not have // another relevant [TransitIPResponseCode]. OtherFailure TransitIPResponseCode = 1 // DuplicateTransitIP indicates that the same transit address appeared more than // once in a [ConnectorTransitIPRequest]. DuplicateTransitIP TransitIPResponseCode = 2 // NoMatchingPeerIPFamily indicates that the peer did not have an associated // IP with the same family as transit IP being registered. NoMatchingPeerIPFamily = 3 // AddrFamilyMismatch indicates that the transit IP and destination IP addresses // do not belong to the same IP family. AddrFamilyMismatch = 4 // UnknownAppName indicates that the connector is not configured to handle requests // for the App name that was specified in the request. UnknownAppName = 5 // MissingAppPermission indicates that the client is not permitted to access // the App name that was specified in the request. MissingAppPermission = 6 // TransitIPNotInPool indicates that the transit address in the request is // not within a transit IP pool the connector is configured with. A client // which sees this has most likely allocated from a pool configuration that // the connector has not received yet, or has already replaced. TransitIPNotInPool = 7 // DisallowedDestination indicates that the destination IP address is not // allowed (including but not limited to loopback, Tailscale, link-local, // and private addresses, along with addresses within the configured magic and // transit IP pools). DisallowedDestination = 8 )
const ( AppConnectorAttrName = "tailscale.com/app-connectors" AppConnectorsExperimentalIPPoolsAttrName = "tailscale.com/app-connectors-experimental-ippools" // DNSAddrScheme is the custom URI scheme used for conn25-managed split DNS // entries to determine the destination at query time rather than configuration // time. DNSAddrScheme = "tailscale-app" )
const ( // DefaultFlowIdleTimeout is the default idle timeout for a flow. // See also [WithFlowIdleTimeout]. DefaultFlowIdleTimeout = 5 * time.Minute // DefaultFlowSweepInterval is the default sweep interval for // automatically removing expired flows. See also [WithFlowSweepInterval]. DefaultFlowSweepInterval = 3 * time.Minute // DefaultMaxRemovedFlowsPerSweep is the default maximum number of // flows removed per sweep. It can be used to tune how long the table // mutex is held during sweeps. See also [WithMaxRemovedFlowsPerSweep]. DefaultMaxRemovedFlowsPerSweep = 1000 )
const TokenHeader = "Tailscale-Conn25-Token"
TokenHeader is the PeerAPI DoH response header a connector uses to hand a client a token for each address it answered with. One header line is sent per A/AAAA answer, formatted as:
Tailscale-Conn25-Token: <ip> <token>
The ip is the correlation key the client uses to match each token to the answer it belongs to in the DNS response body. The token itself is opaque to the client; see TransitIPRequest.Token.
Variables ¶
var ( ErrUnmappedMagicIP = errors.New("unmapped magic IP") // ErrTransitIPNotRoutable is returned when a Magic IP is mapped to a // Transit IP, but that Transit IP has not yet been registered with its // connector and installed in WireGuard, so packets sent to it would be dropped. ErrTransitIPNotRoutable = errors.New("transit IP not yet routable") ErrUnmappedSrcAndTransitIP = errors.New("unmapped src and transit IP") )
Functions ¶
This section is empty.
Types ¶
type ClientFlowRef ¶ added in v1.106.0
type ClientFlowRef struct {
// contains filtered or unexported fields
}
ClientFlowRef is a client-side flow's reference to the address assignment it was counted against.
func (ClientFlowRef) Release ¶ added in v1.106.0
func (r ClientFlowRef) Release()
Release gives up the flow's claim on the address assignment, letting the assignment be reclaimed once nothing else holds it. It must be called once the flow is gone, or right away if the caller ends up installing no flow at all.
func (ClientFlowRef) TransitIP ¶ added in v1.106.0
func (r ClientFlowRef) TransitIP() netip.Addr
TransitIP returns the Transit IP of the assignment the flow was counted against, which is the address its packets should be forwarded to.
type Conn25 ¶
type Conn25 struct {
// contains filtered or unexported fields
}
Conn25 holds state for routing traffic for a domain via a connector.
func (*Conn25) ClientPrepareNewFlowForMagicIP ¶ added in v1.106.0
ClientPrepareNewFlowForMagicIP implements Conn25Datapath. The datapath notifies Conn25 that a flow to magic IP is being established, and Conn25 resolves m to its Transit IP and counts the flow against that address assignment in one step, reporting ok and returning the reference that names that Transit IP and keeps it and its associated addresses from being removed from Conn25's state and returned to their pools while the flow uses them.
If m has an active address assignment whose Transit IP isn't routable yet, it reports ok false and returns ErrTransitIPNotRoutable.
If m has no active address assignment, it reports ok false and returns ErrUnmappedMagicIP when m falls in a configured Magic IP range, and a nil error when it does not, since in that case m is not a Magic IP at all and the traffic to it is potentially valid non-app-connector traffic.
func (*Conn25) ConnectorRealIPForTransitIPConnection ¶ added in v1.98.0
ConnectorRealIPForTransitIPConnection implements Conn25Datapath.
func (*Conn25) GetActiveState ¶ added in v1.102.0
func (c *Conn25) GetActiveState() appctype.Conn25ActiveState
GetActiveState returns active state for the client and the connector, including IP pool usage, address mappings, domains, and active flow counts.
type Conn25Datapath ¶ added in v1.102.0
type Conn25Datapath interface {
// ConnectorRealIPForTransitIPConnection returns a real destination IP for the given
// srcIP and transitIP on a connector. If the transitIP is within a configured Transit IP
// range for an app on the connector, but not mapped to the client at srcIP, implementations
// should return [ErrUnmappedSrcAndTransitIP]. If the transitIP is not within a configured
// Transit IP range, i.e. it is not actually a Transit IP, implementations should return
// a nil error, and a zero-value [netip.Addr] to indicate this is potentially valid,
// non-app-connector traffic.
ConnectorRealIPForTransitIPConnection(srcIP netip.Addr, transitIP netip.Addr) (netip.Addr, error)
// ClientPrepareNewFlowForMagicIP is called before a client-side flow to
// magicIP is installed in the client flow table. It reports whether it
// counted the flow against an address assignment, and if so returns the
// reference that names the Transit IP to forward that flow to and keeps
// that address from being reclaimed.
//
// When ok is true, the caller must call Release on the reference exactly
// once: when the flow is removed, or right away if it ends up installing no
// flow at all. Implementations must count nothing and return ok false and
// the zero [ClientFlowRef] otherwise, including whenever they return a
// non-nil error, since the caller does not release on those paths.
//
// If magicIP is within a configured Magic IP range for an app on the client,
// but not mapped to an active Transit IP, implementations should return
// [ErrUnmappedMagicIP]. If it is mapped to a Transit IP, but that Transit IP
// is not yet usable because WireGuard has not been told to route it to the
// connector, implementations should return [ErrTransitIPNotRoutable]. If
// magicIP is not within a configured Magic IP range, i.e. it is not actually
// a Magic IP, implementations should report ok false with a nil error to
// indicate this potentially valid, non-app-connector traffic.
ClientPrepareNewFlowForMagicIP(magicIP netip.Addr) (ref ClientFlowRef, ok bool, err error)
}
Conn25Datapath is the interface for the surface of *Conn25 that the datapath handler needs. It provides methods for address mapping to help the datapath handler implement DNAT/SNAT, and flow lifecycle handlers so that *Conn25 can keep address assignments active for active flows.
*Conn25 is the only production implementation; the interface exists to let datapath tests substitute a lightweight fake.
type ConnectorTransitIPRequest ¶
type ConnectorTransitIPRequest struct {
// TransitIPs is the list of requested mappings.
TransitIPs []TransitIPRequest `json:"transitIPs,omitempty"`
}
ConnectorTransitIPRequest is the request body for a PeerAPI request to /connector/transit-ip and can include zero or more TransitIP allocation requests.
type ConnectorTransitIPResponse ¶
type ConnectorTransitIPResponse struct {
// TransitIPs is the list of outcomes for each requested mapping. Elements
// correspond to the order of [ConnectorTransitIPRequest.TransitIPs].
TransitIPs []TransitIPResponse `json:"transitIPs,omitempty"`
}
ConnectorTransitIPResponse is the response to a ConnectorTransitIPRequest
type FlowData ¶ added in v1.98.0
type FlowData struct {
FromTun TupleAndAction
FromWG TupleAndAction
// OnRemove, if non-nil, is invoked when the flow is removed from the
// table for any reason (idle expiration, tuple-collision displacement
// in [FlowTable.NewFlow], or capacity eviction). It is called once,
// outside the table's mutex, so it may safely acquire other locks.
OnRemove func()
}
FlowData is an entry stored in the FlowTable constructed by the consumer of the table. It specifies tuples and actions for each direction of the flow.
type FlowTable ¶ added in v1.98.0
type FlowTable struct {
// contains filtered or unexported fields
}
FlowTable stores and retrieves FlowData that can be looked up by 5-tuple flowtrack.Tuple and direction. New entries specify the tuple to use for both directions of traffic flow. The underlying cache is LRU, and the maximum number of entries is specified in calls to NewFlowTable. FlowTable has its own mutex and is safe for concurrent use.
func NewFlowTable ¶ added in v1.98.0
func NewFlowTable(maxEntries int, opts ...FlowTableOption) *FlowTable
NewFlowTable returns a FlowTable with maxEntries maximum entries. A maxEntries of 0 indicates no maximum. See also FlowTable.
func (*FlowTable) Clear ¶ added in v1.104.0
func (t *FlowTable) Clear()
Clear empties the entire FlowTable, losing track of all active flows. This is used when all current flows between this and all other nodes cease to exist; for example, when switching tailnets.
func (*FlowTable) LookupFromTunDevice ¶ added in v1.98.0
func (t *FlowTable) LookupFromTunDevice(k flowtrack.Tuple) (PacketAction, bool)
LookupFromTunDevice looks up a PacketAction that is valid to run on packets observed as coming from the tun device. The tuple must match the direction it was stored with.
func (*FlowTable) LookupFromWireGuard ¶ added in v1.98.0
func (t *FlowTable) LookupFromWireGuard(k flowtrack.Tuple) (PacketAction, bool)
LookupFromWireGuard looks up a PacketAction that is valid to run for packets observed as coming from the WireGuard tunnel. The tuple must match the direction it was stored with.
func (*FlowTable) NewFlow ¶ added in v1.100.0
NewFlow installs data as an flow in the table, and evicts any flow that either tuple already points at. This can result in two flows being evicted if each of the new tuples point at distinct existing flows. If the new flow would cause the table to exceed its maximum size, the least recently used (looked-up or created) flow is evicted. data is not validated, the caller must supply non-nil packet actions.
Any FlowData.OnRemove callbacks belonging to displaced or evicted flows are invoked after the table's mutex is released, before NewFlow returns.
func (*FlowTable) StartExpiredSweeper ¶ added in v1.102.0
StartExpiredSweeper starts a sweeper that removes idle flows that have not been created or looked up for a duration greater than the configured idle timeout. See WithFlowIdleTimeout. The sweep runs at the configured sweep interval. See WithFlowSweepInterval. The sweeper stops when ctx is canceled.
type FlowTableOption ¶ added in v1.102.0
type FlowTableOption func(ft *FlowTable)
FlowTableOption configures options for use with NewFlowTable.
func WithFlowIdleTimeout ¶ added in v1.102.0
func WithFlowIdleTimeout(timeout time.Duration) FlowTableOption
WithFlowIdleTimeout sets the threshold duration for flow idle time before it is eligible for removal. A flow is considered idle for the time that elapses since its creation or last lookup. A duration of 0 means that expiration is disabled. If WithFlowIdleTimeout is not passed to NewFlowTable, then DefaultFlowIdleTimeout is used.
func WithFlowSweepInterval ¶ added in v1.102.0
func WithFlowSweepInterval(ival time.Duration) FlowTableOption
WithFlowSweepInterval sets the interval to automatically remove idle flows that exceed the idle timeout. A value of 0 disables automatic sweeping. If WithFlowSweepInterval is not passed to NewFlowTable, then DefaultFlowSweepInterval is used.
func WithMaxRemovedFlowsPerSweep ¶ added in v1.102.0
func WithMaxRemovedFlowsPerSweep(maxPer int) FlowTableOption
WithMaxRemovedFlowsPerSweep sets maximum number of expired flows that can be removed per sweep. A value of 0 means no maximum. If WithMaxRemovedFlowsPerSweep is not passed to NewFlowTable, then DefaultMaxRemovedFlowsPerSweep is used.
type PacketAction ¶ added in v1.98.0
PacketAction may modify the packet.
type TransitIPRequest ¶
type TransitIPRequest struct {
// TransitIP is the intermediate destination IP that will be received at this
// connector and will be replaced by DestinationIP when performing DNAT.
TransitIP netip.Addr `json:"transitIP,omitzero"`
// DestinationIP is the final destination IP that connections to the TransitIP
// should be mapped to when performing DNAT.
DestinationIP netip.Addr `json:"destinationIP,omitzero"`
// App is the name of the connector application from the tailnet
// configuration.
App string `json:"app,omitzero"`
// Token is supplied by the connector in its PeerAPI DoH response. It should
// not be modified, and shouldn't need to be inspected. It should be
// sent back to the connector in this request for the DestinationIP
// and App for which it was originally received.
Token string `json:"token,omitzero"`
}
TransitIPRequest details a single TransitIP allocation request from a client to a connector.
type TransitIPResponse ¶
type TransitIPResponse struct {
// Code is an error code indicating success or failure of the [TransitIPRequest].
Code TransitIPResponseCode `json:"code,omitzero"`
// Message is an error message explaining what happened, suitable for logging but
// not necessarily suitable for displaying in a UI to non-technical users. It
// should be empty when [Code] is [OK].
Message string `json:"message,omitzero"`
}
TransitIPResponse is the response to a TransitIPRequest
type TransitIPResponseCode ¶
type TransitIPResponseCode int
TransitIPResponseCode appears in TransitIPResponse and signifies success or failure status.
type TupleAndAction ¶ added in v1.100.0
type TupleAndAction struct {
Tuple flowtrack.Tuple
Action PacketAction
}
TupleAndAction wraps the flowtrack.Tuple and the PacketAction to return on lookups to that tuple.