From: Oliver Kurth Date: Tue, 21 Apr 2020 21:43:45 +0000 (-0700) Subject: Common source file changes not applicable to open-vm-tools. X-Git-Tag: stable-11.2.0~254 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa6fb17347de72a56d6c5a6ffcf713b97b9e73c1;p=thirdparty%2Fopen-vm-tools.git Common source file changes not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index fb9d4bdb5..038a9486e 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #if !(defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L) #undef strcpy @@ -6373,3 +6374,91 @@ AsyncTCPSocketListenerError(int error, // IN AsyncSocketHandleError(s, error); } + + +/* + *----------------------------------------------------------------------------- + * + * AsyncSocket_SetKeepAlive -- + * + * Set keep-alive socket option. + * + * Results: + * TRUE if successful. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +Bool +AsyncSocket_SetKeepAlive(AsyncSocket *asock, // IN + int keepIdle) // IN +{ + int fd; + + fd = AsyncSocket_GetFd(asock); +#ifdef WIN32 + { + struct tcp_keepalive keepalive = { 1, keepIdle * 1000, keepIdle * 10 }; + DWORD ret; + + if (WSAIoctl(fd, SIO_KEEPALIVE_VALS, &keepalive, sizeof keepalive, + NULL, 0, &ret, NULL, NULL)) { + Err_Number sysErr = ASOCK_LASTERROR(); + ASOCKLG0(asock, "Could not set keepalive options, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); + } + } +#else + { + static const int keepAlive = 1; + if (keepIdle) { +# ifdef TCP_KEEPIDLE +# define VMTCP_KEEPIDLE TCP_KEEPIDLE +# else +# define VMTCP_KEEPIDLE TCP_KEEPALIVE +# endif + if (setsockopt(fd, + IPPROTO_TCP, + VMTCP_KEEPIDLE, + (const char *)&keepIdle, sizeof keepIdle) != 0) { + Err_Number sysErr = ASOCK_LASTERROR(); + ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); + return FALSE; + } +# ifndef __APPLE__ + { + /* + * Default TCP setting is 7200 sec idle, and 75 interval. So let's + * divide keepIdle by 100 to get an interval. For our 300 seconds + * default that is 3 seconds keepIdle. + */ + int keepIntvl = keepIdle / 100; + + if (keepIntvl < 1) { + keepIntvl = 1; + } + if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, + (const char *)&keepIntvl, sizeof keepIntvl) != 0) { + Err_Number sysErr = ASOCK_LASTERROR(); + ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); + return FALSE; + } + } +# endif /* __APPLE__ */ + } + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, + (const char *)&keepAlive, sizeof keepAlive) != 0) { + Err_Number sysErr = ASOCK_LASTERROR(); + ASOCKLG0(asock, "Could not set TCP_KEEPIDLE, error %d: %s\n", + sysErr, Err_Errno2String(sysErr)); + return FALSE; + } + } +#endif /* WIN32 */ + return TRUE; +} diff --git a/open-vm-tools/lib/include/asyncsocket.h b/open-vm-tools/lib/include/asyncsocket.h index 361230484..27ce6c119 100644 --- a/open-vm-tools/lib/include/asyncsocket.h +++ b/open-vm-tools/lib/include/asyncsocket.h @@ -760,6 +760,9 @@ char *AsyncSocket_WebSocketGetHttpHeader(const char *request, unsigned AsyncSocket_WebSocketGetNumAccepted(AsyncSocket *asock); +Bool AsyncSocket_SetKeepAlive(AsyncSocket *asock, int keepIdle); + + /* * Some logging macros for convenience */ diff --git a/open-vm-tools/lib/include/loglevel_user.h b/open-vm-tools/lib/include/loglevel_user.h index 9b1afb10c..cf491c8e1 100644 --- a/open-vm-tools/lib/include/loglevel_user.h +++ b/open-vm-tools/lib/include/loglevel_user.h @@ -230,6 +230,7 @@ LOGLEVEL_VAR(numa), \ LOGLEVEL_VAR(numaHost), \ LOGLEVEL_VAR(remoteDevice), \ + LOGLEVEL_VAR(vsockProxy), \ LOGLEVEL_VAR(vncDecode), \ LOGLEVEL_VAR(vncEncode), \ LOGLEVEL_VAR(vncBlit), \