From 19e7d48ce89422091f9af93038b9fee075d46e9e Mon Sep 17 00:00:00 2001 From: animalize Date: Tue, 27 Feb 2018 02:10:36 +0800 Subject: bpo-32394: Remove some TCP options on old version Windows. (GH-5523) --- Modules/socketmodule.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'Modules/socketmodule.c') diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index aa715bf95d..c7a0751202 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -305,6 +305,70 @@ http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/net/getaddrinfo.c.diff?r1=1.82& /* Provides the IsWindows7SP1OrGreater() function */ #include +/* remove some flags on older version Windows during run-time. + https://msdn.microsoft.com/en-us/library/windows/desktop/ms738596.aspx */ +typedef struct { + DWORD build_number; /* available starting with this Win10 BuildNumber */ + const char flag_name[20]; +} FlagRuntimeInfo; + +/* IMPORTANT: make sure the list ordered by descending build_number */ +static FlagRuntimeInfo win_runtime_flags[] = { + /* available starting with Windows 10 1709 */ + {16299, "TCP_KEEPIDLE"}, + {16299, "TCP_KEEPINTVL"}, + /* available starting with Windows 10 1703 */ + {15063, "TCP_KEEPCNT"}, + /* available starting with Windows 10 1607 */ + {14393, "TCP_FASTOPEN"} +}; + +static void +remove_unusable_flags(PyObject *m) +{ + PyObject *dict; + OSVERSIONINFOEX info; + DWORDLONG dwlConditionMask; + + dict = PyModule_GetDict(m); + if (dict == NULL) { + return; + } + + /* set to Windows 10, except BuildNumber. */ + memset(&info, 0, sizeof(info)); + info.dwOSVersionInfoSize = sizeof(info); + info.dwMajorVersion = 10; + info.dwMinorVersion = 0; + + /* set Condition Mask */ + dwlConditionMask = 0; + VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + + for (int i=0; i @@ -7890,5 +7954,11 @@ PyInit__socket(void) #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) netdb_lock = PyThread_allocate_lock(); #endif + +#ifdef MS_WINDOWS + /* remove some flags on older version Windows during run-time */ + remove_unusable_flags(m); +#endif + return m; } -- cgit v1.2.1