Skip to content

NODERAWSOCKETS: support UDP multicast group membership - #28147

Merged
guybedford merged 4 commits into
mainfrom
gbedford/udp-multicast-membership
Nov 3, 2026
Merged

guybedford merged 4 commits into
mainfrom
gbedford/udp-multicast-membership

Conversation

@guybedford

@guybedford guybedford commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

This adds UDP multicast group membership to -sNODERAWSOCKETS.

Since #27921, setsockopt rejects options it doesn't model, so IP_ADD_MEMBERSHIP and its IPv6 equivalent now fail with ENOPROTOOPT. Before, they were silently accepted and had no effect.

Group membership is now modelled on both the dgram and udp_wrap backends, which both expose addMembership/dropMembership:

  • IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP (struct ip_mreq, or ip_mreqn with an interface address) and IPV6_JOIN_GROUP/IPV6_LEAVE_GROUP
  • a join made before bind() is applied once the socket is bound, since otherwise libuv would auto-bind it to an ephemeral port
  • groups are joined again on the new socket that a UDP re-connect swaps in (NODERAWSOCKETS: keep the local port when re-connecting a UDP socket #28146)
  • node picks the interface by address (IPv4) or by name (IPv6), so an interface given only by index returns ENODEV
  • as on Linux, the options are set-only, and getsockopt rejects them

test_noderawsockets_udp_multicast_membership covers join and leave, the kernel's EADDRINUSE on a duplicate join and EADDRNOTAVAIL on leaving a group that wasn't joined, a join before bind(), and a short optlen. The IPv6 part is skipped on hosts without an IPv6 multicast route.

Made with AI assistance under my review

@guybedford
guybedford added this pull request to stack #28148 November 3, 2026 05:10
@guybedford
guybedford marked this pull request as ready for review November 3, 2026 05:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements UDP multicast membership support (IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IPV6_JOIN_GROUP, and IPV6_LEAVE_GROUP) in the Node.js socket filesystem library, ensuring memberships are tracked and applied when sockets are bound or reconnected. A critical bug was identified in the IPv6 group address parsing, where 32-bit integers are incorrectly passed to inetNtop6 instead of a 16-byte array, resulting in invalid IPv6 addresses and causing the corresponding test to be silently skipped.

Comment thread src/lib/libsockfs_node.js Resolved
Comment thread src/lib/libsockfs_node.js Resolved
Comment thread src/lib/libsockfs_node.js Resolved
Comment thread src/lib/libsockfs_node.js Resolved
@guybedford
guybedford force-pushed the gbedford/udp-multicast-membership branch from 2d900a3 to dde8572 Compare November 3, 2026 21:51
@guybedford
guybedford force-pushed the gbedford/udp-reconnect-port branch from b9ac161 to 32595c3 Compare November 3, 2026 21:52
@guybedford
guybedford force-pushed the gbedford/udp-multicast-membership branch from dde8572 to d5ab72e Compare November 3, 2026 21:52
Since setsockopt started rejecting unmodelled options, IP_ADD_MEMBERSHIP
and friends fail with ENOPROTOOPT, where before they were silently
ignored.

Model IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP and IPV6_JOIN_GROUP/
IPV6_LEAVE_GROUP on both the dgram and udp_wrap backends. Joins made
before bind() are applied once the socket is bound, and are replayed on
the socket swapped in by a re-connect.
@guybedford
guybedford force-pushed the gbedford/udp-multicast-membership branch from 629bfeb to 163908f Compare November 3, 2026 21:58
@guybedford
guybedford removed this pull request from stack #28148 November 3, 2026 21:58
@guybedford
guybedford changed the base branch from gbedford/udp-reconnect-port to main November 3, 2026 21:58
@guybedford
guybedford enabled auto-merge (squash) November 3, 2026 21:59
@guybedford
guybedford merged commit 51bf0da into main Nov 3, 2026
44 checks passed
@guybedford
guybedford deleted the gbedford/udp-multicast-membership branch November 3, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants