resolvconf

package
v0.0.0-...-4b51ba2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package resolvconf provides a parser for resolv.conf files.

Inspired from nerdctl's resolvconf and tailscale's resolvconffile.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPath is the default path to the resolv.conf that contains information to resolve DNS.
	DefaultPath = "/etc/resolv.conf"
	// SystemdPath is systemd's default path to the resolv.conf that contains information to resolve DNS.
	// This path is used when we detect systemd's systemd-resolved ip address of 127.0.0.53 in /etc/resolv.conf
	SystemdPath = "/run/systemd/resolve/resolv.conf"
)
View Source
var DefaultNameservers = []string{
	"8.8.8.8",
	"8.8.4.4",
	"2001:4860:4860::8888",
	"2001:4860:4860::8844",
}

Note: the default IPv4 & IPv6 resolvers are set to Google's Public DNS This follows Docker's and nerdctl's default behavior.

These are only used if the host's resolv.conf is not available or the name server is localhost.

Functions

func WriteResolvConf

func WriteResolvConf(outputDir string, conf *Config) (string, error)

WriteResolvConf writes the Config to a file in outputDir and returns the path to the file. The intent is that this is written to a containerd snapshot directory to be mounted into a container.

Types

type Config

type Config struct {
	Nameservers   []netip.Addr
	SearchDomains []string
	Options       []string
}

Config is a parsed resolv.conf file.

func DefaultResolvConf

func DefaultResolvConf() *Config

DefaultResolvConf returns a default resolv.conf using `DefaultNameservers`.

func FromHost

func FromHost() (*Config, error)

FromHost parses and returns the host's resolv.conf. If it detects systemd's systemd-resolved ip address it will use systemd's resolv.conf instead.

Additionally, it filters out any loopback addresses as it is assumed that this Config will be used in a container and containers may not be able to use loopback addresses.

func Parse

func Parse(r io.Reader) (*Config, error)

Parse parses a resolv.conf file from r.

func ParseFile

func ParseFile(name string) (*Config, error)

ParseFile parses the named resolv.conf file.

func (*Config) FilterLoopback

func (rc *Config) FilterLoopback()

FilterLoopback filters out any loopback addresses because it is assumed that this Config will be used in a container and containers may not be able to use loopback addresses.

func (*Config) Write

func (rc *Config) Write(w io.Writer) error

Write writes the Config to w.

Jump to

Keyboard shortcuts

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