feat(libSceNet): support SO_DONTROUTE in sceNetSetsockopt and sceNetGetsockopt #12918
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12918"
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 Kikoarl on 2026-10-29T14:16:17Z.
What
Support
NET_SO_DONTROUTE(0x10) insceNetSetsockoptandsceNetGetsockopt(libSceNet).FreeBSD 11.4 defines
SO_DONTROUTE = 0x10, which bypasses normal routing tables and sends packets directly to the network interface. Kernel sockets already mapGuestDontRoutetoSO_DONTROUTEincore/libs/prx/libkernel/Socket/src/SocketOptions.cpp:123, butlibSceNetpreviously lackedNET_SO_DONTROUTE = 0x10and rejected bothsceNetSetsockoptandsceNetGetsockoptwithNET_EOPNOTSUPP.This change:
NET_SO_DONTROUTE = 0x10incore/libs/prx/libSceNet/Export.cpp.NET_SO_DONTROUTEtosceNetSetsockoptmapping toSOL_SOCKET/SO_DONTROUTE.NET_SO_DONTROUTEtosceNetGetsockoptreadback, returning0x10when enabled and0when disabled, matching FreeBSD 11.4sogetoptflag bit behavior.GuestNetBooleanReadback.cppto verify setsockopt and getsockopt for option16(NET_SO_DONTROUTE) across stream/dgram and IPv4/IPv6 sockets with variable buffer lengths and truncated readback.docs/dev/debt/libSceNet.mdto reflectSO_DONTROUTEin the boolean readback entry.Tested
16tocore/libs/tests/GuestNetBooleanReadback.cpp.ctest -R guest_net_boolean_readbackand all 12guest_nettest suites in/tmp/anyps5_build: 100% passed (0 failures).python3 tools/check_conventions.py: 0 errors.Checklist
python3 tools/check_conventions.pyImported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T17:31:57Z.
Review: APPROVED
Approving. I checked this head (
9cf7eb8c98) host-side on macOS arm64. Nothing here is a console measurement.Merge / conventions
git merge-treeontomainbb04a4f1ea: clean.git diff --check: clean.tools/check_conventions.py --base upstream/main: all checks passed.*optlen < sizeof(int)guard insceNetGetsockopt. #11272 adds an empty line after it, and this PR addsNET_SO_DONTROUTEto it. Whichever lands second needs a one-line rebase. There is no semantic overlap.Reference behaviour
sys/kern/uipc_socket.clistsSO_DONTROUTEwith theso_optionsflag cases insosetopt(L2556) andsogetopt(L2797), and reads backso->so_options & sopt->sopt_name(L2808). So the bit-valued readback (0x10/0) and the truncated copy-out match the existing REUSEADDR/BROADCAST path.libkernel'sSocketOptions.cppalready mapsGuestDontRoute = 0x10to hostSO_DONTROUTE, solibSceNetnow agrees with it.Host primitive (macOS 15, arm64): I ran set/get of
SO_DONTROUTEfor AF_INET/AF_INET6 × STREAM/DGRAM with settings{1,-1,0,4,0}. All 20 setsockopt calls returned 0, and getsockopt returned0x10for non-zero settings and0for zero. With the flag set, a UDPsendtoto an off-link address (8.8.8.8) fails withENETUNREACH(51). A send to 127.0.0.1 succeeds. This matches FreeBSD 11.4udp_output(SO_DONTROUTE→IP_ROUTETOIF, L1422) andip_output'sIP_ROUTETOIFbranch returningENETUNREACHwhen no interface is on-link.Mutation harness. I copied the changed set and get branches verbatim into a standalone file. They run against real sockets, and the PR's test loop is reproduced for options 4/16/32. Head: GREEN at -O2, and GREEN under ASan+UBSan.
NET_SO_DONTROUTEfrom the setsockopt option list0x10→ falls through toSO_RCVBUFNET_SO_DONTROUTEfrom the short-optlenexemptioncase NET_SO_DONTROUTE:in getsockopt0x10→SO_BROADCASTThe test covers every changed line.
Optional, non-blocking: the debt line could say what the flag does on each host. Microsoft's SOL_SOCKET options table says Winsock "silently ignore[s] this option and always consult[s] the routing table". So on Windows the flag only round-trips through get and set. On POSIX hosts, an off-link send fails with
ENETUNREACH, as on FreeBSD. That gap is worth one sentence indocs/dev/debt/libSceNet.md. JJenkx's Windows run shows the readback round-trips there.AI-assisted: yes