fix(libkernel): keep IP_TTL, IP_TOS and the multicast options as measured on a PS5 #10320

Merged
orezraey merged 4 commits from upstream-pr/10320 into main 2026-10-24 15:18:18 +00:00
orezraey commented 2026-10-23 17:37:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T17:37:36Z.


What

The IPPROTO_IP socket options measured on a retail PS5 (firmware 13.60) through libkernel_sys.sprx from a payload process. The source and console log are in this gist (pinet4; pinet showed the defaults first). This branch is on top of #10302, which split the socket options debt entry this one edits.

On an AF_INET socket the console:

  • starts IP_TTL at 64, IP_TOS at 0, IP_MULTICAST_TTL at 1 and IP_MULTICAST_LOOP at 1;
  • keeps the low byte of IP_TTL and IP_TOS (300 reads back as 44, -1 as 255, 0x1ff as 0xff, 0 is kept) and fails a value shorter than an int with EINVAL;
  • takes a one-byte or an int IP_MULTICAST_TTL, failing an int above 255 with EINVAL, and reads IP_MULTICAST_LOOP back as 0 or 1;
  • fails the IPPROTO_IP level on an AF_INET6 socket and an unknown level (99) with EINVAL, and an unknown IPPROTO_IP option with ENOPROTOOPT.

AnyPS5 failed the whole IPPROTO_IP level and every unknown level with ENOPROTOOPT. The four options are now kept per socket; IP_TTL (when not 0) and the multicast options are also set on the host socket, so packets leave with them, and an accepted socket takes IP_TTL and IP_TOS from its listener as FreeBSD's syncache_socket does. An int IP_MULTICAST_LOOP keeps only its low byte, as FreeBSD 11.4's inp_setmoptions does (the console was only given 0 and 5). What still differs is in a new debt entry: IP_TOS is not applied to the host's packets, the host's default time to live is not changed to 64, and Winsock applies IP_MULTICAST_LOOP on the receiving socket rather than the sender. IP_MULTICAST_IF, the membership options, SO_REUSEPORT, SO_DEBUG, SO_TIMESTAMP and the TCP keepalive options, which the same log shows the console accepting, are left for separate changes.

Tested

Windows 11, MinGW (winlibs).

  • guest_socket_options checks the defaults, the byte truncation, the one-byte and oversized multicast values, the low byte of an int IP_MULTICAST_LOOP, the AF_INET6 and unknown level answers. The socket and net tests pass three runs in a row.
  • The full suite (-E "^agc_|^select_tests$") passes.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #10302, #8448; #8448 edits the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4986838566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10320). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T17:37:36Z. --- ### What The `IPPROTO_IP` socket options measured on a retail PS5 (firmware 13.60) through `libkernel_sys.sprx` from a payload process. The source and console log are in [this gist](https://gist.github.com/orezraey/d9efe0da49405f19d72cb35279c0db52) (`pinet4`; `pinet` showed the defaults first). This branch is on top of #10302, which split the socket options debt entry this one edits. On an `AF_INET` socket the console: - starts `IP_TTL` at 64, `IP_TOS` at 0, `IP_MULTICAST_TTL` at 1 and `IP_MULTICAST_LOOP` at 1; - keeps the low byte of `IP_TTL` and `IP_TOS` (300 reads back as 44, -1 as 255, 0x1ff as 0xff, 0 is kept) and fails a value shorter than an `int` with `EINVAL`; - takes a one-byte or an `int` `IP_MULTICAST_TTL`, failing an `int` above 255 with `EINVAL`, and reads `IP_MULTICAST_LOOP` back as 0 or 1; - fails the `IPPROTO_IP` level on an `AF_INET6` socket and an unknown level (99) with `EINVAL`, and an unknown `IPPROTO_IP` option with `ENOPROTOOPT`. AnyPS5 failed the whole `IPPROTO_IP` level and every unknown level with `ENOPROTOOPT`. The four options are now kept per socket; `IP_TTL` (when not 0) and the multicast options are also set on the host socket, so packets leave with them, and an accepted socket takes `IP_TTL` and `IP_TOS` from its listener as FreeBSD's `syncache_socket` does. An `int` `IP_MULTICAST_LOOP` keeps only its low byte, as FreeBSD 11.4's `inp_setmoptions` does (the console was only given 0 and 5). What still differs is in a new debt entry: `IP_TOS` is not applied to the host's packets, the host's default time to live is not changed to 64, and Winsock applies `IP_MULTICAST_LOOP` on the receiving socket rather than the sender. `IP_MULTICAST_IF`, the membership options, `SO_REUSEPORT`, `SO_DEBUG`, `SO_TIMESTAMP` and the TCP keepalive options, which the same log shows the console accepting, are left for separate changes. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW (winlibs). - `guest_socket_options` checks the defaults, the byte truncation, the one-byte and oversized multicast values, the low byte of an `int` `IP_MULTICAST_LOOP`, the `AF_INET6` and unknown level answers. The socket and net tests pass three runs in a row. - The full suite (`-E "^agc_|^select_tests$"`) passes. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py`: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #10302, #8448; #8448 edits the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 12:48:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:48:12Z.

