knot

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package knot implements a client for the Knot DNS server's control protocol.

Index

Constants

View Source
const (
	IdxCmd     = 0
	IdxFlags   = 1
	IdxError   = 2
	IdxSection = 3
	IdxItem    = 4
	IdxID      = 5
	IdxZone    = 6
	IdxOwner   = 7
	IdxTTL     = 8
	IdxType    = 9
	IdxData    = 10
	IdxFilters = 11
)

Field index constants for Data, matching knot_ctl_idx_t.

View Source
const DataLen = 12

DataLen is the number of indexed fields in a control data unit. It matches KNOT_CTL_IDX__COUNT from libknot.

Variables

View Source
var ErrAlloc = errors.New("knot: failed to allocate control context")

ErrAlloc is returned when libknot fails to allocate a control context.

Functions

This section is empty.

Types

type Conn

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

Conn is a client connection to the knot control socket.

func NewConn

func NewConn() (*Conn, error)

NewConn allocates a new Conn. Always call Close when done.

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection and frees the underlying C context. After Close, the Conn must not be used.

func (*Conn) Command

func (c *Conn) Command(data Data) ([]Data, error)

Command sends a command and reads the full server response in one call. It is equivalent to calling SendCommand followed by ReadResponse.

func (*Conn) ConfAbort

func (c *Conn) ConfAbort() ([]Data, error)

ConfAbort rolls back the current configuration transaction.

func (*Conn) ConfBegin

func (c *Conn) ConfBegin() ([]Data, error)

ConfBegin starts a configuration write transaction.

func (*Conn) ConfCheck

func (c *Conn) ConfCheck() ([]Data, error)

ConfCheck checks the server configuration for errors.

func (*Conn) ConfCommit

func (c *Conn) ConfCommit() ([]Data, error)

ConfCommit commits the current configuration transaction.

func (*Conn) ConfDiff

func (c *Conn) ConfDiff(section, id, item string) ([]Data, error)

ConfDiff returns configuration differences within the current transaction. All parameters are optional.

func (*Conn) ConfExport

func (c *Conn) ConfExport(filename string, schema bool) ([]Data, error)

ConfExport exports the confdb. filename is optional (empty means stdout). Set schema to true to export the JSON schema instead of the configuration.

func (*Conn) ConfGet

func (c *Conn) ConfGet(section, id, item string) ([]Data, error)

ConfGet reads configuration data within the current transaction. All parameters are optional.

func (*Conn) ConfImport

func (c *Conn) ConfImport(filename string, nopurge bool) ([]Data, error)

ConfImport imports a configuration file into the confdb. Set nopurge to true to preserve existing confdb contents.

func (*Conn) ConfInit

func (c *Conn) ConfInit() ([]Data, error)

ConfInit initialises the configuration database.

func (*Conn) ConfList

func (c *Conn) ConfList(section, id, item string) ([]Data, error)

ConfList lists confdb sections or items. All parameters are optional; pass empty strings to list all top-level sections.

func (*Conn) ConfRead

func (c *Conn) ConfRead(section, id, item string) ([]Data, error)

ConfRead reads the active configuration. All parameters are optional.

func (*Conn) ConfSet

func (c *Conn) ConfSet(section, id, item string, data ...string) ([]Data, error)

ConfSet sets configuration item data within the current transaction. Additional values beyond the first are transmitted as TypeExtra units.

func (*Conn) ConfUnset

func (c *Conn) ConfUnset(section, id, item string, data ...string) ([]Data, error)

ConfUnset removes configuration item data within the current transaction. Additional values beyond the first are transmitted as TypeExtra units.

func (*Conn) Connect

func (c *Conn) Connect(path string) error

Connect connects to the knot control UNIX socket at path.

func (*Conn) ReadResponse

func (c *Conn) ReadResponse() ([]Data, error)

ReadResponse reads response units until the server sends a block or end marker. Each DATA and EXTRA unit is collected into the returned slice. If the server includes an error message in any unit, a *ResponseError is returned alongside whatever rows were collected before it.

func (*Conn) Receive

func (c *Conn) Receive() (Type, Data, error)

Receive waits for and returns the next control unit from the server.

func (*Conn) Reload

func (c *Conn) Reload() ([]Data, error)

Reload reloads the server configuration and any modified zones.

func (*Conn) Send

func (c *Conn) Send(t Type, data *Data) error

Send transmits a control unit of the given type. data is required for TypeData and TypeExtra; pass nil for TypeEnd and TypeBlock.

func (*Conn) SendCommand

func (c *Conn) SendCommand(data Data) error

SendCommand sends a single data unit followed by a block marker, signalling to the server that the full request has been delivered.

func (*Conn) SetTimeout

func (c *Conn) SetTimeout(ms int)

SetTimeout sets the socket operation timeout in milliseconds. Pass 0 for no timeout.

func (*Conn) Stats

func (c *Conn) Stats(module, counter string) ([]Data, error)

Stats returns global statistics. module and counter are both optional; pass empty strings to retrieve all counters across all modules.

func (*Conn) Status

func (c *Conn) Status(detail string) ([]Data, error)

Status checks whether the server is running. detail is optional.

func (*Conn) Stop

func (c *Conn) Stop() ([]Data, error)

Stop stops the server.

func (*Conn) ZoneAbort

func (c *Conn) ZoneAbort(zones ...string) ([]Data, error)

ZoneAbort aborts the current zone transaction. Pass no zones for all.

func (*Conn) ZoneBackup

func (c *Conn) ZoneBackup(backupDir, filters string, zones ...string) ([]Data, error)

ZoneBackup backs up zone data and metadata. backupDir is the +backupdir path (required). filters is optional. Pass no zones for all.

func (*Conn) ZoneBegin

func (c *Conn) ZoneBegin(benevolent bool, zones ...string) ([]Data, error)

ZoneBegin begins a zone transaction. Set benevolent to true to tolerate a pre-existing transaction from another client. Pass no zones to begin a transaction for all zones.

func (*Conn) ZoneCheck

func (c *Conn) ZoneCheck(zones ...string) ([]Data, error)

ZoneCheck checks whether the given zones can be loaded. Pass no zones to check all configured zones.

func (*Conn) ZoneCommit

func (c *Conn) ZoneCommit(zones ...string) ([]Data, error)

ZoneCommit commits the current zone transaction. Pass no zones for all.

func (*Conn) ZoneDiff

func (c *Conn) ZoneDiff(zone string) ([]Data, error)

ZoneDiff returns zone changes within the current transaction.

func (*Conn) ZoneFlush

func (c *Conn) ZoneFlush(filters string, zones ...string) ([]Data, error)

ZoneFlush flushes zone journals into zone files. filters is optional. Pass no zones for all.

func (*Conn) ZoneFreeze

func (c *Conn) ZoneFreeze(zones ...string) ([]Data, error)

ZoneFreeze temporarily postpones automatic zone-changing events. Pass no zones for all.

func (*Conn) ZoneGet

func (c *Conn) ZoneGet(zone, owner, rrType string) ([]Data, error)

ZoneGet returns zone records within the current transaction. owner and rrType are optional filters.

func (*Conn) ZoneKSKSubmitted

func (c *Conn) ZoneKSKSubmitted(zones ...string) ([]Data, error)

ZoneKSKSubmitted confirms that the parent DS record is present after KSK submission. Pass no zones for all.

func (*Conn) ZoneKeyRollover

func (c *Conn) ZoneKeyRollover(zone string, keyType KeyType) ([]Data, error)

ZoneKeyRollover triggers an immediate key rollover for the given zone. keyType must be KeyTypeKSK or KeyTypeZSK.

func (*Conn) ZoneKeysLoad

func (c *Conn) ZoneKeysLoad(zones ...string) ([]Data, error)

ZoneKeysLoad reloads keys from the KASP database and re-signs the zone. Pass no zones for all.

func (*Conn) ZoneNotify

func (c *Conn) ZoneNotify(zones ...string) ([]Data, error)

ZoneNotify sends a NOTIFY to all configured remotes. Pass no zones for all.

func (*Conn) ZonePurge

func (c *Conn) ZonePurge(filters string, zones ...string) ([]Data, error)

ZonePurge purges zone data, zone file, journal, timers, and KASP data. filters is optional. Pass no zones for all.

func (*Conn) ZoneRead

func (c *Conn) ZoneRead(zone, owner, rrType string) ([]Data, error)

ZoneRead returns the zone records currently being served. owner and rrType are optional filters; pass empty strings to return all records.

func (*Conn) ZoneRefresh

