zone

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package zone provides DNS zone management and query handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonExistentDomain = errors.New("non-existent domain")
	ErrNonExistentRRset  = errors.New("non-existent rrset")
	ErrZoneNotFound      = errors.New("zone not found")
)
View Source
var (
	ErrSOAAtApexOnly    = errors.New("zone: SOA record only allowed at zone apex")
	ErrCNAMEAtApex      = errors.New("zone: CNAME not allowed at zone apex")
	ErrMultipleCNAME    = errors.New("zone: only one CNAME allowed per name")
	ErrALIASCoexistence = errors.New("zone: ALIAS cannot coexist with A/AAAA records")
	ErrALIASNotAtApex   = errors.New("zone: ALIAS is primarily for zone apex, consider using CNAME")
)

Validation errors

View Source
var (
	ErrNotInZone        = errors.New("zone: name not in zone")
	ErrInvalidRecord    = errors.New("zone: invalid record")
	ErrCNAMECoexistence = errors.New("zone: CNAME cannot coexist with other records")
	ErrDuplicate        = errors.New("zone: duplicate record")
)

Common errors

View Source
var (
	// ErrNoSOA is returned when a zone file does not contain a SOA record.
	ErrNoSOA = errors.New("zone file has no SOA record")
)

Functions

This section is empty.

Types

type Config added in v0.5.0

type Config struct {
	// Name is the zone's domain name (e.g., "example.com.")
	Name string

	// Store is the backing store (required)
	Store *store.Store

	// SOA parameters
	PrimaryNS string // Primary nameserver (e.g., "ns1.example.com.")
	AdminMbox string // Admin mailbox (e.g., "admin.example.com.")

	// Optional configuration
	DefaultTTL    uint32        // Default TTL for records (default: 3600)
	SOARefresh    uint32        // SOA refresh interval (default: 7200)
	SOARetry      uint32        // SOA retry interval (default: 3600)
	SOAExpire     uint32        // SOA expire time (default: 1209600)
	SOAMinTTL     uint32        // SOA minimum TTL (default: 3600)
	RRSIGValidity time.Duration // RRSIG validity period (default: 30 days)

	// DNSSEC (optional - nil for unsigned zones)
	Signer *signer.Signer

	// ALIAS resolution (optional - nil disables ALIAS support)
	ALIASResolver *alias.Resolver
}

Config holds zone configuration.

type CreateConfig added in v0.5.0

type CreateConfig struct {
	// Name is the zone's domain name (e.g., "example.com.")
	Name string

	// SOA parameters
	PrimaryNS string // Primary nameserver (e.g., "ns1.example.com.")
	AdminMbox string // Admin mailbox (e.g., "admin.example.com.")

	// Optional configuration
	DefaultTTL uint32 // Default TTL for records (default: 3600)
	SOARefresh uint32 // SOA refresh interval (default: 7200)
	SOARetry   uint32 // SOA retry interval (default: 3600)
	SOAExpire  uint32 // SOA expire time (default: 1209600)
	SOAMinTTL  uint32 // SOA minimum TTL (default: 3600)

	// DNSSEC (optional - nil for unsigned zones)
	Signer *signer.Signer
}

CreateConfig holds configuration for creating a new zone.

type Deletion added in v0.5.0

type Deletion struct {
	Name domainname.DomainName
	Type mindnspb.Type
}

Deletion represents a record deletion request.

type LoadConfig added in v0.5.0

type LoadConfig struct {
	// FilePath is the path to the zone file.
	FilePath string

	// Origin is the zone origin (e.g., "example.com.").
	// If empty, will be inferred from the SOA record.
	Origin string

	// Store is the store to use for the zone.
	Store *store.Store
}

LoadConfig configures zone loading from a file.

type Manager added in v0.5.0

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

Manager manages all DNS zones backed by a single store. It serves as the single source of truth for zone data.

func NewManager added in v0.5.0

func NewManager(cfg ManagerConfig) (*Manager, error)

NewManager creates a new zone manager. Call Open() to load existing zones from the store.

func (*Manager) Close added in v0.5.0

func (m *Manager) Close() error

Close closes the manager. Currently a no-op but reserved for future cleanup.

func (*Manager) Count added in v0.5.0

func (m *Manager) Count() int

Count returns the number of zones.

func (*Manager) Create added in v0.5.0

func (m *Manager) Create(ctx context.Context, cfg CreateConfig) (*Zone, error)

Create creates a new zone and stores it.

func (*Manager) Delete added in v0.5.0

func (m *Manager) Delete(ctx context.Context, name domainname.DomainName) error

Delete removes a zone from the store and cache.

func (*Manager) Find added in v0.5.0

func (m *Manager) Find(name domainname.DomainName) (*Zone, error)

Find finds the most specific zone for a domain name. It walks up the domain tree until it finds a matching zone.

func (*Manager) Get added in v0.5.0

func (m *Manager) Get(name domainname.DomainName) (*Zone, error)

Get returns a zone by exact name match.

func (*Manager) List added in v0.5.0

func (m *Manager) List() []domainname.DomainName

List returns all zone names.

func (*Manager) Open added in v0.5.0

func (m *Manager) Open(ctx context.Context) error

Open loads all existing zones from the store into memory. This should be called after NewManager to populate the cache.

func (*Manager) SetSigner added in v0.5.0

func (m *Manager) SetSigner(name domainname.DomainName, sgn *signer.Signer) error

