fix: fallback to tcp if response is truncated
Based on a report `doggo txt google.com @udp://1.1.1.1` failed. This record had 704 bytes as the message length however the response gets truncated if it exceeds 512 bytes with UDP. `dig` transparently fallbacks to `tcp`, so this commit adds the same mechanism.pull/41/head v0.5.3
parent
53f7b70af4
commit
ea7cb3c6cd
|
@ -79,6 +79,24 @@ func (r *ClassicResolver) Lookup(question dns.Question) (Response, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rsp, err
|
return rsp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case the response size exceeds 512 bytes (can happen with lot of TXT records),
|
||||||
|
// fallback to TCP as with UDP the response is truncated. Fallback mechanism is in-line with `dig`.
|
||||||
|
if in.Truncated {
|
||||||
|
switch r.client.Net {
|
||||||
|
case "udp":
|
||||||
|
r.client.Net = "tcp"
|
||||||
|
case "udp4":
|
||||||
|
r.client.Net = "tcp4"
|
||||||
|
case "udp6":
|
||||||
|
r.client.Net = "tcp6"
|
||||||
|
default:
|
||||||
|
r.client.Net = "tcp"
|
||||||
|
}
|
||||||
|
r.resolverOptions.Logger.WithField("protocol", r.client.Net).Debug("Response truncated; retrying now")
|
||||||
|
return r.Lookup(question)
|
||||||
|
}
|
||||||
|
|
||||||
// Pack questions in output.
|
// Pack questions in output.
|
||||||
for _, q := range msg.Question {
|
for _, q := range msg.Question {
|
||||||
ques := Question{
|
ques := Question{
|
||||||
|
|
Loading…
Reference in New Issue