model

package
v0.0.0-...-93bd029 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrorCodeNone       = ""
	ErrorCodeDoNotScan  = "DO_NOT_SCAN"
	ErrorCodeDstunreach = "DST_UNREACH"
	ErrorCodeSendError  = "SEND_ERR"
)

Variables

View Source
var (
	ErrNameTooLong = fmt.Errorf("domain name is too long")
)

Functions

func CompareDomainName

func CompareDomainName(s1, s2 string) (n int)

CompareDomainName compares the names s1 and s2 and returns how many labels they have in common starting from the *right*. The comparison stops at the first inequality. The names are downcased before the comparison.

www.miek.nl. and miek.nl. have two labels in common: miek and nl www.miek.nl. and www.bla.nl. have one label in common: nl

s1 and s2 must be syntactically valid domain names.

func CountLabel

func CountLabel(s string) (labels int)

CountLabel counts the number of labels in the string s. s must be a syntactically valid domain name.

func GetRRValue

func GetRRValue(rr dns.RR) string

func NextLabel

func NextLabel(s string, offset int) (i int, end bool)

NextLabel returns the index of the start of the next label in the string s starting at offset. A negative offset will cause a panic. The bool end is true when the end of the string has been reached. Also see PrevLabel.

func PrevLabel

func PrevLabel(s string, n int) (i int, start bool)

PrevLabel returns the index of the label when starting from the right and jumping n labels to the left. The bool start is true when the start of the string has been overshot. Also see NextLabel.

func Split

func Split(s string) []int

Split splits a name s into its label indexes. www.miek.nl. returns []int{0, 4, 9}, www.miek.nl also returns []int{0, 4, 9}. The root name (.) returns nil. Also see SplitDomainName. s must be a syntactically valid domain name.

Types

type DomainName

type DomainName string

DomainName represents a domain name.

func MustNewDomainName

func MustNewDomainName(value string) DomainName

MustNewDomainName is like NewDomainName, but panics on error.

func NewDomainName

func NewDomainName(value string) (DomainName, error)

NewDomainName creates a domain name based on the string. The will be rooted and casing will be normalized.

func (DomainName) Equal

func (dn DomainName) Equal(other DomainName) bool

func (DomainName) EqualString

func (dn DomainName) EqualString(other string) bool

func (DomainName) GetAncestor

func (dn DomainName) GetAncestor(length int) DomainName

GetAncestor returns an ancestor of the domain name that has the specified numbers of labels (counting the root label) If the length is negative or greater than the labels in the domain name, the function will cause a panic.

func (DomainName) GetLabelCount

func (dn DomainName) GetLabelCount() int

GetLabelCount returns the number of labels in the domain name. The root label (empty string) will be counted. Examples:

"." => 1

"com." => 2

func (DomainName) GetLabels

func (dn DomainName) GetLabels() []string

func (DomainName) GetParents

func (dn DomainName) GetParents() []DomainName

GetParents returns all parents of the domain name, starting from "." ending with the domain name itself

func (DomainName) IsSubDomainOf

func (dn DomainName) IsSubDomainOf(parent DomainName) bool

IsSubDomainOf returns true if the specified domain name is a subdomain of (or equal to) the domain name.

func (DomainName) IsTopLevelDomain

func (dn DomainName) IsTopLevelDomain() bool

IsTopLevelDomain is a convenience function that returns true if the label count is equal to 2 (counting the empty label)

func (DomainName) PrependLabel

func (dn DomainName) PrependLabel(label string) (DomainName, error)

PrependLabel prepends a label to the domain name.

func (DomainName) TrimWWW

func (dn DomainName) TrimWWW() DomainName

TrimWWW returns the domain name without a prepended "www." If the name does not start with "www.", the function will return the original domain name.

func (DomainName) WithWWW

func (dn DomainName) WithWWW() DomainName

WithWWW returns the domain name with a prepended "www." If the name already starts with "www.", the function will return the original domain name.

type ErrorCode

type ErrorCode string

type MessageExchange

type MessageExchange struct {
	// OriginalQuestion contains the question that was asked.
	// in contrast to Message.Question, which returns the question as returned by the name server.
	// Unless the nameserver misbehaves, they should match.
	OriginalQuestion Question

	ResponseAddr string
	NameServerIP netip.Addr

	Metadata Metadata

	Message *dns.Msg

	// Error contains errors like timeouts or connection refusal that occurred during the exchange.
	// If no error occurred, it is nil
	Error *SendError
}

