dns

package
v0.0.0-...-bd9c4bf Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// List of DNS server IP addresses (IPv4 or IPv6)
	DNSServers []string
	// List of search domains for DNS resolution
	SearchDomains []string
}

Config represents the DNS configuration with servers and search domains.

type Linux

type Linux struct{}

Linux implements the DNS interface for Linux.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) GetResolvConfByInterface

func (l *Linux) GetResolvConfByInterface(
	_ string,
) (*Config, 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) SetResolvConfByInterface

func (l *Linux) SetResolvConfByInterface(
	_ []string,
	_ []string,
	_ string,
) error

SetResolvConfByInterface 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 {
	// GetResolvConf retrieves the DNS configuration.
	GetResolvConfByInterface(
		_ string,
	) (*Config, error)
	// SetResolvConfByInterface sets the DNS configuration.
	SetResolvConfByInterface(
		_ []string,
		_ []string,
		_ string,
	) error
}

Provider implements the methods to interact with various DNS components.

type Ubuntu

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

Ubuntu implements the DNS interface for Ubuntu.

func NewUbuntuProvider

func NewUbuntuProvider(
	logger *slog.Logger,
	em exec.Manager,
) *Ubuntu

NewUbuntuProvider factory to create a new Ubuntu instance.

func (*Ubuntu) GetResolvConfByInterface

func (u *Ubuntu) GetResolvConfByInterface(
	interfaceName string,
) (*Config, 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 (*Ubuntu) SetResolvConfByInterface

func (u *Ubuntu) SetResolvConfByInterface(
	servers []string,
	searchDomains []string,
	interfaceName string,
) error

SetResolvConfByInterface 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.

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.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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