dnsmgr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireLock

func AcquireLock(lockPath string) (*fileLock, error)

func CloseDB

func CloseDB(db *gorm.DB) error

func ConnectDatabase

func ConnectDatabase(dbfile string) (*gorm.DB, error)

func ConnectMigrate

func ConnectMigrate(dbfile string) (*gorm.DB, error)

func CopyFile

func CopyFile(srcpath, dstpath string) (err error)

CopyFile copies srcpath to dstpath using a same-directory temp file and rename so a crash cannot leave a truncated destination.

func FilesEqual

func FilesEqual(src, dst string) (bool, error)

FilesEqual reports whether src and dst have the same SHA-256. A missing dst is not an error: equal is false (caller should copy). Other read errors on either file are returned.

func GetBoolean

func GetBoolean(v string) (bool, error)

func GetMACaddress

func GetMACaddress(v string) (string, error)

GetMACaddress parses a MAC and returns canonical lowercase colon form (aa:bb:cc:dd:ee:ff). Accepted input: aa:bb:cc:dd:ee:ff, aa-bb-cc-dd-ee-ff, aabb.ccdd.eeff, aabbccddeeff.

func GetSerial

func GetSerial(db *gorm.DB, zonename string, next bool) (string, error)

GetSerial returns the YYYYMMDDnn serial for zonename. If next is true, the stored serial is incremented and saved.

func MigrateDatabase

func MigrateDatabase(db *gorm.DB) error

func Pprint

func Pprint(data any)

print structures JSON formatted

func ReadConfigFile

func ReadConfigFile(filename string, config *ConfigRoot) error

func ReverseIpv4Addr

func ReverseIpv4Addr(addr netip.Addr) string

func ReverseIpv6Addr

func ReverseIpv6Addr(addr netip.Addr) string

func RunCommand

func RunCommand(cmdline string) error

RunCommand runs a configured command string (e.g. "sudo rndc reload example.com"). The string is split on whitespace; it is not passed to a shell.

func SafeJoin

func SafeJoin(base, name string) (string, error)

SafeJoin joins base and a relative name and rejects empty names, absolute names, and paths that escape base (after cleaning).

func SetupLogging

func SetupLogging(debug bool, loglevel string)

SetupLogging applies -d / --loglevel to the default slog logger. -d forces debug regardless of --loglevel.

func Sha256sum

func Sha256sum(filename string) ([]byte, error)

func SrcJSONLoad

func SrcJSONLoad(dm *DnsManager, filename string) error

func SrcfileLoad

func SrcfileLoad(dm *DnsManager, filename string) error

func VerifyDnsname

func VerifyDnsname(v string) error

VerifyDnsname checks a DNS owner name or target. "@" is allowed. Labels may contain letters, digits, hyphen, underscore (SRV/TLSA), or be "*".

Types

type ConfigDHCP

type ConfigDHCP struct {
	DomainName    string                            `yaml:"domain_name" optional:"true"`
	DNSServers    []string                          `yaml:"dns_servers" optional:"true"`
	HostTemplates map[string]ConfigHostDHCPtemplate `yaml:"host_templates"`
}

type ConfigDHCPtemplateProtocol

type ConfigDHCPtemplateProtocol struct {
	Enable      bool
	Configdir   string
	IncludeFile string `yaml:"includefile"`
	Tmpdir      string
	CmdRestart  string `yaml:"cmd_restart"`
	CmdStatus   string `yaml:"cmd_status"`
}

type ConfigDNS

type ConfigDNS struct {
	HostTemplates map[string]ConfigDNS_HostTemplate `yaml:"host_templates"`
	SOATemplates  map[string]ConfigDNS_SOA_template `yaml:"soa_templates"`
	ZoneTemplates map[string]ConfigDNS_ZoneTemplate `yaml:"zone_templates"`
}

type ConfigDNS_HostTemplate

type ConfigDNS_HostTemplate struct {
	Type          string
	Configdir     string
	IncludeFile   string `yaml:"includefile"`
	ZonesDir      string `yaml:"zonesdir"`
	Zonesfile     string
	Tmpdir        string
	CmdReloadAll  string `yaml:"cmd_reload_all"`
	CmdReloadZone string `yaml:"cmd_reload_zone"`
	CmdRestart    string `yaml:"cmd_restart"`
	CmdStatus     string `yaml:"cmd_status"`
}

