feat(libSceNet): support SO_DONTROUTE in sceNetSetsockopt and sceNetGetsockopt #12918

Merged
Kikoarl merged 1 commit from upstream-pr/12918 into main 2026-11-04 20:00:28 +00:00
Kikoarl commented 2026-10-29 14:16:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-29T14:16:17Z.


What

Support NET_SO_DONTROUTE (0x10) in sceNetSetsockopt and sceNetGetsockopt (libSceNet).

FreeBSD 11.4 defines SO_DONTROUTE = 0x10, which bypasses normal routing tables and sends packets directly to the network interface. Kernel sockets already map GuestDontRoute to SO_DONTROUTE in core/libs/prx/libkernel/Socket/src/SocketOptions.cpp:123, but libSceNet previously lacked NET_SO_DONTROUTE = 0x10 and rejected both sceNetSetsockopt and sceNetGetsockopt with NET_EOPNOTSUPP.

This change:

  • Defines NET_SO_DONTROUTE = 0x10 in core/libs/prx/libSceNet/Export.cpp.
  • Adds NET_SO_DONTROUTE to sceNetSetsockopt mapping to SOL_SOCKET / SO_DONTROUTE.
  • Adds NET_SO_DONTROUTE to sceNetGetsockopt readback, returning 0x10 when enabled and 0 when disabled, matching FreeBSD 11.4 sogetopt flag bit behavior.
  • Extends GuestNetBooleanReadback.cpp to verify setsockopt and getsockopt for option 16 (NET_SO_DONTROUTE) across stream/dgram and IPv4/IPv6 sockets with variable buffer lengths and truncated readback.
  • Updates docs/dev/debt/libSceNet.md to reflect SO_DONTROUTE in the boolean readback entry.

Tested

  • Unit tests: Added option 16 to core/libs/tests/GuestNetBooleanReadback.cpp.
  • Executed ctest -R guest_net_boolean_readback and all 12 guest_net test suites in /tmp/anyps5_build: 100% passed (0 failures).
  • Verified python3 tools/check_conventions.py: 0 errors.

Checklist

  • Tested on local hardware
  • Code conventions verified via python3 tools/check_conventions.py
  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5069651968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12918). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-29T14:16:17Z. --- ### What Support `NET_SO_DONTROUTE` (`0x10`) in `sceNetSetsockopt` and `sceNetGetsockopt` (`libSceNet`). FreeBSD 11.4 defines `SO_DONTROUTE = 0x10`, which bypasses normal routing tables and sends packets directly to the network interface. Kernel sockets already map `GuestDontRoute` to `SO_DONTROUTE` in `core/libs/prx/libkernel/Socket/src/SocketOptions.cpp:123`, but `libSceNet` previously lacked `NET_SO_DONTROUTE = 0x10` and rejected both `sceNetSetsockopt` and `sceNetGetsockopt` with `NET_EOPNOTSUPP`. This change: - Defines `NET_SO_DONTROUTE = 0x10` in `core/libs/prx/libSceNet/Export.cpp`. - Adds `NET_SO_DONTROUTE` to `sceNetSetsockopt` mapping to `SOL_SOCKET` / `SO_DONTROUTE`. - Adds `NET_SO_DONTROUTE` to `sceNetGetsockopt` readback, returning `0x10` when enabled and `0` when disabled, matching FreeBSD 11.4 `sogetopt` flag bit behavior. - Extends `GuestNetBooleanReadback.cpp` to verify setsockopt and getsockopt for option `16` (`NET_SO_DONTROUTE`) across stream/dgram and IPv4/IPv6 sockets with variable buffer lengths and truncated readback. - Updates `docs/dev/debt/libSceNet.md` to reflect `SO_DONTROUTE` in the boolean readback entry. ### Tested - Unit tests: Added option `16` to `core/libs/tests/GuestNetBooleanReadback.cpp`. - Executed `ctest -R guest_net_boolean_readback` and all 12 `guest_net` test suites in `/tmp/anyps5_build`: 100% passed (0 failures). - Verified `python3 tools/check_conventions.py`: 0 errors. ### Checklist - [x] Tested on local hardware - [x] Code conventions verified via `python3 tools/check_conventions.py` - [x] AI-assisted: yes - [x] Depends on: none
