Commit 9aed3394 authored by Bernd Lietzow's avatar Bernd Lietzow

common: handle 0 byte UDP datagram in StandardSocket

This was mistaken as a "soft disconnect" before. The reason is that the
code is shared between UDP and TCP. In TCP this is really a disconnect,
but in UDP it is a valid packet, that can e.g. be created by tools like
nmap.

See e0f8452f
parent fc091383
......@@ -15,6 +15,7 @@
* @throw SocketException
*/
StandardSocket::StandardSocket(int domain, int type, int protocol)
: isDgramSocket(type == SOCK_DGRAM)
{
this->sockDomain = domain;
......@@ -63,6 +64,7 @@ StandardSocket::StandardSocket(int domain, int type, int protocol)
*/
StandardSocket::StandardSocket(int fd, unsigned short sockDomain, struct in_addr peerIP,
std::string peername)
: isDgramSocket(false)
{
this->sock = fd;
this->sockDomain = sockDomain;
......@@ -426,10 +428,22 @@ ssize_t StandardSocket::recv(void *buf, size_t len, int flags)
}
if(recvRes == 0)
throw SocketDisconnectException(std::string("Soft disconnect from ") + peername);
{
if (isDgramSocket)
{
LOG_TOP(GENERAL, NOTICE, "Received empty UDP datagram.", peername);
return 0;
}
else
{
throw SocketDisconnectException(std::string("Soft disconnect from ") + peername);
}
}
else
{
throw SocketDisconnectException(std::string("Recv(): Hard disconnect from ") +
peername + ". SysErr: " + System::getErrString() );
}
}
/**
......@@ -496,11 +510,25 @@ ssize_t StandardSocket::recvfrom(void *buf, size_t len, int flags,
}
if(recvRes == 0)
throw SocketDisconnectException(std::string("Soft disconnect from ") + peername);
{
if (isDgramSocket)
{
struct sockaddr_in* sin = (struct sockaddr_in*)from;
LOG_TOP(GENERAL, NOTICE, "Received empty UDP datagram.", peername,
as("IP", Socket::ipaddrToStr(&sin->sin_addr)), as("port", ntohs(sin->sin_port)));
return 0;
}
else
{
throw SocketDisconnectException(std::string("Soft disconnect from ") + peername);
}
}
else
{
throw SocketDisconnectException(
std::string("Recvfrom(): Hard disconnect from ") + peername + ": " +
System::getErrString() );
}
}
/**
......
......@@ -48,7 +48,8 @@ class StandardSocket : public PooledSocket
protected:
int sock;
unsigned short sockDomain; // socket domain (aka protocol family) e.g. PF_INET
const bool isDgramSocket;
StandardSocket(int fd, unsigned short sockDomain, struct in_addr peerIP,
std::string peername);
......
name: "Empty UDP packet"
desc: "Check that server processes do not shut down when they receive a 0 byte UDP datagram."
xfail_msg: not yet fixed
hosts:
node:
- mgmtd:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment