Documentation
¶
Overview ¶
Package backend defines the contract between the dnsconfig.Manager worker and the per-OS backends it drives.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConflict reports that another identity already publishes a requested // domain or catch-all, or records the requested Windows adapter. A // *ConflictError matches it through errors.Is. ErrConflict = errors.New("domain held by another identity") // ErrGroupPolicyContainerEmpty reports a Group Policy NRPT container with // no rules or values, which makes Windows ignore the local NRPT table. // Set returns it once the local copies are in place, whether or not that // attempt wrote them. ErrGroupPolicyContainerEmpty = errors.New("empty Group Policy NRPT container suppresses local NRPT rules") )
The dnsconfig package re-exports these sentinels and ConflictError, so a backend's error satisfies errors.Is and errors.As for the public names without translation. Text that reaches callers inside the Manager's *Error carries no package prefix, since *Error supplies one.
Functions ¶
func ValidateIdentity ¶
ValidateIdentity reports whether s is an acceptable identity. Each backend checks it again at construction because it interpolates the identity unescaped into scutil scripts, file names, and registry paths.
Types ¶
type Attempt ¶
type Attempt struct {
// NewGoal marks the first attempt after the goal changed, for
// diagnostics. Repeating the current goal, whether by retry, change
// signal, or periodic check, leaves it false.
NewGoal bool
// Converged reports that an earlier attempt at the current goal
// succeeded, so artifacts missing now were removed by something else
// rather than never installed.
Converged bool
// Final marks the cleanup attempt Close makes. It has no retry, so a
// backend requests owed side effects even after a failed phase while
// the cleanup context is still live. Windows requests an owed policy
// notification even after cancellation if its recovery records may be gone.
// macOS removes the resolver files it attributed even when the State-key
// list fails, since those files outlive the keys.
Final bool
}
Attempt describes why the worker is calling Set or Clear, so a backend can tell repair from a first install and the final cleanup from an attempt that will be retried.
type Backend ¶
type Backend interface {
// Set converges the host toward cfg. It reads
// live state, writes only artifacts that differ from cfg, removes
// obsolete owned artifacts, and verifies installation even when nothing
// was written. A converge that finds everything in place writes nothing
// and, with no owed side effect, requests none, except the Windows
// first-attempt adapter reload described in doc.go. A failed attempt does not roll back; one
// that wrote nothing returns Result.Changed false, which lets a change
// signal end the Manager's backoff.
// Side effects still owed are reported in Result.Pending on every
// attempt, failed or not.
Set(ctx context.Context, cfg Config, attempt Attempt) (Result, error)
// ValidateConfig reports whether cfg exceeds a limit of this backend's
// OS mechanism, judged from cfg alone. It reads nothing, so the Manager
// can refuse such a goal synchronously instead of retrying an attempt
// that may never succeed. It may refuse a cfg that fits only because of
// current host state, but a cfg it accepts fits on every host. Set and
// Clear rely on the caller for validated input: the Manager passes Set
// only a Config that passed Config.Validate and ValidateConfig, and calls
// neither after Close.
ValidateConfig(cfg Config) error
// Clear converges the host toward no configuration owned by this
// identity, including a crashed predecessor's artifacts, and completes
// pending side effects. Result.Pending reports unfinished side effects
// even when the attempt fails or every artifact is already gone. An
// inspection failure before the first write returns an error and changes
// nothing.
Clear(ctx context.Context, attempt Attempt) (Result, error)
// Changes returns a channel that receives a value whenever the host may
// have changed in a way that can affect owned artifacts. Sends are
// coalesced and never block; the channel carries no payload because the
// worker re-reads every owned artifact. Close closes the channel; the
// Manager stops reading Changes before it calls Close. A backend with no
// notification source returns nil.
Changes() <-chan struct{}
// Close releases resources and stops signal sources without changing
// system DNS configuration. The public Manager owns close-time cleanup
// by running Clear first with the caller's shutdown cancellation deadline.
// Close must be idempotent.
Close() error
}
Backend is the one-shot toolbox the public Manager's worker drives. It runs no background loops: Set and Clear each make one attempt to converge the host toward a goal and return, and Changes supplies a signal that the host may have drifted. The worker is the only caller of Set and Clear and the only place that retries. The Manager serializes Set, Clear, and Close, so those need not be safe for concurrent use with each other. ValidateConfig and Changes may be called at any time.
type Config ¶
Config mirrors dnsconfig.Config without importing the public package. The Manager passes only validated domains, lowercase and without a trailing dot, the form scutil, resolver files, and NRPT use, so backends compare them without folding case.
type ConflictError ¶
type ConflictError struct {
// Domain is the conflicting domain in canonical form, lowercase with a
// trailing dot, or the root "." for a catch-all.
Domain string
// Holder is the identity that publishes Domain.
Holder string
}
ConflictError reports that another identity already publishes Domain. Backends return it before the first write.
func NewConflictError ¶
func NewConflictError(domain, holder string) *ConflictError
NewConflictError returns a ConflictError for a domain in backend form, converting it to the canonical form callers see. A domain that already carries its trailing dot is accepted as is.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
Error identifies the conflicting domain and its holder.
func (*ConflictError) Is ¶
func (e *ConflictError) Is(target error) bool
Is reports whether target is ErrConflict, so every error carrying a ConflictError matches ErrConflict without a separate wrap.
type FS ¶
type FS interface {
// Open opens a stream so the backend can bound resolver-file reads.
Open(path string) (io.ReadCloser, error)
// WriteFile writes data to path with the given mode, creating or
// truncating the file as needed. perm is honored only on creation; an
// existing file's mode is left unchanged, mirroring os.WriteFile.
//
// The process umask masks perm on creation. Use Chmod afterward when
// resolver files must remain world-readable under a restrictive umask.
WriteFile(path string, data []byte, perm os.FileMode) error
// Chmod sets the mode bits of the file at path, mirroring os.Chmod. A
// missing path returns an error satisfying errors.Is(err, os.ErrNotExist).
Chmod(path string, mode os.FileMode) error
// Sync flushes the file at path, data and metadata, to stable storage.
// It does not follow a link at path. The macOS backend syncs a staged
// resolver file before renaming it into place.
Sync(path string) error
// Remove removes the file at path. Missing files produce an error that
// satisfies errors.Is(err, os.ErrNotExist).
Remove(path string) error
// SyncDir flushes the directory at path to stable storage, making
// earlier removals and renames in it durable. The macOS backend syncs
// /etc/resolver after removing resolver files.
SyncDir(path string) error
// IsRegularFile reports whether path itself is a regular file, without
// following a final link, so a link reports false. A missing path
// returns an error satisfying errors.Is(err, os.ErrNotExist).
IsRegularFile(path string) (bool, error)
// MkdirAll creates path and any missing parents, mirroring os.MkdirAll.
// It returns nil if path already exists as a directory. perm is honored
// only on creation. The macOS backend uses this to create
// /etc/resolver on demand.
MkdirAll(path string, perm os.FileMode) error
// ReadDir returns the directory entries of path, mirroring os.ReadDir.
// A missing path returns an error satisfying errors.Is(err,
// os.ErrNotExist). The macOS backend uses this to sweep stale
// /etc/resolver files.
ReadDir(path string) ([]os.DirEntry, error)
// Rename moves oldpath to newpath, mirroring rename(2): it replaces
// newpath atomically and replaces a link there rather than writing
// through it, so a reader sees either the old file or the complete new
// one. The macOS backend stages resolver files and renames them into
// place.
Rename(oldpath, newpath string) error
}
FS is the filesystem seam used by the macOS backend. The backend serializes access to its resolver files.
type Result ¶
type Result struct {
// Changed reports that this attempt wrote or may have written an artifact;
// a failed write can have partially succeeded.
Changed bool
// Pending reports side effects still owed after this attempt, such as a
// cache flush, Windows adapter reload, or policy notification that
// failed. A nil error means Pending is false: an attempt that cannot
// complete an owed side effect fails. An error does not by itself mean a
// side effect is owed. The Manager logs it with the failure and retries
// the attempt.
Pending bool
}
Result reports what one converge attempt did.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package backendtest checks the shared converge contract of backend.Backend implementations using backend-specific fakes.
|
Package backendtest checks the shared converge contract of backend.Backend implementations using backend-specific fakes. |
|
Package darwin implements the dnsconfig backend for macOS.
|
Package darwin implements the dnsconfig backend for macOS. |
|
Package noop is the fallback backend used on unsupported platforms or when explicitly requested by a caller.
|
Package noop is the fallback backend used on unsupported platforms or when explicitly requested by a caller. |
|
Package windows implements the dnsconfig backend for Windows.
|
Package windows implements the dnsconfig backend for Windows. |