dns

package
v1.5.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultIP        = "127.0.0.1"
	DefaultPort      = 53
	DefaultTTL       = 600 * time.Second
	DefaultCacheSize = 1024
	DefaultTimeout   = 4 * time.Second
)

Variables

This section is empty.

Functions

func BindToDevice

func BindToDevice(fd int, device string) error

BindToDevice binds the socket associated with fd to device.

Types

type Cache

type Cache struct {
	CacheOptions

	// Protects following map
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache stores dns.Msgs and their expiration time

func NewCache

func NewCache(options CacheOptions) *Cache

NewCache returns a new cache

func (*Cache) Add

func (c *Cache) Add(msg *mdns.Msg)

Add adds dns.Msg to the cache

func (*Cache) Capacity

func (c *Cache) Capacity() int

Capacity returns the capacity of the cache

func (*Cache) Count

func (c *Cache) Count() int

Count returns the element count of the cache

func (*Cache) Get

func (c *Cache) Get(msg *mdns.Msg) *mdns.Msg

Get returns the dns.Msg from the cache

func (*Cache) Hits

func (c *Cache) Hits() uint64

Hits returns the number of cache hits

func (*Cache) Misses

func (c *Cache) Misses() uint64

Misses returns the number of cache misses

func (*Cache) Remove

func (c *Cache) Remove(msg *mdns.Msg)

Remove removes the dns.Msg from the cache

func (*Cache) Reset

func (c *Cache) Reset()

Reset resets the cache

type CacheOptions

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

CacheOptions represents the cache options

type Item

type Item struct {
	Expiration time.Time
	Msg        *mdns.Msg
}

Item represents an item in the cache

type Server

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

Server represents udp/tcp server and clients

func NewServer

func NewServer(options ServerOptions) *Server

NewServer returns a new Server

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the ip:port of the server

func (*Server) HandleForwarding

func (s *Server) HandleForwarding(w mdns.ResponseWriter, r *mdns.Msg) (bool, error)

HandleForwarding forwards a request to the nameservers and returns the response

func (*Server) HandleVIC

func (s *Server) HandleVIC(w mdns.ResponseWriter, r *mdns.Msg) (bool, error)

HandleVIC returns a response to a container name/id request

func (*Server) SeenBefore

func (s *Server) SeenBefore(w mdns.ResponseWriter, r *mdns.Msg) (bool, error)

SeenBefore returns the cached response

func (*Server) ServeDNS

func (s *Server) ServeDNS(w mdns.ResponseWriter, r *mdns.Msg)

ServeDNS implements the handler interface

func (*Server) Start

func (s *Server) Start()

Start starts the DNS server

func (*Server) Stop

func (s *Server) Stop()

Stop stops the DNS server gracefully

func (*Server) Wait

func (s *Server) Wait()

Wait block until wg returns

type ServerOptions

type ServerOptions struct {
	IP        string
	Port      int
	Interface string

	Nameservers flagMultipleVar

	Timeout time.Duration

	TTL       time.Duration
	CacheSize int

	Debug bool
}

ServerOptions represents the server options

type SetOfDomains

type SetOfDomains map[string]bool

SetOfDomains is a type for storing string-type domain names as an unsorted set

var f SetOfDomains
f = make(map[string]bool)

Store in the set

f["foo.com"] = true

then to check to see if something is in the 'set':

if f["foo.com"] {

func ReverseLookup

func ReverseLookup(ipAddr string) (domains SetOfDomains)

ReverseLookup returns a set of FQDNs for ipAddr from nameservers in /etc/resolv.conf /etc/hosts and /etc/nsswitch.conf are ignored by this function

Jump to

Keyboard shortcuts

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