@@ -19,17 +19,15 @@ func handleDNS(ctx context.Context, w io.Writer, payload []byte) {
19
19
}
20
20
21
21
if req .Opcode != dns .OpcodeQuery {
22
- verbosef ("ignoring a dns query with non-query opcode (%v)" , req .Opcode )
22
+ errorf ("ignoring a dns query with non-query opcode (%v)" , req .Opcode )
23
23
return
24
24
}
25
25
26
26
// resolve the query
27
27
rrs , err := handleDNSQuery (ctx , & req )
28
28
if err != nil {
29
- verbosef ( "dns failed for %v with error : %v, sending a response with empty answer" , req , err . Error () )
29
+ errorf ( "error performing DNS query : %v, sending a response with empty answer" , err )
30
30
// do not abort here, continue on and send a reply with no answer
31
- // because the client might easily have tried to resolve a non-existent
32
- // hostname
33
31
}
34
32
35
33
resp := new (dns.Msg )
@@ -50,7 +48,6 @@ func handleDNS(ctx context.Context, w io.Writer, payload []byte) {
50
48
errorf ("error writing dns response: %v, abandoning..." , err )
51
49
return
52
50
}
53
- verbosef ("done responding to DNS request (sent %d bytes)" , len (buf ))
54
51
}
55
52
56
53
func dnsTypeCode (t uint16 ) string {
@@ -261,7 +258,9 @@ func handleDNSQuery(ctx context.Context, req *dns.Msg) ([]dns.RR, error) {
261
258
}
262
259
263
260
question := req .Question [0 ]
264
- verbosef ("got dns request for %v (%v)" , question .Name , dnsTypeCode (question .Qtype ))
261
+ questionType := dnsTypeCode (question .Qtype )
262
+
263
+ verbosef ("got dns request for %v (%v)" , question .Name , questionType )
265
264
266
265
// handle the request ourselves
267
266
switch question .Qtype {
@@ -288,6 +287,7 @@ func handleDNSQuery(ctx context.Context, req *dns.Msg) ([]dns.RR, error) {
288
287
rrs = append (rrs , rr )
289
288
}
290
289
return rrs , nil
290
+
291
291
case dns .TypeAAAA :
292
292
ips , err := net .DefaultResolver .LookupIP (ctx , "ip6" , question .Name )
293
293
if err != nil {
@@ -307,7 +307,7 @@ func handleDNSQuery(ctx context.Context, req *dns.Msg) ([]dns.RR, error) {
307
307
return rrs , nil
308
308
}
309
309
310
- verbose ("proxying non-A request to upstream DNS server..." )
310
+ verbosef ("proxying %s request to upstream DNS server..." , questionType )
311
311
312
312
// proxy the request to another server
313
313
request := new (dns.Msg )
@@ -318,13 +318,11 @@ func handleDNSQuery(ctx context.Context, req *dns.Msg) ([]dns.RR, error) {
318
318
dnsClient .Net = "udp"
319
319
response , _ , err := dnsClient .Exchange (request , upstreamDNS )
320
320
if err != nil {
321
- return nil , err
321
+ return nil , fmt . Errorf ( "error in DNS message exchange: %w" , err )
322
322
}
323
323
324
324
verbosef ("got answer from upstream dns server with %d answers" , len (response .Answer ))
325
325
326
- if len (response .Answer ) > 0 {
327
- return response .Answer , nil
328
- }
329
- return nil , fmt .Errorf ("not found" )
326
+ // note that we might have 0 answers here: this means there were no records for the query, which is not an error
327
+ return response .Answer , nil
330
328
}
0 commit comments