MessageExchange represents the exchange of a model.Message with a model.NameServer

func (*MessageExchange) IsSuccess

func (msg *MessageExchange) IsSuccess() bool

type Metadata

type Metadata struct {
	FromCache     bool
	RetryIdx      uint
	ConnId        uint64
	TCP           bool
	IsFinal       bool
	CorrelationId uint64
	ParentId      uint64
	EnqueueTime   time.Time
	DequeueTime   time.Time
	RTT           time.Duration
}

type MsgIdx

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

MsgIdx is an index holding the exchanged messages.

func NewMessageIdx

func NewMessageIdx() *MsgIdx

func (*MsgIdx) AppendMessage

func (msgIdx *MsgIdx) AppendMessage(msg MessageExchange)

func (*MsgIdx) Count

func (msgIdx *MsgIdx) Count() int

func (*MsgIdx) GetIps

func (msgIdx *MsgIdx) GetIps(name DomainName) map[netip.Addr]any

func (*MsgIdx) GetMessagesByIP

func (msgIdx *MsgIdx) GetMessagesByIP(ip netip.Addr) *MsgIterator

func (*MsgIdx) GetMessagesByName

func (msgIdx *MsgIdx) GetMessagesByName(ip netip.Addr, name DomainName) *MsgIterator

func (*MsgIdx) GetMessagesByNameServer

func (msgIdx *MsgIdx) GetMessagesByNameServer(ns *NameServer) *MsgIterator

func (*MsgIdx) GetUniqueNames

func (msgIdx *MsgIdx) GetUniqueNames() map[DomainName]any

GetUniqueNames returns a list of all unique names that are in the index

func (*MsgIdx) Iterate

func (msgIdx *MsgIdx) Iterate() *MsgIterator

type MsgIterator

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

MsgIterator allows iteration over messages without copying the underlying slices

func (*MsgIterator) HasNext

func (iter *MsgIterator) HasNext() bool

func (*MsgIterator) Next

func (iter *MsgIterator) Next() *MessageExchange

func (*MsgIterator) ToList

func (iter *MsgIterator) ToList() []*MessageExchange

type NameServer

type NameServer struct {
	Name DomainName

	// IPAddresses contains the set of unique addresses that were found for this name server.
	IPAddresses common.CompSet[netip.Addr]
	// contains filtered or unexported fields
}

NameServer represents a dns name server.

func NewNameServer

func NewNameServer(name DomainName) *NameServer

func (*NameServer) AddIPs

func (ns *NameServer) AddIPs(ipAddresses ...netip.Addr)

AddIPs adds new IPs to the set of addresses of this server.

func (*NameServer) OnIPAdded

func (ns *NameServer) OnIPAdded(key any, callback func(ip netip.Addr))

type PSL

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

func LoadPSL

func LoadPSL(pslPath string) (*PSL, error)

func (*PSL) GetDepthBelowPublicSuffix

func (psl *PSL) GetDepthBelowPublicSuffix(zone *Zone) int

func (*PSL) GetPrivateParents

func (psl *PSL) GetPrivateParents(dn DomainName) ([]DomainName, DomainName)

GetPrivateParents returns all parents of the domain name, starting from the first private label to the domain name itself. The second value returned, is the longest public suffix that was identified.

func (*PSL) IsPublixSuffix

func (psl *PSL) IsPublixSuffix(dn DomainName) bool

func (*PSL) IsSLD

func (psl *PSL) IsSLD(dn DomainName) bool

func (*PSL) NoPrivate

func (psl *PSL) NoPrivate() *PSL

NoPrivate returns a copy of the PSL with the private part removed, i.e. the part after "===BEGIN PRIVATE DOMAINS==="

func (*PSL) PublicSuffix

func (psl *PSL) PublicSuffix(dn DomainName) DomainName

PublicSuffix uses a public suffix list to return the public suffix of this name

func (*PSL) StorePrivate

func (psl *PSL) StorePrivate(publicSuffix DomainName)

func (*PSL) StorePublic

func (psl *PSL) StorePublic(publicSuffix DomainName)

func (*PSL) ToPLD

func (psl *PSL) ToPLD(dn DomainName) (DomainName, error)

ToPLD uses a public suffix list to return the "pay-level-domain", that is the public suffix of this name plus one label.

func (*PSL) ToPLDNoPrivate

