nameserver

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2015 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxDuration = time.Duration(math.MaxInt64)
	MailboxSize = 16
)
View Source
const (
	DefaultServerPort = 53                 // The default server port
	DefaultHTTPPort   = 6785               // The default http port
	DefaultCLICfgFile = "/etc/resolv.conf" // default "resolv.conf" file to try to load
	DefaultLocalTTL   = 30                 // default TTL for responses for local domain queries
	DefaultUDPBuflen  = 4096               // bigger than the default 512
	DefaultCacheLen   = 8192               // default cache capacity
	DefaultTimeout    = 5000               // default timeout for DNS resolutions (millisecs)
	DefaultMaxAnswers = 1                  // default number of answers provided to users
)
View Source
const (
	DefaultLocalDomain     = "weave.local."       // The default name used for the local domain
	DefaultRefreshInterval = int(DefaultLocalTTL) // Period for background updates with mDNS
	DefaultRelevantTime    = 60                   // When to forget info about remote info if nobody asks...

)
View Source
const (
	CacheNoLocalReplies uint8 = 1 << iota // not found in local network (stored in the cache so we skip another local lookup or some time)
)
View Source
const (
	RDNSDomain = "in-addr.arpa."
)

Variables

This section is empty.

Functions

func LinkLocalMulticastListener

func LinkLocalMulticastListener(ifi *net.Interface) (net.PacketConn, error)

func ServeHTTP added in v1.0.0

func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerCli *docker.Client)

Types

type Cache added in v0.10.0

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

Cache is a thread-safe fixed capacity LRU cache.

func NewCache added in v0.10.0

func NewCache(capacity int, clk clock.Clock) (*Cache, error)

NewCache creates a cache of the given capacity

func (*Cache) Capacity added in v0.10.0

func (c *Cache) Capacity() int

Return the max capacity

func (*Cache) Clear added in v0.10.0

func (c *Cache) Clear()

Clear removes all the entries in the cache

func (*Cache) Get added in v0.10.0

func (c *Cache) Get(request *dns.Msg, maxLen int) (reply *dns.Msg, err error)

Look up for a question's reply from the cache. If no reply is stored in the cache, it returns a `nil` reply and no error.

func (*Cache) Len added in v0.10.0

func (c *Cache) Len() int

Len returns the number of entries in the cache.

func (*Cache) Purge added in v0.10.0

func (c *Cache) Purge()

Purge removes the old elements in the cache

func (*Cache) Put added in v0.10.0

func (c *Cache) Put(request *dns.Msg, reply *dns.Msg, ttl int, flags uint8) int

Add adds a reply to the cache. When `ttl` is equal to `nullTTL`, the cache entry will be valid until the closest TTL in the `reply`

func (*Cache) Remove added in v0.10.0

func (c *Cache) Remove(question *dns.Question)

Remove removes the provided question from the cache.

func (*Cache) String added in v0.11.0

func (c *Cache) String() string

Return the max capacity

type DNSResponseBuilder added in v1.0.0

type DNSResponseBuilder func(r *dns.Msg, q *dns.Question, addrs []ZoneRecord, ttl int) *dns.Msg

type DNSServer added in v0.10.0

type DNSServer struct {
	Zone       Zone
	Upstream   *dns.ClientConfig
	Domain     string // the local domain
	ListenAddr string // the address the server is listening at
	// contains filtered or unexported fields
}

a DNS server

func NewDNSServer added in v0.10.0

func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error)

Creates a new DNS server

func (*DNSServer) ActivateAndServe added in v1.0.0

func (s *DNSServer) ActivateAndServe()

func (*DNSServer) GetPort added in v1.0.0

func (s *DNSServer) GetPort() (int, error)

Get the listen port

func (*DNSServer) Start added in v0.10.0

func (s *DNSServer) Start() error

Start the DNS server

func (*DNSServer) Status added in v0.10.0

func (s *DNSServer) Status() string

Return status string

func (*DNSServer) Stop added in v0.10.0

func (s *DNSServer) Stop() error

Perform a graceful shutdown

type DNSServerConfig added in v0.10.0

