store

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PrefixRRset     byte = 0x01 // RRset data
	PrefixNSEC3     byte = 0x02 // NSEC3 secondary index
	PrefixMeta      byte = 0x03 // Zone metadata
	PrefixChangeLog byte = 0x04 // IXFR change log

	// Separator between key components
	// 0xFF cannot appear in domain labels (labels are 7-bit ASCII)
	Separator byte = 0xFF
)

Key prefixes for BadgerDB

View Source
const (
	MetaSOA    = "soa"
	MetaConfig = "config"
	MetaNSEC3P = "nsec3p"
	MetaSerial = "serial"
)

Metadata keys

View Source
const (
	DefaultMinSerials = 100
	DefaultMaxAge     = 30 * 24 * time.Hour // 30 days
)

Default retention settings

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrZoneExists    = errors.New("zone already exists")
	ErrZoneNotFound  = errors.New("zone not found")
	ErrStopIteration = errors.New("stop iteration")
)

Common errors

Functions

func ChangeLogKey added in v0.5.0

func ChangeLogKey(zone domainname.DomainName, serial, sequence uint32) []byte

ChangeLogKey builds a key for IXFR change log entry. Format: 0x04 | zone-reversed | 0xFF | serial(4B big-endian) | sequence(4B big-endian)

func ChangeLogPrefixForZone added in v0.5.0

func ChangeLogPrefixForZone(zone domainname.DomainName) []byte

ChangeLogPrefixForZone returns prefix for scanning all change logs in a zone. Format: 0x04 | zone-reversed | 0xFF

func ChangeLogPrefixFromSerial added in v0.5.0

func ChangeLogPrefixFromSerial(zone domainname.DomainName, serial uint32) []byte

ChangeLogPrefixFromSerial returns prefix for scanning change logs from a serial. Format: 0x04 | zone-reversed | 0xFF | serial(4B big-endian)

func ExtractSerialFromChangeLogKey added in v0.5.0

func ExtractSerialFromChangeLogKey(key []byte) uint32

ExtractSerialFromChangeLogKey extracts the serial from a change log key. Assumes the key is well-formed.

func ExtractTypeFromRRsetKey added in v0.5.0

func ExtractTypeFromRRsetKey(key []byte) uint16

ExtractTypeFromRRsetKey extracts the type from an RRset key. Assumes the key is well-formed.

func MetaKey added in v0.5.0

func MetaKey(zone domainname.DomainName, key string) []byte

MetaKey builds a key for zone metadata. Format: 0x03 | zone-reversed | 0xFF | key

func MetaPrefixForZone added in v0.5.0

func MetaPrefixForZone(zone domainname.DomainName) []byte

MetaPrefixForZone returns prefix for scanning all metadata in a zone. Format: 0x03 | zone-reversed | 0xFF

func NSEC3IndexKey added in v0.5.0

func NSEC3IndexKey(zone domainname.DomainName, hash string) []byte

NSEC3IndexKey builds a key for NSEC3 hash-to-name index. Format: 0x02 | zone-reversed | 0xFF | hash(base32)

func NSEC3IndexPrefixForZone added in v0.5.0

func NSEC3IndexPrefixForZone(zone domainname.DomainName) []byte

NSEC3IndexPrefixForZone returns prefix for scanning all NSEC3 hashes in a zone. Format: 0x02 | zone-reversed | 0xFF

func RRsetKey added in v0.5.0

func RRsetKey(zone, name domainname.DomainName, rrtype uint16) []byte

RRsetKey builds a key for RRset storage. Format: 0x01 | zone-reversed | 0xFF | name-reversed | 0xFF | type(2B big-endian)

func RRsetPrefixForName added in v0.5.0

func RRsetPrefixForName(zone, name domainname.DomainName) []byte

RRsetPrefixForName returns prefix for scanning all types at a name. Format: 0x01 | zone-reversed | 0xFF | name-reversed | 0xFF

func RRsetPrefixForZone added in v0.5.0

func RRsetPrefixForZone(zone domainname.DomainName) []byte

RRsetPrefixForZone returns prefix for scanning all records in a zone. Format: 0x01 | zone-reversed | 0xFF

Types

type CanonicalName added in v0.5.0

type CanonicalName struct {
	Name  domainname.DomainName
	Types []uint16
}

CanonicalName holds a domain name and its record types for NSEC chain building.

type ChangeRetention added in v0.5.0

type ChangeRetention struct {
	MinSerials uint32        // Keep at least this many serials
	MaxAge     time.Duration // Safety net: prune older than this
}