SetSigner sets the DNSSEC signer for a zone. This is separate from Create because signers may need to be configured after loading zones from the store.

func (*Manager) Store added in v0.5.0

func (m *Manager) Store() *store.Store

Store returns the underlying store.

type ManagerConfig added in v0.5.0

type ManagerConfig struct {
	// Store is the backing BadgerDB store (required).
	Store *store.Store

	// ALIASResolver is the shared resolver for ALIAS records (optional).
	ALIASResolver *alias.Resolver
}

ManagerConfig configures the ZoneManager.

type OpenOption added in v0.5.0

type OpenOption func(*Zone)

OpenOption configures an opened zone.

func WithALIASResolver added in v0.5.0

func WithALIASResolver(r *alias.Resolver) OpenOption

WithALIASResolver sets the ALIAS resolver for the zone.

type QueryOption added in v0.4.2

type QueryOption func(*queryOptions)

func QueryWithDNSSEC added in v0.4.2

func QueryWithDNSSEC() QueryOption

type QueryResult added in v0.4.2

type QueryResult struct {
	Authority  Section
	Answer     Section
	Additional Section
}

type Section added in v0.4.2

type Section []mindnspb.ProtoRR

func (*Section) Add added in v0.4.2

func (s *Section) Add(rr ...mindnspb.ProtoRR)

func (Section) Has added in v0.4.2

func (s Section) Has(rr mindnspb.ProtoRR) bool

type Zone

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

Zone represents a DNS zone with query and mutation capabilities.

func Load added in v0.5.0

func Load(ctx context.Context, cfg LoadConfig) (*Zone, error)

Load parses a zone file and creates a zone with all records. Returns the loaded zone and any error encountered.

func LoadIntoManager added in v0.5.0

func LoadIntoManager(ctx context.Context, mgr *Manager, filePath, origin string) (*Zone, error)

LoadIntoManager parses a zone file and loads it into a Manager. The zone is added to the manager's cache after loading.

func New

func New(ctx context.Context, cfg Config) (*Zone, error)

New creates a new zone and stores its SOA record.

func Open added in v0.5.0

func Open(ctx context.Context, st *store.Store, name string, sgn *signer.Signer, opts ...OpenOption) (*Zone, error)

Open opens an existing zone from the store.

func (*Zone) Add

func (z *Zone) Add(ctx context.Context, rr mindnspb.ProtoRR) error

Add adds a record to the zone. For signed zones, this triggers re-signing.

func (*Zone) Apply added in v0.5.0

func (z *Zone) Apply(ctx context.Context, additions []mindnspb.ProtoRR, deletions []Deletion) error

Apply applies multiple additions and deletions atomically. For signed zones, the zone is re-signed after mutations.

func (*Zone) BatchUpdate added in v0.5.0

BatchUpdate applies a batch of changes atomically with precondition checks. TODO: Implement precondition checking and atomic application.

func (*Zone) DS added in v0.5.0

func (z *Zone) DS() *dns.DS

DS returns the DS record for the zone's KSK (for signed zones only).

func (*Zone) Delete added in v0.5.0

func (z *Zone) Delete(ctx context.Context, name domainname.DomainName, rrtype mindnspb.Type) error

Delete removes an RRset from the zone. For signed zones, this triggers re-signing.

func (*Zone) DeleteRRset added in v0.5.0

func (z *Zone) DeleteRRset(ctx context.Context, name domainname.DomainName, rrtype mindnspb.Type) error

DeleteRRset removes an RRset from the zone.

func (*Zone) GetRRset added in v0.5.0

func (z *Zone) GetRRset(ctx context.Context, name domainname.DomainName, rrtype mindnspb.Type) ([]mindnspb.ProtoRR, error)

GetRRset returns an RRset from the zone.

func (*Zone) IsSigned added in v0.5.0

func (z *Zone) IsSigned() bool

IsSigned returns true if this zone has DNSSEC signing enabled.

func (*Zone) ListRRsets added in v0.5.0

func (z *Zone) ListRRsets(ctx context.Context, nameFilter string, typeFilter mindnspb.Type) ([]*mindnspb.RRset, error)

ListRRsets returns all RRsets in the zone, optionally filtered by name and type.

func (*Zone) Name added in v0.5.0

func (z *Zone) Name() domainname.DomainName

Name returns the zone's domain name.

func (*Zone) Query added in v0.4.2

func (z *Zone) Query(ctx context.Context, qst *mindnspb.Question, opts ...QueryOption) (*QueryResult, error)

func (*Zone) SOA added in v0.5.0

func (z *Zone) SOA(ctx context.Context) (*mindnspb.SOA, error)

SOA returns the zone's SOA record.

func (*Zone) Serial added in v0.5.0

func (z *Zone) Serial(ctx context.Context) (uint32, error)

Serial returns the current zone serial.

func (*Zone) SetRRset added in v0.5.0

func (z *Zone) SetRRset(ctx context.Context, name domainname.DomainName, rrtype mindnspb.Type, rrs []mindnspb.ProtoRR) error

SetRRset replaces an RRset in the zone.

func (*Zone) Signer added in v0.5.0

func (z *Zone) Signer() *signer.Signer

Signer returns the zone's signer (nil for unsigned zones).

func (*Zone) Store added in v0.5.0

func (z *Zone) Store() *store.Store

Store returns the underlying store.

Jump to

Keyboard shortcuts

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