dnsapi_offline: answer DNS client calls without the network (DNS-OFFLINE) #2341

Closed
leonida/mandy
syfyra wants to merge 0 commits from feat/dnsapi-offline into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

syfyra commented 2026-11-26 14:09:17 +00:00

Claimed in the coordination issue as: DNS-OFFLINE

What and why

docs/runtime_imports.md listed dnsapi.dll as the known gap next to the WinHTTP and Winsock2 offline shims: "a title that calls it reaches the host's resolver". The host's DNS client sends a query for any name. It also sends dynamic updates (DnsModifyRecordsInSet_*, DnsReplaceRecordSet*), server checks (DnsValidateServerStatus) and DNS-SD / multicast DNS on the local link (DnsService*, DnsStartMulticastQuery). The DnsService* functions are the ones the games partition of windns.h offers a GDK title, besides the free functions.

runtime/shims/dnsapi_offline.cpp vets the documented functions that can send. dnsapi.dll stays host-owned (owns_dll), like ws2_32.dll, so LoadLibrary returns the real module, and DnsRecordListFree, DnsFree, DnsQueryConfig, DnsCancelQuery and the name helpers stay the host's.

function offline answer
DnsQuery_A/W/UTF8, DnsQueryEx for localhost (any case, trailing dot) or a loopback literal (127.0.0.0/8 in plain decimal, ::1, ::ffff:127.x) the host's answer with the network switched off
the same for every other name DNS_ERROR_RECORD_DOES_NOT_EXIST, no records
DnsQueryRaw, DnsModifyRecordsInSet_A/W/UTF8, DnsReplaceRecordSetA/W/UTF8, DnsServiceBrowse/Resolve/Register/DeRegister, DnsStartMulticastQuery ERROR_NETWORK_UNREACHABLE before anything is sent; no callback
DnsValidateServerStatus succeeds, status DNS_VALSVR_ERROR_UNREACHABLE; the server is never asked