rooklz commented 2026-10-29 17:31:57 +00:00 (Migrated from github.com)

Imported 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-tree onto main bb04a4f1ea: clean. git diff --check: clean. tools/check_conventions.py --base upstream/main: all checks passed.
  • Merge order with #11272 (Queuse, same file): stacking this PR on #11272 gives one textual conflict, the *optlen < sizeof(int) guard in sceNetGetsockopt. #11272 adds an empty line after it, and this PR adds NET_SO_DONTROUTE to it. Whichever lands second needs a one-line rebase. There is no semantic overlap.

Reference behaviour

  • FreeBSD 11.4 sys/kern/uipc_socket.c lists SO_DONTROUTE with the so_options flag cases in sosetopt (L2556) and sogetopt (L2797), and reads back so->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's SocketOptions.cpp already maps GuestDontRoute = 0x10 to host SO_DONTROUTE, so libSceNet now agrees with it.

Host primitive (macOS 15, arm64): I ran set/get of SO_DONTROUTE for AF_INET/AF_INET6 × STREAM/DGRAM with settings {1,-1,0,4,0}. All 20 setsockopt calls returned 0, and getsockopt returned 0x10 for non-zero settings and 0 for zero. With the flag set, a UDP sendto to an off-link address (8.8.8.8) fails with ENETUNREACH (51). A send to 127.0.0.1 succeeds. This matches FreeBSD 11.4 udp_output (SO_DONTROUTE → IP_ROUTETOIF, L1422) and ip_output's IP_ROUTETOIF branch returning ENETUNREACH when 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.

mutant result
drop NET_SO_DONTROUTE from the setsockopt option list RED
setsockopt map 0x10 → falls through to SO_RCVBUF RED
drop NET_SO_DONTROUTE from the short-optlen exemption RED
drop case NET_SO_DONTROUTE: in getsockopt RED
getsockopt map 0x10 → SO_BROADCAST RED

The 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 in docs/dev/debt/libSceNet.md. JJenkx's Windows run shows the readback round-trips there.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5702193433 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12918#pullrequestreview-5702193433). Originally posted by [rooklz](https://github.com/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-tree` onto `main` `bb04a4f1ea`: clean. `git diff --check`: clean. `tools/check_conventions.py --base upstream/main`: all checks passed. - Merge order with #11272 (Queuse, same file): stacking this PR on #11272 gives one textual conflict, the `*optlen < sizeof(int)` guard in `sceNetGetsockopt`. #11272 adds an empty line after it, and this PR adds `NET_SO_DONTROUTE` to it. Whichever lands second needs a one-line rebase. There is no semantic overlap. **Reference behaviour** - FreeBSD 11.4 `sys/kern/uipc_socket.c` lists `SO_DONTROUTE` with the `so_options` flag cases in `sosetopt` (L2556) and `sogetopt` (L2797), and reads back `so->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`'s `SocketOptions.cpp` already maps `GuestDontRoute = 0x10` to host `SO_DONTROUTE`, so `libSceNet` now agrees with it. **Host primitive (macOS 15, arm64):** I ran set/get of `SO_DONTROUTE` for AF_INET/AF_INET6 × STREAM/DGRAM with settings `{1,-1,0,4,0}`. All 20 setsockopt calls returned 0, and getsockopt returned `0x10` for non-zero settings and `0` for zero. With the flag set, a UDP `sendto` to an off-link address (8.8.8.8) fails with `ENETUNREACH` (51). A send to 127.0.0.1 succeeds. This matches FreeBSD 11.4 `udp_output` (`SO_DONTROUTE` → `IP_ROUTETOIF`, L1422) and `ip_output`'s `IP_ROUTETOIF` branch returning `ENETUNREACH` when 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. | mutant | result | |---|---| | drop `NET_SO_DONTROUTE` from the setsockopt option list | RED | | setsockopt map `0x10` → falls through to `SO_RCVBUF` | RED | | drop `NET_SO_DONTROUTE` from the short-`optlen` exemption | RED | | drop `case NET_SO_DONTROUTE:` in getsockopt | RED | | getsockopt map `0x10` → `SO_BROADCAST` | RED | The 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](https://learn.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options) 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 in `docs/dev/debt/libSceNet.md`. JJenkx's Windows run shows the readback round-trips there. AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12918
No description provided.