this probably has at least one mistake/bug/typo but will move our DoS

protection into the low level UDP lib
This commit is contained in:
DarthArgus
2016-09-26 06:27:53 +00:00
parent 41639d8156
commit e395177e8f
10 changed files with 50 additions and 37 deletions
+24
View File
@@ -174,6 +174,7 @@ UdpManager::Params::Params()
portAliveDelay = 0;
noDataTimeout = 0;
maxConnections = 10;
maxConnectionsPerIP = 0;
port = 0;
portRange = 0;
pooledPacketMax = 1000;
@@ -997,8 +998,31 @@ void UdpManager::ProcessRawPacket(const PacketHistoryEntry *e)
// connection establish packet must always be at least 6 bytes long as we must have a version number, no matter how it changes
if (e->mBuffer[0] == 0 && e->mBuffer[1] == UdpConnection::cUdpPacketConnect && e->mLen == UdpConnection::cUdpPacketConnectSize)
{
if (mParams.maxConnectionsPerIP > 0)
{
UdpConnection *alreadyExists;
int clientConnections = 0;
for (int i = 1; i != 65535; i++)
{
alreadyExists = AddressGetConnection(e->mIp, i);
if (alreadyExists != nullptr)
{
clientConnections++;
}
}
if (clientConnections >= mParams.maxConnectionsPerIP)
{
printf("Possible DoS attempt? Client %i attempted more connections than the limit (%i). Dropping!", e->mIp, mParams.maxConnectionsPerIP);
return;
}
}
if (mConnectionListCount >= mParams.maxConnections)
{
return; // can't handle any more connections, so ignore this request entirely
}
int protocolVersion = UdpMisc::GetValue32(e->mBuffer + 2);
if (protocolVersion == cProtocolVersion)