func (psl *PSL) ToPLDNoPrivate(dn DomainName) (DomainName, error)

ToPLDNoPrivate is like ToPLD, but will not consider the "private" part of the PSL (i.e. the part after "===BEGIN PRIVATE DOMAINS===")

type Question

type Question struct {
	Name  DomainName
	Type  uint16
	Class uint16
}

A Question is asked by clients to name servers in search for a response

func Ask

func Ask(name DomainName, qType uint16) Question

Ask creates a question with the specified parameters. Ask is an alternative way of creating the question struct (less lines needed)

type SendError

type SendError struct {
	Message string
	Code    ErrorCode
}

SendError represents an error when communicating with a DNS name server like a timeout or a connection refusal.

type Zone

type Zone struct {
	// The name of the zone
	Name DomainName

	// The parent zone
	Parent *Zone

	// Subzones of the zone
	Subzones []*Zone

	// The authoritative name servers of the zone.
	NameServers []*NameServer
	// contains filtered or unexported fields
}

Zone represents a DNS zone

func NewZone

func NewZone(name DomainName, nameservers []*NameServer) *Zone

func (*Zone) AddZoneDependencies

func (zone *Zone) AddZoneDependencies(seenMap map[DomainName]any)

func (*Zone) AppendNameServer

func (zone *Zone) AppendNameServer(nameServer *NameServer) bool

func (*Zone) AppendNameServers

func (zone *Zone) AppendNameServers(nameServers ...*NameServer)

AppendNameServers appends to the list of the zones name servers.

func (*Zone) CreateOrGetSubzone

func (zone *Zone) CreateOrGetSubzone(name DomainName) (z *Zone, loaded bool, err error)

CreateOrGetSubzone returns the non-proper subzone whose name is equal to the provided domain name or creates one if no such zone exists yet. This method can also return the zone itself, if the provided name is equal to the zone name. The second return value indicates, whether the subzone was loaded (true) or created (false)

func (*Zone) FixNameServer

func (zone *Zone) FixNameServer(seed string, n int)

FixNameServer picks a n random name servers from the zone to be used for all further queries. The fixed nameserver will be returned via GetNameServers() Repeated calls to FixNameServer will have no effect.

func (*Zone) Flatten

func (zone *Zone) Flatten() []*Zone

Flatten returns a flat array of zones, including this zone, subzones, subzones of subzones etc.

func (*Zone) GetClosestEnclosingZone

func (zone *Zone) GetClosestEnclosingZone(domainName DomainName) *Zone

GetClosestEnclosingZone Returns the zone whose name is the "the longest existing ancestor of a name." [rfc5155] of the provided name.

func (*Zone) GetDepth

func (zone *Zone) GetDepth() int

func (*Zone) GetNameServers

func (zone *Zone) GetNameServers() []*NameServer

GetNameServers returns the name servers of the zone. If FixNameServer was called, only the fixed name server will be returned.

func (*Zone) GetNameServersRecursive

func (zone *Zone) GetNameServersRecursive() []*NameServer

func (*Zone) GetNames

func (zone *Zone) GetNames(msgSet *MsgIdx) []DomainName

GetNames extracts a list of all unique names that are in the zone

func (*Zone) GetRecords

func (zone *Zone) GetRecords(msgSet *MsgIdx) []dns.RR

GetRecords returns all the distinct resource records that could be retrieved for the zone. It can be expensive, use with care.

func (*Zone) GetZoneDependencies

func (zone *Zone) GetZoneDependencies() map[DomainName]any

func (*Zone) GoToRoot

func (zone *Zone) GoToRoot() *Zone

GoToRoot return the root zone.

func (*Zone) HasNameServer

func (zone *Zone) HasNameServer(nameServer *NameServer) bool

func (*Zone) HasNameServerWithName

func (zone *Zone) HasNameServerWithName(nsName DomainName) bool

func (*Zone) IsNameServerFixed

func (zone *Zone) IsNameServerFixed() bool

IsNameServerFixed returns true if a name server was fixed via FixNameServer.

func (*Zone) IsParentOf

func (zone *Zone) IsParentOf(child *Zone) bool

IsParentOf returns true if the zone is the direct parent of the child.

func (*Zone) OnNameServerAdded

func (zone *Zone) OnNameServerAdded(key any, callback func(ns *NameServer))

func (*Zone) RemoveSubzone

func (zone *Zone) RemoveSubzone(name DomainName) bool

Jump to

Keyboard shortcuts

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