Documentation
¶
Index ¶
- func AcquireLock(lockPath string) (*fileLock, error)
- func CloseDB(db *gorm.DB) error
- func ConnectDatabase(dbfile string) (*gorm.DB, error)
- func ConnectMigrate(dbfile string) (*gorm.DB, error)
- func CopyFile(srcpath, dstpath string) (err error)
- func FilesEqual(src, dst string) (bool, error)
- func GetBoolean(v string) (bool, error)
- func GetMACaddress(v string) (string, error)
- func GetSerial(db *gorm.DB, zonename string, next bool) (string, error)
- func LoadZoneIncludes(cfg *ConfigRoot, baseDir string) error
- func MigrateDatabase(db *gorm.DB) error
- func Pprint(data any)
- func ReadConfigFile(filename string, config *ConfigRoot) error
- func ReverseIpv4Addr(addr netip.Addr) string
- func ReverseIpv6Addr(addr netip.Addr) string
- func RunCommand(cmdline string) error
- func SafeJoin(base, name string) (string, error)
- func SetupLogging(debug bool, loglevel string)
- func Sha256sum(filename string) ([]byte, error)
- func SrcJSONLoad(dm *DnsManager, filename string) error
- func SrcfileLoad(dm *DnsManager, filename string) error
- func VerifyDnsname(v string) error
- type ConfigDHCP
- type ConfigDHCPtemplateProtocol
- type ConfigDNS
- type ConfigDNS_HostTemplate
- type ConfigDNS_SOA_template
- type ConfigDNS_TemplateNS
- type ConfigDNS_ZoneTemplate
- type ConfigDataGroups
- type ConfigDataType
- type ConfigDestination
- type ConfigDestinations
- type ConfigHostDHCPtemplate
- type ConfigPrefix
- type ConfigRoot
- type ConfigSource
- type ConfigSources
- type ConfigZone
- type ConfigZoneInclude
- type DNSManager
- func (dns *DNSManager) PreUpdate() error
- func (dns *DNSManager) Reload(zonename string, hostDnsTemplate *ConfigDNS_HostTemplate) error
- func (dns *DNSManager) ReloadAll(hostDnsTemplate *ConfigDNS_HostTemplate) error
- func (dns *DNSManager) Restart(hostDnsTemplate *ConfigDNS_HostTemplate) error
- func (dns *DNSManager) Status(hostDnsTemplate *ConfigDNS_HostTemplate) error
- func (dns *DNSManager) Update(host *ConfigDNS_HostTemplate, newSerial bool) error
- func (dns *DNSManager) UpdateCommit(host *ConfigDNS_HostTemplate) error
- func (dns *DNSManager) UpdateZone(host *ConfigDNS_HostTemplate, zone *Zone, newSerial bool) error
- type DNSManagerOpt
- type DnsManager
- func (dm *DnsManager) AddForwardRecord(domain string, record *Record) error
- func (dm *DnsManager) AddForwardZone(hostDnsTemplate *ConfigDNS_HostTemplate, configZone *ConfigZone) error
- func (dm *DnsManager) AddReverseRecord(domain string, record *Record) error
- func (dm *DnsManager) AddReverseZone(hostDnsTemplate *ConfigDNS_HostTemplate, configZone *ConfigZone) error
- func (dm *DnsManager) Load() error
- func (dm *DnsManager) LoadZones() error
- func (dm *DnsManager) PrintRecords()
- func (dm *DnsManager) Restart() error
- func (dm *DnsManager) Status() error
- func (dm *DnsManager) Sync() error
- func (dm *DnsManager) VerifyRecords() error
- type IncludePaths
- type KeaDHCPManager
- type KeaDHCPManagerOpt
- type Record
- type RecordsType
- type Zone
- type ZonesType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireLock ¶
func CopyFile ¶
CopyFile copies srcpath to dstpath using a same-directory temp file and rename so a crash cannot leave a truncated destination.
func FilesEqual ¶
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 GetMACaddress ¶
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 ¶
GetSerial returns the YYYYMMDDnn serial for zonename. If next is true, the stored serial is incremented and saved.
func LoadZoneIncludes ¶ added in v1.2.1
func LoadZoneIncludes(cfg *ConfigRoot, baseDir string) error
LoadZoneIncludes reads dnsmgr2 include items. An include-only list item (no host templates) is expanded and its zones/prefixes are appended to the preceding item. Include files listed on a group that already has a host template are appended onto that group. Relative paths are resolved against baseDir. Include lists are cleared after a successful load so a second call is a no-op.
func MigrateDatabase ¶
func ReadConfigFile ¶
func ReadConfigFile(filename string, config *ConfigRoot) error
func ReverseIpv4Addr ¶
func ReverseIpv6Addr ¶
func RunCommand ¶
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 ¶
SafeJoin joins base and a relative name and rejects empty names, absolute names, and paths that escape base (after cleaning).
func SetupLogging ¶
SetupLogging applies -d / --loglevel to the default slog logger. -d forces debug regardless of --loglevel.
func SrcJSONLoad ¶
func SrcJSONLoad(dm *DnsManager, filename string) error
func SrcfileLoad ¶
func SrcfileLoad(dm *DnsManager, filename string) error
func VerifyDnsname ¶
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 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 ¶
dns->zone_templates:
type ConfigDNS_ZoneTemplate ¶
type ConfigDataGroups ¶
type ConfigDataGroups []ConfigDataType
type ConfigDataType ¶
type ConfigDataType struct {
HostDnsTemplate string `yaml:"host_dns_template"`
HostDhcpTemplate string `yaml:"host_dhcp_template"`
// Include is a separate dnsmgr2 list item (not a field of
// host_dns_template). A string or a list of YAML files; loaded zones
// and prefixes are appended to the preceding list item. Paths are
// relative to the main config file's directory unless they are
// absolute.
Include IncludePaths `yaml:"include,omitempty"`
Prefixes []ConfigPrefix
Zones []ConfigZone
}
type ConfigDestination ¶
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
// ConfigDir is the directory of the main YAML file. Relative include
// paths are resolved against it. Not read from YAML.
ConfigDir string `yaml:"-" boa:"ignore"`
}
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 ¶
ConfigSource is a records input. Type is "file" (text) or "json".
type ConfigSources ¶
type ConfigSources []ConfigSource
type ConfigZone ¶
type ConfigZoneInclude ¶ added in v1.2.1
type ConfigZoneInclude struct {
Zones []ConfigZone `yaml:"zones,omitempty"`
Prefixes []ConfigPrefix `yaml:"prefixes,omitempty"`
Include IncludePaths `yaml:"include,omitempty"`
}
ConfigZoneInclude is the document written into a zone include file. Either this mapping (zones: / prefixes: / include:) or a YAML list of ConfigZone is accepted.
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 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) 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) VerifyRecords ¶
func (dm *DnsManager) VerifyRecords() error
type IncludePaths ¶ added in v1.2.1
type IncludePaths []string
IncludePaths is one path or a YAML list of paths.
func (*IncludePaths) UnmarshalYAML ¶ added in v1.2.1
func (p *IncludePaths) UnmarshalYAML(unmarshal func(interface{}) error) 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 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
}