Skip to content

Commit

Permalink
Try setting IP_RECVORIGDSTADDR when possible
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle committed Oct 14, 2024
1 parent d64c0b3 commit c3ac60c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.epoll.Native;
import io.netty.channel.unix.UnixChannelOption;
import lombok.experimental.UtilityClass;
Expand Down Expand Up @@ -70,19 +71,23 @@ public static boolean isReusePortAvailable() {
@SuppressWarnings({"rawtypes, unchecked"})
public static boolean setupBootstrap(AbstractBootstrap bootstrap) {
boolean success = true;
Channel channel = bootstrap.register().channel();
if (REUSEPORT_AVAILABLE) {
// Guessing whether so_reuseport is available based on kernel version is cool, but unreliable.
Channel channel = bootstrap.register().channel();
if (channel.config().setOption(UnixChannelOption.SO_REUSEPORT, true)) {
bootstrap.option(UnixChannelOption.SO_REUSEPORT, true);
} else {
// If this occurs, we guessed wrong and reuseport is not available
GeyserImpl.getInstance().getLogger().debug("so_reuseport is not available despite version being " + Native.KERNEL_VERSION);
success = false;
}
// Now yeet that channel
channel.close();

// Only possible on Linux with Epoll, but allows proper replies on multiple UDP interfaces when bound to INADDR_ANY
if (channel.config().setOption(EpollChannelOption.IP_RECVORIGDSTADDR, true)) {
bootstrap.option(EpollChannelOption.IP_RECVORIGDSTADDR, true);
}
}
channel.close();
return success;
}

Expand Down

0 comments on commit c3ac60c

Please sign in to comment.