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_DST socket option is Linux-specific)
  • Netty epoll transport (EpollSocketChannel) — the NIO transport does not expose the raw file descriptor, so this resolver returns null for 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.

See Also:
  • Constructor Details

    • SoOriginalDstResolver

      public SoOriginalDstResolver()
  • Method Details

    • isSupported

      public boolean isSupported()
      Returns true if 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 false so the resolver harmlessly falls through to the next strategy in the chain.

    • resolve

      public InetSocketAddress resolve(io.netty.channel.Channel channel)
      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 getsockopt call fails (errno, decode failure, etc.)
      Specified by:
      resolve in interface TransparentProxyHandler.OriginalDestinationResolver
      Parameters:
      channel - the accepted Netty channel
      Returns:
      the original destination, or null if unavailable