Documentation ¶
Overview ¶
Package dnsutil provides a motley collection functions which manipulated and render structs created by the "net" and "github.com/miekg/dns".
Index ¶
- Constants
- func ChompCanonicalName(n string) string
- func ClassToString(c dns.Class) (s string)
- func DeducePtr(rr dns.RR) (ptr *dns.PTR, key string)
- func IPToReverseQName(ip net.IP) string
- func InDomain(sub, parent string) bool
- func InvertPtrToIP(qName string) (net.IP, bool, error)
- func InvertPtrToIPv4(qName string) (net.IP, bool, error)
- func InvertPtrToIPv6(qName string) (net.IP, bool, error)
- func OpcodeToString(o int) (s string)
- func PrettyA(rr *dns.A, includeName bool) (s string)
- func PrettyAAAA(rr *dns.AAAA, includeName bool) (s string)
- func PrettyAddr(rr dns.RR, includeName bool) (s string)
- func PrettyMsg1(m *dns.Msg) string
- func PrettyNS(rr *dns.NS, includeName bool) (s string)
- func PrettyPTR(rr *dns.PTR, includeName bool) (s string)
- func PrettyQuestion(q dns.Question) string
- func PrettyRR(rr dns.RR, includeName bool) string
- func PrettyRRSet(rrs []dns.RR, includeName bool) (s string)
- func PrettySOA(rr *dns.SOA, includeName bool) (s string)
- func PrettyShortNSSet(rrs []dns.RR) string
- func RRIsEqual(a, b dns.RR) bool
- func RcodeToString(r int) (s string)
- func ShortenLookupError(err error) error
- func SynthesizePTR(qname, suffix string, ip net.IP) *dns.PTR
- func TypeToString(t uint16) (s string)
- func ValidDelegation(response *dns.Msg) bool
Constants ¶
const ( V4Suffix = ".in-addr.arpa." // The leading '.' is important here as some callers V6Suffix = ".ip6.arpa." // rely on strings.HasSuffix() to label match. TCPNetwork = "tcp" // Yeah, yea, a bit silly, but case is important UDPNetwork = "udp" // so having consts here avoids pernickety errors MaxUDPSize uint16 = 1232 // Generally suggested as universally safe in edns0 )
Variables ¶
This section is empty.
Functions ¶
func ChompCanonicalName ¶
ChompCanonicalName makes a name canonical but loses the trailing dot. For logging and mock processing, where zones names are often converted to file names, the trailing dot is more of a hindrance than a help, so this helps.
func ClassToString ¶ added in v1.1.0
ClassToString converts an miekg class to a string, but if the resulting string is empty it's replaced with the numeric value.
func DeducePtr ¶
DeducePtr converts a dns.A/AAAA RR into a dns.PTR or returns the supplied RR if it's already a recognizable/convertable PTR. If the wrong type of RR is supplied a nil value is returned. The returned "key" value is effectively the IP address expressed as a string regardless of the RR type. It can be used by callers who want to reference the PTR via the original or extracted IP address.
func IPToReverseQName ¶
IPToReverseQName converts an IP address into the reverse string normally looked up in the reverse path. It includes the reverse suffix, is fully qualified and is ready for querying.
An empty string is returned if the IP address cannot be parsed.
This is not intended to be a high-speed function.
func InDomain ¶ added in v1.4.0
InDomain returns true if the purported sub-domain is in-domain of the parent domain. This function assumes two relatively well-formed domain names but makes sure they are both Canonical before comparisons are made. In the interest of being "helpful" the parent domain may or may not have a leading "." as that is common for a lot of domain storage in this program.
func InvertPtrToIP ¶
InvertPtrToIP extracts and inverts the purported IP address from a reverse qName. Like any name in the DNS, a reverse qName does not *have* to represent an IP address, but this code ignores all else. Return an error if an IP address cannot be extracted. The return bool is true if the IP address is as valid as far as it goes, but is truncated.
func InvertPtrToIPv4 ¶
InvertPtrToIPv4 takes the first part of the reverse qName from the ipv4 zone and converts it back into an ipv4 Address, if possible. As a reminder, a dig -x 192.168.1.2 results in a qName of 2.1.168.192.in-addr.arpa. The suffix is removed by the caller leaving just 2.1.168.192. There are of course no guarantees that this string is in reversed IP address format as a rogue query can come in directly with anything in qName, thus all the checking and potential error return if the string doesn't parse.
The returned bool is true if the IP address is valid as far as it goes, but is truncated, e.g. 1.168.192.in-addr.arpa. The reason for converting truncated IPs is so that the caller can distinguish between a malformed address and a truncated one as the former results in an NXDomain and the latter results in a NoError.
func InvertPtrToIPv6 ¶
InvertPtrToIPv6 takes the first part of the reverse query name, and converts it back into an ipv6 address, if possible. Expected input looks something like: 3.f.6.d.4.d.3.b.c.4.3.0.1.3.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa less the "ip6.arpa" suffix.
The returned bool is true if the IP address is valid as far as it goes, but is truncated, e.g. 0.8.e.f.ip6.arpa returns an ipv6 address of fe80::0 with truncated=true. See the discussion of InvertPtrToIPv4.
func OpcodeToString ¶ added in v1.1.0
OpcodeToString converts an miekg opcode to a string, but if the resulting string is empty it's replaced with the numeric value.
func PrettyAAAA ¶
PrettyAAAA returns a compact representation of a single AAAA RR
func PrettyAddr ¶
PrettyAddr returns a compact representation of the single address RR. It can be either an A or an AAAA RR.
func PrettyMsg1 ¶
PrettyMsg1 returns a compact string representing the complete message.
func PrettyQuestion ¶
PrettyQuestion returns a compact representation of the dns.Question
func PrettyRR ¶
PrettyRR returns a compact representation of the single RR. Known RR-types use the other pretty functions while unknown RRs use the general rendering offered by miekg.
func PrettyRRSet ¶
PrettyRRSet returns a compact representation of the slice of RRs. Each RR is separated a comma.
func PrettyShortNSSet ¶
PrettyShortNSSet returns just the name server names (RHS) separated by ", "
func RRIsEqual ¶
RRIsEqual returns true if the RRs are "effectively" identical. That means they are identical excepting for TTL. Miekg does not offer an IsEqual() public function that compares the non-header part of an RR so we use the Stringer function and compare them as a string. A bit of a hack as we have to remove the header part of the string to eliminate the TTL, but it works, albeit slowly.
func RcodeToString ¶ added in v1.1.0
RcodeToString converts an miekg rcode to a string, but if the resulting string is empty it's replaced with the numeric value.
func ShortenLookupError ¶
ShortenLookupError turns a long unwieldy error return from net.Resolver into a succinct error in the common cases which don't require the extensive error normally returned.
func SynthesizePTR ¶
SynthesizePTR converts an IP address into a synthetic PTR. Mainly it just string substitutes ":" and "." in ip addresses to "-" which is an acceptable <domain-name> character.
According to rfc1035 Ptr has to hold a <domain-name> which is constrainted to "let-dig-hyp", but I'll bet if the Ptr data contained "." and ":" (which would allow an *exact* representation of the query address) that almost nothing would care. If you want to toy with that idea, set obeyRFC to false.
The suffix parameter is assumed to be canonical.
func TypeToString ¶ added in v1.1.0
TypeToString converts an miekg type to a string, but if the resulting string is empty it's replaced with the numeric value.
func ValidDelegation ¶
ValidDelegation returns true if the message contains a standard-conforming delegation response.
Strictly, a valid delegation is one which is !Authoritative, has zero Answer RRs, has at least one Ns RR and optional contains glue in Extra.
Types ¶
This section is empty.