feat(libSceNetCtl): implement sceNetCtlGetNatInfo #10790
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10790"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by leorossi2005 on 2026-10-25T00:50:47Z.
What
Declare the
NetCtlNatInfostructure layout (size,stun_status,nat_type,mapped_addr) and implementsceNetCtlGetNatInfoby performing RFC 5389 STUN binding discovery over UDP from the active host IPv4 interface againststun.playstation.netand fallback public STUN servers (stun.cloudflare.com,stun.l.google.com,stun1.l.google.com), with a test hook (NetCtlSetStunServers_nid_no_patch) for offline testing:SCE_NET_CTL_ERROR_NOT_INITIALIZED), null pointer (SCE_NET_CTL_ERROR_INVALID_ADDR),info->size == 16(SCE_NET_CTL_ERROR_INVALID_SIZE), and active IPv4 connectivity (SCE_NET_CTL_ERROR_NOT_CONNECTED).DiscoverNatInfocall to a 1000 ms total time budget (up to 600 ms for DNS resolution and 300 ms per UDP probe). Caches only successful results (stun_status == 2) for 60 s per local IPv4 address; failures are not cached and re-probe on the next call.NetCtlNatInfomatching retail PS5 call sites (Borderlands 4PPSA01494, MXGP 26PPSA30839, Super Meat Boy 3DPPSA31162) and physical PS5 console packet captures (ps5_nat_captures.zip):stun_status = 1,nat_type = 0,mapped_addr = 0when discovery fails or times out.stun_status = 2,nat_type = 1when the mapped IPv4 endpoint matches the local socket endpoint.stun_status = 2,nat_type = 2when the mapped IPv4 endpoint is consistent across two distinct STUN endpoints from the same local socket.stun_status = 2,nat_type = 3when the mapped port changes across distinct STUN endpoints from the same local socket.Tested
sceNetCtlGetNatInfocheck and advances into game loading routines.ctest --test-dir build -R guest_net_ctl -V:guest_net_ctl_testspasses 100% (validates pre-init, null pointer, invalid struct size, offline state, silent-server timeout followed by re-probe on responding server, mismatched transaction ID rejection, single-server incomplete NAT failure, NAT type 1, NAT type 2, cache reuse, and NAT type 3 viaCHANGED-ADDRESS).nat_type = 0).guest_net_ctl_tests).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T00:53:14Z.
Review: CHANGES_REQUESTED
The changed source and test translation units pass GCC 12.2 syntax checks with
-Wall -Wextra -Werror -Wno-unused-parameter;git diff --checkand the current-main conventions check also pass. The hosted path-filtered jobs skip the product test, so I could not verify the reported title run or the integrated test locally.I found a blocking correctness issue in the reported values.
FindHostIpv4Interfaceonly establishes that the host has a local IPv4 interface; this implementation then reports STUN success and NAT type 2 without performing STUN or measuring the NAT mapping, and copies that local interface address intomapped_addr. A local interface address does not establish the externally mapped address or NAT type. The test currently comparesmapped_addrto the same host-interface address and asserts the two hard-coded status values, so it does not validate those claims. The documented field layout and meanings are consistent with VitaSDK'sSceNetCtlNatInfodefinition.Please either implement and test actual NAT discovery/classification, or leave this export unimplemented (with the gap recorded as technical debt) until the values can be reported truthfully. Please also avoid claiming STUN success or a NAT type from interface presence alone.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:20:40Z.
Review: CHANGES_REQUESTED
The revision fixes the original issue: it now sends real STUN Binding Requests and only reports success after receiving a response. The changed files pass
git diff --check, and the hosted conventions, eligibility, labels, and report checks pass. The product build/test jobs are skipped by the repository's PR path filters; I did not run the Windows title test or the integratedguest_net_ctltest locally.I found a blocking issue in the NAT classification evidence. RFC 5780's mapping procedure requires an initial response with
OTHER-ADDRESS, followed by requests to the alternate address at the primary port and, when needed, the alternate address and port. Here, the code compares the initial mapping with a request to the OTHER-ADDRESS endpoint (which uses both the alternate IP and port), or with any other configured STUN service. The tests use two independent loopback servers and assert only equality/difference of their synthetic mappings. This does not establish the mapping behavior described by RFC 5780, nor that those behaviors correspond to PlayStation'snat_typevalues 1/2/3.Please either provide a source or hardware evidence for the PS5
nat_typeclassification and implement/test the corresponding probes, or report only the measured mapped address/STUN result while leaving the NAT type unknown until it can be established. RFC 5780's mapping procedure is in section 4.3; VitaSDK confirms theSceNetCtlNatInfolayout but does not document the field semantics.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T03:00:10Z.
Review: DISMISSED
The latest revision addresses my prior NAT-type concern: it now leaves
nat_typeunknown and reports only a successful STUN result plus the mapped IPv4 address. I found a separate protocol/security issue inProbeStunServer:g_stunTransactionCounterstarts at 1 and the 96-bit transaction ID is deterministically derived from that counter. The current STUN specification requires a randomly selected 96-bit transaction ID, which is used to correlate responses and contributes to resistance against spoofed responses (RFC 8489, Section 5). Please generate transaction IDs with a suitable OS cryptographic random source and add a test that confirms the request uses a fresh transaction ID and ignores a response with a mismatched ID. Hosted conventions, eligibility, labels and report pass, while product test jobs are skipped; I did not independently runguest_net_ctlon this head.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T22:32:16Z.
Review: CHANGES_REQUESTED
Thanks for the rework; the layout, the status/NAT values and the STUN parsing look right to me, and the transaction-ID and mismatch tests pin real behaviour. Two things need changing before merge:
core/libs/prx/libSceNetCtl/Export.cpp:918-931caches every result, failures included, keyed only on the local address and the config generation. One timeout (Wi-Fi not settled yet, a dropped UDP packet, DNS not ready) makesstun_status = 1/nat_type = 0permanent for the whole process, and a router change that doesn't alter the host IPv4 address is never seen. Please cache only successful results and give them a bounded lifetime (or re-probe on failure), and add a test: a first call against a silent server, then a second call against a responding one, must report the second result.Export.cpp:574-587,:735and:776: the call does a blockinggetaddrinfofor four hosts and then probes the servers one after another with 300 ms each, plus the secondaries, all on the guest thread with no overall limit. Please put a total time budget onDiscoverNatInfo(resolution included) so the worst case is bounded and stated indocs/dev/debt/libSceNetCtl.md.Smaller points:
*.np.stun.playstation.net. That is acceptable as a documented deviation, but the debt line should say that these third-party hosts receive the host's IP on the first call.Testedsection as untested rather than listed with the covered cases.