The loopback names go to the host with DNS_QUERY_NO_WIRE_QUERY, NO_NETBT, NO_MULTICAST and NO_HOSTS_FILE added. WIRE_ONLY, MULTICAST_ONLY, BYPASS_CACHE and RETURN_MESSAGE are removed, because the host refuses them next to NO_WIRE_QUERY with ERROR_INVALID_PARAMETER. Server lists (pExtra, pDnsServerList, version 3's custom servers) are dropped. The records are the host's own, so the title frees them as usual.

The rest follows measurements on Windows 11 with a small probe (cache-only queries, no names sent):

  • localhost with DNS_QUERY_NO_WIRE_QUERY (also with NO_HOSTS_FILE) gives 127.0.0.1 and ::1, and a literal gives its own record.
  • A name the host cannot answer without the wire gives DNS_ERROR_RECORD_DOES_NOT_EXIST, so the shim uses the same code. An empty name gives the machine's own addresses, and any other literal gives itself; the shim refuses both. It also does not read the resolver cache or the hosts file, as the Winsock2 lookups don't, so a title can't read what other programs resolved.
  • DnsQueryEx with a completion callback returns localhost at once, without calling back. The shim therefore completes every query before it returns (no shim query is ever pending), and DnsCancelQuery stays the host's.
  • DnsQueryEx rejects a null request, result or name, a result Version other than 1 and a request Version 7 with ERROR_INVALID_PARAMETER. The shim keeps those checks for refused names too.
  • 0127.0.0.1 is refused, as in the Winsock2 lookups: the host itself answers it with ERROR_INVALID_NAME.

Refused names and functions are logged once ([rt] dnsapi: offline, refused <function> <name>). Not covered: undocumented exports (DnsQueryExA/W/UTF8, DnsValidateServer_A/W, the internal Dns_* and Socket_* helpers).

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • New runtime/test/dnsapi_offline_test.cpp (ctest dnsapi_offline), 46 checks, all pass. It covers:

    • the bindings, and that the module stays host-owned;
    • localhost, LocalHost., 127.45.6.7, ::1 and ::ffff:127.0.0.1 through DnsQuery_W, _A, _UTF8 and DnsQueryEx, also with WIRE_ONLY, MULTICAST_ONLY, BYPASS_CACHE, RETURN_MESSAGE, a server list, version 3 custom servers or a completion callback;
    • that other options still reach the host (NO_LOCAL_NAME refuses localhost on both);
    • the refusals: a .invalid name, an SRV lookup, an empty name, RFC 5737 / RFC 3849 literals, 0127.0.0.1, foo.localhost, localhost.example, ::1%1, non-ASCII names in W and UTF-8, a reverse lookup;
    • DnsQueryEx's argument checks;
    • the twelve sending functions, with no callback (DnsService* are given real callbacks that count);
    • DnsValidateServerStatus.

    Only loopback names reach the host's DNS client.

  • Full ctest -j 8 (169 CPU tests, no Vulkan SDK here): all pass.

  • gta6rt builds with the shim and needs no dnsapi.lib (host calls are resolved at run time from System32).

  • Merges without new conflicts against every pull request that touches runtime/CMakeLists.txt, runtime/shims/registry.cpp or docs/runtime_imports.md, including #400 (which also edits the owns_dll host list).

  • scripts/check_no_game_data.py on the five files.

Not tested under Wine.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

Claimed in the coordination issue as: DNS-OFFLINE ### What and why `docs/runtime_imports.md` listed `dnsapi.dll` as the known gap next to the WinHTTP and Winsock2 offline shims: "a title that calls it reaches the host's resolver". The host's DNS client sends a query for any name. It also sends dynamic updates (`DnsModifyRecordsInSet_*`, `DnsReplaceRecordSet*`), server checks (`DnsValidateServerStatus`) and DNS-SD / multicast DNS on the local link (`DnsService*`, `DnsStartMulticastQuery`). The `DnsService*` functions are the ones the games partition of `windns.h` offers a GDK title, besides the free functions. `runtime/shims/dnsapi_offline.cpp` vets the documented functions that can send. `dnsapi.dll` stays host-owned (`owns_dll`), like `ws2_32.dll`, so `LoadLibrary` returns the real module, and `DnsRecordListFree`, `DnsFree`, `DnsQueryConfig`, `DnsCancelQuery` and the name helpers stay the host's. | function | offline answer | |---|---| | `DnsQuery_A/W/UTF8`, `DnsQueryEx` for `localhost` (any case, trailing dot) or a loopback literal (`127.0.0.0/8` in plain decimal, `::1`, `::ffff:127.x`) | the host's answer with the network switched off | | the same for every other name | `DNS_ERROR_RECORD_DOES_NOT_EXIST`, no records | | `DnsQueryRaw`, `DnsModifyRecordsInSet_A/W/UTF8`, `DnsReplaceRecordSetA/W/UTF8`, `DnsServiceBrowse/Resolve/Register/DeRegister`, `DnsStartMulticastQuery` | `ERROR_NETWORK_UNREACHABLE` before anything is sent; no callback | | `DnsValidateServerStatus` | succeeds, status `DNS_VALSVR_ERROR_UNREACHABLE`; the server is never asked | The loopback names go to the host with `DNS_QUERY_NO_WIRE_QUERY`, `NO_NETBT`, `NO_MULTICAST` and `NO_HOSTS_FILE` added. `WIRE_ONLY`, `MULTICAST_ONLY`, `BYPASS_CACHE` and `RETURN_MESSAGE` are removed, because the host refuses them next to `NO_WIRE_QUERY` with `ERROR_INVALID_PARAMETER`. Server lists (`pExtra`, `pDnsServerList`, version 3's custom servers) are dropped. The records are the host's own, so the title frees them as usual. The rest follows measurements on Windows 11 with a small probe (cache-only queries, no names sent): - `localhost` with `DNS_QUERY_NO_WIRE_QUERY` (also with `NO_HOSTS_FILE`) gives `127.0.0.1` and `::1`, and a literal gives its own record. - A name the host cannot answer without the wire gives `DNS_ERROR_RECORD_DOES_NOT_EXIST`, so the shim uses the same code. An empty name gives the machine's own addresses, and any other literal gives itself; the shim refuses both. It also does not read the resolver cache or the hosts file, as the Winsock2 lookups don't, so a title can't read what other programs resolved. - `DnsQueryEx` with a completion callback returns `localhost` at once, without calling back. The shim therefore completes every query before it returns (no shim query is ever pending), and `DnsCancelQuery` stays the host's. - `DnsQueryEx` rejects a null request, result or name, a result `Version` other than 1 and a request `Version` 7 with `ERROR_INVALID_PARAMETER`. The shim keeps those checks for refused names too. - `0127.0.0.1` is refused, as in the Winsock2 lookups: the host itself answers it with `ERROR_INVALID_NAME`. Refused names and functions are logged once (`[rt] dnsapi: offline, refused <function> <name>`). Not covered: undocumented exports (`DnsQueryExA/W/UTF8`, `DnsValidateServer_A/W`, the internal `Dns_*` and `Socket_*` helpers). ### Tested Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo: - New `runtime/test/dnsapi_offline_test.cpp` (ctest `dnsapi_offline`), 46 checks, all pass. It covers: - the bindings, and that the module stays host-owned; - `localhost`, `LocalHost.`, `127.45.6.7`, `::1` and `::ffff:127.0.0.1` through `DnsQuery_W`, `_A`, `_UTF8` and `DnsQueryEx`, also with `WIRE_ONLY`, `MULTICAST_ONLY`, `BYPASS_CACHE`, `RETURN_MESSAGE`, a server list, version 3 custom servers or a completion callback; - that other options still reach the host (`NO_LOCAL_NAME` refuses `localhost` on both); - the refusals: a `.invalid` name, an SRV lookup, an empty name, RFC 5737 / RFC 3849 literals, `0127.0.0.1`, `foo.localhost`, `localhost.example`, `::1%1`, non-ASCII names in W and UTF-8, a reverse lookup; - `DnsQueryEx`'s argument checks; - the twelve sending functions, with no callback (`DnsService*` are given real callbacks that count); - `DnsValidateServerStatus`. Only loopback names reach the host's DNS client. - Full `ctest -j 8` (169 CPU tests, no Vulkan SDK here): all pass. - `gta6rt` builds with the shim and needs no `dnsapi.lib` (host calls are resolved at run time from System32). - Merges without new conflicts against every pull request that touches `runtime/CMakeLists.txt`, `runtime/shims/registry.cpp` or `docs/runtime_imports.md`, including #400 (which also edits the `owns_dll` host list). - `scripts/check_no_game_data.py` on the five files. Not tested under Wine. GPUs tested: n/a (CPU tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fiestorra commented 2026-11-30 10:37:54 +00:00

Verified, with a note on how the control had to be run: this pull request adds a new shim file, so reverting it means deleting it, not checking out an older version.

1. It applies. merge-tree clean; the commits cherry-pick onto main 012b79a67 without a conflict.

2. It builds and its test passes:

ctest -R 'dnsapi_offline'
100% tests passed, 0 tests failed out of 1

3. The control, correctly: git checkout origin/main -- <file> cannot revert a file that main never had - it fails for that path and leaves the new shim in place, which is a false negative I hit first. Deleting it and reverting the registration is the honest version:

Remove-Item runtime/shims/dnsapi_offline.cpp
git checkout origin/main -- runtime/shims/registry.cpp
cmake --build … --target dnsapi_offline_test   -> does not compile

The test cannot exist without the shim, so this is a compile-level control, not a behavioural one: it proves the test is bound to the new file, not that it would catch a wrong implementation of it.

4. What the change is: a new dnsapi_offline.cpp that answers the DNS client API (dnsapi.dll) for a mapped title without the network, registered in registry.cpp next to the other offline shims. The header comment explains the gap it closes: calls that reached the host's DNS client directly could send a query for any name, including multicast DNS on the local link.

What I did not test: the resolution behaviour itself against the documented contract - a behavioural control for this one would have to shim a fake resolver and assert on what the shim returns for a name, which the test as written does not do (it resolves every export through rt::shims::find and checks the not shimmed list).

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change. 22 controls so far: 15 bite, 5 do not, 3 are compile-level only - and this one is compile-level because the file is new.

Written with an AI assistant.

**Verified, with a note on how the control had to be run: this pull request adds a new shim file, so reverting it means deleting it, not checking out an older version.** **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `012b79a67` without a conflict. **2. It builds and its test passes:** ``` ctest -R 'dnsapi_offline' 100% tests passed, 0 tests failed out of 1 ``` **3. The control, correctly:** `git checkout origin/main -- <file>` **cannot revert a file that `main` never had** - it fails for that path and leaves the new shim in place, which is a false negative I hit first. Deleting it and reverting the registration is the honest version: ``` Remove-Item runtime/shims/dnsapi_offline.cpp git checkout origin/main -- runtime/shims/registry.cpp cmake --build … --target dnsapi_offline_test -> does not compile ``` **The test cannot exist without the shim**, so this is a **compile-level control**, not a behavioural one: it proves the test is bound to the new file, **not** that it would catch a wrong implementation of it. **4. What the change is:** a new `dnsapi_offline.cpp` that answers the DNS client API (`dnsapi.dll`) for a mapped title without the network, registered in `registry.cpp` next to the other offline shims. **The header comment explains the gap it closes**: calls that reached the host's DNS client directly could send a query for any name, including multicast DNS on the local link. **What I did not test:** the resolution behaviour itself against the documented contract - **a behavioural control for this one would have to shim a fake resolver and assert on what the shim returns for a name, which the test as written does not do** (it resolves every export through `rt::shims::find` and checks the *not shimmed* list). **Why I am commenting:** I verify open pull requests that replay onto current `main`, then revert **only** the source change. **22 controls so far: 15 bite, 5 do not, 3 are compile-level only** - and this one is compile-level because the file is new. Written with an AI assistant.
aslan2142 commented 2026-12-01 12:30:08 +00:00

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:44:04 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.