Skip to content

dns64: the synthesized AAAA answer carries the A question, so stub resolvers drop it and time out #258

Open

Description

@ShiroiKuma0

With protocol translation on "auto" (PtModeAuto, which rethink-app sets whenever its translation setting is off) and a tunnel that carries both families, the AAAA query of any host that has no AAAA records is answered with a synthesized AAAA — and that answer goes out carrying the A question, not the AAAA one the client asked. Stub resolvers match an answer to their query by id and question, drop it, and wait out their full timeout.

Seen from the user's side: on a dual-stack network every page that touches a v4-only host stalls for seconds to tens of seconds, because getaddrinfo waits for both the A and the AAAA answer. The second lookup of the same host is fine (answered from the alg cache, with the right question), which makes it easy to miss.

Observed on the engine pinned by rethink-app v0.5.8 (d3d530ea3e); the code below is unchanged on n2 HEAD (c2788705).

Where

intra/x64/dns64.go, (*dns64).eval:

ans4, err := d.query64(network, ansin, r, uid)   // the A query the engine makes itself
...
ans64, didTranslate := xdns.TranslateRecords(ans4, dns.TypeA, func(r dns.RR) ...)
...
return ans64

TranslateRecords starts from EmptyResponseFromMessage(ansin) — where its ansin is ans4 — and that copies srcMsg.Question. So ans64 keeps the question of the A query (Request4FromResponse6 sets qname A); the id happens to be right because Request4FromResponse6 copies it. alg.go:q then takes ans64 as ansin and the client gets it as is.

Evidence

The engine's own log shows the query finishing in ~0.3 s:

dns: fwd: 1 for 10190 (fid: 422057297edeb268 / tunnel); query homedepot.com:28 ...
doh: ... q: homedepot.com:28, data: --, code: 0, px: Base, dur: 52ms
dns64: for 10190 over udp: CachePreferred q(homedepot.com.) / a(true) / e(<nil>)
dns64: homedepot.com. for 10190: translated on CachePreferred[CachePreferred] response(1)
alg: q: ok; for ...:homedepot.com:28 ... real: [64:ff9b:1:fffe::23c9:5f53] => subst invalid IP | 64:ff9b:1:da19:100:d63:4bfa:5c2a
dns: fwd: 10 for CachePreferred[10190] (fid: 422057297edeb268) ...

while the client that asked times out:

$ dig @10.111.222.3 +tries=1 +time=6 AAAA lowes.com
;; ;; Question section mismatch: got lowes.com/A/IN
;; communications error to 10.111.222.3#53: timed out

A raw UDP query confirms it: asked bestbuy.com type 28 with id 4660, the reply has id 4660, qd 1 an 1, question bestbuy.com type 1.

First AAAA lookup of fresh v4-only hosts (stackoverflow.com, amazon.com, x.com, twitter.com, duckduckgo.com, ebay.com, imdb.com): no usable answer within 10–25 s; the upstream resolver itself answers the same question in ~0.1 s; the second try through the tunnel answers in ~70 ms. Hosts that do have AAAA records, and DNSSEC-authenticated empty answers (hasauth skips eval), are not affected.

Fix

Restore the question (and id) of the answer being translated before returning it:

if len(ansin.Question) > 0 {
	ans64.Question = append([]dns.Question(nil), ansin.Question...)
	ans64.Id = ansin.Id
}
return ans64

With that, the same first lookups answer in 70–520 ms with type 28 in the question, and dig no longer reports a mismatch. Patch: ShiroiKuma0@cc72988d

Separately, it may be worth not synthesizing at all in PtModeAuto when the network underneath has native IPv4: the client already has (or is about to get) the A answer, and the synthesized address only buys a translated connection to the same place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions