src/Cedar/Listener.c
// Check whether this is a DOS attack

Check whether this is a DOS attack
Check whether this is a DOS attack
bool CheckDosAttack(LISTENER *r, SOCK *s)
{
	DOS *d;
	bool ok = true;
	if (r == NULL || s == NULL)
	{
		return false;
	}
	LockList(r->DosList);
	{
		RefreshDosList(r);
		d = SearchDosList(r, &s->RemoteIP);
		if (d != NULL)
		{
			d->LastConnectedTick = Tick64();
			d->CurrentExpireSpan = MIN(d->CurrentExpireSpan * (UINT64)2, DOS_TABLE_EXPIRES_MAX);
			d->AccessCount++;
			if (d->AccessCount > DOS_TABLE_MAX_LIMIT_PER_IP)
			{
				ok = false;
			}
		}
		else
		{
			d = ZeroMalloc(sizeof(DOS));
			d->CurrentExpireSpan = (UINT64)DOS_TABLE_EXPIRES_FIRST;
			d->FirstConnectedTick = d->LastConnectedTick = Tick64();
			d->AccessCount = 1;
			d->DeleteEntryTick = d->FirstConnectedTick + (UINT64)DOS_TABLE_EXPIRES_TOTAL;
			Copy(&d->IpAddress, &s->RemoteIP, sizeof(IP));
			Add(r->DosList, d);
		}
	}
	UnlockList(r->DosList);
	return ok;
}
bool CheckDosAttack ( LISTENER * r , SOCK * s ) { DOS * d ; bool ok = true ; if ( r == NULL || s == NULL ) { return false ; } LockList ( r -> DosList ) ; { RefreshDosList ( r ) ; d = SearchDosList ( r , & s -> RemoteIP ) ; if ( d != NULL ) { d -> LastConnectedTick = Tick64 ( ) ; d -> CurrentExpireSpan = MIN ( d -> CurrentExpireSpan * ( UINT64 ) 2 , DOS_TABLE_EXPIRES_MAX ) ; d -> AccessCount ++ ; if ( d -> AccessCount > DOS_TABLE_MAX_LIMIT_PER_IP ) { ok = false ; } } else { d = ZeroMalloc ( sizeof ( DOS ) ) ; d -> CurrentExpireSpan = ( UINT64 ) DOS_TABLE_EXPIRES_FIRST ; d -> FirstConnectedTick = d -> LastConnectedTick = Tick64 ( ) ; d -> AccessCount = 1 ; d -> DeleteEntryTick = d -> FirstConnectedTick + ( UINT64 ) DOS_TABLE_EXPIRES_TOTAL ; Copy ( & d -> IpAddress , & s -> RemoteIP , sizeof ( IP ) ) ; Add ( r -> DosList , d ) ; } } UnlockList ( r -> DosList ) ; return ok ; }
Check whether this is a DOS attack
Check whether this is a DOS attack
// Validate arguments
 // Delete old entries from the DOS attack list
 // Search the table
 // There is a entry already
 // This should mean being under a DOS attack
 // Create a new entry