type DNSServerConfig struct {
	// The zone
	Zone Zone
	// (Optional) client config file for resolving upstream servers
	UpstreamCfgFile string
	// (Optional) DNS client config for the fallback server(s)
	UpstreamCfg *dns.ClientConfig
	// (Optional) port number (for TCP and UDP)
	Port int
	// (Optional) cache size
	CacheLen int
	// (Optional) disable the cache
	CacheDisabled bool
	// (Optional) timeout for DNS queries
	Timeout int
	// (Optional) UDP buffer length
	UDPBufLen int
	// (Optional) force a specific cache
	Cache ZoneCache
	// (Optional) TTL for local domain responses
	LocalTTL int
	// (Optional) TTL for negative results in the local domain (defaults to LocalTTL)
	CacheNegLocalTTL int
	// (Optional) for a specific clock provider
	Clock clock.Clock
	// (Optional) Listening socket read timeout (in milliseconds)
	ListenReadTimeout int
	// Maximum number of answers provided to users
	MaxAnswers int
}

type DuplicateError

type DuplicateError struct {
}

func (DuplicateError) Error

func (dup DuplicateError) Error() string

type IPv4 added in v0.11.0

type IPv4 [4]byte

simple IPv4 type that can be used as a key in a map (in contrast with net.IP), used for sets of IPs, etc...

func (IPv4) String added in v0.11.0

func (ip IPv4) String() string

type LookupError

type LookupError string

func (LookupError) Error

func (ops LookupError) Error() string

type LookupFunc added in v0.9.0

type LookupFunc func(ZoneLookup, *dns.Msg, *dns.Question) *dns.Msg

type MDNSAction added in v0.10.0

type MDNSAction func()

type MDNSClient

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

func NewMDNSClient

func NewMDNSClient() (*MDNSClient, error)

func (*MDNSClient) InsistentLookupInaddr added in v0.11.0

func (client *MDNSClient) InsistentLookupInaddr(inaddr string) ([]ZoneRecord, error)

Perform an insistent lookup for an IP address, returning either a list of names or an error Insistent queries will wait up to `mDNSTimeout` milliseconds for responses

func (*MDNSClient) InsistentLookupName added in v0.11.0

func (client *MDNSClient) InsistentLookupName(name string) ([]ZoneRecord, error)

Perform lookup for a name, returning either a list of IP addresses or an error Insistent queries will wait up to `mDNSTimeout` milliseconds for responses

func (*MDNSClient) LookupInaddr added in v0.9.0

func (client *MDNSClient) LookupInaddr(inaddr string) ([]ZoneRecord, error)

Perform a lookup for an IP address, returning either a name or an error

func (*MDNSClient) LookupName added in v0.9.0

func (client *MDNSClient) LookupName(name string) ([]ZoneRecord, error)

Perform a lookup for a name, returning either an IP address or an error

func (*MDNSClient) ResponseCallback

func (c *MDNSClient) ResponseCallback(r *dns.Msg)

Async - called from dns library multiplexer

func (*MDNSClient) SendQuery

func (c *MDNSClient) SendQuery(name string, querytype uint16, insistent bool, responseCh chan<- *Response)

Async

func (*MDNSClient) Start

func (c *MDNSClient) Start(ifi *net.Interface) (err error)

func (*MDNSClient) Stop added in v0.11.0

func (c *MDNSClient) Stop() error

type MDNSServer

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

func NewMDNSServer

func NewMDNSServer(zone Zone, local bool, ttl int) (*MDNSServer, error)

Create a new mDNS server Nothing will be done (including port bindings) until you `Start()` the server

func (*MDNSServer) Start

func (s *MDNSServer) Start(ifi *net.Interface) (err error)

Start the mDNS server

func (*MDNSServer) Stop added in v0.10.0

func (s *MDNSServer) Stop() error

Stop the mDNS server

func (*MDNSServer) Zone added in v0.11.0

func (s *MDNSServer) Zone() Zone

type Record

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

A basic record struct (satisfying the ZoneRecord interface)

func (Record) IP

func (r Record) IP() net.IP

func (Record) Name

func (r Record) Name() string

func (Record) Priority added in v0.11.0

func (r Record) Priority() int

func (Record) String added in v0.11.0

func (r Record) String() string

func (Record) TTL added in v0.11.0

func (r Record) TTL() int

func (Record) Weight added in v0.11.0

func (r Record) Weight() int

type Response added in v0.9.0

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

func (Response) Equal added in v0.11.0

func (r Response) Equal(r2 *Response) bool

func (Response) IP added in v0.11.0

func (r Response) IP() net.IP

