src/Cedar/Listener.c
// Jump here if there is accepted connection in the TCP

Jump here if there is accepted connection in the TCP
Jump here if there is accepted connection in the TCP
void TCPAccepted(LISTENER *r, SOCK *s)
{
	TCP_ACCEPTED_PARAM *data;
	THREAD *t;
	char tmp[MAX_SIZE];
	UINT num_clients_from_this_ip = 0;
	CEDAR *cedar;
	if (r == NULL || s == NULL)
	{
		return;
	}
	cedar = r->Cedar;
	num_clients_from_this_ip = GetNumIpClient(&s->RemoteIP);
	if (disable_dos == false && r->DisableDos == false && r->Protocol != LISTENER_INPROC)
	{
		UINT max_uec, now_uec;
		if (CheckDosAttack(r, s) == false)
		{
			Debug("DOS Attack 1 !!\n");
			IPToStr(tmp, sizeof(tmp), &s->RemoteIP);
			SLog(r->Cedar, "LS_LISTENER_DOS", r->Port, tmp, s->RemotePort);
			return;
		}
		if (StrCmpi(s->UnderlayProtocol, SOCK_UNDERLAY_NATIVE_V6) == 0 ||
			StrCmpi(s->UnderlayProtocol, SOCK_UNDERLAY_NATIVE_V4) == 0)
		{
			if (IsInNoSsl(r->Cedar, &s->RemoteIP))
			{
				Debug("DOS Attack 2 !!\n");
				IPToStr(tmp, sizeof(tmp), &s->RemoteIP);
				SLog(r->Cedar, "LS_LISTENER_DOS", r->Port, tmp, s->RemotePort);
				return;
			}
		}
		if (num_clients_from_this_ip > GetMaxConnectionsPerIp())
		{
			Debug("DOS Attack 3 !!\n");
			IPToStr(tmp, sizeof(tmp), &s->RemoteIP);
			SLog(r->Cedar, "LS_LISTENER_DOS", r->Port, tmp, s->RemotePort);
			return;
		}
		max_uec = GetMaxUnestablishedConnections();
		now_uec = GetUnestablishedConnections(cedar);
		if (now_uec > max_uec)
		{
			Debug("DOS Attack 4 !!\n");
			SLog(r->Cedar, "LS_LISTENER_MAXUEC", max_uec, now_uec);
			return;
		}
	}
	IPToStr(tmp, sizeof(tmp), &s->RemoteIP);
	data = ZeroMalloc(sizeof(TCP_ACCEPTED_PARAM));
	data->r = r;
	data->s = s;
	if (r->ThreadProc == TCPAcceptedThread)
	{
		Inc(cedar->AcceptingSockets);
	}
	t = NewThread(r->ThreadProc, data);
	WaitThreadInit(t);
	Free(data);
	ReleaseThread(t);
}
void TCPAccepted ( LISTENER * r , SOCK * s ) { TCP_ACCEPTED_PARAM * data ; THREAD * t ; char tmp [ MAX_SIZE ] ; UINT num_clients_from_this_ip = 0 ; CEDAR * cedar ; if ( r == NULL || s == NULL ) { return ; } cedar = r -> Cedar ; num_clients_from_this_ip = GetNumIpClient ( & s -> RemoteIP ) ; if ( disable_dos == false && r -> DisableDos == false && r -> Protocol != LISTENER_INPROC ) { UINT max_uec , now_uec ; if ( CheckDosAttack ( r , s ) == false ) { Debug ( " \n " ) ; IPToStr ( tmp , sizeof ( tmp ) , & s -> RemoteIP ) ; SLog ( r -> Cedar , " " , r -> Port , tmp , s -> RemotePort ) ; return ; } if ( StrCmpi ( s -> UnderlayProtocol , SOCK_UNDERLAY_NATIVE_V6 ) == 0 || StrCmpi ( s -> UnderlayProtocol , SOCK_UNDERLAY_NATIVE_V4 ) == 0 ) { if ( IsInNoSsl ( r -> Cedar , & s -> RemoteIP ) ) { Debug ( " \n " ) ; IPToStr ( tmp , sizeof ( tmp ) , & s -> RemoteIP ) ; SLog ( r -> Cedar , " " , r -> Port , tmp , s -> RemotePort ) ; return ; } } if ( num_clients_from_this_ip > GetMaxConnectionsPerIp ( ) ) { Debug ( " \n " ) ; IPToStr ( tmp , sizeof ( tmp ) , & s -> RemoteIP ) ; SLog ( r -> Cedar , " " , r -> Port , tmp , s -> RemotePort ) ; return ; } max_uec = GetMaxUnestablishedConnections ( ) ; now_uec = GetUnestablishedConnections ( cedar ) ; if ( now_uec > max_uec ) { Debug ( " \n " ) ; SLog ( r -> Cedar , " " , max_uec , now_uec ) ; return ; } } IPToStr ( tmp , sizeof ( tmp ) , & s -> RemoteIP ) ; data = ZeroMalloc ( sizeof ( TCP_ACCEPTED_PARAM ) ) ; data -> r = r ; data -> s = s ; if ( r -> ThreadProc == TCPAcceptedThread ) { Inc ( cedar -> AcceptingSockets ) ; } t = NewThread ( r -> ThreadProc , data ) ; WaitThreadInit ( t ) ; Free ( data ) ; ReleaseThread ( t ) ; }
Jump here if there is accepted connection in the TCP
Jump here if there is accepted connection in the TCP
// Validate arguments
 // DOS attack check
