Net: forward zero-address datagram disconnects #2064

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2066 into main
fuzeofficlal commented 2026-11-25 04:20:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:20:15Z.


Fixes #891.

Summary

  • Allow zero sockaddr forms (all-zero AF_UNSPEC, 0.0.0.0:0, and [::]:0) past reachable in net::connect and net::WSAConnect (crates/victory-hle/src/modules/net.rs), forwarding the caller's (name, len) buffer unchanged to the host's ws2_32.dll.
  • Datagram (SOCK_DGRAM) sockets disconnect cleanly without leaving the machine, while stream (SOCK_STREAM) sockets receive the native Winsock error (WSAEADDRNOTAVAIL for 0.0.0.0:0, WSAEAFNOSUPPORT for all-zero AF_UNSPEC), and non-zero ports (0.0.0.0:80) or external peers remain blocked with WSAENETUNREACH.

Verification

  • modules::net::tests::zero_address_accepts_only_disconnect_forms
  • modules::net::tests::zero_address_disconnects_datagram_sockets_while_blocking_external_peers (covers UDP disconnect via connect/WSAConnect, TCP SOCK_STREAM WSAEADDRNOTAVAIL/WSAEAFNOSUPPORT, and blocked external/non-zero-port peers)
  • cargo test -p victory-hle --locked, cargo clippy -p victory-hle --tests --locked -- -D warnings, and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5485107413 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T04:20:15Z. --- Fixes #891. ### Summary - Allow zero `sockaddr` forms (all-zero `AF_UNSPEC`, `0.0.0.0:0`, and `[::]:0`) past `reachable` in `net::connect` and `net::WSAConnect` (`crates/victory-hle/src/modules/net.rs`), forwarding the caller's `(name, len)` buffer unchanged to the host's `ws2_32.dll`. - Datagram (`SOCK_DGRAM`) sockets disconnect cleanly without leaving the machine, while stream (`SOCK_STREAM`) sockets receive the native Winsock error (`WSAEADDRNOTAVAIL` for `0.0.0.0:0`, `WSAEAFNOSUPPORT` for all-zero `AF_UNSPEC`), and non-zero ports (`0.0.0.0:80`) or external peers remain blocked with `WSAENETUNREACH`. ### Verification - `modules::net::tests::zero_address_accepts_only_disconnect_forms` - `modules::net::tests::zero_address_disconnects_datagram_sockets_while_blocking_external_peers` (covers UDP disconnect via `connect`/`WSAConnect`, TCP `SOCK_STREAM` `WSAEADDRNOTAVAIL`/`WSAEAFNOSUPPORT`, and blocked external/non-zero-port peers) - `cargo test -p victory-hle --locked`, `cargo clippy -p victory-hle --tests --locked -- -D warnings`, and `cargo xtask policy`: passed.
catminou4 commented 2026-11-25 04:26:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:26:28Z.

Review: COMMENTED


Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.

Zero-address datagram disconnects forwarded — net-stack edge case; good defensive forwarding.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051850908 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#pullrequestreview-6051850908). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:26:28Z. **Review:** COMMENTED --- Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff. Zero-address datagram disconnects forwarded — net-stack edge case; good defensive forwarding.
jeremygold02 commented 2026-11-25 05:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:26:09Z.


Triage verdict — Keep the disconnect fix, account for the Wine result (a6d773e)

Evidence

  • @fuzeofficlal’s patch revisits #891 after @acleofe’s #1071 closed without merging. Both let the host handle the datagram disconnect. This version adds explicit zero-address classification controls and checks both entry points. Forwarding and tests
  • The earlier independent Wine run found that the native host call and wrapper agreed: the zeroed address-family case disconnected, while the IPv4 zero-address case returned success without disassociating the datagram socket. The new integration test still requires that second case to produce WSAENOTCONN, so the earlier platform difference remains relevant. Prior Wine comparison

Checks and limits

  • Compared the current test to the earlier Wine report. I did not rerun the new head on Wine, so the prior result is evidence of a compatibility case to verify.

