Skip to content

dns alg: a v6 alg flow that cannot be dialed over v6 is reset after syn-ack instead of falling back to the host's v4 addresses #259

Open

Description

@ShiroiKuma0

With the DNS ALG on and a tunnel that carries both families, an app that dials the v6 alg ip of a host gets, for real ips, only the AAAA answer that alg ip was minted for. If none of those v6 addresses can be dialed, the flow is reset — after netstack has already syn-acked the app. Having "connected", the app never tries the A answer itself, so it sees a connection reset in the middle of its TLS handshake, again and again, for a host that is perfectly reachable over v4.

Two situations produce this, and in neither is anything logged that points at the cause:

  1. The network underneath has no v6 at all while the tunnel routes it (rethink-app: IP version "IPv4 & IPv6" on a v4-only Wi-Fi). Every v6 dial fails at once with network is unreachable. Seen with a WebView-based app: net_error -101, about a hundred resets per page refresh. It "healed" only when the v6 mapping's ips aged out and the flow was re-resolved by name.
  2. The flow is handed to a proxy that carries no v6 — a v4-only WireGuard tunnel — on a network whose own v6 works. No proxy can route the flow, and it is reset just the same. Measured from an app bound to such a tunnel, on dual-stack mobile data: curl -4 to four sites loads in 0.2–0.7 s, curl -6 to the same sites is reset at connect time every time, and plain curl is reset on every site that has AAAA records (connect succeeds in ~2 ms, then Recv failure: Connection reset by peer).

makeIPPorts says "happy-eyeballs from clients should take care of dialing both families", but the client's happy eyeballs is defeated here: its v6 attempt succeeds at the TCP level (settings.SupportHappyEyeballs is false, and netstack completes the handshake before the egress dial), so it has no reason to fall back.

Observed on the engine pinned by rethink-app v0.5.8 (d3d530ea3e); intra/common.go onFlow / makeIPPorts are unchanged in this respect on n2 HEAD (c2788705).

What I did

In onFlow, before listener.Flow (so that the client's ip rules see every address that may actually be dialed): for a v6 alg flow whose real ips are all v6, while both families are in use, resolve the domain's v4 addresses (dialers.ResolveFor, capped at 4) and append them to the flow's ip list. In makeIPPorts, when both families are in use, keep the flow's own family first, so the v4 addresses are reached only after every v6 address has failed. A failure for want of a route is instant in both situations above, so the fallback costs nothing visible.

With that, the same curl -6 and plain curl fetches through the v4-only tunnel succeed in 0.15–0.5 s, and the v4-only-Wi-Fi case loads normally.

Patches (two commits; the second widens the first from "v6 looks down underneath" to every v6 alg flow, which is what case 2 needs, since the proxy is not known before listener.Flow):

Not covered

A v6 path that is black-holed rather than unrouted (dials hang until they time out): the v6 addresses still go first, and the loop gives up after retryTimeout before reaching v4. I have not seen that case in practice, so I left it alone.

Activity

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