Package org.mockserver.netty.proxy
Class SoOriginalDstResolver
java.lang.Object
org.mockserver.netty.proxy.SoOriginalDstResolver
- All Implemented Interfaces:
TransparentProxyHandler.OriginalDestinationResolver
public class SoOriginalDstResolver
extends Object
implements TransparentProxyHandler.OriginalDestinationResolver
Resolves the original destination of a transparently intercepted TCP connection
by calling
getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, ...) via JNA on Linux.
This is an O(1) socket-option read — significantly faster than the O(n)
/proc/net/nf_conntrack scan used by ConntrackOriginalDestinationResolver.
It is tried first in the CompositeOriginalDestinationResolver chain.
Platform requirements:
- Linux (the
SO_ORIGINAL_DSTsocket option is Linux-specific) - Netty epoll transport (
EpollSocketChannel) — the NIO transport does not expose the raw file descriptor, so this resolver returnsnullfor NIO channels (allowing the conntrack resolver to take over) - JNA native library loadable at runtime
On unsupported platforms (macOS, Windows, or Linux without epoll transport), this
resolver returns null from resolve(Channel), causing the composite
chain to proceed to the next strategy. It never throws.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif this resolver can function on the current platform: Linux OS, Netty epoll transport available, and JNA native loadable.resolve(io.netty.channel.Channel channel) Resolves the original destination for the given channel.
-
Constructor Details
-
SoOriginalDstResolver
public SoOriginalDstResolver()
-
-
Method Details
-
isSupported
public boolean isSupported()Returnstrueif this resolver can function on the current platform: Linux OS, Netty epoll transport available, and JNA native loadable.All checks are performed defensively — any linkage error, class-not-found, or unsatisfied-link causes this to return
falseso the resolver harmlessly falls through to the next strategy in the chain. -
resolve
Resolves the original destination for the given channel.Returns
null(never throws) when:- The platform is unsupported (not Linux, no epoll, no JNA)
- The channel is not an
EpollSocketChannel(e.g., NIO transport) - The
getsockoptcall fails (errno, decode failure, etc.)
- Specified by:
resolvein interfaceTransparentProxyHandler.OriginalDestinationResolver- Parameters:
channel- the accepted Netty channel- Returns:
- the original destination, or
nullif unavailable
-