Next step

  • Preserve the native Windows contract check and run the loopback-only fixture on Wine separately. If Wine still differs, document which behavior the project intends to provide before treating both environments as covered. Keep credit for #1071’s implementation and test evidence.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152840058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#issuecomment-7152840058). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:26:09Z. --- **Triage verdict — Keep the disconnect fix, account for the Wine result** (`a6d773e`) **Evidence** - @fuzeofficlal’s patch revisits #891 after @acleofe’s #1071 closed without merging. Both let the host handle the datagram disconnect. This version adds explicit zero-address classification controls and checks both entry points. [Forwarding and tests](https://github.com/Marvisak/VIctory/blob/a6d773e2c33a2c9b1296f00528e78df44a699a35/crates/victory-hle/src/modules/net.rs#L221-L269) - The earlier independent Wine run found that the native host call and wrapper agreed: the zeroed address-family case disconnected, while the IPv4 zero-address case returned success without disassociating the datagram socket. The new integration test still requires that second case to produce `WSAENOTCONN`, so the earlier platform difference remains relevant. [Prior Wine comparison](https://github.com/Marvisak/VIctory/pull/1071#issuecomment-7136785135) **Checks and limits** - Compared the current test to the earlier Wine report. I did not rerun the new head on Wine, so the prior result is evidence of a compatibility case to verify. **Next step** - Preserve the native Windows contract check and run the loopback-only fixture on Wine separately. If Wine still differs, document which behavior the project intends to provide before treating both environments as covered. Keep credit for #1071’s implementation and test evidence. This verification was AI-assisted.
fuzeofficlal commented 2026-11-25 05:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T05:00:22Z.


Updated in 379e1baa — thanks @jeremygold02 for pointing back to the Wine 11.22 comparison in #1071 (@ThomasHFWright).

On Wine, ws2_32!connect disassociates a datagram socket when sa_family == AF_UNSPEC (all-zero sockaddr), whereas forwarding AF_INET 0.0.0.0:0 verbatim leaves the peer associated on Linux/Wine (send succeeds instead of returning WSAENOTCONN). connect and WSAConnect now canonicalize any accepted zero_address (AF_UNSPEC, 0.0.0.0:0, or [::]:0) to an AF_UNSPEC all-zero sockaddr of the caller's length before calling host ws2_32.dll, giving consistent disassociation and WSAENOTCONN behavior on both native Windows and Wine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153360796 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#issuecomment-7153360796). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T05:00:22Z. --- Updated in `379e1baa` — thanks @jeremygold02 for pointing back to the Wine 11.22 comparison in #1071 (`@ThomasHFWright`). On Wine, `ws2_32!connect` disassociates a datagram socket when `sa_family == AF_UNSPEC` (all-zero `sockaddr`), whereas forwarding `AF_INET` `0.0.0.0:0` verbatim leaves the peer associated on Linux/Wine (`send` succeeds instead of returning `WSAENOTCONN`). `connect` and `WSAConnect` now canonicalize any accepted `zero_address` (`AF_UNSPEC`, `0.0.0.0:0`, or `[::]:0`) to an `AF_UNSPEC` all-zero `sockaddr` of the caller's length before calling host `ws2_32.dll`, giving consistent disassociation and `WSAENOTCONN` behavior on both native Windows and Wine.
Marvisak commented 2026-11-25 11:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:24:24Z.


Automated triage for the maintainers.

Needs work. This needs the maintainer's decision, because it still adds a path past reachable in crates/victory-hle/src/modules/net.rs (connect, WSAConnect). The code itself now looks right to me.

On your reply: confirmed in 1f723fb. The AF_UNSPEC rewrite is gone, so connect and WSAConnect pass the caller's own (name, len) to the host when zero_address holds. That covers both earlier points: a stream socket now gets the host's own error, and WSAConnect behaves however the host behaves for 0.0.0.0:0. The new SOCK_STREAM assertions (WSAEADDRNOTAVAIL for 0.0.0.0:0, WSAEAFNOSUPPORT for all-zero AF_UNSPEC) and the checks that 0.0.0.0:80 and off-machine peers still get WSAENETUNREACH test the right things. zero_address only accepts a zero port and a zero address (plus zero flowinfo and scope for IPv6), so nothing it lets through can reach another machine.