func (Response) Name added in v0.9.0

func (r Response) Name() string

func (Response) Priority added in v0.11.0

func (r Response) Priority() int

func (Response) String added in v0.11.0

func (r Response) String() string

func (Response) TTL added in v0.11.0

func (r Response) TTL() int

func (Response) Weight added in v0.11.0

func (r Response) Weight() int

type Zone

type Zone interface {
	ZoneObservable
	ZoneLookup
	// The domain where we operate (eg, "weave.local.")
	Domain() string
	// Add a record in the local database
	AddRecord(ident string, name string, ip net.IP) error
	// Delete matching records (uninitialised values act as wildcards)
	DeleteRecords(ident string, name string, ip net.IP) (count int)
	// Lookup for a name in the whole domain
	DomainLookupName(name string) ([]ZoneRecord, error)
	// Lookup for an address in the whole domain
	DomainLookupInaddr(inaddr string) ([]ZoneRecord, error)
	// Return a status string
	Status() string
}

type ZoneCache added in v0.11.0

type ZoneCache interface {
	// Get from the cache
	Get(request *dns.Msg, maxLen int) (reply *dns.Msg, err error)
	// Put in the cache
	Put(request *dns.Msg, reply *dns.Msg, ttl int, flags uint8) int
	// Remove from the cache
	Remove(question *dns.Question)
	// Purge all expired entries from the cache
	Purge()
	// Remove all entries
	Clear()
	// Return the cache length
	Len() int
	// Return the max capacity
	Capacity() int
}

The cache interface

type ZoneConfig added in v1.0.0

type ZoneConfig struct {
	// The local domain
	Domain string
	// The interface where mDNS operates
	Iface *net.Interface
	// Refresh interval for local names in the zone database (disabled by default) (in seconds)
	RefreshInterval int
	// Forget about remote info if nobody asks for it in this time (in seconds)
	RelevantTime int
	// TTL returnined in local asnwers (with mDNS)
	LocalTTL int
	// Force a specific mDNS client
	MDNSClient ZoneMDNSClient
	// Force a specific mDNS server
	MDNSServer ZoneMDNSServer
	// For a specific clock provider
	Clock clock.Clock
}

type ZoneDb

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

Zone database The zone database contains the locally known information about the zone. The zone database uses some other mechanisms (eg, mDNS) for finding unknown information or for keeping current information up to date.

func NewZoneDb added in v0.11.0

func NewZoneDb(config ZoneConfig) (zone *ZoneDb, err error)

Create a new zone database

func (*ZoneDb) AddRecord

func (zone *ZoneDb) AddRecord(ident string, name string, ip net.IP) (err error)

Add a record with `name` pointing to `ip`

func (*ZoneDb) ContainerDied added in v0.10.0

func (zone *ZoneDb) ContainerDied(ident string) error

Notify that a container has died

func (*ZoneDb) DeleteRecords added in v1.0.0

func (zone *ZoneDb) DeleteRecords(ident string, name string, ip net.IP) int

Delete matching records (uninitialised values act as wildcards)

func (*ZoneDb) Domain added in v0.11.0

func (zone *ZoneDb) Domain() string

Obtain the domain where this database keeps information for

func (*ZoneDb) DomainLookupInaddr added in v1.0.0

func (zone *ZoneDb) DomainLookupInaddr(inaddr string) (res []ZoneRecord, err error)

Perform a lookup for a IP address in the zone The address can be resolved either with the local database or with some other resolution method (eg, a mDNS query)

func (*ZoneDb) DomainLookupName added in v1.0.0

func (zone *ZoneDb) DomainLookupName(name string) (res []ZoneRecord, err error)

Perform a lookup for a name in the zone The name can be resolved locally with the local database or with some other resolution method (eg, a mDNS query)

func (*ZoneDb) HasNameLocalInfo added in v1.0.0

func (zone *ZoneDb) HasNameLocalInfo(n string) bool

func (*ZoneDb) HasNameRemoteInfo added in v1.0.0

func (zone *ZoneDb) HasNameRemoteInfo(n string) bool

Return true if the we have obtained some information for a name from remote peers We can have both local (eg, introduced through the HTTP API) and remote (eg, mDNS) information for a name. This method only checks if there is remote information...

func (*ZoneDb) IsNameExpired added in v1.0.0

func (zone *ZoneDb) IsNameExpired(n string) bool

