Repository navigation
fix(libSceNetCtl): read the default route from the routing table on macOS - #6685
Conversation
…acOS sceNetCtlGetInfo found the host's default route in /proc/net/route, which macOS does not have, so every IPv4 query threw "the host routing table is unavailable" there. On macOS it now reads the IPv4 routes that have a gateway with sysctl(NET_RT_FLAGS, RTF_GATEWAY) and keeps those to 0.0.0.0 that are up, neither rejecting nor host routes, on an interface that still exists. An interface-scoped default route ranks after the unscoped one, the route macOS sends traffic by. The parsing is exported as NetCtlDefaultRoutes_nid_no_patch so it can be tested on a routing table built by hand.
… route A routing table built by hand with an unscoped default route, a host route, a host route to 0.0.0.0, a rejecting default route, an interface-scoped default route, one that is down, one on an interface that does not exist and a truncated last message must give the unscoped route first and the scoped one after it, and must count every match while writing only as many as fit.
…t throws on macOS
|
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.
|
|
Windows and Linux results for 80a9ef9, merged onto
Reverted for the middle column: AI-assisted: yes |
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
…ute-macos # Conflicts: # docs/dev/debt/libSceNetCtl.md
|
Thanks, @blawesom. I checked your AI-assisted: yes |
…le on macOS (@DavidSamir) Replaces this branch's equivalent sysctl(NET_RT_DUMP) reader with the PR's, which parses the routing messages in a separate function with its own tests and is the version going upstream. This branch's macOS byte counters for sceNetCtlGetIfStat, which the PR does not cover, are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le on macOS (@DavidSamir) Replaces this branch's equivalent sysctl(NET_RT_DUMP) reader with the PR's, which parses the routing messages in a separate function with its own tests and is the version going upstream. This branch's macOS byte counters for sceNetCtlGetIfStat, which the PR does not cover, are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ute-macos # Conflicts: # docs/dev/debt/libSceNetCtl.md
…ute-macos # Conflicts: # core/libs/tests/GuestNetCtl.cpp # docs/dev/debt/libSceNetCtl.md
…ute-macos # Conflicts: # core/libs/tests/GuestNetCtl.cpp
|
Checked the diff: the macOS path is confined to |
Brings in main's 49 newer commits. Seven of the PRs this branch carried are now in main (boykopovar#6647, boykopovar#6667, boykopovar#6668, boykopovar#6685, boykopovar#6686, boykopovar#6767, boykopovar#6802), so the branch shrinks by them. Conflicts: - GuestGetrlimit: main adds a check that 1024 stdio streams open on Windows; it runs after this branch's descriptor exhaustion helper, which Windows and macOS share. - the relinker keeps this branch's macOS fixture test beside main's macOS fixed-base test from boykopovar#6802. - the libkernel and shader debt files take main's text and keep this branch's short macOS entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 ofmaince991f1 with 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 ontomain5d9dcc4: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 run