feat: add protocol tweaks to dns.Message
parent
f4d5f30b91
commit
18078cdb7c
|
@ -39,6 +39,7 @@ type QueryFlags struct {
|
||||||
Strategy string `koanf:"strategy" strategy:"-"`
|
Strategy string `koanf:"strategy" strategy:"-"`
|
||||||
InsecureSkipVerify bool `koanf:"skip-hostname-verification" skip-hostname-verification:"-"`
|
InsecureSkipVerify bool `koanf:"skip-hostname-verification" skip-hostname-verification:"-"`
|
||||||
TLSHostname string `koanf:"tls-hostname" tls-hostname:"-"`
|
TLSHostname string `koanf:"tls-hostname" tls-hostname:"-"`
|
||||||
|
RetryCount int `koanf:"retry" retry:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nameserver represents the type of Nameserver
|
// Nameserver represents the type of Nameserver
|
||||||
|
|
|
@ -63,14 +63,14 @@ func NewClassicResolver(server string, classicOpts ClassicResolverOpts, resolver
|
||||||
func (r *ClassicResolver) Lookup(question dns.Question) (Response, error) {
|
func (r *ClassicResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
var (
|
var (
|
||||||
rsp Response
|
rsp Response
|
||||||
messages = prepareMessages(question, r.resolverOptions.Ndots, r.resolverOptions.SearchList)
|
messages = prepareMessages(question, r.resolverOptions)
|
||||||
)
|
)
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
r.resolverOptions.Logger.WithFields(logf.Fields{
|
r.resolverOptions.Logger.WithFields(logf.Fields{
|
||||||
"domain": msg.Question[0].Name,
|
"domain": msg.Question[0].Name,
|
||||||
"ndots": r.resolverOptions.Ndots,
|
"ndots": r.resolverOptions.Ndots,
|
||||||
"nameserver": r.server,
|
"nameserver": r.server,
|
||||||
}).Debug("Attempting to resolve")
|
}).Debug("attempting to resolve")
|
||||||
|
|
||||||
// Since the library doesn't include tcp.Dial time,
|
// Since the library doesn't include tcp.Dial time,
|
||||||
// it's better to not rely on `rtt` provided here and calculate it ourselves.
|
// it's better to not rely on `rtt` provided here and calculate it ourselves.
|
||||||
|
|
|
@ -46,14 +46,14 @@ func NewDNSCryptResolver(server string, dnscryptOpts DNSCryptResolverOpts, resol
|
||||||
func (r *DNSCryptResolver) Lookup(question dns.Question) (Response, error) {
|
func (r *DNSCryptResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
var (
|
var (
|
||||||
rsp Response
|
rsp Response
|
||||||
messages = prepareMessages(question, r.resolverOptions.Ndots, r.resolverOptions.SearchList)
|
messages = prepareMessages(question, r.resolverOptions)
|
||||||
)
|
)
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
r.resolverOptions.Logger.WithFields(logf.Fields{
|
r.resolverOptions.Logger.WithFields(logf.Fields{
|
||||||
"domain": msg.Question[0].Name,
|
"domain": msg.Question[0].Name,
|
||||||
"ndots": r.resolverOptions.Ndots,
|
"ndots": r.resolverOptions.Ndots,
|
||||||
"nameserver": r.server,
|
"nameserver": r.server,
|
||||||
}).Debug("Attempting to resolve")
|
}).Debug("attempting to resolve")
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
in, err := r.client.Exchange(&msg, r.resolverInfo)
|
in, err := r.client.Exchange(&msg, r.resolverInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func NewDOHResolver(server string, resolverOpts Options) (Resolver, error) {
|
||||||
func (r *DOHResolver) Lookup(question dns.Question) (Response, error) {
|
func (r *DOHResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
var (
|
var (
|
||||||
rsp Response
|
rsp Response
|
||||||
messages = prepareMessages(question, r.resolverOptions.Ndots, r.resolverOptions.SearchList)
|
messages = prepareMessages(question, r.resolverOptions)
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
|
@ -53,7 +53,7 @@ func (r *DOHResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
"domain": msg.Question[0].Name,
|
"domain": msg.Question[0].Name,
|
||||||
"ndots": r.resolverOptions.Ndots,
|
"ndots": r.resolverOptions.Ndots,
|
||||||
"nameserver": r.server,
|
"nameserver": r.server,
|
||||||
}).Debug("Attempting to resolve")
|
}).Debug("attempting to resolve")
|
||||||
// get the DNS Message in wire format.
|
// get the DNS Message in wire format.
|
||||||
b, err := msg.Pack()
|
b, err := msg.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,7 +37,7 @@ func NewDOQResolver(server string, resolverOpts Options) (Resolver, error) {
|
||||||
func (r *DOQResolver) Lookup(question dns.Question) (Response, error) {
|
func (r *DOQResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
var (
|
var (
|
||||||
rsp Response
|
rsp Response
|
||||||
messages = prepareMessages(question, r.resolverOptions.Ndots, r.resolverOptions.SearchList)
|
messages = prepareMessages(question, r.resolverOptions)
|
||||||
)
|
)
|
||||||
|
|
||||||
session, err := quic.DialAddr(r.server, r.tls, nil)
|
session, err := quic.DialAddr(r.server, r.tls, nil)
|
||||||
|
@ -51,7 +51,7 @@ func (r *DOQResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
"domain": msg.Question[0].Name,
|
"domain": msg.Question[0].Name,
|
||||||
"ndots": r.resolverOptions.Ndots,
|
"ndots": r.resolverOptions.Ndots,
|
||||||
"nameserver": r.server,
|
"nameserver": r.server,
|
||||||
}).Debug("Attempting to resolve")
|
}).Debug("attempting to resolve")
|
||||||
|
|
||||||
// ref: https://www.rfc-editor.org/rfc/rfc9250.html#name-dns-message-ids
|
// ref: https://www.rfc-editor.org/rfc/rfc9250.html#name-dns-message-ids
|
||||||
msg.Id = 0
|
msg.Id = 0
|
||||||
|
|
|
@ -22,6 +22,12 @@ type Options struct {
|
||||||
Strategy string
|
Strategy string
|
||||||
InsecureSkipVerify bool
|
InsecureSkipVerify bool
|
||||||
TLSHostname string
|
TLSHostname string
|
||||||
|
|
||||||
|
// DNS Protocol Flags.
|
||||||
|
Authoritative bool
|
||||||
|
AuthenticatedData bool
|
||||||
|
CheckingDisabled bool
|
||||||
|
RecursionDesired bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolver implements the configuration for a DNS
|
// Resolver implements the configuration for a DNS
|
||||||
|
|
|
@ -11,17 +11,22 @@ import (
|
||||||
|
|
||||||
// prepareMessages takes a DNS Question and returns the
|
// prepareMessages takes a DNS Question and returns the
|
||||||
// corresponding DNS messages for the same.
|
// corresponding DNS messages for the same.
|
||||||
func prepareMessages(q dns.Question, ndots int, searchList []string) []dns.Msg {
|
func prepareMessages(q dns.Question, opts Options) []dns.Msg {
|
||||||
var (
|
var (
|
||||||
possibleQNames = constructPossibleQuestions(q.Name, ndots, searchList)
|
possibleQNames = constructPossibleQuestions(q.Name, opts.Ndots, opts.SearchList)
|
||||||
messages = make([]dns.Msg, 0, len(possibleQNames))
|
messages = make([]dns.Msg, 0, len(possibleQNames))
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, qName := range possibleQNames {
|
for _, qName := range possibleQNames {
|
||||||
msg := dns.Msg{}
|
msg := dns.Msg{
|
||||||
// generate a random id for the transaction.
|
MsgHdr: dns.MsgHdr{
|
||||||
msg.Id = dns.Id()
|
Id: dns.Id(),
|
||||||
msg.RecursionDesired = true
|
Authoritative: opts.Authoritative,
|
||||||
|
AuthenticatedData: opts.AuthenticatedData,
|
||||||
|
CheckingDisabled: opts.CheckingDisabled,
|
||||||
|
RecursionDesired: opts.RecursionDesired,
|
||||||
|
},
|
||||||
|
}
|
||||||
// It's recommended to only send 1 question for 1 DNS message.
|
// It's recommended to only send 1 question for 1 DNS message.
|
||||||
msg.Question = []dns.Question{{
|
msg.Question = []dns.Question{{
|
||||||
Name: qName,
|
Name: qName,
|
||||||
|
|
Loading…
Reference in New Issue