Documentation
¶
Overview ¶
Package dns implements low-level DNS message encoding and decoding to interface with RFC 8484 "DNS Queries over HTTPS" (DoH) services.
Example:
qq := &dns.Message{
RD: 1,
Question: []dns.Question{{
Name: "www.google.com",
Type: 1,
Class: 1,
}},
}
result, err := dns.DoH(context.Background(), qq, "https://1.1.1.1/dns-query")
if err != nil {
fmt.Fprintf(os.Stderr, "dns.DoH: %v", err)
os.Exit(1)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(result)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrDecodeError = errors.New("decode error")
)
Functions ¶
Types ¶
type CERT ¶ added in v0.1.4
type CERT struct {
Type uint16 `json:"type"`
KeyTag uint16 `json:"keytag"`
Algorithm uint8 `json:"algorithm"`
Certificate []byte `json:"certificate"`
}
CERT represents a CERT Resource Record.
type DNSKEY ¶ added in v0.1.4
type DNSKEY struct {
Flags uint16 `json:"flags"`
Protocol uint8 `json:"protocol"`
Algorithm uint8 `json:"algorithm"`
PublicKey []byte `json:"publickey"`
}
DNSKEY represents a DNSKEY Resource Record.
type DS ¶ added in v0.1.4
type DS struct {
KeyTag uint16 `json:"keytag"`
Algorithm uint8 `json:"algorithm"`
DigestType uint8 `json:"digesttype"`
Digest []byte `json:"digest"`
}
DS represents a DS Resource Record.
type HTTPS ¶
type HTTPS struct {
Priority uint16 `json:"priority"`
Target string `json:"target,omitempty"`
ALPN []string `json:"alpn,omitempty"`
NoDefaultALPN bool `json:"no-default-alpn,omitempty"`
Port uint16 `json:"port,omitempty"`
IPv4Hint []net.IP `json:"ipv4hint,omitempty"`
IPv6Hint []net.IP `json:"ipv6hint,omitempty"`
ECH []byte `json:"ech,omitempty"`
}
HTTPS represents a HTTPS Resource Record. RFC 9460
type LOC ¶ added in v0.1.4
type LOC struct {
Version uint8 `json:"version"`
Size float64 `json:"size"` // meters
HorizPre float64 `json:"horizpre"` // meters
VertPre float64 `json:"vertpre"` // meters
Latitude float64 `json:"latitude"` // degrees
Longitude float64 `json:"longitude"` // degrees
Altitude float64 `json:"altitude"` // meters above reference altitude
}
LOC represents a LOC Resource Record. RFC 1876
type Message ¶
type Message struct {
// Header
ID uint16 `json:"id,omitempty"`
QR uint8 `json:"qr"`
OpCode uint8 `json:"opcode,omitempty"`
AA uint8 `json:"aa,omitempty"`
TC uint8 `json:"tc,omitempty"`
RD uint8 `json:"rd,omitempty"`
RA uint8 `json:"ra,omitempty"`
RCode uint8 `json:"rcode"`
// Question section
Question []Question `json:"question,omitempty"`
// Answer section
Answer []RR `json:"answer,omitempty"`
// Authority section
Authority []RR `json:"authority,omitempty"`
// Additional information section
Additional []RR `json:"additional,omitempty"`
}
Message is a RFC 1035 DNS Message.
func DecodeMessage ¶
DecodeMessage decodes a DNS message.
func (*Message) AddPadding ¶ added in v0.2.6
func (m *Message) AddPadding()
AddPadding adds padding to a message to make its size a multiple of 128.
func (Message) Bytes ¶
Bytes returns the serialized message. It includes only the header and the question section.
func (Message) ResponseCode ¶ added in v0.2.6
ResponseCode returns the Extended RCODE.
type NSEC ¶ added in v0.1.4
type NSEC struct {
NextDomainName string `json:"nextdomainname"`
TypeBitMaps []byte `json:"typebitmaps"`
}
NSEC represents a NSEC Resource Record.
type Question ¶
type Question struct {
Name string `json:"name"`
Type uint16 `json:"type"`
Class uint16 `json:"class"`
}
A question for a name server.
type RR ¶
type RR struct {
Name string `json:"name"`
Type uint16 `json:"type"`
Class uint16 `json:"class"`
TTL uint32 `json:"ttl"`
Data any `json:"data"`
}
A Resource Record.
type RRSIG ¶ added in v0.1.4
type RRSIG struct {
TypeCovered uint16 `json:"typecovered"`
Algorithm uint8 `json:"algorithm"`
Labels uint8 `json:"labels"`
OriginalTTL uint32 `json:"originalttl"`
SignatureExpiration uint32 `json:"signatureexpiration"`
SignatureInception uint32 `json:"signatureinception"`
KeyTag uint16 `json:"keytag"`
SignerName string `json:"signername"`
Signature []byte `json:"signature"`
}
RRSIG represents a RRSIG Resource Record.
type SOA ¶
type SOA struct {
MName string `json:"mname"`
RName string `json:"rname"`
Serial uint32 `json:"serial"`
Refresh uint32 `json:"refresh"`
Retry uint32 `json:"retry"`
Expire uint32 `json:"expire"`
Minimum uint32 `json:"minimum"`
}
SOA represents a SOA Resource Record.
type SRV ¶
type SRV struct {
Priority uint16 `json:"priority"`
Weight uint16 `json:"weight"`
Port uint16 `json:"port"`
Target string `json:"target"`
}
SRV represents a SRV Resource Record.
type SVCB ¶
type SVCB struct {
Priority uint16 `json:"priority"`
Target string `json:"target"`
Params []SVCBParam `json:"params"`
}
SVCB represents a SVCB Resource Record. RFC 9460