mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-26 15:14:42 +00:00
Don't use SO_REUSEADDR on Win32 platforms
SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT on Linux/BSD. ie it allows 2 apps to listen to the same port at once. Thus we must not set it on Win32 platforms See http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
837154a151
commit
37697d828b
@ -2060,6 +2060,7 @@ virSetCloseExec;
|
|||||||
virSetDeviceUnprivSGIO;
|
virSetDeviceUnprivSGIO;
|
||||||
virSetInherit;
|
virSetInherit;
|
||||||
virSetNonBlock;
|
virSetNonBlock;
|
||||||
|
virSetSockReuseAddr;
|
||||||
virSetUIDGID;
|
virSetUIDGID;
|
||||||
virSetUIDGIDWithCaps;
|
virSetUIDGIDWithCaps;
|
||||||
virStrIsPrint;
|
virStrIsPrint;
|
||||||
|
@ -255,8 +255,7 @@ int virNetSocketNewListenTCP(const char *nodename,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt = 1;
|
if (virSetSockReuseAddr(fd) < 0) {
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
|
||||||
virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
|
virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -460,15 +459,13 @@ int virNetSocketNewConnectTCP(const char *nodename,
|
|||||||
|
|
||||||
runp = ai;
|
runp = ai;
|
||||||
while (runp) {
|
while (runp) {
|
||||||
int opt = 1;
|
|
||||||
|
|
||||||
if ((fd = socket(runp->ai_family, runp->ai_socktype,
|
if ((fd = socket(runp->ai_family, runp->ai_socktype,
|
||||||
runp->ai_protocol)) < 0) {
|
runp->ai_protocol)) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("Unable to create socket"));
|
virReportSystemError(errno, "%s", _("Unable to create socket"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
if (virSetSockReuseAddr(fd) < 0) {
|
||||||
VIR_WARN("Unable to enable port reuse");
|
VIR_WARN("Unable to enable port reuse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,6 @@ static int virPortAllocatorBindToPort(bool *used,
|
|||||||
struct sockaddr* addr;
|
struct sockaddr* addr;
|
||||||
size_t addrlen;
|
size_t addrlen;
|
||||||
int v6only = 1;
|
int v6only = 1;
|
||||||
int reuse = 1;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
bool ipv6 = false;
|
bool ipv6 = false;
|
||||||
@ -143,8 +142,7 @@ static int virPortAllocatorBindToPort(bool *used,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&reuse,
|
if (virSetSockReuseAddr(fd) < 0) {
|
||||||
sizeof(reuse)) < 0) {
|
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to set socket reuse addr flag"));
|
_("Unable to set socket reuse addr flag"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -136,6 +136,29 @@ int virSetCloseExec(int fd)
|
|||||||
return virSetInherit(fd, false);
|
return virSetInherit(fd, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
|
||||||
|
* on Linux/BSD. ie it allows 2 apps to listen to the same
|
||||||
|
* port at once which is certainly not what we want here.
|
||||||
|
*
|
||||||
|
* Win32 sockets have Linux/BSD-like SO_REUSEADDR behaviour
|
||||||
|
* by default, so we can be a no-op.
|
||||||
|
*
|
||||||
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int virSetSockReuseAddr(int fd)
|
||||||
|
{
|
||||||
|
int opt = 1;
|
||||||
|
return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
virPipeReadUntilEOF(int outfd, int errfd,
|
virPipeReadUntilEOF(int outfd, int errfd,
|
||||||
char **outbuf, char **errbuf) {
|
char **outbuf, char **errbuf) {
|
||||||
|
@ -42,6 +42,7 @@ int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
|||||||
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
|
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int virSetSockReuseAddr(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virPipeReadUntilEOF(int outfd, int errfd,
|
int virPipeReadUntilEOF(int outfd, int errfd,
|
||||||
char **outbuf, char **errbuf);
|
char **outbuf, char **errbuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user