fix(libkernel): join and leave multicast groups as measured on a PS5 #10331

Merged
orezraey merged 17 commits from upstream-pr/10331 into main 2026-10-24 19:03:17 +00:00
orezraey commented 2026-10-23 18:10:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T18:10:28Z.


What

Multicast group membership and IP_MULTICAST_IF 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 (pmcast). This branch is on top of #10330 (and so #10327, #10320 and #10302), which edit the same option code and debt entries.

On a datagram socket the console:

  • joins 224.0.0.251 through INADDR_ANY and 224.0.0.252 through 127.0.0.1, fails a second join of the same group with EADDRINUSE (48), and takes a 12-byte value as an 8-byte ip_mreq;
  • fails a value shorter than 8 bytes and a group outside 224.0.0.0/4 with EINVAL, and an interface address it does not have with EADDRNOTAVAIL;
  • drops a joined group, and fails dropping it again or dropping one never joined with EADDRNOTAVAIL (49);
  • reads IP_MULTICAST_IF as INADDR_ANY, then as the address set, accepts a zeroed 12-byte ip_mreqn, and fails a value shorter than 4 bytes with EINVAL.

A stream socket fails IP_ADD_MEMBERSHIP with EOPNOTSUPP (45).

AnyPS5 failed all three options with ENOPROTOOPT, so a title could not join a group for LAN discovery. They now check what the console checked, track the joined groups per socket (Winsock answers a second join with EINVAL, not EADDRINUSE), and are set on the host socket. The other multicast options also fail with EOPNOTSUPP on a stream socket now, as FreeBSD 11.4's inp_setmoptions and inp_getmoptions do, and a drop through INADDR_ANY leaves the first joined group of that address on any interface, as its inp_leave_group does; neither was measured. An ip_mreqn with an interface index or with any non-zero byte in its address fields throws, since only the all-zero form was measured, and so does reading IP_MULTICAST_IF into 12 bytes, and the debt entry lists that and the interface error that comes from the host.

Tested