dns->host_template:

type ConfigDNS_SOA_template

type ConfigDNS_SOA_template struct {
	Mname        string
	Rname        string
	SerialFormat string `yaml:"serial_format"`
	Refresh      int
	Retry        int
	Expire       int
	Minimum      int
}

dns->soa_templates:

type ConfigDNS_TemplateNS

type ConfigDNS_TemplateNS struct {
	Name  string
	TTL   string
	Type  string
	Value string
}

dns->zone_templates:

type ConfigDNS_ZoneTemplate

type ConfigDNS_ZoneTemplate struct {
	SOA            string
	DefaultTTL     string `yaml:"default_ttl"`
	NS             []ConfigDNS_TemplateNS
	AllowUpdate    []string `yaml:"allow_update"`
	DNSSECpolicy   string   `yaml:"dnssec_policy"`
	ParentalAgents []string `yaml:"parental_agents"`
	ZoneOptions    []string `yaml:"zone_options"`
}

type ConfigDataGroups

type ConfigDataGroups []ConfigDataType

type ConfigDataType

type ConfigDataType struct {
	HostDnsTemplate  string `yaml:"host_dns_template"`
	HostDhcpTemplate string `yaml:"host_dhcp_template"`
	Prefixes         []ConfigPrefix
	Zones            []ConfigZone
}

type ConfigDestination

type ConfigDestination struct {
	Type string
	Name string
}

ConfigDestination is accepted in YAML for compatibility and ignored. Drivers are selected by host_dns_template / host_dhcp_template.

type ConfigDestinations

type ConfigDestinations []ConfigDestination

type ConfigHostDHCPtemplate

type ConfigHostDHCPtemplate struct {
	Type string
	IPv4 ConfigDHCPtemplateProtocol `yaml:"ipv4"`
	IPv6 ConfigDHCPtemplateProtocol `yaml:"ipv6"`
}

type ConfigPrefix

type ConfigPrefix struct {
	Name       string
	Range      string
	Gateway    string
	SubnetMask string   `yaml:"subnet_mask"`
	DNSServers []string `yaml:"dns_servers" optional:"true"`
}

ConfigPrefix is a DHCP subnet. Name is a CIDR prefix (192.168.1.0/24). Range is an optional pool (192.168.1.100-192.168.1.200). Gateway defaults to the first usable address in the prefix. SubnetMask defaults to the mask implied by the prefix length (IPv4 only). DNSServers, when set, override dhcp.dns_servers for this subnet only.

type ConfigRoot

type ConfigRoot struct {
	Dbfile       string `yaml:"dbfile"`
	Sources      ConfigSources
	Destinations ConfigDestinations
	DHCP         ConfigDHCP
	DNS          ConfigDNS

	Dnsmgr2 ConfigDataGroups
}

func LoadConfigFile

func LoadConfigFile(filename string) (ConfigRoot, error)

LoadConfigFile reads a dnsmgr2 YAML config. Callers such as factum2-dns use this instead of reimplementing YAML load.

type ConfigSource

type ConfigSource struct {
	Type string
	Name string
}

ConfigSource is a records input. Type is "file" (text) or "json".

type ConfigSources

type ConfigSources []ConfigSource

type ConfigZone

type ConfigZone struct {
	Name        string
	Type        string // forward, reverse4, reverse6
	DnsTemplate string `yaml:"dns_template"`
}

type DNSManager

type DNSManager struct {
	P DNSManagerOpt
}

func NewISCBINDManager

func NewISCBINDManager(p DNSManagerOpt) *DNSManager

Create a manager, which handles the DNS server

func (*DNSManager) PreUpdate

func (dns *DNSManager) PreUpdate() error

Resolve all referenses in Config

func (*DNSManager) Reload

func (dns *DNSManager) Reload(zonename string, hostDnsTemplate *ConfigDNS_HostTemplate) error

func (*DNSManager) ReloadAll

func (dns *DNSManager) ReloadAll(hostDnsTemplate *ConfigDNS_HostTemplate) error

func (*DNSManager) Restart

func (dns *DNSManager) Restart(hostDnsTemplate *ConfigDNS_HostTemplate) error

func (*DNSManager) Status

func (dns *DNSManager) Status(hostDnsTemplate *ConfigDNS_HostTemplate) error

func (*DNSManager) Update

