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

Open
github-bot wants to merge 1 commit from github-bot/gh-2341 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-26 14:09 UTC · original
syfyra:feat/dnsapi-offline → main · +705 −2 · 5 files · 1 commits · draft

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

**@⁠syfyra** on GitHub · 2026-11-26 14:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2341) `syfyra:feat/dnsapi-offline` → `main` · +705 −2 · 5 files · 1 commits · draft 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)
docs/runtime_imports.md listed dnsapi.dll as the known gap next to the
WinHTTP and Winsock2 shims: a title that calls it reaches the host's DNS
client, which sends a query for any name, and dynamic updates, server
checks and DNS-SD (multicast DNS) as well.

dnsapi.dll stays host-owned like ws2_32.dll. DnsQuery_A/W/UTF8 and
DnsQueryEx answer "localhost" and loopback literals through the host
with the network switched off (NO_WIRE_QUERY, NO_NETBT, NO_MULTICAST,
NO_HOSTS_FILE; wire-only options and server lists dropped); every other
name fails with DNS_ERROR_RECORD_DOES_NOT_EXIST, the host's own answer
for a name it cannot resolve without the wire. DnsQueryEx completes
before it returns, as the host does for local names. DnsQueryRaw, the
update functions, DnsService* and DnsStartMulticastQuery fail with
ERROR_NETWORK_UNREACHABLE, and DnsValidateServerStatus reports the
server unreachable. New ctest dnsapi_offline (46 checks).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:13:44 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2341/head:github-bot/gh-2341'
git switch 'github-bot/gh-2341'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2341'
git switch 'github-bot/gh-2341'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2341'
git switch 'github-bot/gh-2341'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2341'
git switch 'main'
git merge --squash 'github-bot/gh-2341'
git switch 'main'
git merge --ff-only 'github-bot/gh-2341'
git switch 'main'
git merge 'github-bot/gh-2341'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.