Documentation ¶
Overview ¶
Package dns provides a DNS server for resolving services against.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MetricsFactory = promauto.With(MetricsRegistry)
var MetricsRegistry = prometheus.NewRegistry()
MetricsRegistry is the metrics registry in which all DNS metrics are registered.
Functions ¶
func IsSubDomain ¶
IsSubDomain returns true if child is the same as or a subdomain of parent. Both names should be in canonical form.
func ParseReverse ¶
ParseReverse parses name as a reverse lookup name. If name is not a reverse name, the returned IP is invalid. The second return value indicates how many bits of the address are present. The third return value is true if there are extra labels before the reverse name.
func SplitLastLabel ¶
SplitLastLabel splits off the last label of a domain name. For example, "www.example.com." is split into "www.example." and "com".
Types ¶
type EmptyDNSHandler ¶
type EmptyDNSHandler struct{}
EmptyDNSHandler is a handler that does not handle any queries. It can be used as a placeholder with SetHandler when a handler is inactive.
func (EmptyDNSHandler) HandleDNS ¶
func (EmptyDNSHandler) HandleDNS(*Request)
type Handler ¶
type Handler interface {
HandleDNS(r *Request)
}
Handler can handle DNS requests. The handler should first inspect the query and decide if it wants to handle it. If not, it should return immediately. The next handler will then be tried. Otherwise, it should fill in the Reply, and then call SendReply. The Answer section may already contain CNAMEs that have been followed.
type Request ¶
type Request struct { // Reply is the reply that will be sent, and should be filled in by the // handler. It is guaranteed to contain exactly one question. Reply *dns.Msg // Writer will be used to send the reply, and contains network information. Writer dns.ResponseWriter // Qopt is the OPT record from the query, or nil if not present. Qopt *dns.OPT // Ropt, if non-nil, is the OPT record that will be added to the reply. The // handler can modify this as needed. Ropt is nil when Qopt is nil. Ropt *dns.OPT // Qname contains the current question name. This is different from the // original question in Reply.Question[0].Name if a CNAME has been followed // already. Qname string // QnameCanonical contains the canonicalized name of the question. This means // that ASCII letters are lowercased. QnameCanonical string // Qtype contains the question type for convenient access. Qtype uint16 // Handled is set to true when the current question name has been handled and // no other handlers should be attempted. Handled bool // contains filtered or unexported fields }
Request represents an incoming DNS query that is being handled.
func CreateTestRequest ¶
CreateTestRequest creates a Request for use in tests.
func (*Request) AddCNAME ¶
AddCNAME adds a CNAME record to the answer section, and either sends the reply if the query is for the CNAME itself, or else marks the lookup to be restarted at the new name. target must be fully qualified.
func (*Request) AddExtendedError ¶
AddExtendedError adds an Extended DNS Error Option if the reply has an OPT. See RFC 8914.
func (*Request) SendReply ¶
func (r *Request) SendReply()
SendReply sends the reply. It may only be called once.
func (*Request) SetAuthoritative ¶
func (r *Request) SetAuthoritative()
SetAuthoritative marks the reply as authoritative.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a DNS server service with configurable handlers.
The number and names of handlers is fixed when New is called. For each name in handlerNames there is a corresponding pointer to a handler in the handlers slice at the same index, which can be atomically updated at runtime through its atomic.Pointer via the SetHandler function.
func New ¶
New creates a Service instance. DNS handlers with the names given in handlerNames must be set with SetHandler. When serving DNS queries, they will be tried in the order they appear here. Doing it this way instead of directly passing a []Handler avoids circular dependencies.
func (*Service) RunListenerAddr ¶
RunListenerAddr runs a DNS listener on a specific address.
func (*Service) SetHandler ¶
SetHandler sets the handler of the given name. This name must have been registered when creating the Service. As long as SetHandler has not been called for a registered name, any queries that are not already handled by an earlier handler in the sequence return SERVFAIL. SetHandler may be called multiple times, each call replaces the previous handler of the same name.
Directories ¶
Path | Synopsis |
---|---|
Package forward implements a forwarding proxy.
|
Package forward implements a forwarding proxy. |
cache
Package cache implements a cache.
|
Package cache implements a cache. |
proxy
Package proxy implements a forwarding proxy.
|
Package proxy implements a forwarding proxy. |
up
Package up is used to run a function for some duration.
|
Package up is used to run a function for some duration. |
Package kubernetes provides the kubernetes backend.
|
Package kubernetes provides the kubernetes backend. |
object
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.
|
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures. |