dnssync

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0 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 dnssync keeps a Technitium zone in step with hlab's inventory.

The inventory already knows every machine's name, address and hardware address. Keeping the DNS server's idea of the fleet in step with it by hand is exactly the sort of task that is done once, correctly, and then quietly rots as machines are added and addresses change.

Index

Constants

View Source
const (
	MarkerRecord = "hlab:record"
	MarkerDone   = "hlab:dns-done"
	MarkerNoAuth = "hlab:no-admin-password"
)

Markers the scripts print.

View Source
const (
	MarkerJSON  = "hlab:json"
	MarkerScope = "hlab:scope"
)

Markers separating the two raw API responses the read script returns.

View Source
const PasswordPath = "/opt/hlab/stacks/technitium/config/admin-password"

PasswordPath is where the Technitium stack keeps its admin password.

Variables

This section is empty.

Functions

func BuildReadScript

func BuildReadScript(zone string) (string, error)

BuildReadScript renders the script that dumps a zone's A records.

The raw response comes back and is parsed here rather than picked apart with sed on the machine. Technitium nests the address inside an rData object, so any line-oriented extraction separates a record's name from its value and silently finds nothing — which reads as an empty zone and would have hlab recreate every record it already has.

func BuildSyncScript

func BuildSyncScript(zone string, changes []Change, reservations []Reservation) (string, error)

BuildSyncScript renders the script that applies the plan.

Only creates and updates are emitted. Nothing is ever deleted: the zone is shared with every device DHCP registers, and a name hlab does not recognise is far more likely to be somebody's phone than a mistake.

func ParseRecords

func ParseRecords(out string) (map[string]string, error)

ParseRecords reads the A records out of the read script's output.

func ParseReservations

func ParseReservations(out string) map[string]string

ParseReservations reads the reserved leases the scope already holds, keyed by hardware address.

Without this the plan asserts every reservation on every run and therefore always claims there is work to do, which trains an operator to ignore it.

func ParseScopeRange

func ParseScopeRange(out string) (start, end string)

ParseScopeRange reports the addresses the DHCP scope hands out.

A reservation outside that range means nothing: the server will never offer the address, so pinning it is at best noise and at worst an error the operator has to interpret. Statically configured machines deliberately live outside the pool, which is exactly the case this excludes.

func ValidateZone

func ValidateZone(zone string) error

ValidateZone rejects a zone name that is not a zone name.

It is interpolated into a URL inside a root shell script, so it is checked rather than trusted.

Types

type Action

type Action string

Action is what should happen to one record.

const (
	// Create is a name the zone does not have.
	Create Action = "create"
	// Update is a name whose address disagrees with the inventory.
	Update Action = "update"
	// Unchanged needs nothing.
	Unchanged Action = "unchanged"
	// Extra is a name in the zone that hlab does not know about. It is
	// reported and never removed.
	Extra Action = "extra"
)

type Change

type Change struct {
	Action  Action `json:"action" yaml:"action"`
	Name    string `json:"name" yaml:"name"`
	Address string `json:"address,omitempty" yaml:"address,omitempty"`
	// Was is the address the zone currently holds, when they disagree.
	Was string `json:"was,omitempty" yaml:"was,omitempty"`
}

Change is one difference between the inventory and the zone.

type Plan

type Plan struct {
	Zone         string        `json:"zone" yaml:"zone"`
	Changes      []Change      `json:"changes,omitempty" yaml:"changes,omitempty"`
	Reservations []Reservation `json:"reservations,omitempty" yaml:"reservations,omitempty"`
	Skipped      []string      `json:"skipped,omitempty" yaml:"skipped,omitempty"`
}

Plan is the whole difference.

func Diff

func Diff(zone string, want []Record, have map[string]string) Plan

Diff compares what the inventory wants with what the zone holds.

func (Plan) Actionable

func (p Plan) Actionable() bool

Actionable reports whether anything would change.

type Record

type Record struct {
	Name    string `json:"name" yaml:"name"`
	Address string `json:"address" yaml:"address"`
}

Record is one name the zone should hold.

func DesiredRecords

func DesiredRecords(hosts []inventory.Host, zone string) ([]Record, []string)

DesiredRecords derives the names a zone should hold from the inventory.

Only managed machines are included. An unmanaged record is something a scan saw once; publishing it as authoritative DNS would give a name to a machine nobody has verified, and hlab has no way to notice when it goes away.

type Reservation

type Reservation struct {
	Name    string `json:"name" yaml:"name"`
	MAC     string `json:"mac" yaml:"mac"`
	Address string `json:"address" yaml:"address"`
}

Reservation pins a machine's address in DHCP.

func DesiredReservations

func DesiredReservations(hosts []inventory.Host) []Reservation

DesiredReservations pins each machine's address to the interface that holds it, so DHCP cannot hand that address to something else.

The MAC is taken from the interface actually carrying the machine's address rather than the first one found: a machine with both wired and wireless interfaces would otherwise have its address reserved against the wrong one, which is worse than no reservation because it looks done.

func MissingReservations

func MissingReservations(want []Reservation, have map[string]string, start, end string) []Reservation

MissingReservations drops the ones the scope already holds correctly, and the ones it could never hold at all.

An address outside the scope's range is not reservable: the server will never offer it, so pinning it is noise. Statically configured machines are deliberately outside the pool, which is exactly what this excludes — and they never ask DHCP for an address anyway.

Jump to

Keyboard shortcuts

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