fix(libkernel): report the wildcard local address after a UDP association is dissolved #8682
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8682"
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 xXPBSXx on 2026-10-20T20:53:25Z.
What
udp_disconnectresets the local address toINADDR_ANYand keeps the port. Dissolving the association withconnecttoAF_UNSPECleft the host socket's local address in place, sogetsocknamestill returned127.0.0.1(Windows; Linux for a socket bound to an explicit port). The socket now remembers that its association was dissolved andgetsocknamereports the wildcard address (IPv4 and IPv6) until the nextbindorconnect. The host socket itself is unchanged; the Technical debt entry forconnecttoAF_UNSPECsays so.guest_udpruns the check on Windows now.Fixes #8681
Overlap:
git merge-treehas conflicts with #8499 (two), #8448 (one) and #7511 (one) inUdp.cpp; the other open socket PRs (#8670, #8492, #8483, #8474, #8463, #7850, #7090) are clean. Whichever lands second rebases.pr_overlapwas not run.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on current upstream/main + this commit:
guest_udpfails without the change toUdp.cppand passes with it; 10 other socket tests pass.python tools/check_conventions.py --base upstream/main: passes. Not tested: Linux/macOS, the IPv6 path, a console.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Overlap note: #8344 adds independent
Socket::peertracking (socketpairgetpeername) inUdp.cpp; this PR addsSocket::localAddressCleared. No behavior duplicate, but theSocketmember hunks must be kept together if both land.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:59:10Z.
Review: COMMENTED
The stored flag and
getsocknameadjustment cover bothAF_INETandAF_INET6, and the description says the wildcard address is reported for both families. The new regression only exercises an IPv4 socket, so the IPv6 branch currently has no coverage (the description also notes it was not tested). Could you add an IPv6 case where the host supports it, checking the address becomes::while the bound port is preserved afterconnect(AF_UNSPEC)?Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T21:03:18Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL201-202core/libs/prx/libkernel/Socket/src/Udp.cppL120core/libs/prx/libkernel/Socket/src/Udp.cppL300-310docs/dev/debt/libkernel.mdL202-203core/libs/prx/libkernel/Socket/src/Udp.cppL1270-1271core/libs/prx/libkernel/Socket/src/Udp.cppL1270-1271Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestUdp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T21:25:56Z.
Thanks @MarcZX10: added the IPv6 case in
f6d8cca311. Afterconnect(AF_UNSPEC)on an AF_INET6 socket bound to::1,getsocknamekeeps the port and reports::; the test skips hosts without IPv6 or::1. With only the IPv6 branch of the fix removed,guest_udpfails on Windows; with it, it passes. Not run on Linux/macOS.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:19:17Z.
Review: APPROVED
The current head
f6d8cca311records the cleared local-address state for both IPv4 and IPv6, then reports the wildcard address while preserving the host-assigned port. The new IPv6 regression checks the port and::, and the author reports Windows failure when only the IPv6 fix is removed and a pass with it. Hosted build/runtime jobs are path-skipped, so I am relying on the reported Windows run; Linux/macOS remain untested. I also left a note about the CMake-style merge-order concern in the UDP implementation: #8344 adds an independentSocket::peermember in the same struct and should be included in the overlap notes.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:19:18Z.
One overlap entry appears to be missing from the PR description: the overlap bot flags #8344 on
Udp.cpp. I checked that diff; it adds independentSocket::peertracking for socketpairgetpeername, while this PR addslocalAddressCleared. There is no behavior duplicate, but theSocketmember hunks need to be retained together if both land. Please include #8344 in the manual merge-order notes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:31:08Z.
@xXPBSXx Thanks. The FreeBSD reference (
udp_disconnectresets the local address and keeps the port) is right, and the Windows test coverage is useful.One concern. When the port is non-zero,
Disconnectleaves the host socket bound where it was (e.g. 127.0.0.1:port), and the PR only changes whatgetsocknamereports. After anAF_UNSPECdisconnect, a guest that readsgetsockname, sees the wildcard address, and thensendtos a non-loopback destination still gets the host's loopback-bound failure, whilegetsocknamesaid it could. The project's rule is that a call does what it reports or throws, and a reported state the host doesn't have is harder to diagnose than the current answer.Two options. (1) Actually move the host socket to the wildcard address: for example, create a new host UDP socket, bind it to wildcard:port, copy the stored options, and swap it in under the socket's lock. (2) If a title needs only the
getsocknamevalue, name the title and the call sequence, and keep the debt note explicit that sends still use the old address. Which title reads the local address after dissolving the association?Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T23:55:22Z.
@oneandonlydean you are right, and I measured it before answering. Probe (plain Winsock, Windows 10 Pro 19045, WinLibs GCC 15.2.0): an UDP socket
connected to a loopback peer, thenconnect(AF_UNSPEC), thengetsockname, thensendtoto this machine's LAN address:getsocknameafter itsendtoto the LAN addressconnectpicked the address)0.0.0.0:<port>127.0.0.1127.0.0.1:<port>So the masking only changes the answer for the explicitly bound case, and there it reports a state the host does not have: exactly the failure mode you describe. (The implicit case already reports the wildcard address on
main.)Which title reads the local address after dissolving the association? I do not know of one. I found this by comparing against
in_pcbdisconnect, not from a title run, and I cannot name a title or call sequence. So I will not claim option 2.Option 1 is not something I want to land blind. The host handle in
Socket::valueis read without a lock in about 50 places (recv, poll, send), and the socket options are set directly on the native handle, so a new socket would need every option the guest set replayed (broadcast, buffer sizes, multicast memberships, TTL/TOS, nonblocking) and a bind of the same port while the old socket still owns it. A guest thread blocked inrecvfromon the old handle would also fail. That is a much larger change than this PR, with no title behind it.Proposal: I close this PR rather than leave a reported state without a host counterpart. If you prefer to keep a record, I can open a docs-only PR that adds the divergence to the libkernel debt file (after
AF_UNSPEC, an explicitly bound UDP socket keeps its bound address; FreeBSD resets it to the wildcard), with the table above as evidence. Tell me which one you want, or if you want option 1 anyway I will do it as a separate PR with asendtonon-loopback test.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T00:51:48Z.
Two corrections to my reply above:
udp_disconnect(udp_usrreq.c), not inin_pcbdisconnect(which only clears the foreign address and port). I named the wrong function.main; only the explicitly bound row is the case this PR changes. I will attach the probe output as a log from a fresh run and correct the table if it differs.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:09:34Z.
@xXPBSXx Thanks for measuring it. The table settles it: the masking changes the answer only for the explicitly bound socket, and there the host is still on 127.0.0.1. For an implicitly bound socket,
mainalready passes the host's0.0.0.0:<port>throughgetsockname.So yes, please close this one, and the docs-only PR is welcome. Put it in
docs/dev/debt/libkernel.md: afterconnect(AF_UNSPEC), a UDP socket explicitly bound to an address keeps that address (andgetsocknamereports it), where FreeBSD'sudp_disconnectresets it to the wildcard and keeps the port. Say it was found by comparing againstin_pcbdisconnect, not on a title, and link your probe table.We don't want option 1 without a title: replaying every stored option and swapping the handle under concurrent
recvfrom/sendis a lot of risk for a value no known title reads. If a title turns up that needs it, thesendtonon-loopback test you describe is the right place to start.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:05:25Z.
Closing as agreed with @oneandonlydean above: the PR makes
getsocknamereport the wildcard address afterconnect(AF_UNSPEC)on an explicitly bound UDP socket, but the host socket stays bound to that address, so a reported state has no host counterpart and no known title needs it. Swapping the host handle is too risky without a title.A docs-only PR is welcome: add to
docs/dev/debt/libkernel.mdthat afterconnect(AF_UNSPEC)an explicitly bound UDP socket keeps its address (andgetsocknamereports it), where FreeBSD'sudp_disconnectresets it to the wildcard and keeps the port, found by comparing against FreeBSD and not on a title, with the probe table linked. Feel free to reopen if a title turns up that needs it.Pull request closed