@@ -7,14 +7,18 @@ import (
7
7
"net"
8
8
"runtime"
9
9
"strings"
10
+ "time"
10
11
11
12
"github.com/miekg/dns"
12
13
"github.com/sirupsen/logrus"
13
14
)
14
15
15
- // Truncate for avoiding "Parse error" from `busybox nslookup`
16
- // https://github.com/lima-vm/lima/issues/380
17
- const truncateSize = 512
16
+ const (
17
+ // Truncate for avoiding "Parse error" from `busybox nslookup`
18
+ // https://github.com/lima-vm/lima/issues/380
19
+ truncateSize = 512
20
+ ipv6ResponseDelay = time .Second
21
+ )
18
22
19
23
var defaultFallbackIPs = []string {"8.8.8.8" , "1.1.1.1" }
20
24
@@ -159,15 +163,18 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
159
163
switch q .Qtype {
160
164
case dns .TypeAAAA :
161
165
if ! h .ipv6 {
162
- // A "correct" answer would be to set `handled = true` and return a NODATA response.
163
- // Unfortunately some older resolvers use a slow random source to set the transaction id.
166
+ // Unfortunately some older resolvers use a slow random source to set the Transaction ID.
164
167
// This creates a problem on M1 computers, which are too fast for that implementation:
165
- // Both the A and AAAA queries might end up with the same id. Returning NODATA for AAAA
166
- // is faster, so would arrive first, and be treated as the response to the A query.
167
- // To avoid this, we will treat an AAAA query as an A query when IPv6 has been disabled.
168
- // This way it is either a valid response for an A query, or the A records will be discarded
169
- // by a genuine AAAA query, resulting in the desired NODATA response.
170
- qtype = dns .TypeA
168
+ // Both the A and AAAA queries might end up with the same id. Therefore, we wait for
169
+ // 1 second and then we return NODATA for AAAA. This will allow the client to receive
170
+ // the correct response even when both Transaction IDs are the same.
171
+ time .Sleep (ipv6ResponseDelay )
172
+ // See RFC 2308 section 2.2 which suggests that NODATA is indicated by setting the
173
+ // RCODE to NOERROR along with zero entries in the response.
174
+ reply .SetRcode (req , dns .RcodeSuccess )
175
+ reply .SetReply (req )
176
+ handled = true
177
+ break
171
178
}
172
179
fallthrough
173
180
case dns .TypeA :
0 commit comments