Skip to content

Commit ee8e4f4

Browse files
committed
Add EDNS0 FORMERR fallback and TCP-on-UDP-failure to queryRaw
- Retry without EDNS0 if resolver returns FORMERR - Fall back to TCP if UDP query fails entirely (middlebox/firewall)
1 parent 398bbec commit ee8e4f4

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

internal/scanner/dns.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ func queryRaw(resolver, domain string, qtype uint16, timeout time.Duration) (*dn
2626
defer cancel()
2727

2828
r, _, err := c.ExchangeContext(ctx, m, addr)
29+
30+
// If EDNS0 caused FORMERR, retry without it
31+
if err == nil && r != nil && r.Rcode == dns.RcodeFormatError {
32+
m.Extra = nil // strip EDNS0 OPT record
33+
r, _, err = c.ExchangeContext(ctx, m, addr)
34+
}
35+
36+
// If UDP failed entirely, try TCP before giving up
2937
if err != nil || r == nil {
30-
return nil, false
38+
c.Net = "tcp"
39+
r, _, err = c.ExchangeContext(ctx, m, addr)
40+
if err != nil || r == nil {
41+
return nil, false
42+
}
3143
}
3244

3345
// Retry over TCP if response was truncated

0 commit comments

Comments
 (0)