server

package
v0.0.0-...-89729b7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConfig

func CheckConfig(config *Config) error

func CreateListenAddress

func CreateListenAddress(listen string) (string, error)

func CreateNameservers

func CreateNameservers(servers []string) ([]string, error)

func CreateSearchDomains

func CreateSearchDomains(domains []string) ([]string, error)

func CreateStubMap

func CreateStubMap(stubzones []string) (map[string][]string, error)

func Fit

func Fit(m *dns.Msg, size int, tcp bool) (*dns.Msg, bool)

Fit will make m fit the size. If a message is larger than size then entire additional section is dropped. If it is still to large and the transport is udp we return a truncated message. If the transport is tcp we are going to drop RR from the answer section until it fits. When this is case the returned bool is true.

func ResolvConf

func ResolvConf(config *Config, forceNdots bool) error

Types

type Config

type Config struct {
	// The ip:port go-dnsmasq should be listening on for incoming DNS requests.
	DnsAddr string `json:"dns_addr,omitempty"`
	// bind to port(s) activated by systemd. If set to true, this overrides DnsAddr.
	Systemd bool `json:"systemd,omitempty"`
	// Rewrite host's network config making go-dnsmasq the default resolver
	DefaultResolver bool `json:"default_resolver,omitempty"`
	// Search domains used to qualify queries
	SearchDomains []string `json:"search_domains,omitempty"`
	// Replicates GNU libc's use of /etc/resolv.conf search domains
	EnableSearch bool `json:"append_domain,omitempty"`
	// Path to the hostfile
	Hostsfile string `json:"hostfile,omitempty"`
	// Path to the directory of hostfiles
	DirectoryHostsfiles string `json:"directory_hostsfiles,omitempty"`
	// Hostfile Polling
	PollInterval time.Duration `json:"poll_interval,omitempty"`
	// Round robin A/AAAA replies. Default is true.
	RoundRobin bool `json:"round_robin,omitempty"`
	// List of ip:port, seperated by commas of recursive nameservers to forward queries to.
	Nameservers []string `json:"nameservers,omitempty"`
	// Never provide a recursive service.
	NoRec       bool          `json:"no_rec,omitempty"`
	ReadTimeout time.Duration `json:"read_timeout,omitempty"`
	// Default TTL, in seconds. Defaults to 360.
	Ttl uint32 `json:"ttl,omitempty"`
	// Default TTL for Hostfile records, in seconds. Defaults to 30.
	HostsTtl uint32 `json:"hostfile_ttl,omitempty"`
	// RCache, capacity of response cache in resource records stored.
	RCache int `json:"rcache,omitempty"`
	// RCacheTtl, how long to cache in seconds.
	RCacheTtl time.Duration `json:"rcache_ttl,omitempty"`
	// How many dots a name must have before we allow to forward the query as-is. Defaults to 1.
	FwdNdots int `json:"fwd_ndots,omitempty"`
	// How many dots a name must have before we do an initial absolute query. Defaults to 1.
	Ndots int `json:"ndots,omitempty"`

	Verbose bool `json:"-"`

	// Stub zones support. Map contains domainname -> nameserver:port
	Stub map[string][]string
}

Config provides options to the go-dnsmasq resolver

type Counter

type Counter interface {
	Inc(i int64)
}

Counter is the metric interface used by this package

var (
	StatsForwardCount     Counter = nopCounter{}
	StatsStubForwardCount Counter = nopCounter{}
	StatsLookupCount      Counter = nopCounter{}
	StatsRequestCount     Counter = nopCounter{}
	StatsDnssecOkCount    Counter = nopCounter{}
	StatsNameErrorCount   Counter = nopCounter{}
	StatsNoDataCount      Counter = nopCounter{}

	StatsDnssecCacheMiss Counter = nopCounter{}

	StatsCacheMiss Counter = nopCounter{}
	StatsCacheHit  Counter = nopCounter{}
)

type Hostfile

type Hostfile interface {
	FindHosts(name string) ([]net.IP, error)
	FindReverse(name string) (string, error)
}

type PluggableFunc

type PluggableFunc func(m *dns.Msg, q dns.Question, targetName string, isTCP bool) (*dns.Msg, error)

type Server

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

func New

func New(hostfile Hostfile, config *Config, v string, f *PluggableFunc) *Server

New returns a new Server.

func (*Server) AddressRecords

func (s *Server) AddressRecords(q dns.Question, name string) (records []dns.RR, err error)

func (*Server) PTRRecords

func (s *Server) PTRRecords(q dns.Question) (records []dns.RR, err error)

func (*Server) RoundRobin

func (s *Server) RoundRobin(rrs []dns.RR)

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run is a blocking operation that starts the Server listening on the DNS ports.

func (*Server) ServeDNS

func (s *Server) ServeDNS(w dns.ResponseWriter, req *dns.Msg)

func (*Server) ServeDNSForward

func (s *Server) ServeDNSForward(w dns.ResponseWriter, req *dns.Msg) *dns.Msg

ServeDNSForward resolves a query by forwarding to a recursive nameserver

func (*Server) ServeDNSReverse

func (s *Server) ServeDNSReverse(w dns.ResponseWriter, req *dns.Msg) *dns.Msg

ServeDNSReverse is the handler for DNS requests for the reverse zone. If nothing is found locally the request is forwarded to the forwarder for resolution.

func (*Server) ServerFailure

func (s *Server) ServerFailure(m, req *dns.Msg)

type Writer

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

Writer type

func NewWriter

func NewWriter(proto, addr string) *Writer

NewWriter return writer

func (*Writer) Close

func (w *Writer) Close() error

Close func

func (*Writer) Hijack

func (w *Writer) Hijack()

Hijack func

func (*Writer) Internal

func (w *Writer) Internal() bool

Internal func

func (*Writer) LocalAddr

func (w *Writer) LocalAddr() net.Addr

LocalAddr func

func (*Writer) Msg

func (w *Writer) Msg() *dns.Msg

Msg return current dns message

func (*Writer) Proto

func (w *Writer) Proto() string

Proto func

func (*Writer) Rcode

func (w *Writer) Rcode() int

Rcode return message response code

func (*Writer) RemoteAddr

func (w *Writer) RemoteAddr() net.Addr

RemoteAddr func

func (*Writer) RemoteIP

func (w *Writer) RemoteIP() net.IP

RemoteIP func

func (*Writer) Reset

func (w *Writer) Reset(rw dns.ResponseWriter)

Reset func

func (*Writer) TsigStatus

func (w *Writer) TsigStatus() error

TsigStatus func

func (*Writer) TsigTimersOnly

func (w *Writer) TsigTimersOnly(ok bool)

TsigTimersOnly func

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Write func

func (*Writer) WriteMsg

func (w *Writer) WriteMsg(msg *dns.Msg) error

WriteMsg func

func (*Writer) Written

func (w *Writer) Written() bool

Written func

Jump to

Keyboard shortcuts

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