routedns

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package routedns answers "where does this sandbox hostname go?" for a static Caddy config (plans/ingress-proxy-routing.md §3.2, task T3).

Caddy's config stays static. Instead of one route per sandbox (each route write reloads Caddy's whole config and drops ~2.6% of new connections), Caddy asks a loopback DNS responder:

owner:   reverse_proxy dynamic A name={http.request.host}.  → OwnerTable
ingress: caddy-l4 dial "{l4.tls.server_name}.rt.internal"   → IngressIndex

Bytes stay in Caddy. sandboxd only answers where, so a sandboxd restart never resets established connections. Both tables are keyed by the EXACT hostname Caddy's old per-sandbox matchers used. Nothing parses sandbox IDs out of hostnames on the answer path; IDs may contain dashes, so parsing would be ambiguous.

Index

Constants

View Source
const (
	ProbeName = "_aerolvm-route-probe." + IngressZone
	ProbeIP   = "127.0.0.9"
)

ProbeName is answered with ProbeIP so a boot check can prove the node's SYSTEM resolver routes the ingress zone to this responder. caddy-l4 dials through that resolver; a node whose routing domain is missing must not turn the flag on.

View Source
const IngressZone = caddy.RouteDNSZone

IngressZone is the suffix caddy-l4 appends to the SNI before dialing ("{l4.tls.server_name}.rt.internal"). The node's resolver routes this domain (and only this domain) to the responder.

Variables

This section is empty.

Functions

func DerivedPort

func DerivedPort(host string, toolboxPort int) int

DerivedPort is the port Caddy's static map yields for host.

Types

type IngressEntry

type IngressEntry struct {
	SandboxID   string
	OwnerNodeID string
	OwnerHost   string // data-plane host (IP or DNS name)
	// Routable: public, actively owned, not reserved or deleting. A known
	// but unroutable host is answered like an unknown one (the local router
	// gives 503/404), never spliced to a guessed owner.
	Routable bool
	Custom   bool // a tenant custom domain (not under the platform domain)
	// Why an entry is not routable, for the router's answer: Private → 404
	// (the sandbox exists but is not public); InFlux → 503 + Retry-After
	// (orphaned, reserved, deleting, or no data-plane host yet).
	Private bool
	InFlux  bool
}

IngressEntry is where one SNI hostname goes from an ingress node.

type IngressIndex

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

IngressIndex maps every SNI hostname of every placement to its owner. It covers ALL placements (review T3): any ingress routes any sandbox, and routing does not depend on a shard-aware load balancer. It is rebuilt from the placement view (the delta feed keeps that current) and swapped in atomically.

func NewIngressIndex

func NewIngressIndex() *IngressIndex

func (*IngressIndex) Len

func (x *IngressIndex) Len() int

func (*IngressIndex) Lookup

func (x *IngressIndex) Lookup(host string) (IngressEntry, bool)

func (*IngressIndex) Remove

func (x *IngressIndex) Remove(sandboxID string)

Remove drops every host of a deleted placement.

func (*IngressIndex) Replace

func (x *IngressIndex) Replace(placements []cluster.Placement, domain string)

Replace rebuilds the index from placements. domain is the platform domain (hosts are {id}.{domain} and {id}-{port}.{domain}).

func (*IngressIndex) Upsert

func (x *IngressIndex) Upsert(p cluster.Placement, domain string)

Upsert replaces one placement's hosts: new ones are added, and ones it no longer has (a removed custom domain or unexposed port) are dropped.

type MissLookup

type MissLookup func(ctx context.Context, sandboxID string) (cluster.Placement, bool)

MissLookup resolves a placement the ingress index doesn't hold yet (a brand-new sandbox's first connection). It is the cluster's internal placement point read.

type OwnerTable

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

OwnerTable is the owner node's route table: what Caddy's per-sandbox http routes used to hold. The service's route-intent seam (publicRouteWriter) maintains it, so it has exactly the semantics of the routes it replaces.

func NewOwnerTable

func NewOwnerTable() *OwnerTable

func (*OwnerTable) Delete

func (t *OwnerTable) Delete(host string)

func (*OwnerTable) DeleteFunc

func (t *OwnerTable) DeleteFunc(match func(host string) bool)

DeleteFunc removes every host match selects (e.g. all of a sandbox). It mirrors Caddy's DeleteSandboxRoute, which also dropped the sandbox's custom-hostname matchers that rode the root route.

func (*OwnerTable) Len

func (t *OwnerTable) Len() int

func (*OwnerTable) Lookup

func (t *OwnerTable) Lookup(host string) (OwnerTarget, bool)

func (*OwnerTable) Set

func (t *OwnerTable) Set(host string, target OwnerTarget)

Set records a target. An empty host is ignored.

func (*OwnerTable) SetState

func (t *OwnerTable) SetState(host string, state TargetState)

SetState changes only the state of an existing or new entry (wake and in-flux routes carry no upstream).

type OwnerTarget

type OwnerTarget struct {
	IP    net.IP
	Port  int
	State TargetState
	// SandboxID and GuestPort let the sandboxd router serve a fallback
	// request (wake, masked, mediator) through the existing wake proxy.
	SandboxID string
	GuestPort int
}

OwnerTarget is where one hostname goes on its owner node.

type Responder

type Responder struct {
	// Domain is the platform domain ({id}.{Domain}).
	Domain string
	// SelfNodeID identifies placements this node owns.
	SelfNodeID string
	// LocalIP is the node-local listener that terminates with the wildcard
	// cert and routes through the static route: used for owner == self, and
	// for unroutable platform hosts so the local router can answer 503/404
	// (review 1A, wildcard only per T5).
	LocalIP net.IP
	// ToolboxPort is the static map's default port (root host).
	ToolboxPort int

	Owner   *OwnerTable
	Ingress *IngressIndex
	Miss    MissLookup

	// NegativeTTL bounds how long a failed on-miss lookup is remembered, so
	// a flood of connections for an unknown host costs one control-plane
	// read, not one per connection.
	NegativeTTL time.Duration
	// contains filtered or unexported fields
}

Responder is the loopback DNS server Caddy consults.

func (*Responder) ListenAndServe

func (r *Responder) ListenAndServe(ctx context.Context, addr string) error

ListenAndServe serves UDP and TCP on addr (loopback) until ctx ends.

func (*Responder) ServeDNS

func (r *Responder) ServeDNS(w dns.ResponseWriter, req *dns.Msg)

ServeDNS implements dns.Handler. Every answer is authoritative and nothing recurses: a query about a sandbox hostname never leaves this node.

type TargetState

type TargetState int

TargetState distinguishes an answerable upstream from a hostname that must fall back to the sandboxd router (Caddy's static fallback upstream), which owns wake-on-request and in-flux 503s.

const (
	TargetReady  TargetState = iota // answer A with the target IP
	TargetWake                      // serverless and stopped: router wakes it
	TargetInFlux                    // failover or placement in flux: router answers 503
	// TargetRouter always takes the fallback: the route needs per-route
	// behaviour a static Caddy route cannot express, such as E2B
	// maskRequestHost (a per-route upstream Host rewrite). The router already
	// applies it.
	TargetRouter
)

Jump to

Keyboard shortcuts

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