From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 3967A3857007; Wed, 1 Jul 2020 18:32:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3967A3857007 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: tcp: Support TCP_FASTOPEN X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: e037192b505b4f233fca9a6deafc9797210f6693 X-Git-Newrev: 0feb77c26084be83ce3aaeebc17b999bb3627efa Message-Id: <20200701183228.3967A3857007@sourceware.org> Date: Wed, 1 Jul 2020 18:32:28 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jul 2020 18:32:28 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0feb77c26084be83ce3aaeebc17b999bb3627efa commit 0feb77c26084be83ce3aaeebc17b999bb3627efa Author: Corinna Vinschen Date: Tue Jun 30 14:34:19 2020 +0200 Cygwin: tcp: Support TCP_FASTOPEN TCP_FASTOPEN is supported since W10 1607. Fake otherwise. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.h | 3 ++- winsup/cygwin/fhandler_socket_inet.cc | 47 ++++++++++++++++++++++++++++++++--- winsup/cygwin/include/netinet/tcp.h | 1 + winsup/cygwin/wincap.cc | 44 ++++++++++++++++++++++++++++++++ winsup/cygwin/wincap.h | 2 ++ 5 files changed, 93 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index c6ce6d8e1..57f282105 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -718,7 +718,8 @@ class fhandler_socket_wsock: public fhandler_socket class fhandler_socket_inet: public fhandler_socket_wsock { private: - bool oobinline; /* True if option SO_OOBINLINE is set */ + bool oobinline; /* True if option SO_OOBINLINE is set */ + bool tcp_fastopen; /* True if TCP_FASTOPEN is set on older systems */ protected: int af_local_connect () { return 0; } diff --git a/winsup/cygwin/fhandler_socket_inet.cc b/winsup/cygwin/fhandler_socket_inet.cc index ad17f48f1..1e837d72c 100644 --- a/winsup/cygwin/fhandler_socket_inet.cc +++ b/winsup/cygwin/fhandler_socket_inet.cc @@ -691,7 +691,8 @@ fhandler_socket_wsock::set_socket_handle (SOCKET sock, int af, int type, fhandler_socket_inet::fhandler_socket_inet () : fhandler_socket_wsock (), - oobinline (false) + oobinline (false), + tcp_fastopen (false) { } @@ -1693,6 +1694,20 @@ fhandler_socket_inet::setsockopt (int level, int optname, const void *optval, ignore = true; break; + case TCP_FASTOPEN: + /* Fake FastOpen on older systems. */ + if (!wincap.has_tcp_fastopen ()) + { + if (type != SOCK_STREAM) + { + set_errno (EOPNOTSUPP); + return -1; + } + ignore = true; + tcp_fastopen = *(int *) optval ? true : false; + } + break; + default: break; } @@ -1825,6 +1840,29 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval, optname = convert_ws1_ip_optname (optname); break; + case IPPROTO_TCP: + switch (optname) + { + case TCP_FASTOPEN: + /* Fake FastOpen on older systems */ + if (!wincap.has_tcp_fastopen ()) + { + if (type != SOCK_STREAM) + { + set_errno (EOPNOTSUPP); + return -1; + } + *(int *) optval = tcp_fastopen ? 1 : 0; + *optlen = sizeof (int); + return 0; + } + break; + + default: + break; + } + break; + default: break; } @@ -1869,6 +1907,10 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval, onebyte = true; break; + case TCP_FASTOPEN: + onebyte = true; + break; + default: break; } @@ -1881,8 +1923,7 @@ fhandler_socket_inet::getsockopt (int level, int optname, const void *optval, /* Regression in Vista and later: instead of a 4 byte BOOL value, a 1 byte BOOLEAN value is returned, in contrast to older systems and the documentation. Since an int type is expected by the calling - application, we convert the result here. For some reason only three - BSD-compatible socket options seem to be affected. */ + application, we convert the result here. */ BOOLEAN *in = (BOOLEAN *) optval; int *out = (int *) optval; *out = *in; diff --git a/winsup/cygwin/include/netinet/tcp.h b/winsup/cygwin/include/netinet/tcp.h index 5503a3fd6..ab1cd12bf 100644 --- a/winsup/cygwin/include/netinet/tcp.h +++ b/winsup/cygwin/include/netinet/tcp.h @@ -125,5 +125,6 @@ struct tcphdr { */ #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ #define TCP_MAXSEG 0x04 /* get maximum segment size (r/o on windows) */ +#define TCP_FASTOPEN 0x0f /* enable FastOpen on listeners */ #endif diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 4d136007f..be6d71d12 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -46,6 +46,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:false, }, }; @@ -77,6 +78,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:false, }, }; @@ -108,6 +110,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:false, }, }; @@ -139,6 +142,7 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:false, }, }; @@ -170,6 +174,39 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared)) has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:false, + }, +}; + +wincaps wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared)) = { + def_guard_pages:2, + mmap_storage_high:0x700000000000LL, + { + is_server:false, + needs_count_in_si_lpres2:false, + needs_query_information:false, + has_gaa_largeaddress_bug:false, + has_broken_alloc_console:true, + has_console_logon_sid:true, + has_precise_system_time:true, + has_microsoft_accounts:true, + has_processor_groups:true, + has_broken_prefetchvm:true, + has_new_pebteb_region:false, + has_broken_whoami:false, + has_unprivileged_createsymlink:false, + has_unbiased_interrupt_time:true, + has_precise_interrupt_time:true, + has_posix_unlink_semantics:false, + has_case_sensitive_dirs:false, + has_posix_rename_semantics:false, + no_msv1_0_s4u_logon_in_wow64:false, + has_con_24bit_colors:false, + has_con_broken_csi3j:false, + has_con_broken_il_dl:false, + has_con_esc_rep:false, + has_extended_mem_api:false, + has_tcp_fastopen:true, }, }; @@ -201,6 +238,7 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:true, }, }; @@ -232,6 +270,7 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:false, + has_tcp_fastopen:true, }, }; @@ -263,6 +302,7 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:true, + has_tcp_fastopen:true, }, }; @@ -294,6 +334,7 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_broken_il_dl:false, has_con_esc_rep:false, has_extended_mem_api:true, + has_tcp_fastopen:true, }, }; @@ -325,6 +366,7 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_broken_il_dl:true, has_con_esc_rep:true, has_extended_mem_api:true, + has_tcp_fastopen:true, }, }; @@ -378,6 +420,8 @@ wincapc::init () caps = &wincap_10_1709; else if (version.dwBuildNumber >= 15063) caps = &wincap_10_1703; + else if (version.dwBuildNumber >= 14393) + caps = &wincap_10_1607; else caps = & wincap_10_1507; } diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index cf13de535..54a880af7 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -40,6 +40,7 @@ struct wincaps unsigned has_con_broken_il_dl : 1; unsigned has_con_esc_rep : 1; unsigned has_extended_mem_api : 1; + unsigned has_tcp_fastopen : 1; }; }; @@ -103,6 +104,7 @@ public: bool IMPLEMENT (has_con_broken_il_dl) bool IMPLEMENT (has_con_esc_rep) bool IMPLEMENT (has_extended_mem_api) + bool IMPLEMENT (has_tcp_fastopen) void disable_case_sensitive_dirs () {