util

package
v0.6.14 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package util contains helper functions that don't belong anywhere else

Index

Constants

This section is empty.

Variables

View Source
var ErrNotError = errors.New("not an error")

ErrNotError is an error that is not actually an error.

Functions

func InitLogger

func InitLogger(verbosity int) (log *logawl.Logger)

InitLogger initializes the logawl instance.

func ParseSubnet

func ParseSubnet(subnet string, opts *Options) error

ParseSubnet takes a subnet argument and makes it into one that the DNS library understands.

func ReverseDNS

func ReverseDNS(address string, querInt uint16) (string, error)

ReverseDNS is given an IP or phone number and returns a canonical string to be queried.

Types

type Display

type Display struct {

	// Comments?
	Comments bool `json:"comments" example:"true"`
	// QUESTION SECTION
	Question bool `json:"question" example:"true"`
	// OPT PSEUDOSECTION
	Opt bool `json:"opt" example:"true"`
	// ANSWER SECTION
	Answer bool `json:"answer" example:"true"`
	// AUTHORITY SECTION
	Authority bool `json:"authority" example:"true"`
	// ADDITIONAL SECTION
	Additional bool `json:"additional" example:"true"`
	// Query time, message size, etc.
	Statistics bool `json:"statistics" example:"true"`
	// Display TTL in response
	TTL bool `json:"ttl" example:"true"`

	// Display Class in response
	ShowClass bool `json:"showClass" example:"true"`
	// Display query before it is sent
	ShowQuery bool `json:"showQuery" example:"false"`
	// Display TTL as human-readable
	HumanTTL bool `json:"humanTTL" example:"false"`
	// Translate Punycode back to Unicode
	UcodeTranslate bool `json:"unicode" example:"true"`
}

Display contains toggles for what to (and not to) display.

type EDNS

type EDNS struct {
	// Subnet to originate query from.
	Subnet dns.EDNS0_SUBNET `json:"subnet"`
	// Must Be Zero flag
	ZFlag uint16 `json:"zflag" example:"0"`
	// UDP buffer size
	BufSize uint16 `json:"bufSize" example:"1232"`
	// Enable/Disable EDNS entirely
	EnableEDNS bool `json:"edns" example:"false"`
	// Sending EDNS cookie
	Cookie bool `json:"cookie" example:"true"`
	// Enabling DNSSEC
	DNSSEC bool `json:"dnssec" example:"false"`
	// Sending EDNS Expire
	Expire bool `json:"expire" example:"false"`
	// Sending EDNS TCP keepopen
	KeepOpen bool `json:"keepOpen" example:"false"`
	// Sending EDNS NSID
	Nsid bool `json:"nsid" example:"false"`
	// Send EDNS Padding
	Padding bool `json:"padding" example:"false"`
	// Set EDNS version (default: 0)
	Version uint8 `json:"version" example:"0"`
}

EDNS contains toggles for various EDNS options.

type ErrHTTPStatus

type ErrHTTPStatus struct {
	// Status code
	Code int
}

ErrHTTPStatus is returned when DoH returns a bad status code.

func (*ErrHTTPStatus) Error

func (e *ErrHTTPStatus) Error() string

type HTTPSOptions

type HTTPSOptions struct {
	// URL endpoint
	Endpoint string `json:"endpoint" example:"/dns-query"`

	// True, make GET request.
	// False, make POST request.
	Get bool `json:"get" example:"false"`
}

HTTPSOptions are options exclusively for DNS-over-HTTPS queries.

type HeaderFlags

type HeaderFlags struct {
	// Authoritative Answer DNS query flag
	AA bool `json:"authoritative" example:"false"`
	// Authenticated Data DNS query flag
	AD bool `json:"authenticatedData" example:"false"`
	// Checking Disabled DNS query flag
	CD bool `json:"checkingDisabled" example:"false"`
	// QueRy DNS query flag
	QR bool `json:"query" example:"false"`
	// Recursion Desired DNS query flag
	RD bool `json:"recursionDesired" example:"true"`
	// Recursion Available DNS query flag
	RA bool `json:"recursionAvailable" example:"false"`
	// TrunCated DNS query flag
	TC bool `json:"truncated" example:"false"`
	// Zero DNS query flag
	Z bool `json:"zero" example:"false"`
}

HeaderFlags are the flags that are in DNS headers.

type Options

type Options struct {
	// The logger
	Logger *logawl.Logger `json:"-"`
	// Host to verify TLS cert with
	TLSHost string `json:"tlsHost" example:""`
	// EDNS Options
	EDNS

	// HTTPS options :)
	HTTPSOptions

	// DNS request :)
	Request

	// Verbosity levels, see [logawl.AllLevels]
	Verbosity int `json:"-" example:"0"`
	// Display options
	Display Display
	// Ignore Truncation
	Truncate bool `json:"ignoreTruncate" example:"false"`
	// Ignore BADCOOKIE
	BadCookie bool `json:"ignoreBadCookie" example:"false"`
	// Print only the answer
	Short bool `json:"short" example:"false"`
	// When Short is true, display where the query came from
	Identify bool `json:"identify" example:"false"`
	// Perform a reverse DNS query when true
	Reverse bool `json:"reverse" example:"false"`

	HeaderFlags

	// Display resposne as JSON
	JSON bool `json:"-" xml:"-" yaml:"-"`
	// Display response as XML
	XML bool `json:"-" xml:"-" yaml:"-"`
	// Display response as YAML
	YAML bool `json:"-" xml:"-" yaml:"-"`

	// Use TCP instead of UDP to make the query
	TCP bool `json:"tcp" example:"false"`
	// Use DNS-over-TLS to make the query
	TLS bool `json:"dnsOverTLS" example:"false"`
	// When using TLS, ignore certificates
	TLSNoVerify bool `json:"tlsNoVerify" example:"false"`
	// Use DNS-over-HTTPS to make the query
	HTTPS bool `json:"dnsOverHTTPS" example:"false"`
	// Use DNS-over-QUIC to make the query
	//nolint:tagliatelle // QUIC is an acronym
	QUIC bool `json:"dnsOverQUIC" example:"false"`
	// Use DNSCrypt to make the query
	DNSCrypt bool `json:"dnscrypt" example:"false"`

	// Force IPv4 only
	IPv4 bool `json:"forceIPv4" example:"false"`
	// Force IPv6 only
	IPv6 bool `json:"forceIPv6" example:"false"`

	// Trace from the root
	Trace bool `json:"trace" example:"false"`
}

Options is the grand structure for all query options.

type Request

type Request struct {
	// Server to query
	Server string `json:"server" example:"1.0.0.1"`
	// Domain to query
	Name string `json:"name" example:"example.com"`
	// Duration to wait until marking request as failed
	Timeout time.Duration `json:"timeout" example:"2000000000"`
	// Port to make DNS request on
	Port int `json:"port" example:"53"`
	// Number of failures to make before giving up
	Retries int `json:"retries" example:"2"`
	// Request type, eg. A, AAAA, NAPTR
	Type uint16 `json:"type" example:"1"`
	// Request class, eg. IN
	Class uint16 `json:"class" example:"1"`
}

Request is a structure for a DNS query.

type Response

type Response struct {
	// The full DNS response
	DNS *dns.Msg `json:"response"`
	// The time it took to make the DNS query
	RTT time.Duration `json:"rtt" example:"2000000000"`
}

Response is the DNS response.

Jump to

Keyboard shortcuts

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