dnsserver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dnsserver implements a DNS server, that uses the given resolvers to handle requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCachingResolver

func NewCachingResolver(back Resolver) *cachingResolver

NewCachingResolver returns a new resolver which implements a cache on top of the given one.

Types

type DomainMap

type DomainMap map[string]string

DomainMap maps a DNS name to an arbitrary string.

func DomainMapFromString

func DomainMapFromString(s string) (DomainMap, error)

DomainMapFromString takes a string in the form of "domain1:addr1,domain2:addr2,..." and returns a dnsserver.DomainMap like {"domain1": "addr1", "domain2": "addr2", ...}.

func (DomainMap) GetExact

func (m DomainMap) GetExact(domain string) (string, bool)

GetExact value for the given domain, using an exact lookup (the domain must match exactly what was set).

func (DomainMap) GetMostSpecific

func (m DomainMap) GetMostSpecific(domain string) (string, bool)

GetMostSpecific value for the given domain, using a most-specific lookup (we pick the map entry that is closest to the domain).

func (DomainMap) Set

func (m DomainMap) Set(domain, value string)

Set the value for the given domain.

type Resolver

type Resolver interface {
	// Initialize the resolver.
	Init() error

	// Maintain performs resolver maintenance. It's expected to run
	// indefinitely, but may return early if appropriate.
	Maintain()

	// Query responds to a DNS query.
	Query(r *dns.Msg, tr *trace.Trace) (*dns.Msg, error)
}

Resolver is the interface for DNS resolvers that can answer queries.

type Server

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

Server implements a DNS proxy, which will (mostly) use the given resolver to resolve queries.

func New

func New(addr string, resolver Resolver, unqUpstream string, serverOverrides DomainMap) *Server

New *Server, which will listen on addr, use resolver as the backend resolver, and use unqUpstream to resolve unqualified queries.

func (*Server) Handler

func (s *Server) Handler(w dns.ResponseWriter, r *dns.Msg)

Handler for the incoming DNS queries.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe()

ListenAndServe launches the DNS proxy.

Jump to

Keyboard shortcuts

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