Skip to content

Fix /net_restart and IPv6 multicast bugs - #2002

Open
slipher wants to merge 6 commits into
DaemonEngine:masterfrom
slipher:ip6lan
Open

slipher wants to merge 6 commits into
DaemonEngine:masterfrom
slipher:ip6lan

Conversation

@slipher

@slipher slipher commented Sep 30, 2026

Copy link
Copy Markdown
Member
  • Fix the net_restart command on *nix. It has the same issue with leaking sockets into the NaCl process that Windows did.
  • Fix various bugs with IPv6 multicast (used for finding LAN servers).

Correctly set the IPV6_MULTICAST_IF option on the IP6 socket. This
option affects outgoing multicast packets. Those are used by the client
when searching for IPv6 LAN servers. The old code setting
IPV6_MULTICAST_IF was useless because it was in NET_JoinMulticast6()
which is only called when starting a server.
Avoid leaking socket fd's into gamelogic subprocesses, which causes a
'bind: address already in use' error upon /net_restart.

The same bug was fixed for Windows in
f70cf74.
Internet sources say you are supposed to bind to the all-zeroes address
if you want to receive multicast packets, not the multicast address.
Indeed, when tested on Windows the attempt to bind to a multicast
address produced an error.
else
{
if ( ( multicast6_socket = NET_IP6Socket( net_mcast6addr->string, ntohs( boundto.sin6_port ), nullptr, &err ) ) == INVALID_SOCKET )
if ( ( multicast6_socket = NET_IP6Socket( nullptr, ntohs( boundto.sin6_port ), false, nullptr, &err ) ) == INVALID_SOCKET )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why nullptr now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Don't try to bind to IPv6 multicast address

Internet sources say you are supposed to bind to the all-zeroes address
if you want to receive multicast packets, not the multicast address.
Indeed, when tested on Windows the attempt to bind to a multicast
address produced an error.

And null is treated as the all-zeroes address.

for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i-- )
{
ip6_socket = NET_IP6Socket( net_ip6->string, port6, &boundto, &err );
bool sendingMulticast = !serverMode && !( net_enabled->integer & NET_DISABLEMCAST );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why conditional here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Only the client can send multicast packets. This is supposed to be the equivalent of the IPv4 broadcast, to search for servers in a LAN. The server responds with a normal packet.

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