dns

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 34 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dns emulates Cloud DNS (SRS 5.2): the dns.googleapis.com v1 REST control plane (managed zones, record sets, changes; FR-DNS-001/002; zone IAM policies, FR-IAM-003; server and response policies, FR-DNS-006) and an authoritative DNS data plane on UDP and TCP that answers from the stored zones and response policies and forwards other names to the host resolver (FR-DNS-003/004).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNXDomain = errors.New("dns: name does not exist")
	ErrRefused  = errors.New("dns: query refused")
	ErrServFail = errors.New("dns: server failure")
)

Errors returned by Resolve.

Functions

func New

func New(env *emu.Env) emu.Service

New returns the service.

Types

type Service

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

Service is the Cloud DNS service module.

func (*Service) Addr

func (s *Service) Addr() string

Addr returns the data plane's host:port (UDP and TCP).

func (*Service) ApplySeed

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed implements emu.Seeder.

func (*Service) CreateZone

func (s *Service) CreateZone(proj string, z *dnsv1.ManagedZone) (*dnsv1.ManagedZone, error)

CreateZone creates a managed zone with its automatic SOA and NS record sets (recorded as change "0", like Cloud DNS). It does not check IAM.

func (*Service) DeleteZone

func (s *Service) DeleteZone(proj, name string) error

DeleteZone deletes an empty zone (only the apex SOA and NS remain); otherwise it fails with containerNotEmpty as Cloud DNS does.

func (*Service) EnvVars

func (s *Service) EnvVars(gateway string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer. gcloud's dns client has base URL https://dns.googleapis.com/dns/v1/, so the override includes /dns/v1/.

func (*Service) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

ExportSeed implements emu.SeedExporter: every managed zone with its record sets. The SOA record (whose serial every change bumps) and an apex NS record the zone was created with are left out, as creating the zone makes them. Routing-policy record sets, TTLs of 0, forwarding, peering, DNSSEC and logging configs, GKE cluster bindings, DNS policies and response policies have no seed form and are not exported.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Operations added in v0.2.0

func (s *Service) Operations() []emu.OperationInfo

Operations implements emu.OperationLister. A change is an Operation on its managed zone (CONTEXT.md), pending until the configured latency has passed; managedZoneOperations complete at once.

func (*Service) Ready

func (s *Service) Ready() error

Ready reports whether the data plane is listening.

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register mounts the REST API at /dns/v1/ (root, as the Go client and gcloud address it), under the /dns/ gateway prefix and in host mode, and on the admin API (admin.go) the console's query endpoint and doctor's forwarding report.

func (*Service) Reset

func (s *Service) Reset(context.Context) error

Reset drops the in-memory query index; it is rebuilt from the store on the next query.

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, name string, qtype uint16) ([]mdns.RR, error)

Resolve answers a query the way the data plane would and returns the answer section. A name that does not exist yields ErrNXDomain; a name outside every zone is forwarded (ErrRefused when forwarding is off). NODATA is an empty slice with a nil error. Other services (GKE CoreDNS, LB) use it to resolve emulated names in-process.

func (*Service) ResourceCounts added in v0.2.0

func (s *Service) ResourceCounts() map[string]int

ResourceCounts implements emu.ResourceCounter.

func (*Service) SetAddressMapper

func (s *Service) SetAddressMapper(f func(ip net.IP, network string) net.IP)

SetAddressMapper installs a function that rewrites A record addresses in answers (UDP/TCP server and Resolve) for a client on network ("" outside every VPC): the load balancer maps forwarding rule IPs to the local listeners that serve them for host clients (FR-LB-002, FR-INT-004). f returns nil to leave an address unchanged.

func (*Service) SetHostNames added in v0.7.0

func (s *Service) SetHostNames(suffixes []string, f func(ctx context.Context, name string, qtype uint16) ([]mdns.RR, int))

SetHostNames installs f to answer host queries for names under suffixes (lower case, fully qualified): f returns the answer and its rcode, and a CNAME it returns is chased like one from a zone. A nil f removes it.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens the DNS data plane: TCP via env.Listen("dns") and UDP on the same port number.

A dynamic port must be free for both protocols. Windows reserves different port ranges for each and hands out ephemeral ports in sequence, so every retry of TCP's pick can land in one UDP-reserved block (#206); without a --port-range, retries try random ephemeral ports instead.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop shuts the data plane down. It reports a failure to close the TCP listener; the UDP socket's close error stays inside mdns, which needs the *net.UDPConn itself to reply from the address a query was sent to.

func (*Service) UpsertRRSet

func (s *Service) UpsertRRSet(proj, zone string, rs *dnsv1.ResourceRecordSet) error

UpsertRRSet creates or replaces an rrset in a zone as one change. It does not check IAM; other services (e.g. the LB registering A records for forwarding rules) may use it.

Jump to

Keyboard shortcuts

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