Returns true if the info we have for a remote name has expired. Local names are never expired Returns false if we do not have info for this name from remote peers.

func (*ZoneDb) IsNameRelevant added in v1.0.0

func (zone *ZoneDb) IsNameRelevant(n string) bool

Return true if a remote name is still relevant

func (*ZoneDb) LookupInaddr added in v0.9.0

func (zone *ZoneDb) LookupInaddr(inaddr string) (res []ZoneRecord, err error)

Perform a lookup for a IP address in the zone The address can be resolved locally with the local database

func (*ZoneDb) LookupName added in v0.9.0

func (zone *ZoneDb) LookupName(name string) (res []ZoneRecord, err error)

Perform a lookup for a name in the zone The name can be resolved locally with the local database

func (*ZoneDb) ObserveInaddr added in v1.0.0

func (zone *ZoneDb) ObserveInaddr(inaddr string, observer ZoneRecordObserver) (err error)

Observe a IP address. The IP address must be exit in the database. IP address observers are notified when - the IP is removed - the name is removed The observer will be invoked on any change/removal that affects this IP. Each observer will be invoked at least once (but possibly more). After that, they will be removed. The observer should not try to lock the ZoneDB (you will get a deadlock)

func (*ZoneDb) ObserveName added in v1.0.0

func (zone *ZoneDb) ObserveName(name string, observer ZoneRecordObserver) (err error)

Observe a name. The name must have at least one valid IP address. Name observers are notified when - an IP is added - an IP is removed - the name is removed The observer will be invoked on any change/removal that affects this name. Each observer will be invoked at least once (but possibly more). After that, they will be removed. The observer should not try to lock the ZoneDB (you will get a deadlock)

func (*ZoneDb) Start added in v1.0.0

func (zone *ZoneDb) Start() (err error)

Start the zone database

func (*ZoneDb) Status added in v1.0.0

func (zone *ZoneDb) Status() string

Return the status string

func (*ZoneDb) Stop added in v1.0.0

func (zone *ZoneDb) Stop() error

Perform a graceful shutdown of the zone database

func (*ZoneDb) String added in v0.10.0

func (zone *ZoneDb) String() string

Get the string representation of a zone

type ZoneLookup added in v0.11.0

type ZoneLookup interface {
	// Lookup for a name
	LookupName(name string) ([]ZoneRecord, error)
	// Lookup for an address
	LookupInaddr(inaddr string) ([]ZoneRecord, error)
}

type ZoneLookupFunc added in v1.0.0

type ZoneLookupFunc func(target string) ([]ZoneRecord, error)

type ZoneMDNS added in v1.0.0

type ZoneMDNS interface {
	// Start the service
	Start(*net.Interface) error
	// Stop the service
	Stop() error
}

A basic mDNS service

type ZoneMDNSClient added in v1.0.0

type ZoneMDNSClient interface {
	ZoneMDNS
	ZoneLookup
	// Perform an insistent lookup for a name
	InsistentLookupName(name string) ([]ZoneRecord, error)
	// Perform an insistent lookup for a reverse address
	InsistentLookupInaddr(inaddr string) ([]ZoneRecord, error)
}

A mDNS client interface

type ZoneMDNSServer added in v1.0.0

type ZoneMDNSServer interface {
	ZoneMDNS
	// Return the Zone database used by the server
	Zone() Zone
}

A mDNS server

type ZoneObservable added in v1.0.0

type ZoneObservable interface {
	// Observe anything that affects a particular name in the zone
	ObserveName(name string, observer ZoneRecordObserver) error
	// Observe anything that affects a particular IP in the zone
	ObserveInaddr(inaddr string, observer ZoneRecordObserver) error
}

type ZoneObserverFunc added in v1.0.0

type ZoneObserverFunc func(string, ZoneRecordObserver) error

type ZoneRecord added in v0.11.0

type ZoneRecord interface {
	Name() string  // The name for this IP
	IP() net.IP    // The IP (v4) address
	Priority() int // The priority
	Weight() int   // The weight
	TTL() int      // TTL
}

A zone record Note: we will try to keep all the zone records information is concentrated here. Maybe not all queries will

use things like priorities or weights, but we do not want to create a hierarchy for dealing with all
possible queries...

type ZoneRecordObserver added in v0.11.0

type ZoneRecordObserver func()

Jump to

Keyboard shortcuts

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