Windows 11, MinGW (winlibs).

  • guest_socket_options checks the short and unicast values, the stream socket, a drop of a group never joined and the all-zero 12-byte IP_MULTICAST_IF; the forms with a non-zero address are not pinned by a test. guest_socket_options_multicast (the same executable in its multicast mode) requires the join, the double join, both drops, a join through 127.0.0.1 dropped through INADDR_ANY and the loopback IP_MULTICAST_IF readback to succeed, so it fails on a host that cannot join a group. The socket and net tests pass three runs in a row.
  • The full suite (-E "^agc_|^select_tests$") passes apart from guest_kqueue, which fails only under -j 14, as on main.
  • 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: #10330, #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:4987245156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10331). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T18:10:28Z. --- ### What Multicast group membership and `IP_MULTICAST_IF` 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) (`pmcast`). This branch is on top of #10330 (and so #10327, #10320 and #10302), which edit the same option code and debt entries. On a datagram socket the console: - joins 224.0.0.251 through `INADDR_ANY` and 224.0.0.252 through 127.0.0.1, fails a second join of the same group with `EADDRINUSE` (48), and takes a 12-byte value as an 8-byte `ip_mreq`; - fails a value shorter than 8 bytes and a group outside 224.0.0.0/4 with `EINVAL`, and an interface address it does not have with `EADDRNOTAVAIL`; - drops a joined group, and fails dropping it again or dropping one never joined with `EADDRNOTAVAIL` (49); - reads `IP_MULTICAST_IF` as `INADDR_ANY`, then as the address set, accepts a zeroed 12-byte `ip_mreqn`, and fails a value shorter than 4 bytes with `EINVAL`. A stream socket fails `IP_ADD_MEMBERSHIP` with `EOPNOTSUPP` (45). AnyPS5 failed all three options with `ENOPROTOOPT`, so a title could not join a group for LAN discovery. They now check what the console checked, track the joined groups per socket (Winsock answers a second join with `EINVAL`, not `EADDRINUSE`), and are set on the host socket. The other multicast options also fail with `EOPNOTSUPP` on a stream socket now, as FreeBSD 11.4's `inp_setmoptions` and `inp_getmoptions` do, and a drop through `INADDR_ANY` leaves the first joined group of that address on any interface, as its `inp_leave_group` does; neither was measured. An `ip_mreqn` with an interface index or with any non-zero byte in its address fields throws, since only the all-zero form was measured, and so does reading `IP_MULTICAST_IF` into 12 bytes, and the debt entry lists that and the interface error that comes from the host. ### 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 short and unicast values, the stream socket, a drop of a group never joined and the all-zero 12-byte `IP_MULTICAST_IF`; the forms with a non-zero address are not pinned by a test. `guest_socket_options_multicast` (the same executable in its `multicast` mode) requires the join, the double join, both drops, a join through 127.0.0.1 dropped through `INADDR_ANY` and the loopback `IP_MULTICAST_IF` readback to succeed, so it fails on a host that cannot join a group. The socket and net tests pass three runs in a row. - The full suite (`-E "^agc_|^select_tests$"`) passes apart from `guest_kqueue`, which fails only under `-j 14`, as on `main`. - `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: #10330, #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:13 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Checked against main 39a36bbec8 and gist d9efe0da (pmcast.c/pmcast.log), FreeBSD release/11.4.0 sys/netinet/in_mcast.c:

  • The join/drop/IP_MULTICAST_IF errors match pmcast.log case by case (48/22/22/49 for joins, 49 for both failed drops, 42 for a membership get, 45 on the stream socket). The stack merges cleanly into current main; it carries #10320 and needs to land after it.
  • Drop matching (SocketOptions.cpp:368) needs the exact (group, interface address) used to join. FreeBSD 11.4 inp_leave_group leaves ifp NULL for INADDR_ANY (in_mcast.c:2286-2296), and imo_match_group then matches the group on any interface. So join {224.0.0.252, 127.0.0.1} followed by drop {224.0.0.252, 0.0.0.0} succeeds in that code, but returns EADDRNOTAVAIL here. pmcast doesn't measure this. Could it either match by group when the interface is INADDR_ANY, or be listed in the debt entry next to the join-side note?
  • IP_MULTICAST_IF get with a 12-byte buffer (SocketOptions.cpp:430) returns 4 bytes, whereas FreeBSD 11.4 inp_getmoptions (in_mcast.c:1803-1810) returns the whole ip_mreqn. Since the unmeasured 12-byte set forms now throw, should the 12-byte get also throw, or go in the debt entry?
  • Small description fix: pmcast.c joins 224.0.0.252 (not .251) through 127.0.0.1.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638289951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10331#pullrequestreview-5638289951). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:48:13Z. **Review:** COMMENTED --- Checked against main 39a36bbec8 and gist d9efe0da (pmcast.c/pmcast.log), FreeBSD release/11.4.0 sys/netinet/in_mcast.c: - The join/drop/`IP_MULTICAST_IF` errors match pmcast.log case by case (48/22/22/49 for joins, 49 for both failed drops, 42 for a membership get, 45 on the stream socket). The stack merges cleanly into current main; it carries #10320 and needs to land after it. - Drop matching (SocketOptions.cpp:368) needs the exact (group, interface address) used to join. FreeBSD 11.4 `inp_leave_group` leaves `ifp` NULL for INADDR_ANY (in_mcast.c:2286-2296), and `imo_match_group` then matches the group on any interface. So join {224.0.0.252, 127.0.0.1} followed by drop {224.0.0.252, 0.0.0.0} succeeds in that code, but returns EADDRNOTAVAIL here. pmcast doesn't measure this. Could it either match by group when the interface is INADDR_ANY, or be listed in the debt entry next to the join-side note? - `IP_MULTICAST_IF` get with a 12-byte buffer (SocketOptions.cpp:430) returns 4 bytes, whereas FreeBSD 11.4 `inp_getmoptions` (in_mcast.c:1803-1810) returns the whole `ip_mreqn`. Since the unmeasured 12-byte set forms now throw, should the 12-byte get also throw, or go in the debt entry? - Small description fix: pmcast.c joins 224.0.0.252 (not .251) through 127.0.0.1. 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!10331
No description provided.