[PR #2341] dnsapi_offline: answer DNS client calls without the network (DNS-OFFLINE) #2345

Open
opened 2026-11-26 21:20:54 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2341
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: feat/dnsapi-offline


📝 Commits (1)

  • e203d57 dnsapi_offline: answer DNS client calls without the network (DNS-OFFLINE)

📊 Changes

5 files changed (+705 additions, -2 deletions)

View changed files

📝 docs/runtime_imports.md (+41 -2)
📝 runtime/CMakeLists.txt (+16 -0)
➕ runtime/shims/dnsapi_offline.cpp (+294 -0)
📝 runtime/shims/registry.cpp (+1 -0)
➕ runtime/test/dnsapi_offline_test.cpp (+353 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2341 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/dnsapi-offline` --- ### 📝 Commits (1) - [`e203d57`](https://github.com/ubiquitarianism/leonida/commit/e203d5794e3ab893c182e66830d77e9c2d64ae44) dnsapi_offline: answer DNS client calls without the network (DNS-OFFLINE) ### 📊 Changes **5 files changed** (+705 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/runtime_imports.md` (+41 -2) 📝 `runtime/CMakeLists.txt` (+16 -0) ➕ `runtime/shims/dnsapi_offline.cpp` (+294 -0) 📝 `runtime/shims/registry.cpp` (+1 -0) ➕ `runtime/test/dnsapi_offline_test.cpp` (+353 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2345
No description provided.