landns

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package landns is the core implementation of the Landns.

Please see also package github.com/macrat/client/go-client if you want make client of the Landns.

Index

Examples

Constants

View Source
const (
	// DefaultTTL is the default TTL in the configuration file.
	DefaultTTL uint32 = 3600
)

Variables

View Source
var (
	ErrMultiLineDynamicRecord     = Error{Type: TypeArgumentError, Message: "DynamicRecord can't have multi line"}
	ErrInvalidDynamicRecordFormat = Error{Type: TypeArgumentError, Message: "DynamicRecord invalid format"}
	ErrNoSuchRecord               = Error{Type: TypeArgumentError, Message: "no such record"}
)

Functions

func QtypeToString

func QtypeToString(qtype uint16) string

QtypeToString is helper for dns type number to human readable string like "A" or "TXT".

Types

type AddressRecord

type AddressRecord struct {
	Name    Domain
	TTL     uint32
	Address net.IP
}

AddressRecord is the Record of A or AAAA.

func (AddressRecord) GetName

func (r AddressRecord) GetName() Domain

GetName is getter to name of record.

func (AddressRecord) GetQtype

func (r AddressRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (AddressRecord) GetTTL

func (r AddressRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (AddressRecord) IsV4

func (r AddressRecord) IsV4() bool

IsV4 is checker for guess that which of IPv4 (A record) or IPv6 (AAAA record).

func (AddressRecord) String

func (r AddressRecord) String() string

String is make record string.

func (AddressRecord) ToRR

func (r AddressRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (AddressRecord) Validate

func (r AddressRecord) Validate() error

Validate is validator of record.

func (AddressRecord) WithoutTTL

func (r AddressRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type AlternateResolver

type AlternateResolver []Resolver

AlternateResolver is list of Resolver.

AlternateResolver will response only first respond unlike ResolverSet.

func (AlternateResolver) Close

func (ar AlternateResolver) Close() error

Close is close all upstream resolvers.

func (AlternateResolver) RecursionAvailable

func (ar AlternateResolver) RecursionAvailable() bool

RecursionAvailable is returns `true` if upstream resolvers at least one returns `true`.

func (AlternateResolver) Resolve

func (ar AlternateResolver) Resolve(resp ResponseWriter, req Request) error

Resolve is resolver using first respond upstream resolvers.

func (AlternateResolver) String

func (ar AlternateResolver) String() string

String is returns simple human readable string.

type CnameRecord

type CnameRecord struct {
	Name   Domain
	TTL    uint32
	Target Domain
}

CnameRecord is the Record of CNAME.

func (CnameRecord) GetName

func (r CnameRecord) GetName() Domain

GetName is getter to name of record.

func (CnameRecord) GetQtype

func (r CnameRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (CnameRecord) GetTTL

func (r CnameRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (CnameRecord) String

func (r CnameRecord) String() string

String is make record string.

func (CnameRecord) ToRR

func (r CnameRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (CnameRecord) Validate

func (r CnameRecord) Validate() error

Validate is validator of record.

func (CnameRecord) WithoutTTL

func (r CnameRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type Domain

type Domain string

Domain is the type for domain.

Example
a := landns.Domain("example.com")
b := a.Normalized()
fmt.Println(string(a), "->", string(b))

c := landns.Domain("")
d := c.Normalized()
fmt.Println(string(c), "->", string(d))
Output:

example.com -> example.com.
 -> .

func (Domain) MarshalText

func (d Domain) MarshalText() ([]byte, error)

MarshalText is make bytes text.

func (Domain) Normalized

func (d Domain) Normalized() Domain

Normalized is normalizer for make FQDN.

func (Domain) String

func (d Domain) String() string

String is converter to Domain to string.

String will convert to FQDN.

func (Domain) ToPath

func (d Domain) ToPath() string

ToPath is make reversed path string like /com/example.

func (*Domain) UnmarshalText

func (d *Domain) UnmarshalText(text []byte) error

UnmarshalText is parse text from bytes.

func (Domain) Validate

func (d Domain) Validate() error

Validate is validator to domain.

type DynamicAPI

type DynamicAPI struct {
	Resolver DynamicResolver
}

DynamicAPI is API request handler.

func (DynamicAPI) DeleteRecordByID

func (d DynamicAPI) DeleteRecordByID(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) DeleteRecords

func (d DynamicAPI) DeleteRecords(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) GetAllRecords

func (d DynamicAPI) GetAllRecords(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) GetRecordByID

func (d DynamicAPI) GetRecordByID(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) GetRecordsByGlob

func (d DynamicAPI) GetRecordsByGlob(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) GetRecordsBySuffix

func (d DynamicAPI) GetRecordsBySuffix(path, req, remote string) (string, *HTTPError)

func (DynamicAPI) Handler

func (d DynamicAPI) Handler() http.Handler

func (DynamicAPI) PostRecords

func (d DynamicAPI) PostRecords(path, req, remote string) (string, *HTTPError)

type DynamicRecord

type DynamicRecord struct {
	Record   Record
	ID       *int
	Volatile bool
	Disabled bool
}

DynamicRecord is the record information for DynamicResolver.

Example
record, _ := landns.NewDynamicRecord("example.com. 600 IN A 127.0.0.1")
fmt.Println("name:", record.Record.GetName(), "disabled:", record.Disabled)

record, _ = landns.NewDynamicRecord(";test.service 300 IN TXT \"hello world\"")
fmt.Println("name:", record.Record.GetName(), "disabled:", record.Disabled)
Output:

name: example.com. disabled: false
name: test.service. disabled: true

func NewDynamicRecord

func NewDynamicRecord(record string) (DynamicRecord, error)

NewDynamicRecord will parse record text and make new DynamicRecord.

func (DynamicRecord) MarshalText

func (r DynamicRecord) MarshalText() ([]byte, error)

MarshalText is marshal DynamicRecord to text.

func (DynamicRecord) String

func (r DynamicRecord) String() string

String is get printable string.

Example
record, _ := landns.NewDynamicRecord("example.com. 600 IN A 127.0.0.1")

fmt.Println(record)

record.Disabled = true
fmt.Println(record)

id := 10
record.ID = &id
fmt.Println(record)
Output:

example.com. 600 IN A 127.0.0.1
;example.com. 600 IN A 127.0.0.1
;example.com. 600 IN A 127.0.0.1 ; ID:10

func (*DynamicRecord) UnmarshalText

func (r *DynamicRecord) UnmarshalText(text []byte) error

UnmarshalText is unmarshal DynamicRecord from text.

func (DynamicRecord) VolatileRecord

func (r DynamicRecord) VolatileRecord() (VolatileRecord, error)

VolatileRecord is make VolatileRecord from DynamicRecord.

type DynamicRecordSet

type DynamicRecordSet []DynamicRecord

DynamicRecordSet is list of DynamicRecord

Example
records, _ := landns.NewDynamicRecordSet(`
	a.example.com. 100 IN A 127.0.0.1
	b.example.com. 200 IN A 127.0.1.2
`)

for _, r := range records {
	fmt.Println(r.Record.GetName())
	fmt.Println(r)
}
Output:

a.example.com.
a.example.com. 100 IN A 127.0.0.1
b.example.com.
b.example.com. 200 IN A 127.0.1.2

func NewDynamicRecordSet

func NewDynamicRecordSet(records string) (DynamicRecordSet, error)

NewDynamicRecordSet will parse record text and make new DynamicRecordSet.

func (DynamicRecordSet) MarshalText

func (rs DynamicRecordSet) MarshalText() ([]byte, error)

func (DynamicRecordSet) String

func (rs DynamicRecordSet) String() string

func (*DynamicRecordSet) UnmarshalText

func (rs *DynamicRecordSet) UnmarshalText(text []byte) error

type DynamicResolver

type DynamicResolver interface {
	Resolver

	SetRecords(DynamicRecordSet) error
	Records() (DynamicRecordSet, error)
	SearchRecords(Domain) (DynamicRecordSet, error)
	GlobRecords(string) (DynamicRecordSet, error)
	GetRecord(int) (DynamicRecordSet, error)
	RemoveRecord(int) error
}

type Error

type Error struct {
	Type     ErrorType
	Original error
	Message  string
}

Error is error type of Landns.

func (Error) Error

func (e Error) Error() string

Error is converter to human readable string.

func (Error) String

func (e Error) String() string

String is getter to human readable string.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap is getter of original error.

type ErrorSet

type ErrorSet []error

ErrorSet is list of errors.

func (ErrorSet) Error

func (e ErrorSet) Error() string

Error is getter for description string.

type ErrorType

type ErrorType uint8

ErrorType is type of Error.

const (
	// TypeInternalError is a error for Landns internal error.
	TypeInternalError ErrorType = iota + 1

	// TypeExternalError is a error for the error caused from external libraries.
	TypeExternalError

	// TypeArgumentError is a error for invalid argument error.
	TypeArgumentError

	// TypeExpirationError is error for record has expired.
	TypeExpirationError
)

func (ErrorType) String

func (t ErrorType) String() string

String is converter to human readable string.

type EtcdResolver

type EtcdResolver struct {
	Timeout time.Duration
	Prefix  string
	// contains filtered or unexported fields
}

EtcdResolver is one implements of DynamicResolver using etcd.

func NewEtcdResolver

func NewEtcdResolver(endpoints []string, prefix string, timeout time.Duration, metrics *Metrics) (*EtcdResolver, error)

NewEtcdResolver is constructor of EtcdResolver.

func (*EtcdResolver) Close

func (er *EtcdResolver) Close() error

Close is disconnector from etcd server.

func (*EtcdResolver) GetRecord

func (er *EtcdResolver) GetRecord(id int) (DynamicRecordSet, error)

GetRecord is get record by id.

func (*EtcdResolver) GlobRecords

func (er *EtcdResolver) GlobRecords(glob string) (DynamicRecordSet, error)

GlobRecords is search records by glob string.

func (*EtcdResolver) Records

func (er *EtcdResolver) Records() (DynamicRecordSet, error)

Records is DynamicRecord getter.

func (*EtcdResolver) RecursionAvailable

func (er *EtcdResolver) RecursionAvailable() bool

RecursionAvailable is always returns `false`.

func (*EtcdResolver) RemoveRecord

func (er *EtcdResolver) RemoveRecord(id int) error

RemoveRecord is remove record by id.

func (*EtcdResolver) Resolve

func (er *EtcdResolver) Resolve(w ResponseWriter, r Request) error

Resolve is resolver using etcd.

func (*EtcdResolver) SearchRecords

func (er *EtcdResolver) SearchRecords(d Domain) (DynamicRecordSet, error)

SearchRecords is search records by domain prefix.

func (*EtcdResolver) SetRecords

func (er *EtcdResolver) SetRecords(rs DynamicRecordSet) error

SetRecords is DynamicRecord setter.

func (*EtcdResolver) String

func (er *EtcdResolver) String() string

String is description string getter.

type ForwardResolver

type ForwardResolver struct {
	Upstreams []*net.UDPAddr
	Metrics   *Metrics
	// contains filtered or unexported fields
}

ForwardResolver is recursion resolver.

func NewForwardResolver

func NewForwardResolver(upstreams []*net.UDPAddr, timeout time.Duration, metrics *Metrics) ForwardResolver

NewForwardResolver is make new ForwardResolver.

func (ForwardResolver) Close

func (fr ForwardResolver) Close() error

Close is closer to ForwardResolver.

func (ForwardResolver) RecursionAvailable

func (fr ForwardResolver) RecursionAvailable() bool

RecursionAvailable is always returns true.

func (ForwardResolver) Resolve

func (fr ForwardResolver) Resolve(w ResponseWriter, r Request) error

Resolve is resolver using upstream DNS servers.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
}

HTTPError is error message of HTTP method.

func (HTTPError) Error

func (e HTTPError) Error() string

Error is make string for response to client.

func (HTTPError) ServeHTTP

func (e HTTPError) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is behave as http.Handler.

type Handler

type Handler struct {
	Resolver           Resolver
	Metrics            *Metrics
	RecursionAvailable bool
}

Handler is the implements of dns.Handler of package github.com/miekg/dns.

func NewHandler

func NewHandler(resolver Resolver, metrics *Metrics) Handler

NewHandler is constructor of Handler.

func (Handler) ServeDNS

func (h Handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

ServeDNS is the method for resolve record.

type LocalCache

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

LocalCache is in-memory cache manager for Resolver.

func NewLocalCache

func NewLocalCache(upstream Resolver, metrics *Metrics) *LocalCache

NewLocalCache is constructor of LocalCache.

LocalCache will start background goroutine. So you have to ensure to call LocalCache.Close.

func (*LocalCache) Close

func (lc *LocalCache) Close() error

Close is closer to LocalCache.

func (*LocalCache) RecursionAvailable

func (lc *LocalCache) RecursionAvailable() bool

RecursionAvailable is returns same as upstream.

func (*LocalCache) Resolve

func (lc *LocalCache) Resolve(w ResponseWriter, r Request) error

Resolve is resolver using cache or the upstream resolver.

func (*LocalCache) String

func (lc *LocalCache) String() string

String is getter to description string.

type MessageBuilder

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

MessageBuilder is one implements of ResponseWriter for make dns.Msg of package github.com/miekg/dns.

func NewMessageBuilder

func NewMessageBuilder(request *dns.Msg, recursionAvailable bool) *MessageBuilder

func (*MessageBuilder) Add

func (mb *MessageBuilder) Add(r Record) error

func (*MessageBuilder) Build

func (mb *MessageBuilder) Build() *dns.Msg

Build is builder of dns.Msg.

func (*MessageBuilder) IsAuthoritative

func (mb *MessageBuilder) IsAuthoritative() bool

func (*MessageBuilder) SetNoAuthoritative

func (mb *MessageBuilder) SetNoAuthoritative()

type Metrics

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

Metrics is the metrics collector for the Prometheus.

func NewMetrics

func NewMetrics(namespace string) *Metrics

NewMetrics is constructor for Metrics.

func (*Metrics) CacheHit

func (m *Metrics) CacheHit(req Request)

CacheHit is collector of cache hit rate.

func (*Metrics) CacheMiss

func (m *Metrics) CacheMiss(req Request)

CacheMiss is collector of cache hit rate.

func (*Metrics) Collect

func (m *Metrics) Collect(ch chan<- prometheus.Metric)

Collect is collect metrics to the Prometheus.

func (*Metrics) Describe

func (m *Metrics) Describe(ch chan<- *prometheus.Desc)

Describe is register descriptions to the Prometheus.

func (*Metrics) Error

func (m *Metrics) Error(req Request, err error)

Error is collector of error.

func (*Metrics) HTTPHandler

func (m *Metrics) HTTPHandler() (http.Handler, error)

HTTPHandler is make http.Handler.

func (*Metrics) Start

func (m *Metrics) Start(request *dns.Msg) func(*dns.Msg)

Start is starter timer for collect resolve duration.

func (*Metrics) UpstreamTime

func (m *Metrics) UpstreamTime(duration time.Duration)

UpstreamTime is collector of recursion resolve.

type MxRecord

type MxRecord struct {
	Name       Domain
	TTL        uint32
	Preference uint16
	Target     Domain
}

MxRecord is the Record of CNAME.

func (MxRecord) GetName

func (r MxRecord) GetName() Domain

GetName is getter to name of record.

func (MxRecord) GetQtype

func (r MxRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (MxRecord) GetTTL

func (r MxRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (MxRecord) String

func (r MxRecord) String() string

String is make record string.

func (MxRecord) ToRR

func (r MxRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (MxRecord) Validate

func (r MxRecord) Validate() error

Validate is validator of record.

func (MxRecord) WithoutTTL

func (r MxRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type NsRecord

type NsRecord struct {
	Name   Domain
	Target Domain
}

NsRecord is the Record of NS.

func (NsRecord) GetName

func (r NsRecord) GetName() Domain

GetName is getter to name of record.

func (NsRecord) GetQtype

func (r NsRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (NsRecord) GetTTL

func (r NsRecord) GetTTL() uint32

GetTTL is always returns 0 because NS record has no TTL.

func (NsRecord) String

func (r NsRecord) String() string

Strings is make record string.

func (NsRecord) ToRR

func (r NsRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (NsRecord) Validate

func (r NsRecord) Validate() error

Validate is validator of record.

func (NsRecord) WithoutTTL

func (r NsRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type Proto

type Proto string

Proto is type of protocol ("tcp" or "udp").

func (Proto) MarshalText

func (p Proto) MarshalText() ([]byte, error)

MarshalText is make bytes text.

func (Proto) Normalized

func (p Proto) Normalized() Proto

Normalized is normalizer for Proto.

func (Proto) String

func (p Proto) String() string

String is getter to string.

String will returns "tcp" if proto is empty string.

func (*Proto) UnmarshalText

func (p *Proto) UnmarshalText(text []byte) error

UnmarshalText is parse text to Proto.

func (Proto) Validate

func (p Proto) Validate() error

Validate is validator of Proto.

Returns error if value is not "tcp", "udp", or empty string.

type PtrRecord

type PtrRecord struct {
	Name   Domain
	TTL    uint32
	Domain Domain
}

PtrRecord is the Record of PTR.

func (PtrRecord) GetName

func (r PtrRecord) GetName() Domain

GetName is getter to name of record.

func (PtrRecord) GetQtype

func (r PtrRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (PtrRecord) GetTTL

func (r PtrRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (PtrRecord) String

func (r PtrRecord) String() string

String is make record string.

func (PtrRecord) ToRR

func (r PtrRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (PtrRecord) Validate

func (r PtrRecord) Validate() error

Validate is validator of record.

func (PtrRecord) WithoutTTL

func (r PtrRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type Record

type Record interface {
	fmt.Stringer

	GetQtype() uint16      // Get query type like dns.TypeA of package github.com/miekg/dns.
	GetName() Domain       // Get domain name of the Record.
	GetTTL() uint32        // Get TTL for the Record.
	ToRR() (dns.RR, error) // Get response record for dns.Msg of package github.com/miekg/dns.
	Validate() error       // Validation Record and returns error if invalid.
	WithoutTTL() string    // Get record string that replaced TTL number with "0".
}

Record is the record entry of DNS.

func NewRecord

func NewRecord(str string) (Record, error)

NewRecord is make new Record from query string.

Example
record, _ := landns.NewRecord("example.com. 600 IN A 127.0.0.1")

fmt.Println(record.GetName())
fmt.Println(record.GetTTL())
fmt.Println(record.String())
Output:

example.com.
600
example.com. 600 IN A 127.0.0.1

func NewRecordFromRR

func NewRecordFromRR(rr dns.RR) (Record, error)

NewRecordFromRR is make new Record from dns.RR of package github.com/miekg/dns.

Example
rr, _ := dns.NewRR("example.com. 600 IN A 127.0.0.1")
record, _ := landns.NewRecordFromRR(rr)

fmt.Println(record.GetName())
fmt.Println(record.GetTTL())
fmt.Println(record.String())
Output:

example.com.
600
example.com. 600 IN A 127.0.0.1

func NewRecordWithExpire

func NewRecordWithExpire(str string, expire time.Time) (Record, error)

NewRecordWithExpire is make new Record from query string with expire time.

Example
record, _ := landns.NewRecordWithExpire("example.com. 600 IN A 127.0.0.1", time.Now().Add(10*time.Second))

fmt.Println(record.GetName())
fmt.Println(record.GetTTL())
fmt.Println(record.String())
Output:

example.com.
10
example.com. 10 IN A 127.0.0.1

func NewRecordWithTTL

func NewRecordWithTTL(str string, ttl uint32) (Record, error)

NewRecordWithTTL is make new Record with TTL.

type RedisCache

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

RedisCache is redis cache manager for Resolver.

func NewRedisCache

func NewRedisCache(addr net.Addr, database int, password string, upstream Resolver, metrics *Metrics) (RedisCache, error)

NewRedisCache is constructor of RedisCache.

RedisCache will make connection to the Redis server. So you have to ensure to call RedisCache.Close.

func (RedisCache) Close

func (rc RedisCache) Close() error

Close is disconnect from Redis server.

func (RedisCache) RecursionAvailable

func (rc RedisCache) RecursionAvailable() bool

RecursionAvailable is returns same as upstream.

func (RedisCache) Resolve

func (rc RedisCache) Resolve(w ResponseWriter, r Request) error

Resolve is resolver using cache or the upstream resolver.

func (RedisCache) String

func (rc RedisCache) String() string

String is description string getter.

type Request

type Request struct {
	dns.Question

	RecursionDesired bool
}

Request is structure of DNS question.

func NewRequest

func NewRequest(name string, qtype uint16, recursionDesired bool) Request

NewRequest is constructor for Request.

func (Request) QtypeString

func (req Request) QtypeString() string

QtypeString is getter to human readable record type.

func (Request) String

func (req Request) String() string

String is converter to query string.

type Resolver

type Resolver interface {
	io.Closer

	Resolve(ResponseWriter, Request) error
	RecursionAvailable() bool // Checking that recursion resolve is available or not.
}

Resolver is the interface of record resolver.

type ResolverConfig

type ResolverConfig struct {
	TTL       *uint32                      `yaml:"ttl,omitempty"`
	Addresses map[Domain][]net.IP          `yaml:"address,omitempty"`
	Cnames    map[Domain][]Domain          `yaml:"cname,omitempty"`
	Texts     map[Domain][]string          `yaml:"text,omitempty"`
	Services  map[Domain][]SrvRecordConfig `yaml:"service,omitempty"`
}

ResolverConfig is configuration for static zone.

type ResolverSet

type ResolverSet []Resolver

ResolverSet is list of Resolver.

ResolverSet will merge all resolver's responses unlike AlternateResolver.

func (ResolverSet) Close

func (rs ResolverSet) Close() error

Close is close all upstream resolvers.

func (ResolverSet) RecursionAvailable

func (rs ResolverSet) RecursionAvailable() bool

RecursionAvailable is returns `true` if upstream resolvers at least one returns `true`.

func (ResolverSet) Resolve

func (rs ResolverSet) Resolve(resp ResponseWriter, req Request) error

Resolve is resolver using all upstream resolvers.

func (ResolverSet) String

func (rs ResolverSet) String() string

String is returns simple human readable string.

type ResponseCallback

type ResponseCallback struct {
	Callback      func(Record) error
	Authoritative bool
}

ResponseCallback is one implements of ResponseWriter for callback function.

func NewResponseCallback

func NewResponseCallback(callback func(Record) error) *ResponseCallback

func (*ResponseCallback) Add

func (rc *ResponseCallback) Add(r Record) error

func (*ResponseCallback) IsAuthoritative

func (rc *ResponseCallback) IsAuthoritative() bool

func (*ResponseCallback) SetNoAuthoritative

func (rc *ResponseCallback) SetNoAuthoritative()

type ResponseWriter

type ResponseWriter interface {
	Add(Record) error      // Add new record into response.
	IsAuthoritative() bool // Check current response is authoritative or not.
	SetNoAuthoritative()   // Set no authoritative.
}

ResponseWriter is interface for Resolver.

type ResponseWriterHook

type ResponseWriterHook struct {
	Writer ResponseWriter
	OnAdd  func(Record) error
}

ResponseWriterHook is a wrapper of ResponseWriter for hook events.

func (ResponseWriterHook) Add

func (rh ResponseWriterHook) Add(r Record) error

func (ResponseWriterHook) IsAuthoritative

func (rh ResponseWriterHook) IsAuthoritative() bool

func (ResponseWriterHook) SetNoAuthoritative

func (rh ResponseWriterHook) SetNoAuthoritative()

type Server

type Server struct {
	Name            string
	Metrics         *Metrics
	DynamicResolver DynamicResolver
	Resolvers       Resolver // Resolvers for this server. Must include DynamicResolver.
	DebugMode       bool
}

Server is the Landns server instance.

func (*Server) DNSHandler

func (s *Server) DNSHandler() dns.Handler

DNSHandler is getter of dns.Handler of package github.com/miekg/dns

func (*Server) HTTPHandler

func (s *Server) HTTPHandler() (http.Handler, error)

HTTPHandler is getter of http.Handler.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context, apiAddress *net.TCPAddr, dnsAddress *net.UDPAddr, dnsProto string) error

ListenAndServe is starter of server.

type SimpleResolver

type SimpleResolver map[uint16]map[Domain][]Record

SimpleResolver is a simple static implements of Resolver.

func NewSimpleResolver

func NewSimpleResolver(records []Record) SimpleResolver

NewSimpleResolver is constructor of SimpleResolver.

func NewSimpleResolverFromConfig

func NewSimpleResolverFromConfig(config []byte) (SimpleResolver, error)

NewSimpleResolverFromConfig is make SimpleResolver from configuration text.

func (SimpleResolver) Close

func (sr SimpleResolver) Close() error

Close is closer.

func (SimpleResolver) RecursionAvailable

func (sr SimpleResolver) RecursionAvailable() bool

RecursionAvailable is always returns false.

func (SimpleResolver) Resolve

func (sr SimpleResolver) Resolve(w ResponseWriter, r Request) error

Resolve is resolve matched records.

func (SimpleResolver) String

func (sr SimpleResolver) String() string

String is returns simple human readable string.

func (SimpleResolver) Validate

func (sr SimpleResolver) Validate() error

Validate is validation all records.

type SqliteResolver

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

SqliteResolver is one implements of DynamicResolver using Sqlite3.

func NewSqliteResolver

func NewSqliteResolver(path string, metrics *Metrics) (*SqliteResolver, error)

func (*SqliteResolver) Close

func (sr *SqliteResolver) Close() error

func (*SqliteResolver) GetRecord

func (sr *SqliteResolver) GetRecord(id int) (DynamicRecordSet, error)

func (*SqliteResolver) GlobRecords

func (sr *SqliteResolver) GlobRecords(pattern string) (DynamicRecordSet, error)

func (*SqliteResolver) Records

func (sr *SqliteResolver) Records() (DynamicRecordSet, error)

func (*SqliteResolver) RecursionAvailable

func (sr *SqliteResolver) RecursionAvailable() bool

func (*SqliteResolver) RemoveRecord

func (sr *SqliteResolver) RemoveRecord(id int) error

func (*SqliteResolver) Resolve

func (sr *SqliteResolver) Resolve(w ResponseWriter, r Request) error

func (*SqliteResolver) SearchRecords

func (sr *SqliteResolver) SearchRecords(suffix Domain) (DynamicRecordSet, error)

func (*SqliteResolver) SetRecords

func (sr *SqliteResolver) SetRecords(rs DynamicRecordSet) error

func (*SqliteResolver) String

func (sr *SqliteResolver) String() string

type SrvRecord

type SrvRecord struct {
	Name     Domain
	TTL      uint32
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   Domain
}

SrvRecord is the Record of SRV.

func (SrvRecord) GetName

func (r SrvRecord) GetName() Domain

GetName is getter to name of record.

func (SrvRecord) GetQtype

func (r SrvRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (SrvRecord) GetTTL

func (r SrvRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (SrvRecord) String

func (r SrvRecord) String() string

String is make record string.

func (SrvRecord) ToRR

func (r SrvRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (SrvRecord) Validate

func (r SrvRecord) Validate() error

Validate is validator of record.

func (SrvRecord) WithoutTTL

func (r SrvRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type SrvRecordConfig

type SrvRecordConfig struct {
	Service  string `yaml:"service"`
	Proto    Proto  `yaml:"proto,omitempty"`
	Priority uint16 `yaml:"priority,omitempty"`
	Weight   uint16 `yaml:"weight,omitempty"`
	Port     uint16 `yaml:"port"`
	Target   Domain `yaml:"target"`
}

SrvRecordConfig is configuration for SRV record of static zone.

func (SrvRecordConfig) ToRecord

func (s SrvRecordConfig) ToRecord(name Domain, ttl uint32) SrvRecord

ToRecord is converter to SrvRecord.

type TxtRecord

type TxtRecord struct {
	Name Domain
	TTL  uint32
	Text string
}

TxtRecord is the Record of TXT.

func (TxtRecord) GetName

func (r TxtRecord) GetName() Domain

GetName is getter to name of record.

func (TxtRecord) GetQtype

func (r TxtRecord) GetQtype() uint16

GetQtype is getter to query type number like dns.TypeA or dns.TypeTXT of package github.com/miekg/dns.

func (TxtRecord) GetTTL

func (r TxtRecord) GetTTL() uint32

GetTTL is getter to TTL of record.

func (TxtRecord) String

func (r TxtRecord) String() string

String is make record string.

func (TxtRecord) ToRR

func (r TxtRecord) ToRR() (dns.RR, error)

ToRR is converter to dns.RR of package github.com/miekg/dns

func (TxtRecord) Validate

func (r TxtRecord) Validate() error

Validate is validator of record.

func (TxtRecord) WithoutTTL

func (r TxtRecord) WithoutTTL() string

WithoutTTL is make record string but mask TTL number.

type VolatileRecord

type VolatileRecord struct {
	RR     dns.RR
	Expire time.Time
}

VolatileRecord is record value that has expire datetime.

func NewVolatileRecord

func NewVolatileRecord(record string) (VolatileRecord, error)

NewVolatileRecord will parse record text and make new VolatileRecord.

func (VolatileRecord) MarshalText

func (r VolatileRecord) MarshalText() ([]byte, error)

MarshalText is marshal VolatileRecord to text.

func (VolatileRecord) Record

func (r VolatileRecord) Record() (Record, error)

Record is Record getter.

func (VolatileRecord) String

func (r VolatileRecord) String() string

String is get printable string.

func (*VolatileRecord) UnmarshalText

func (r *VolatileRecord) UnmarshalText(text []byte) error

UnmarshalText is unmarshal VolatileRecord from text.

Directories

Path Synopsis
Package logger is the simple logger library for Landns.
Package logger is the simple logger library for Landns.
httplog
Package httplog is logging utilities for HTTP server.
Package httplog is logging utilities for HTTP server.
logtest
Package logtest is the dummy logger for testing Landns.
Package logtest is the dummy logger for testing Landns.
Package testutil is testing helpers for the Landns.
Package testutil is testing helpers for the Landns.

Jump to

Keyboard shortcuts

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