Review: COMMENTED


Checked against main 39a36bbec8 and gist d9efe0da (pinet4.c/pinet4.log), FreeBSD release/11.4.0 sys/netinet/in_mcast.c and Microsoft's IPPROTO_IP socket options page:

  • Every measured value in the description matches pinet4.log: the defaults, the low-byte TTL/TOS storage, the short-value EINVAL, the one-byte and >255 multicast TTL, the AF_INET6 and level-99 EINVAL, and ENOPROTOOPT for an unknown option. The branch also merges cleanly into current main.
  • IP_MULTICAST_LOOP with an int above 255 (SocketOptions.cpp:309): FreeBSD 11.4 inp_setmoptions (in_mcast.c:2799-2802) truncates to u_char before !!, so an int 256 turns loopback off, but number != 0 here turns it on. The probe only tried 0 and 5, so this isn't measured. Would (number & 0xff) != 0 be the safer reading?
  • Microsoft's docs say Winsock's IP_MULTICAST_LOOP takes effect on the receiving socket, while the BSD option acts on the sender. Passing the guest value to the host therefore may not give the console's meaning on Windows. I couldn't run this; could the new debt entry mention it?
  • On a stream socket the multicast TTL/LOOP options still reach the host here, where FreeBSD 11.4 returns EOPNOTSUPP (in_mcast.c:2713-2715). #10331 adds that check, so this only matters if this PR lands on its own.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638289890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10320#pullrequestreview-5638289890). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:48:12Z. **Review:** COMMENTED --- Checked against main 39a36bbec8 and gist d9efe0da (pinet4.c/pinet4.log), FreeBSD release/11.4.0 sys/netinet/in_mcast.c and Microsoft's IPPROTO_IP socket options page: - Every measured value in the description matches pinet4.log: the defaults, the low-byte TTL/TOS storage, the short-value EINVAL, the one-byte and >255 multicast TTL, the AF_INET6 and level-99 EINVAL, and ENOPROTOOPT for an unknown option. The branch also merges cleanly into current main. - `IP_MULTICAST_LOOP` with an int above 255 (SocketOptions.cpp:309): FreeBSD 11.4 `inp_setmoptions` (in_mcast.c:2799-2802) truncates to `u_char` before `!!`, so an int 256 turns loopback off, but `number != 0` here turns it on. The probe only tried 0 and 5, so this isn't measured. Would `(number & 0xff) != 0` be the safer reading? - Microsoft's docs say Winsock's `IP_MULTICAST_LOOP` takes effect on the receiving socket, while the BSD option acts on the sender. Passing the guest value to the host therefore may not give the console's meaning on Windows. I couldn't run this; could the new debt entry mention it? - On a stream socket the multicast TTL/LOOP options still reach the host here, where FreeBSD 11.4 returns EOPNOTSUPP (in_mcast.c:2713-2715). #10331 adds that check, so this only matters if this PR lands on its own. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10320
No description provided.