dns

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package dns provides DNS configuration management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Darwin

type Darwin struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Darwin implements the DNS interface for Darwin (macOS).

func NewDarwinProvider

func NewDarwinProvider(
	logger *slog.Logger,
	em exec.Manager,
) *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) DeleteNetplanConfig

func (d *Darwin) DeleteNetplanConfig(
	_ string,
) (bool, error)

DeleteNetplanConfig returns ErrUnsupported on Darwin.

func (*Darwin) GetResolvConfByInterface

func (d *Darwin) GetResolvConfByInterface(
	interfaceName string,
) (*GetResult, error)

GetResolvConfByInterface retrieves the DNS configuration for a specific network interface using the `scutil --dns` command on macOS.

It parses resolver blocks from scutil output, matching by interface name via the `if_index` field. If no resolver matches the requested interface, it returns an error.

Example scutil --dns output:

resolver #1
  search domain[0] : example.com
  nameserver[0] : 192.168.1.1
  nameserver[1] : 8.8.8.8
  if_index : 6 (en0)

func (*Darwin) UpdateResolvConfByInterface

func (d *Darwin) UpdateResolvConfByInterface(
	_ []string,
	_ []string,
	_ string,
	_ bool,
) (*UpdateResult, error)

UpdateResolvConfByInterface returns ErrUnsupported on Darwin. Darwin is a development platform only; mutations are not supported.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the DNS interface for Debian.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	stateKV jetstream.KeyValue,
	em exec.Manager,
	hostname string,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) DeleteNetplanConfig

func (u *Debian) DeleteNetplanConfig(
	_ string,
) (bool, error)

DeleteNetplanConfig removes the managed DNS Netplan config file.

func (*Debian) GetResolvConfByInterface

func (u *Debian) GetResolvConfByInterface(
	interfaceName string,
) (*GetResult, error)

GetResolvConfByInterface retrieves the DNS configuration for a specific network interface using the `resolvectl` command. It returns a Config struct containing the DNS servers and search domains for the interface, and an error if something goes wrong.

Cross-platform considerations:

  • This function is designed specifically for Linux systems that utilize `systemd-resolved` for managing DNS configurations.
  • It relies on the `resolvectl` command, which is available on systems with `systemd` version 237 or later. On non-systemd systems or older versions of Linux, this functionality may not be available.

Notes about the implementation:

  • This function queries DNS information dynamically using `resolvectl`, which supports per-interface configurations and reflects the live state of DNS settings managed by `systemd-resolved`.
  • If no search domains are configured for the interface, the function defaults to returning `["."]` to indicate the root domain.

Requirements:

  • The `resolvectl` command must be installed and available in the system path.
  • The caller must have sufficient privileges to query network settings for the specified interface.

See `systemd-resolved.service(8)` manual page for further information.

func (*Debian) UpdateResolvConfByInterface

func (u *Debian) UpdateResolvConfByInterface(
	servers []string,
	searchDomains []string,
	interfaceName string,
	overrideDHCP bool,
) (*UpdateResult, error)

UpdateResolvConfByInterface updates the DNS configuration for a specific network interface by generating a Netplan drop-in file and applying it. The function preserves existing settings for values that are not specified and delegates idempotency to the Netplan state tracker.

The read path still uses resolvectl to query current DNS state. The write path generates a Netplan YAML file under /etc/netplan/osapi-dns.yaml and applies it via `netplan generate` + `netplan apply`.

type DebianDocker

type DebianDocker struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

DebianDocker implements the DNS Provider interface for Debian-family systems running inside Docker containers. It reads DNS configuration from /etc/resolv.conf directly (no systemd-resolved). Updates are not supported because container DNS is managed by the runtime.

func NewDebianDockerProvider

func NewDebianDockerProvider(
	logger *slog.Logger,
	fs avfs.VFS,
) *DebianDocker

NewDebianDockerProvider factory to create a new DebianDocker instance.

func (*DebianDocker) DeleteNetplanConfig

func (d *DebianDocker) DeleteNetplanConfig(
	_ string,
) (bool, error)

DeleteNetplanConfig returns ErrUnsupported in containers.

func (*DebianDocker) GetResolvConfByInterface

func (d *DebianDocker) GetResolvConfByInterface(
	_ string,
) (*GetResult, error)

GetResolvConfByInterface reads DNS configuration from /etc/resolv.conf. The interfaceName parameter is accepted but ignored — containers have a single global DNS configuration managed by the container runtime.

func (*DebianDocker) UpdateResolvConfByInterface

func (d *DebianDocker) UpdateResolvConfByInterface(
	_ []string,
	_ []string,
	_ string,
	_ bool,
) (*UpdateResult, error)

UpdateResolvConfByInterface returns ErrUnsupported for container environments. DNS configuration in containers is managed by the container runtime (Docker, Kubernetes), not the agent.

type GetResult

type GetResult struct {
	// List of DNS server IP addresses (IPv4 or IPv6)
	DNSServers []string
	// List of search domains for DNS resolution
	SearchDomains []string
	// Changed indicates whether system state was modified.
	Changed bool `json:"changed"`
}

GetResult represents the DNS configuration with servers and search domains.

type Linux

type Linux struct {
	provider.FactsAware
}

Linux implements the DNS interface for Linux.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) DeleteNetplanConfig

func (l *Linux) DeleteNetplanConfig(
	_ string,
) (bool, error)

DeleteNetplanConfig returns ErrUnsupported on generic Linux.

func (*Linux) GetResolvConfByInterface

func (l *Linux) GetResolvConfByInterface(
	_ string,
) (*GetResult, error)

GetResolvConfByInterface retrieves the DNS configuration for a specific network interface using the `resolvectl` command. It returns a Config struct containing the DNS servers and search domains for the interface, and an error if something goes wrong.

func (*Linux) UpdateResolvConfByInterface

func (l *Linux) UpdateResolvConfByInterface(
	_ []string,
	_ []string,
	_ string,
	_ bool,
) (*UpdateResult, error)

UpdateResolvConfByInterface updates the DNS configuration for a specific network interface using the `resolvectl` command. It applies new DNS servers and search domains if provided, while preserving existing settings for values that are not specified. The function returns an error if the operation fails.

type Provider

type Provider interface {
	// GetResolvConfByInterface retrieves the DNS configuration.
	GetResolvConfByInterface(
		interfaceName string,
	) (*GetResult, error)
	// UpdateResolvConfByInterface updates the DNS configuration.
	// Returns an UpdateResult indicating whether the configuration was changed.
	// When overrideDHCP is true, DHCP-provided DNS servers are disabled so
	// only the configured servers are used.
	UpdateResolvConfByInterface(
		servers []string,
		searchDomains []string,
		interfaceName string,
		overrideDHCP bool,
	) (*UpdateResult, error)
	// DeleteNetplanConfig removes the managed DNS Netplan config file.
	DeleteNetplanConfig(
		interfaceName string,
	) (bool, error)
}

Provider implements the methods to interact with various DNS components.

type UpdateResult

type UpdateResult struct {
	// Changed indicates whether the DNS configuration was actually modified.
	Changed bool `json:"changed"`
}

UpdateResult represents the outcome of a DNS update operation.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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