The remaining question is policy: whether the maintainer accepts a second exception beside the loopback rule in the net module. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159649754 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#issuecomment-7159649754). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:24:24Z. --- <!-- victory-triage v1 head=1f723fb0b4ede757e49cbb26d564203232ba1855 verdict=needs-work at=2026-11-25T11:23:22Z --> Automated triage for the maintainers. **Needs work.** This needs the maintainer's decision, because it still adds a path past `reachable` in `crates/victory-hle/src/modules/net.rs` (`connect`, `WSAConnect`). The code itself now looks right to me. On your reply: confirmed in `1f723fb`. The `AF_UNSPEC` rewrite is gone, so `connect` and `WSAConnect` pass the caller's own `(name, len)` to the host when `zero_address` holds. That covers both earlier points: a stream socket now gets the host's own error, and `WSAConnect` behaves however the host behaves for `0.0.0.0:0`. The new `SOCK_STREAM` assertions (`WSAEADDRNOTAVAIL` for `0.0.0.0:0`, `WSAEAFNOSUPPORT` for all-zero `AF_UNSPEC`) and the checks that `0.0.0.0:80` and off-machine peers still get `WSAENETUNREACH` test the right things. `zero_address` only accepts a zero port and a zero address (plus zero flowinfo and scope for IPv6), so nothing it lets through can reach another machine. The remaining question is policy: whether the maintainer accepts a second exception beside the loopback rule in the `net` module. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-25 11:05:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:50:46Z.


Updated in 1f723fb0 per triage feedback:

  • Removed the AF_UNSPEC sockaddr rewrite so connect and WSAConnect forward the caller's (name, len) unchanged to host Winsock when zero_address(name, len) holds.
  • Extended zero_address_disconnects_datagram_sockets_while_blocking_external_peers with a SOCK_STREAM TCP socket check verifying connect and WSAConnect with 0.0.0.0:0 fail with WSAEADDRNOTAVAIL (10049) (and all-zero AF_UNSPEC fails with WSAEAFNOSUPPORT), while UDP datagram sockets disconnect cleanly and 0.0.0.0:80 / external addresses stay blocked.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7160249832 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#issuecomment-7160249832). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T10:50:46Z. --- Updated in `1f723fb0` per triage feedback: - Removed the `AF_UNSPEC` `sockaddr` rewrite so `connect` and `WSAConnect` forward the caller's `(name, len)` unchanged to host Winsock when `zero_address(name, len)` holds. - Extended `zero_address_disconnects_datagram_sockets_while_blocking_external_peers` with a `SOCK_STREAM` TCP socket check verifying `connect` and `WSAConnect` with `0.0.0.0:0` fail with `WSAEADDRNOTAVAIL` (`10049`) (and all-zero `AF_UNSPEC` fails with `WSAEAFNOSUPPORT`), while UDP datagram sockets disconnect cleanly and `0.0.0.0:80` / external addresses stay blocked.
cloph-dsp commented 2026-11-27 03:32:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T03:32:03Z.


Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, no game data).

  • PR head 1f723fb, merge base 940d32f.
  • cargo test --locked -p victory-hle --lib -- modules::net::tests::zero_address_accepts_only_disconnect_forms --exact --test-threads=1 --quiet -> test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 144 filtered out.
  • git diff --check 940d32f HEAD -> exit 0.
  • Negative control: the new test name is absent from 940d32f (git grep -c ... crates/victory-hle/src/modules/net.rs -> exit 1).

Note: only the named synthetic test was replayed; the full crate suite was not run, and Windows socket behaviour beyond the synthetic forms was not exercised. GPU/driver: N/A (CPU-only HLE test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7209064456 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2066#issuecomment-7209064456). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T03:32:03Z. --- Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, no game data). - PR head `1f723fb`, merge base `940d32f`. - `cargo test --locked -p victory-hle --lib -- modules::net::tests::zero_address_accepts_only_disconnect_forms --exact --test-threads=1 --quiet` -> `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 144 filtered out`. - `git diff --check 940d32f HEAD` -> exit 0. - Negative control: the new test name is absent from `940d32f` (`git grep -c ... crates/victory-hle/src/modules/net.rs` -> exit 1). Note: only the named synthetic test was replayed; the full crate suite was not run, and Windows socket behaviour beyond the synthetic forms was not exercised. GPU/driver: N/A (CPU-only HLE test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2066:upstream-pr/2066'
git switch 'upstream-pr/2066'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2066'
git switch 'upstream-pr/2066'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2066'
git switch 'upstream-pr/2066'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2066'
git switch 'main'
git merge --squash 'upstream-pr/2066'
git switch 'main'
git merge --ff-only 'upstream-pr/2066'
git switch 'main'
git merge 'upstream-pr/2066'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
Marvisak/VIctory!2064
No description provided.