dns

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Answer record type for DNS response messages
	Answer RecordType = "answer"
	// Authority record type for DNS response messages
	Authority = "authority"
	// Additional record type for DNS response messages
	Additional = "additional"
)

Variables

View Source
var QueryTypes = map[string]uint16{
	"A":     dns.TypeA,
	"AAAA":  dns.TypeAAAA,
	"CNAME": dns.TypeCNAME,
	"MX":    dns.TypeMX,
	"NS":    dns.TypeNS,
}

QueryTypes is a map of the DNS query type with the correspondence type in dns package.

Functions

func InitializeContext

func InitializeContext(ctx context.Context) context.Context

InitializeContext adds the DNS Session to the context. The new context is returned because context is immutable.

Types

type ContextKey

type ContextKey string

ContextKey defines a type to store the Context in context.Context.

type Logger

type Logger struct {
	Log *golium.Logger
}

Logger logs the DNS request and response in a configurable file.

func GetLogger

func GetLogger() *Logger

GetLogger returns the logger for DNS requests and responses. If the logger is not created yet, it creates a new instance of Logger.

func (Logger) LogRequest

func (l Logger) LogRequest(request *dns.Msg, corr string)

LogRequest logs a DNS request in the configured log file.

func (Logger) LogResponse

func (l Logger) LogResponse(response *dns.Msg, corr string)

LogResponse logs a DNS response in the configured log file.

type Record

type Record struct {
	Name  *string
	Type  *string
	Class *string
	Data  *string
	TTL   *uint
}

Record is an abstraction of a DNS records (based on dns.RR). It aims to checks the most relevant fields of a DNS records.

func (*Record) IsContained

func (r *Record) IsContained(rrs []dns.RR) bool

IsContained checks if the record matches with any of the actual DNS records of the slice.

func (*Record) Matches

func (r *Record) Matches(rr dns.RR) bool

Matches checks if the record contains the same information in the fields of the actual DNS record (of type dns.RR).

func (Record) String

func (r Record) String() string

type RecordType

type RecordType string

RecordType enumerates the possible types of DNS records: answer, authority and additional records.

type Session

type Session struct {
	// Server is the address to the DNS server, including the server port (e.g. 8.8.8.8:53).
	Server string
	// Transport is the network protocol used to send the queries
	// (valid values: UDP, DoT, Doh with GET, DoH with POST)
	Transport string
	// DNS query options (EDNS0)
	Options []dns.EDNS0
	// Query parameters
	DoHQueryParams map[string][]string
	// Query contains the DNS request message.
	Query *dns.Msg
	// Response contains the DNS response message.
	Response *dns.Msg
	// RTT is the response time.
	RTT time.Duration
	// Timeout is the maximum time to wait for a response. Expressed in Milliseconds
	Timeout time.Duration
}

Session contains the information related to a DNS query and response.

func GetSession

func GetSession(ctx context.Context) *Session

GetSession returns the DNS session stored in context. Note that the context should be previously initialized with InitializeContext function.

func (*Session) ConfigureDoHQueryParams

func (s *Session) ConfigureDoHQueryParams(ctx context.Context, params map[string][]string)

ConfigureDoHQueryParams stores a table of query parameters in the application context.

func (*Session) ConfigureOptions

func (s *Session) ConfigureOptions(ctx context.Context, options []dns.EDNS0)

ConfigureOptions adds EDNS0 options to be included in the DNS query.

func (*Session) ConfigureServer

func (s *Session) ConfigureServer(ctx context.Context, svr, transport string)

ConfigureServer configures the DNS server location and the transport protocol.

func (*Session) SendDoHQuery

func (s *Session) SendDoHQuery(
	ctx context.Context,
	method string,
	qtype uint16,
	qdomain string,
	recursive bool,
) error

SendDoHQuery sends a DoH query to resolve a domain.

func (*Session) SendDoTQuery

func (s *Session) SendDoTQuery(
	ctx context.Context,
	qtype uint16,
	qdomain string,
	recursive bool,
) error

SendDoTQuery sends a DoT query to resolve a domain.

func (*Session) SendUDPQuery

func (s *Session) SendUDPQuery(
	ctx context.Context,
	qtype uint16,
	qdomain string,
	recursive bool,
) error

SendUDPQuery sends a DNS query to resolve a domain.

func (*Session) SetDNSResponseTimeout

func (s *Session) SetDNSResponseTimeout(ctx context.Context, timeout int)

SetDNSResponseTimeout configures a DNS response timeout.

func (*Session) ValidateResponseWithCode

func (s *Session) ValidateResponseWithCode(ctx context.Context, expectedCode string) error

ValidateResponseWithCode validates the code of the DNS response.

func (*Session) ValidateResponseWithNumberOfRecords

func (s *Session) ValidateResponseWithNumberOfRecords(
	ctx context.Context,
	expectedRecords int,
	recordType RecordType,
) error

ValidateResponseWithNumberOfRecords validates the amount of records in a DNS response for one of the record types: answer, authority, additional.

func (*Session) ValidateResponseWithOneOfCodes

func (s *Session) ValidateResponseWithOneOfCodes(
	ctx context.Context,
	expectedCodes []string,
) error

ValidateResponseWithOneOfCodes validates the code of the DNS response againt a list of valid codes.

func (*Session) ValidateResponseWithRecords

func (s *Session) ValidateResponseWithRecords(
	ctx context.Context,
	recordType RecordType,
	expectedRecords []Record,
) error

ValidateResponseWithRecords validates that the response contains the following records for one of the record types: answer, authority, additional.

type Steps

type Steps struct {
}

Steps type is responsible to initialize the DNS client steps in godog framework.

func (Steps) InitializeSteps

func (s Steps) InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context

InitializeSteps adds client DNS steps to the scenario context. It implements StepInitializer interface. It returns a new context (context is immutable) with the DNS Context.

Jump to

Keyboard shortcuts

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