dns

package
v0.0.0-...-851e5e8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dns is responsible for configuring dns on various Linux distros.

Index

Constants

View Source
const (
	HostsFilePath = "/etc/hosts"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultSetter

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

DefaultSetter handleds DNS in this order:

1. If systemd-resolve command is available and systemd-resolved.service is running, systemd-resolve DBUS API is used.

2. In case of systemd-resolve is not accessible, resolvectl (which is part of systemd-resolve package) command line utility is used.

3. In absence of systemd-resolve, resolvconf command line utility is used, which modifies /etc/resolv.conf by adding or removing lines.

4. In case the resolvconf command line utility fails, /etc/resolv.conf is backed up and modified directly by NordVPN.

func NewSetter

func NewSetter(publisher events.Publisher[string]) *DefaultSetter

func (*DefaultSetter) Set

func (d *DefaultSetter) Set(iface string, nameservers []string) error

Set DNS for a given iface if the system supports per interface DNS settings. Also, backup current DNS settings (only in case of direct resolv.conf edit). Backup is not overridden, so its safe to call this function multiple times in a row.

func (*DefaultSetter) Unset

func (d *DefaultSetter) Unset(iface string) error

Unset DNS for network interface, restore DNS from a backup, if backup is available, and remove the backup on success.

type Getter

type Getter interface {
	Get(isThreatProtectionLite bool, isIPv6 bool) []string
	LookupIP(host string) ([]net.IP, error)
}

type Host

type Host struct {
	IP          netip.Addr
	FQDN        string
	DomainNames []string
}

func (Host) String

func (h Host) String() string

type HostnameSetter

type HostnameSetter interface {
	SetHosts(Hosts) error
	UnsetHosts() error
}

Add hostname interface

type Hosts

type Hosts []Host

type HostsFileSetter

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

HostsFileSetter modifies the hosts file in order to add custom DNS

func NewHostsFileSetter

func NewHostsFileSetter(filePath string) *HostsFileSetter

func (*HostsFileSetter) SetHosts

func (s *HostsFileSetter) SetHosts(hosts Hosts) error

func (*HostsFileSetter) UnsetHosts

func (s *HostsFileSetter) UnsetHosts() error

type Method

type Method interface {
	Set(iface string, nameservers []string) error
	Unset(iface string) error
	IsAvailable() bool
	Name() string
}

Method is abstraction of DNS handling method

type NameServers

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

func NewNameServers

func NewNameServers(servers []string) *NameServers

func (*NameServers) Get

func (n *NameServers) Get(isThreatProtectionLite bool, ipv6 bool) []string

Get nameservers selected by the given criteria.

func (*NameServers) LookupIP

func (n *NameServers) LookupIP(host string) ([]net.IP, error)

type ResolvConfFile

type ResolvConfFile struct{}

Direct file resolv.conf editing based DNS handling method. This is last fallback method if others are not available

func (*ResolvConfFile) IsAvailable

func (m *ResolvConfFile) IsAvailable() bool

func (*ResolvConfFile) Name

func (m *ResolvConfFile) Name() string

func (*ResolvConfFile) Set

func (m *ResolvConfFile) Set(iface string, nameservers []string) error

func (*ResolvConfFile) Unset

func (m *ResolvConfFile) Unset(iface string) error

type Resolvconf

type Resolvconf struct{}

Resolvconf based DNS handling method

func (*Resolvconf) IsAvailable

func (m *Resolvconf) IsAvailable() bool

func (*Resolvconf) Name

func (m *Resolvconf) Name() string

func (*Resolvconf) Set

func (m *Resolvconf) Set(iface string, nameservers []string) error

func (*Resolvconf) Unset

func (m *Resolvconf) Unset(iface string) error

type Resolvectl

type Resolvectl struct{}

Systemd-resolved and resolvectl based DNS handling method

func (*Resolvectl) IsAvailable

func (m *Resolvectl) IsAvailable() bool

func (*Resolvectl) Name

func (m *Resolvectl) Name() string

func (*Resolvectl) Set

func (m *Resolvectl) Set(iface string, nameservers []string) error

func (*Resolvectl) Unset

func (m *Resolvectl) Unset(iface string) error

type Resolved

type Resolved struct{}

Systemd-resolved DBUS API based DNS handling method

func (*Resolved) IsAvailable

func (m *Resolved) IsAvailable() bool

func (*Resolved) Name

func (m *Resolved) Name() string

func (*Resolved) Set

func (m *Resolved) Set(iface string, nameservers []string) error

func (*Resolved) Unset

func (m *Resolved) Unset(iface string) error

type Setter

type Setter interface {
	Set(iface string, nameservers []string) error
	Unset(iface string) error
}

Setter is responsible for configuring DNS.

Jump to

Keyboard shortcuts

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