Skip to content

Commit 45ca822

Browse files
authored
Merge pull request #1289 from Nino-K/return-nodata-ipv6
Return NODATA for IPv6 AAAA question types
2 parents 25b137d + 66b2056 commit 45ca822

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

pkg/hostagent/dns/dns.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import (
77
"net"
88
"runtime"
99
"strings"
10+
"time"
1011

1112
"github.com/miekg/dns"
1213
"github.com/sirupsen/logrus"
1314
)
1415

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+
)
1822

1923
var defaultFallbackIPs = []string{"8.8.8.8", "1.1.1.1"}
2024

@@ -159,15 +163,18 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
159163
switch q.Qtype {
160164
case dns.TypeAAAA:
161165
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.
164167
// 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
171178
}
172179
fallthrough
173180
case dns.TypeA:

0 commit comments

Comments
 (0)