File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ type Server struct {
46
46
Mux * dns.ServeMux
47
47
48
48
client * dns.Client
49
+ tcpClient * dns.Client
49
50
domain string
50
51
sometimes * rate.Limiter
51
52
prom struct {
@@ -69,9 +70,10 @@ func NewServer(addr, domain string) *Server {
69
70
hostname , _ := os .Hostname ()
70
71
ip , _ , _ := net .SplitHostPort (addr )
71
72
server := & Server {
72
- Mux : dns .NewServeMux (),
73
- client : & dns.Client {},
74
- domain : domain ,
73
+ Mux : dns .NewServeMux (),
74
+ client : & dns.Client {},
75
+ tcpClient : & dns.Client {Net : "tcp" },
76
+ domain : domain ,
75
77
upstream : []string {
76
78
// https://developers.google.com/speed/public-dns/docs/using#google_public_dns_ip_addresses
77
79
"8.8.8.8:53" ,
@@ -424,6 +426,17 @@ func (s *Server) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
424
426
}
425
427
continue // fall back to next-slower upstream
426
428
}
429
+ if in .Truncated {
430
+ // Truncated response (exceeds UDP packet size), retry over TCP:
431
+ // https://www.rfc-editor.org/rfc/rfc2181#section-9
432
+ in , _ , err = s .tcpClient .Exchange (r , u )
433
+ if err != nil {
434
+ if s .sometimes .Allow () {
435
+ log .Printf ("resolving %v failed: %v" , r .Question , err )
436
+ }
437
+ continue // fall back to next-slower upstream
438
+ }
439
+ }
427
440
w .WriteMsg (in )
428
441
if idx > 0 {
429
442
// re-order this upstream to the front of s.upstream.
You can’t perform that action at this time.
0 commit comments