ChangeRetention configures IXFR change history retention.

type Config added in v0.5.0

type Config struct {
	Path      string          // Database path (empty for in-memory)
	InMemory  bool            // Force in-memory mode
	Retention ChangeRetention // IXFR change retention settings
}

Config holds store configuration.

type NSEC3Name added in v0.5.0

type NSEC3Name struct {
	Hash       string // Base32 encoded hash
	Original   domainname.DomainName
	Types      []uint16
	IsOptedOut bool // For opt-out support
}

NSEC3Name holds a hashed domain name for NSEC3 chain building.

type ProtoRRWithMeta added in v0.5.0

type ProtoRRWithMeta struct {
	Record   mindnspb.ProtoRR
	Metadata *mindnspb.RecordMetadata
}

ProtoRRWithMeta pairs a record with its policy metadata.

type Store added in v0.5.0

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

Store is the BadgerDB-backed DNS store. Intentionally coupled to BadgerDB - no abstraction.

func Open added in v0.5.0

func Open(cfg Config) (*Store, error)

Open creates or opens a BadgerDB store.

func (*Store) BuildNSEC3Chain added in v0.5.0

func (s *Store) BuildNSEC3Chain(ctx context.Context, zone domainname.DomainName, param *mindnspb.NSEC3PARAMData, ttl uint32) error

BuildNSEC3Chain creates NSEC3 records for the entire zone.

func (*Store) BuildNSECChain added in v0.5.0

func (s *Store) BuildNSECChain(ctx context.Context, zone domainname.DomainName, ttl uint32) error

BuildNSECChain creates NSEC records for the entire zone. This should be called within a transaction.

func (*Store) Close added in v0.5.0

func (s *Store) Close() error

Close closes the database.

func (*Store) CreateZone added in v0.5.0

func (s *Store) CreateZone(ctx context.Context, zone domainname.DomainName, soa *mindnspb.SOA) error

CreateZone creates a new zone with initial SOA.

func (*Store) DB added in v0.5.0

func (s *Store) DB() *badger.DB

DB returns the underlying BadgerDB instance. Use with caution - for advanced operations only.

func (*Store) DeleteRRset added in v0.5.0

func (s *Store) DeleteRRset(ctx context.Context, zone, name domainname.DomainName, rrtype mindnspb.Type) error

DeleteRRset removes records for a name and type.

func (*Store) DeleteZone added in v0.5.0

func (s *Store) DeleteZone(ctx context.Context, zone domainname.DomainName) error

DeleteZone removes a zone and all its records.

func (*Store) GetAllTypesForName added in v0.5.0

func (s *Store) GetAllTypesForName(ctx context.Context, zone, name domainname.DomainName) (map[mindnspb.Type][]mindnspb.ProtoRR, error)

GetAllTypesForName retrieves all record types at a name.

func (*Store) GetChanges added in v0.5.0

func (s *Store) GetChanges(ctx context.Context, zone domainname.DomainName, fromSerial, toSerial uint32) ([]*mindnspb.ChangeSet, error)

GetChanges retrieves change sets between two serial numbers for IXFR. Returns change sets in order from fromSerial to toSerial (exclusive of fromSerial).

func (*Store) GetMetadata added in v0.5.0

func (s *Store) GetMetadata(ctx context.Context, zone domainname.DomainName) (*mindnspb.ZoneMetadata, error)

GetMetadata retrieves zone metadata.

func (*Store) GetNSEC3OriginalName added in v0.5.0

func (s *Store) GetNSEC3OriginalName(ctx context.Context, zone domainname.DomainName, hash string) (domainname.DomainName, error)

GetNSEC3OriginalName retrieves the original name for an NSEC3 hash.

func (*Store) GetRRset added in v0.5.0

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

GetRRset retrieves records for a name and type.

func (*Store) GetSerial added in v0.5.0

func (s *Store) GetSerial(ctx context.Context, zone domainname.DomainName) (uint32, error)

GetSerial returns the current serial for a zone.

func (*Store) HasChangesFrom added in v0.5.0

func (s *Store) HasChangesFrom(ctx context.Context, zone domainname.DomainName, serial uint32) (bool, error)

HasChangesFrom checks if we have change sets starting from the given serial. Used to determine if IXFR is possible or if we need AXFR.

func (*Store) IterateCanonical added in v0.5.0

func (s *Store) IterateCanonical(ctx context.Context, zone domainname.DomainName, fn func(CanonicalName) error) error