func (dns *DNSManager) Update(host *ConfigDNS_HostTemplate, newSerial bool) error

Write all zone files

func (*DNSManager) UpdateCommit

func (dns *DNSManager) UpdateCommit(host *ConfigDNS_HostTemplate) error

Copy zonefiles if changed to destination with new serial number and reload zone

func (*DNSManager) UpdateZone

func (dns *DNSManager) UpdateZone(host *ConfigDNS_HostTemplate, zone *Zone, newSerial bool) error

Write one zonefile, optionally update SOA serial

type DNSManagerOpt

type DNSManagerOpt struct {
	Dbfile     string
	DB         *gorm.DB
	ConfigDNS  *ConfigDNS
	ConfigData ConfigDataGroups
	Zones      ZonesType
}

type DnsManager

type DnsManager struct {
	C            ConfigRoot
	Zones        *ZonesType // All zones
	ZonesForward *ZonesType // All forward zones
	ZoneReverse4 *bart.Table[*Zone]
	ZoneReverse6 *bart.Table[*Zone]
	DB           *gorm.DB
}

func NewDnsManager

func NewDnsManager(p ConfigRoot) (*DnsManager, error)

Create a manager, that handles the DNS server

func (*DnsManager) AddForwardRecord

func (dm *DnsManager) AddForwardRecord(domain string, record *Record) error

Add a record to a zone Handle generation of reverse DNS records

func (*DnsManager) AddForwardZone

func (dm *DnsManager) AddForwardZone(hostDnsTemplate *ConfigDNS_HostTemplate, configZone *ConfigZone) error

Add a forward zone, such as example.com

func (*DnsManager) AddReverseRecord

func (dm *DnsManager) AddReverseRecord(domain string, record *Record) error

func (*DnsManager) AddReverseZone

func (dm *DnsManager) AddReverseZone(hostDnsTemplate *ConfigDNS_HostTemplate, configZone *ConfigZone) error

Add a reverse zone, such as

192.168.1.0/24
2a00:ff40:1000::/48

func (*DnsManager) Load

func (dm *DnsManager) Load() error

Load all sources

func (*DnsManager) LoadZones

func (dm *DnsManager) LoadZones() error

Go through configuration of zones, and create internal data structures

func (*DnsManager) PrintRecords

func (dm *DnsManager) PrintRecords()

func (*DnsManager) Restart

func (dm *DnsManager) Restart() error

func (*DnsManager) Status

func (dm *DnsManager) Status() error

func (*DnsManager) Sync

func (dm *DnsManager) Sync() error

Sync all destinations

func (*DnsManager) VerifyRecords

func (dm *DnsManager) VerifyRecords() error

type KeaDHCPManager

type KeaDHCPManager struct {
	P KeaDHCPManagerOpt
	// contains filtered or unexported fields
}

func NewKeaDHCPManager

func NewKeaDHCPManager(p KeaDHCPManagerOpt) *KeaDHCPManager

func (*KeaDHCPManager) Restart

func (k *KeaDHCPManager) Restart(proto *ConfigDHCPtemplateProtocol) error

func (*KeaDHCPManager) Status

func (k *KeaDHCPManager) Status(proto *ConfigDHCPtemplateProtocol, family string) error

func (*KeaDHCPManager) Update

func (k *KeaDHCPManager) Update() error

func (*KeaDHCPManager) UpdateCommit

func (k *KeaDHCPManager) UpdateCommit() error

type KeaDHCPManagerOpt

type KeaDHCPManagerOpt struct {
	ConfigDHCP *ConfigDHCP
	Host       *ConfigHostDHCPtemplate
	Prefixes   []ConfigPrefix
	Zones      ZonesType
}

type Record

type Record struct {
	Name    string
	TTL     int64
	Type    string
	Value   string
	MAC     string
	Forward bool // generate forwarding records?
	Reverse bool // generate PTR record?
}

type RecordsType

type RecordsType []*Record

type Zone

type Zone struct {
	Name       string
	ConfigZone *ConfigZone

	DNS     *ConfigDNS_ZoneTemplate
	SOA     *ConfigDNS_SOA_template
	Host    *ConfigDNS_HostTemplate
	Zone    *Zone
	DstFile string
	TmpFile string
	Records RecordsType
}

type ZonesType

type ZonesType []*Zone

Jump to

Keyboard shortcuts

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