Documentation
¶
Index ¶
- Constants
- Variables
- func CompareDomainName(s1, s2 string) (n int)
- func CountLabel(s string) (labels int)
- func GetRRValue(rr dns.RR) string
- func NextLabel(s string, offset int) (i int, end bool)
- func PrevLabel(s string, n int) (i int, start bool)
- func Split(s string) []int
- type DomainName
- func (dn DomainName) Equal(other DomainName) bool
- func (dn DomainName) EqualString(other string) bool
- func (dn DomainName) GetAncestor(length int) DomainName
- func (dn DomainName) GetLabelCount() int
- func (dn DomainName) GetLabels() []string
- func (dn DomainName) GetParents() []DomainName
- func (dn DomainName) IsSubDomainOf(parent DomainName) bool
- func (dn DomainName) IsTopLevelDomain() bool
- func (dn DomainName) PrependLabel(label string) (DomainName, error)
- func (dn DomainName) TrimWWW() DomainName
- func (dn DomainName) WithWWW() DomainName
- type ErrorCode
- type MessageExchange
- type Metadata
- type MsgIdx
- func (msgIdx *MsgIdx) AppendMessage(msg MessageExchange)
- func (msgIdx *MsgIdx) Count() int
- func (msgIdx *MsgIdx) GetIps(name DomainName) map[netip.Addr]any
- func (msgIdx *MsgIdx) GetMessagesByIP(ip netip.Addr) *MsgIterator
- func (msgIdx *MsgIdx) GetMessagesByName(ip netip.Addr, name DomainName) *MsgIterator
- func (msgIdx *MsgIdx) GetMessagesByNameServer(ns *NameServer) *MsgIterator
- func (msgIdx *MsgIdx) GetUniqueNames() map[DomainName]any
- func (msgIdx *MsgIdx) Iterate() *MsgIterator
- type MsgIterator
- type NameServer
- type PSL
- func (psl *PSL) GetDepthBelowPublicSuffix(zone *Zone) int
- func (psl *PSL) GetPrivateParents(dn DomainName) ([]DomainName, DomainName)
- func (psl *PSL) IsPublixSuffix(dn DomainName) bool
- func (psl *PSL) IsSLD(dn DomainName) bool
- func (psl *PSL) NoPrivate() *PSL
- func (psl *PSL) PublicSuffix(dn DomainName) DomainName
- func (psl *PSL) StorePrivate(publicSuffix DomainName)
- func (psl *PSL) StorePublic(publicSuffix DomainName)
- func (psl *PSL) ToPLD(dn DomainName) (DomainName, error)
- func (psl *PSL) ToPLDNoPrivate(dn DomainName) (DomainName, error)
- type Question
- type SendError
- type Zone
- func (zone *Zone) AddZoneDependencies(seenMap map[DomainName]any)
- func (zone *Zone) AppendNameServer(nameServer *NameServer) bool
- func (zone *Zone) AppendNameServers(nameServers ...*NameServer)
- func (zone *Zone) CreateOrGetSubzone(name DomainName) (z *Zone, loaded bool, err error)
- func (zone *Zone) FixNameServer(seed string, n int)
- func (zone *Zone) Flatten() []*Zone
- func (zone *Zone) GetClosestEnclosingZone(domainName DomainName) *Zone
- func (zone *Zone) GetDepth() int
- func (zone *Zone) GetNameServers() []*NameServer
- func (zone *Zone) GetNameServersRecursive() []*NameServer
- func (zone *Zone) GetNames(msgSet *MsgIdx) []DomainName
- func (zone *Zone) GetRecords(msgSet *MsgIdx) []dns.RR
- func (zone *Zone) GetZoneDependencies() map[DomainName]any
- func (zone *Zone) GoToRoot() *Zone
- func (zone *Zone) HasNameServer(nameServer *NameServer) bool
- func (zone *Zone) HasNameServerWithName(nsName DomainName) bool
- func (zone *Zone) IsNameServerFixed() bool
- func (zone *Zone) IsParentOf(child *Zone) bool
- func (zone *Zone) OnNameServerAdded(key any, callback func(ns *NameServer))
- func (zone *Zone) RemoveSubzone(name DomainName) bool
Constants ¶
const ( ErrorCodeNone = "" ErrorCodeDoNotScan = "DO_NOT_SCAN" ErrorCodeDstunreach = "DST_UNREACH" ErrorCodeSendError = "SEND_ERR" )
Variables ¶
var (
ErrNameTooLong = fmt.Errorf("domain name is too long")
)
Functions ¶
func CompareDomainName ¶
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 ¶
CountLabel counts the number of labels in the string s. s must be a syntactically valid domain name.
func GetRRValue ¶
func NextLabel ¶
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.
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 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 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) 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.
type PSL ¶
type PSL struct {
// contains filtered or unexported fields
}
func (*PSL) GetDepthBelowPublicSuffix ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
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) HasNameServer ¶
func (zone *Zone) HasNameServer(nameServer *NameServer) bool
func (*Zone) HasNameServerWithName ¶
func (zone *Zone) HasNameServerWithName(nsName DomainName) bool
func (*Zone) IsNameServerFixed ¶
IsNameServerFixed returns true if a name server was fixed via FixNameServer.
func (*Zone) IsParentOf ¶
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