Skip to content

Commit

Permalink
enable IP_TRANSPARENT on epoll channel bind
Browse files Browse the repository at this point in the history
  • Loading branch information
argha-c committed Oct 2, 2023
1 parent 7c7786b commit 1d4541f
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 <a href="https://github.com/adamfisk/LittleProxy">LittleProxy</a> which was great as a reference.
*
* User: michaels
* Date: 11/8/14
* Time: 8:39 PM
* <p>
* 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 =
Expand Down Expand Up @@ -141,9 +137,9 @@ public class Server {
public static final AtomicReference<Class<? extends Channel>> 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
Expand All @@ -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.
Expand Down Expand Up @@ -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<ChannelOption<?>, ?> optionEntry : serverGroup.transportChannelOptions.entrySet()) {
serverBootstrap = serverBootstrap.option((ChannelOption) optionEntry.getKey(), optionEntry.getValue());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -543,4 +548,4 @@ private static boolean kqueueIsAvailable() {
}
return available;
}
}
}

0 comments on commit 1d4541f

Please sign in to comment.