Skip to content

Fix LAN discovery for SRB2 servers

Hanicef requested to merge Hanicef/SRB2:fix-lan-discovery into next

so, turns out SRB2 had logic to be able to automatically discover servers over LAN, but it didn't work. for IPv4, the reason was simple: no port was specified for LAN discovery, so the system just failed to send the packet from the system (that's what the CONS_Alert helped me discover: i got EINVAL whenever i tried to search).

with IPv6, however, the cause was more complex. because of how IPv6 scopes work, the concept of broadcasting doesn't exist for IPv6. instead, it's replaced with something called multicasting, which is a more efficient method for discovering hosts as it only sends packets to systems that actually listens for it rather than sending it to all addresses on the network. the way that it works is that it splits the address into two parts: the part that specifies which scope to send it to and the other part that specifies the address that it sends towards. the scope is important since it tells how deep to send the packet; in this case, we use ff15 to specify a dynamic address on site level (which basically means: send it to every single node that listens to this on the network on all zones). the address is then used to limit off so only servers that are actually hosting an SRB2 server actually receives the packet (the address can be anything, but in this case i picked 57e1:1a12 in hopes that nobody else will pick the same address).

then, just like you need to do SO_BROADCAST in order to allow broadcasting on IPv4, you need to specify which multicast address to listen to in order to receive multicast packets, which is done with IPV6_JOIN_GROUP. the system will then automatically send an ICMPv6 packet to the router to tell it that it want to receive packets from that address, and thus allowing servers to be discovered via IPv6.

(i also went ahead and removed some redundant IP address lookups, since looking up address constants is pointless)

NOTE: you'll probably notice that LAN servers will appear twice in the server list. this is not a bug but rather a side effect caused by the server being discovered over both IPv4 and IPv6. i plan to add a feature that allows us to differentiate IPv4 and IPv6 servers by adding some sort of indicator on IPv6 servers, but that's for another PR.

Merge request reports