From 540c90546f4749130aad611b8a14373e427185c3 Mon Sep 17 00:00:00 2001 From: KarloX2 <15713553+KarloX2@users.noreply.github.com> Date: Tue, 19 Feb 2019 17:22:11 +0100 Subject: [PATCH] CORE-6004: Add a switch to disable the "TCP Loopback Fast Path" option (Windows only) --- builds/install/misc/firebird.conf.in | 8 ++++++++ doc/Firebird_conf.txt | 1 + src/common/config/config.cpp | 6 ++++++ src/common/config/config.h | 4 ++++ src/remote/inet.cpp | 16 +++++++++------- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/builds/install/misc/firebird.conf.in b/builds/install/misc/firebird.conf.in index 79ebef7655..556a3a083f 100644 --- a/builds/install/misc/firebird.conf.in +++ b/builds/install/misc/firebird.conf.in @@ -768,6 +768,14 @@ # #TcpNoNagle = 1 +# +# Either enables or disables the "TCP Loopback Fast Path" feature (SIO_LOOPBACK_FAST_PATH). +# Applies to Windows (version 8/2012 or higher) only. +# +# Type: Boolean, default 1 (true) +# +#TcpLoopbackFastPathOption = 1 + # # Allows setting of IPV6_V6ONLY socket option. If enabled, IPv6 sockets # allow only IPv6 communication and separate sockets must be used for diff --git a/doc/Firebird_conf.txt b/doc/Firebird_conf.txt index b54283614d..4d26cb9375 100644 --- a/doc/Firebird_conf.txt +++ b/doc/Firebird_conf.txt @@ -124,6 +124,7 @@ Only meaningful for Windows SS on SMP systems. OldParameterOrdering boolean default false TcpRemoteBufferSize integer default 8192 (bytes) TcpNoNagle boolean default false +TcpLoopbackFastPathOption boolean default true IpcMapSize integer default 4096 (bytes) DefaultDbCachePages integer default SS: 2048. CS: 75 ConnectionTimeout integer default 180 (seconds) diff --git a/src/common/config/config.cpp b/src/common/config/config.cpp index 776a519c5f..70e04b92a7 100644 --- a/src/common/config/config.cpp +++ b/src/common/config/config.cpp @@ -148,6 +148,7 @@ const Config::ConfigEntry Config::entries[MAX_CONFIG_KEY] = {TYPE_INTEGER, "CpuAffinityMask", (ConfigValue) 0}, {TYPE_INTEGER, "TcpRemoteBufferSize", (ConfigValue) 8192}, // bytes {TYPE_BOOLEAN, "TcpNoNagle", (ConfigValue) true}, + {TYPE_BOOLEAN, "TcpLoopbackFastPathOption",(ConfigValue) true}, {TYPE_INTEGER, "DefaultDbCachePages", (ConfigValue) -1}, // pages {TYPE_INTEGER, "ConnectionTimeout", (ConfigValue) 180}, // seconds {TYPE_INTEGER, "DummyPacketInterval", (ConfigValue) 0}, // seconds @@ -492,6 +493,11 @@ bool Config::getTcpNoNagle() const return get(KEY_TCP_NO_NAGLE); } +bool Config::getTcpLoopbackFastPathOption() const +{ + return get(KEY_TCP_LOOPBACK_FAST_PATH_OPTION); +} + bool Config::getIPv6V6Only() const { return get(KEY_IPV6_V6ONLY); diff --git a/src/common/config/config.h b/src/common/config/config.h index 2b21714dff..4cb7bbba33 100644 --- a/src/common/config/config.h +++ b/src/common/config/config.h @@ -95,6 +95,7 @@ public: KEY_CPU_AFFINITY_MASK, KEY_TCP_REMOTE_BUFFER_SIZE, KEY_TCP_NO_NAGLE, + KEY_TCP_LOOPBACK_FAST_PATH_OPTION, KEY_DEFAULT_DB_CACHE_PAGES, KEY_CONNECTION_TIMEOUT, KEY_DUMMY_PACKET_INTERVAL, @@ -252,6 +253,9 @@ public: // Disable Nagle algorithm bool getTcpNoNagle() const; + // Enable or disable the TCP Loopback Fast Path option + bool getTcpLoopbackFastPathOption() const; + // Let IPv6 socket accept only IPv6 packets bool getIPv6V6Only() const; diff --git a/src/remote/inet.cpp b/src/remote/inet.cpp index b9ff2ddb7f..7cc4e52712 100644 --- a/src/remote/inet.cpp +++ b/src/remote/inet.cpp @@ -3242,16 +3242,18 @@ static bool setNoNagleOption(rem_port* port) bool setFastLoopbackOption(SOCKET s) { #ifdef WIN_NT - int optval = 1; - DWORD bytes = 0; + if (Config::getDefaultConfig()->getTcpLoopbackFastPathOption()) + { + int optval = 1; + DWORD bytes = 0; - int ret = WSAIoctl(s, SIO_LOOPBACK_FAST_PATH, &optval, sizeof(optval), - NULL, 0, &bytes, 0, 0); + int ret = WSAIoctl(s, SIO_LOOPBACK_FAST_PATH, &optval, sizeof(optval), + NULL, 0, &bytes, 0, 0); - return (ret == 0); -#else - return false; + return (ret == 0); + } #endif + return false; } void setStopMainThread(FPTR_INT func)