dnsx

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Based on github.com/miekg/dns/serve_mux.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeWildcard

func MakeWildcard(fqdn string) string

func MakeWildcards

func MakeWildcards(fqdn string) []string

func Must

func Must(rrs []dns.RR, err error) []dns.RR

Must is a helper that wraps a call to a function returning ([]dns.RR, error) and panics if the error is non-nil.

func NewRR

func NewRR(name string, qtype uint16, ttl int, value string) dns.RR

NewRR creates dns.RR using provided parameters.

func NewRRs

func NewRRs(name string, qtype uint16, ttl int, values []string) []dns.RR

NewRRs creates array of dns.RR using provided parameters.

func ParseRecords

func ParseRecords(s string, origin string) ([]dns.RR, error)

ParseRecords parses DNS records from string.

func ParseRecordsFile

func ParseRecordsFile(rdr io.Reader, origin string) ([]dns.RR, error)

ParseRecordsFile parses DNS records from file.

func QtypeString

func QtypeString(qtype uint16) string

QtypeString return string representation of uint16 DNS query type.

func RRToString

func RRToString(rr dns.RR) string

RRToString returns string representation of dns.RR value.

func RRsToStrings

func RRsToStrings(rrs []dns.RR) []string

RRsToStings returns representaion of []dns.RR as []string.

func ReplaceWildcards

func ReplaceWildcards(rrs []dns.RR, name string) []dns.RR

Types

type Answer

type Answer struct {
	Name string `json:"name"`
	Type string `json:"type"`
	TTL  uint32 `json:"ttl"`
}

Answer represents a DNS answer.

type Handler

type Handler interface {
	ServeDNS(context.Context, dns.ResponseWriter, *dns.Msg)
}

func ChainHandler

func ChainHandler(set RecordGetter, next Handler) Handler

ChainHandler tries to handle query using provided DNS records set, if there is no answer for the query in set it calls next dns.Handler.

func NotifyHandler

func NotifyHandler(notify NofitifyFunc, next Handler) Handler

NotifyHandler calls notify function after processing query.

func RecordSetHandler

func RecordSetHandler(set RecordGetter) Handler

RecordSetHandler wraps RecordGetter interface and implements Handlerinterface using it.

type HandlerFunc

type HandlerFunc func(context.Context, dns.ResponseWriter, *dns.Msg)

func (HandlerFunc) ServeDNS

func (f HandlerFunc) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)

type HandlerProvider

type HandlerProvider interface {
	Handler
	challenge.Provider
}

func ChallengeHandler

func ChallengeHandler(next Handler) HandlerProvider

type Meta

type Meta struct {
	Question Question `json:"question"`
	Answer   []Answer `json:"answer,omitempty"`
}

Meta contains DNS-specific event metadata.

type NofitifyFunc

type NofitifyFunc func(
	ctx context.Context,
	remoteAddr net.Addr,
	receivedAt *time.Time,
	read []byte,
	written []byte,
	combined []byte,
	meta *Meta,
)

type Option

type Option func(*options)

func NotifyStartedFunc

func NotifyStartedFunc(f func()) Option

type Question

type Question struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Question represents a DNS question.

type RecordGetter

type RecordGetter interface {
	Get(ctx context.Context, name string, qtype uint16) ([]dns.RR, error)
}

RecordGetter is an interface which must be implemented by any records providers like database records, in-memory records, etc.

type Recorder

type Recorder struct {
	dns.ResponseWriter
	Rcode int
	Len   int
	Msg   *dns.Msg
	Start time.Time
}

Recorder is a type of dns.ResponseWriter that captures the rcode code written to it and also the size of the message written in the response. A rcode code does not have to be written, however, in which case 0 must be assumed. It is best to have the constructor initialize this type with that default status code.

func NewRecorder

func NewRecorder(w dns.ResponseWriter) *Recorder

NewRecorder makes and returns a new Recorder, which captures the DNS rcode from the ResponseWriter and also the length of the response message written through it.

func (*Recorder) Write

func (r *Recorder) Write(buf []byte) (int, error)

Write is a wrapper that records the length of the message that gets written.

func (*Recorder) WriteMsg

func (r *Recorder) WriteMsg(res *dns.Msg) error

WriteMsg records the status code and calls the underlying ResponseWriter's WriteMsg method.

type Records

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

Records represents in memory stored DNS records.

func NewRecords

func NewRecords(rrs []dns.RR) *Records

NewRecords returns new initialized Records instance.

func (*Records) Add

func (r *Records) Add(rr dns.RR)

Add adds new DNS record to Records.

func (*Records) Del

func (r *Records) Del(name string, qtype uint16) error

Del removes DNS record from Records.

func (*Records) Get

func (r *Records) Get(ctx context.Context, name string, qtype uint16) ([]dns.RR, error)

Get returns DNS record from Records. Returns nil if no records found. Handles wildcards.

type ServeMux

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

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler Handler)

Handle adds a handler to the ServeMux for pattern.

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(context.Context, dns.ResponseWriter, *dns.Msg))

HandleFunc adds a handler function to the ServeMux for pattern.

func (*ServeMux) ServeDNS

func (mux *ServeMux) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.Msg)

type Server

type Server interface {
	ListenAndServe() error
}

func New

func New(addr string, h Handler, opts ...Option) Server

New is convenient constructor for server.

Jump to

Keyboard shortcuts

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