func (c *Conn) ZoneRefresh(zones ...string) ([]Data, error)

ZoneRefresh forces a slave zone refresh. Pass no zones for all.

func (*Conn) ZoneReload

func (c *Conn) ZoneReload(zones ...string) ([]Data, error)

ZoneReload reloads zones from disk. Pass no zones to reload all.

func (*Conn) ZoneRestore

func (c *Conn) ZoneRestore(backupDir, filters string, zones ...string) ([]Data, error)

ZoneRestore restores zone data and metadata. backupDir is the +backupdir path (required). filters is optional. Pass no zones for all.

func (*Conn) ZoneRetransfer

func (c *Conn) ZoneRetransfer(zones ...string) ([]Data, error)

ZoneRetransfer forces a slave zone retransfer without a serial check. Pass no zones for all.

func (*Conn) ZoneSerialSet

func (c *Conn) ZoneSerialSet(zone, serial string) ([]Data, error)

ZoneSerialSet gets or sets the SOA serial for a zone. Pass an empty string to retrieve the current serial, a plain number to set it, or "+N" to increment by N.

func (*Conn) ZoneSet

func (c *Conn) ZoneSet(zone, owner, ttl, rrType, rdata string) ([]Data, error)

ZoneSet adds or replaces a zone record within the current transaction. ttl is optional; pass an empty string to use the zone default.

func (*Conn) ZoneSign

func (c *Conn) ZoneSign(zones ...string) ([]Data, error)

ZoneSign re-signs automatically signed zones. Pass no zones for all.

func (*Conn) ZoneStats

func (c *Conn) ZoneStats(zone, module, counter string) ([]Data, error)

ZoneStats returns statistics for a zone. module and counter are optional.

func (*Conn) ZoneStatus

func (c *Conn) ZoneStatus(filters string, zones ...string) ([]Data, error)

ZoneStatus returns the status of zones. filters is an optional space-separated list of +filter names (e.g. "+role +serial"). Pass no zones to query all configured zones.

func (*Conn) ZoneThaw

func (c *Conn) ZoneThaw(zones ...string) ([]Data, error)

ZoneThaw dismisses a zone freeze. Pass no zones for all.

func (*Conn) ZoneUnset

func (c *Conn) ZoneUnset(zone, owner, rrType, rdata string) ([]Data, error)

ZoneUnset removes records from a zone within the current transaction. rrType and rdata narrow the match; pass empty strings to remove more broadly.

func (*Conn) ZoneValidate

func (c *Conn) ZoneValidate(zones ...string) ([]Data, error)

ZoneValidate triggers DNSSEC validation. Pass no zones for all.

func (*Conn) ZoneXFRFreeze

func (c *Conn) ZoneXFRFreeze(zones ...string) ([]Data, error)

ZoneXFRFreeze temporarily disables outgoing AXFR/IXFR. Pass no zones for all.

func (*Conn) ZoneXFRThaw

func (c *Conn) ZoneXFRThaw(zones ...string) ([]Data, error)

ZoneXFRThaw re-enables outgoing AXFR/IXFR. Pass no zones for all.

type Data

type Data [DataLen]string

Data holds the string fields of a knot control data unit. Index each field using the Idx* constants.

type KeyType

type KeyType string

KeyType is the DNSSEC key type for ZoneKeyRollover.

const (
	KeyTypeKSK KeyType = "ksk"
	KeyTypeZSK KeyType = "zsk"
)

type KnotError

type KnotError struct {
	Code int
}

KnotError represents a libknot error code returned by the C library.

func (*KnotError) Error

func (e *KnotError) Error() string

type ResponseError

type ResponseError struct {
	Message string
}

ResponseError is a server-side error reported inside a knot response unit.

func (*ResponseError) Error

func (e *ResponseError) Error() string

type Type

type Type int

Type is the type of a knot control unit.

const (
	TypeEnd   Type = Type(C.KNOT_CTL_TYPE_END)
	TypeData  Type = Type(C.KNOT_CTL_TYPE_DATA)
	TypeExtra Type = Type(C.KNOT_CTL_TYPE_EXTRA)
	TypeBlock Type = Type(C.KNOT_CTL_TYPE_BLOCK)
)

Control unit type constants, matching knot_ctl_type_t.

Jump to

Keyboard shortcuts

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