IterateCanonical iterates over all names in a zone in canonical (DNSSEC) order. The callback receives each name and its record types.

func (*Store) IterateNSEC3Order added in v0.5.0

func (s *Store) IterateNSEC3Order(ctx context.Context, zone domainname.DomainName, param *mindnspb.NSEC3PARAMData, fn func(NSEC3Name) error) error

IterateNSEC3Order iterates over all names in NSEC3 hash order.

func (*Store) ListZones added in v0.5.0

func (s *Store) ListZones(ctx context.Context) ([]domainname.DomainName, error)

ListZones returns all zone names.

func (*Store) PruneChanges added in v0.5.0

func (s *Store) PruneChanges(ctx context.Context, zone domainname.DomainName) error

PruneChanges removes old change sets based on retention policy. Keeps MinSerials recent serials or changes newer than MaxAge.

func (*Store) Retention added in v0.5.0

func (s *Store) Retention() ChangeRetention

Retention returns the configured change retention settings.

func (*Store) SetRRset added in v0.5.0

func (s *Store) SetRRset(ctx context.Context, zone, name domainname.DomainName, rrtype mindnspb.Type, records []mindnspb.ProtoRR) error

SetRRset stores records, replacing any existing.

func (*Store) Update added in v0.5.0

func (s *Store) Update(ctx context.Context, zone domainname.DomainName, fn func(*Txn) error, opts ...UpdateOptions) error

Update executes a read-write transaction with change tracking. Changes are recorded for IXFR and the zone serial is incremented. Use opts to control serial behavior (e.g., for signed zones).

func (*Store) UpdateMetadata added in v0.5.0

func (s *Store) UpdateMetadata(ctx context.Context, zone domainname.DomainName, meta *mindnspb.ZoneMetadata) error

UpdateMetadata updates zone metadata.

func (*Store) View added in v0.5.0

func (s *Store) View(ctx context.Context, zone domainname.DomainName, fn func(*Txn) error) error

View executes a read-only transaction.

type Txn added in v0.5.0

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

Txn wraps a BadgerDB transaction with change tracking for IXFR.

func (*Txn) Additions added in v0.5.0

func (t *Txn) Additions() []*mindnspb.ChangeRecord

Additions returns the tracked additions in this transaction.

func (*Txn) CommitChanges added in v0.5.0

func (t *Txn) CommitChanges(newSerial uint32) error

CommitChanges explicitly records changes with the specified serial. Use this when DeferSerial was set and you want to commit after signing.

func (*Txn) DeleteRRset added in v0.5.0

func (t *Txn) DeleteRRset(name domainname.DomainName, rrtype mindnspb.Type) error

DeleteRRset deletes an RRset within the transaction, tracking the change.

func (*Txn) Deletions added in v0.5.0

func (t *Txn) Deletions() []*mindnspb.ChangeRecord

Deletions returns the tracked deletions in this transaction.

func (*Txn) GetAllTypesForName added in v0.5.0

func (t *Txn) GetAllTypesForName(name domainname.DomainName) (map[mindnspb.Type][]mindnspb.ProtoRR, error)

GetAllTypesForName retrieves all RRsets for a name within the transaction.

func (*Txn) GetRRset added in v0.5.0

func (t *Txn) GetRRset(name domainname.DomainName, rrtype mindnspb.Type) ([]mindnspb.ProtoRR, error)

GetRRset retrieves an RRset within the transaction.

func (*Txn) HasChanges added in v0.5.0

func (t *Txn) HasChanges() bool

HasChanges returns true if there are pending changes.

func (*Txn) IterateCanonical added in v0.5.0

func (t *Txn) IterateCanonical(fn func(CanonicalName) error) error

IterateCanonicalInTxn iterates over all names within an existing transaction. This allows the signer to see uncommitted changes from the same transaction.

func (*Txn) SetRRset added in v0.5.0

func (t *Txn) SetRRset(name domainname.DomainName, rrtype mindnspb.Type, records []mindnspb.ProtoRR) error

SetRRset sets an RRset within the transaction, tracking the change.

type UpdateOptions added in v0.5.0

type UpdateOptions struct {
	// DeferSerial skips automatic serial increment.
	// Use this when the caller (e.g., Signer) will manage serial timing.
	DeferSerial bool

	// NewSerial, if non-zero and DeferSerial is false, sets the specific serial.
	// Useful for Signer to set the serial explicitly after signing.
	NewSerial uint32
}

UpdateOptions configures transaction behavior.

Jump to

Keyboard shortcuts

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