From 1d4541fa27eaa5cd116eaf26efd70cee76b4c30d Mon Sep 17 00:00:00 2001 From: argha-c <007.argha@gmail.com> Date: Mon, 2 Oct 2023 11:34:38 -0700 Subject: [PATCH] enable IP_TRANSPARENT on epoll channel bind --- .../com/netflix/zuul/netty/server/Server.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java b/zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java index 675db44d06..2c87edda66 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java +++ b/zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java @@ -16,6 +16,7 @@ package com.netflix.zuul.netty.server; +import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.VisibleForTesting; import com.netflix.appinfo.InstanceInfo; import com.netflix.config.DynamicBooleanProperty; @@ -63,9 +64,6 @@ import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutorChooserFactory; import io.netty.util.concurrent.ThreadPerTaskExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.net.InetSocketAddress; import java.nio.channels.spi.SelectorProvider; import java.util.ArrayList; @@ -80,21 +78,19 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; - -import static com.google.common.base.Preconditions.checkNotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * * NOTE: Shout-out to LittleProxy which was great as a reference. - * - * User: michaels - * Date: 11/8/14 - * Time: 8:39 PM + *

+ * User: michaels Date: 11/8/14 Time: 8:39 PM */ public class Server { + /** - * This field is effectively a noop, as Epoll is enabled automatically if available. This can be disabled by - * using the {@link #FORCE_NIO} property. + * This field is effectively a noop, as Epoll is enabled automatically if available. This can be disabled by using + * the {@link #FORCE_NIO} property. */ @Deprecated public static final DynamicBooleanProperty USE_EPOLL = @@ -141,9 +137,9 @@ public class Server { public static final AtomicReference> defaultOutboundChannelType = new AtomicReference<>(); /** - * Use {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics, - * EventLoopConfig)} - * instead. + * Use + * {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics, + * EventLoopConfig)} instead. */ @SuppressWarnings("rawtypes") @Deprecated @@ -161,9 +157,9 @@ public Server( } /** - * Use {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics, - * EventLoopConfig)} - * instead. + * Use + * {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics, + * EventLoopConfig)} instead. */ @SuppressWarnings({"unchecked", "rawtypes" }) // Channel init map has the wrong generics and we can't fix without api breakage. @@ -298,6 +294,11 @@ private ChannelFuture setupServerBootstrap( serverBootstrap.childOption(ChannelOption.TCP_NODELAY, true); serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); + if (epollIsAvailable()) { + LOG.info("******* Enabling IP_TRANSPARENT for epoll channel bound to {}", listenAddress); + serverBootstrap.childOption(EpollChannelOption.IP_TRANSPARENT, true); + } + // Apply transport specific socket options. for (Map.Entry, ?> optionEntry : serverGroup.transportChannelOptions.entrySet()) { serverBootstrap = serverBootstrap.option((ChannelOption) optionEntry.getKey(), optionEntry.getValue()); @@ -329,14 +330,18 @@ private ChannelFuture setupServerBootstrap( /** * Override for metrics or informational purposes * - * @param clientToProxyBossPool - acceptor pool + * @param clientToProxyBossPool - acceptor pool * @param clientToProxyWorkerPool - worker pool */ public void postEventLoopCreationHook( - EventLoopGroup clientToProxyBossPool, EventLoopGroup clientToProxyWorkerPool) {} + EventLoopGroup clientToProxyBossPool, EventLoopGroup clientToProxyWorkerPool) { + } private final class ServerGroup { - /** A name for this ServerGroup to use in naming threads. */ + + /** + * A name for this ServerGroup to use in naming threads. + */ private final String name; private final int acceptorThreads; @@ -543,4 +548,4 @@ private static boolean kqueueIsAvailable() { } return available; } -} \ No newline at end of file +}