fix(libkernel): connect and send to INADDR_ANY through 127.0.0.1 on Windows as FreeBSD reaches the local host #15782
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15782"
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 Ragbie on 2026-11-04T14:41:53Z.
What
On Windows,
connect,sendtoandsendmsgtoINADDR_ANYon anAF_INETsocket, or to::ffff:0.0.0.0on a dual-stackAF_INET6socket, now reach the local host through127.0.0.1. Before, they went to the host unchanged and failed withEADDRNOTAVAIL, as thelibkernel.mddebt entry "connect to the unspecified address" recorded. #14876 did theAF_INET6::half ofconnect; this is the IPv4 half.in_pcbconnect_setupfails port 0 withEADDRNOTAVAIL, then replaces anINADDR_ANYdestination with the first interface address (the jail's address in a jail).tcp_connect,udp_connectandudp_outputall go through it; the v4-mapped form reaches it throughtcp6_usr_connect,udp6_connectandudp6_output. Aconnector unconnected send to 0.0.0.0 therefore reaches the local machine.127.0.0.1is the address that always reaches the local host, matches::1for the IPv6 half, and is what Linux uses for an unbound socket. The debt entry keeps the remaining difference: the peer a guest reads back can differ from the console's.The code (
Udp.cpp):LoopbackForUnspecifiedInet: rewrites anAF_INETINADDR_ANY, or anAF_INET6::ffff:0.0.0.0, to the loopback address.connect: the mapping runs after the multicast check andZeroPortConnect, as FreeBSD rejects multicast and port 0 first.RefuseClosedLoopbackAtOncemoved to the same point, so a port-0 refusal no longer leaves the socket's no-SYN-retransmission setting behind.sendto: the mapping runs afterZeroPortSend, becauseudp_output's port-0 rule depends on whether the destination isINADDR_ANY.GuestUdp's 0.0.0.0:0 case still getsEADDRNOTAVAIL.sendmsgon an IP socket goes throughsendto_nid_postfix.sceNetSendtoas unchanged.Tested
guest_socket_port_zero, newCheckUnspecifiedInet(stream and datagram):127.0.0.1.connectto0.0.0.0on the server's port returns 0,getpeernamereports127.0.0.1on that port, and data flows.sendtoto0.0.0.0reaches the server. A dual-stackAF_INET6socket withIPV6_V6ONLYcleared reaches it withsendtoand withconnectto::ffff:0.0.0.0.Windows 11 Pro, Intel Core i5-14600KF, NVIDIA GPU, WinLibs GCC 15.2.0, full Release build with
libs:connect to INADDR_ANY must reach 127.0.0.1 on the same port (errno 49).AF_INET:sendto ::ffff:0.0.0.0 must reach 127.0.0.1 (errno 49).guest_socket_port_zeropasses with--repeat until-fail:3. The 159 tests matchingsocket|net|udp|tcp|connect|sendto|poll|select|kqueue|epollpass, exceptselect_tests_MissingCommandTests, which fails withWinError 1314because this user cannot create symbolic links.ctest:99% tests passed, 6 tests failed out of 4005. All six fail onmainon this machine too:test_registrationandselect_tests_MissingCommandTestsfail withWinError 1314.agc_driver_direct_write_completion,agc_driver_image_plane_address_on_line,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_laneare GPU tests on an NVIDIA card.check_skips.pyreports one skip,guest_fopen_errors, which skips itself here because this user cannot create symbolic links.#ifdef _WIN32blocks insendtowere joined. The socket tests above were run again on that state.Linux (Ubuntu 24.04 container, GCC 13.3.0): the code is unchanged there, and the new test passes, since the host kernel reaches the loopback address. The 121 tests matching the same pattern pass.
macOS: not tested; the code is unchanged there. The macOS CI jobs do not run this test.
Overlaps: a trial merge with #14043 and #11223 (mine, both in
Udp.cpp) has no conflicts (git merge-tree).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)