fix(libSceNetCtl): read the default route from the routing table on macOS #6685
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6685"
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 DavidSamir on 2026-10-16T04:46:15Z.
What
sceNetCtlGetInfofinds the host's default route in/proc/net/route, which macOS does not have, so on macOS every IPv4 query throws:On macOS it now reads the IPv4 routes that have a gateway with
sysctl({CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_FLAGS, RTF_GATEWAY}), the tablenetstat -rnshows, and keeps the routes to 0.0.0.0 that are up, neither rejecting nor host routes, on an interface that still exists. macOS keeps an unscoped default route, the one it sends traffic by, beside interface-scoped ones (RTF_IFSCOPE), which rank after it. Address, netmask, MTU and DNS servers already come fromgetifaddrs,SIOCGIFMTUand/etc/resolv.conf, which macOS has. Linux and Windows are unchanged.The parsing is exported as
NetCtlDefaultRoutes_nid_no_patch, likeNetCtlReadByteCounter_nid_no_patch, so a test can feed it a routing table built by hand: an unscoped default route, a host route, a host route to 0.0.0.0, a rejecting default route, an interface-scoped one, one that is down, one on an interface that does not exist and a truncated last message.sceNetCtlGetIfStatkeeps throwing on macOS, now with a debt entry: an unprivileged process reads the interface byte counters, throughgetifaddrsandsysctl(NET_RT_IFLIST2)alike, reduced to their low 32 bits (en0here: 426753024 received against 47671393472 innetstat -ib, 11 times 2^32 less), so a total would wrap every 4 GiB.Commits: the macOS route lookup, its test, the debt entries.
Tested
macOS 26.7.1, Apple M2 on Wi-Fi, AppleClang 21.0.0, x86-64 build under Rosetta, Release.
maindoes not build libc and libkernel on macOS for other reasons as well (#4627, #4630, #6124 and mugurc's macOS branches address them), so the tests ran in a local tree ofmaince991f1ecwith those merged.main:guest_net_ctlaborts with the error above.guest_net_ctlpasses 5 runs of 5. The values it reads match the host: address 192.168.0.102, gateway 192.168.0.1 (route -n get default), MTU 1500, first IPv4 DNS server 192.168.0.1 (/etc/resolv.conf).tools/check_conventions.py --base origin/mainandgit diff --checkpass.Windows 11 (WinLibs GCC 15.2.0 r7, UCRT, Release) and Ubuntu 24.04 under WSL2 (GCC 13.3.0, Release), head
80a9ef9e3merged ontomain5d9dcc42d:guest_net_ctlpass 3 runs of 3 with the change, and 3 runs of 3 withlibSceNetCtl/Export.cppas onmainand the tests kept. It passes either way there: their code paths are unchanged and the new test case is compiled on macOS only.Overlap: #6138 (callbacks) edits the declarations and the start of
maininGuestNetCtl.cpp, and #6039, #6138 and #6227 edit thesceNetCtlGetInfoentry next to the new debt entries; none of them changes how the route is found. #6044 movesGuestNetCtl.cpp. Whichever lands second rebases.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)sceNetCtlGetInfo, but on macOS neither reached it in a 45 s runImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T05:32:20Z.
Some 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/libSceNetCtl.mdcore/libs/tests/GuestNetCtl.cppcore/libs/prx/libSceNetCtl/Export.cppImported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-16T07:33:43Z.
Windows and Linux results for
80a9ef9e3b, merged ontomain5d9dcc42d2:main, new tests keptguest_net_ctl3/3guest_net_ctl3/3Reverted for the middle column:
libSceNetCtl/Export.cpp. The test passes either way on both hosts, as expected for a macOS-only routing-table path. Windows and Linux still build and pass with it.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T10:52:28Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One docs-debt conflict, unioned.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
90d1f458a.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-17T15:34:33Z.
Thanks, @blawesom. I checked your
rebase/6685against this branch: the code commits are identical, and the debt-file commit differs only by the conflict resolution. Rather than force-pushing, I merged currentmaininto the branch with the same resolution, so the history stays as reviewed. The PR's diff againstmainnow matches your rebase. Head is26bc5ce87, and it merges cleanly withmain.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:50:46Z.
Checked the diff: the macOS path is confined to
__APPLE__, the routing-message parser stays insidertm_msglen/sa_lenand the buffer size, the filters (up, not reject/host, destination 0.0.0.0, existing interface) and the scoped-route ranking match the description, the test pins values on a hand-built table including the truncated last message, and the debt entries are in place. Linux/Windows code paths are unchanged. macOS runtime behaviour relies on the author's run; merged.