Modules/BochsGA - Oops, didn't need that magic break
[tpg/acess2.git] / Modules / IPStack / tcp.c
index 3952d8e..bb71fdb 100644 (file)
@@ -26,7 +26,7 @@ void  TCP_StartConnection(tTCPConnection *Conn);
 void   TCP_SendPacket(tTCPConnection *Conn, size_t Length, tTCPHeader *Data);
 void   TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
 void   TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Header, int Length);
-void   TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length);
+int    TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length);
 void   TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection);
 Uint16 TCP_GetUnusedPort();
  int   TCP_AllocatePort(Uint16 Port);
@@ -135,17 +135,10 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
        tTCPListener    *srv;
        tTCPConnection  *conn;
 
-       Log_Log("TCP", "TCP_GetPacket: SourcePort = %i, DestPort = %i",
-               ntohs(hdr->SourcePort), ntohs(hdr->DestPort));
-/*
-       Log_Log("TCP", "TCP_GetPacket: SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
-       Log_Log("TCP", "TCP_GetPacket: AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber));
-       Log_Log("TCP", "TCP_GetPacket: DataOffset = %i", hdr->DataOffset >> 4);
-       Log_Log("TCP", "TCP_GetPacket: WindowSize = %i", htons(hdr->WindowSize));
-       Log_Log("TCP", "TCP_GetPacket: Checksum = 0x%x", htons(hdr->Checksum));
-       Log_Log("TCP", "TCP_GetPacket: UrgentPointer = 0x%x", htons(hdr->UrgentPointer));
-*/
-       Log_Log("TCP", "TCP_GetPacket: Flags = %s%s%s%s%s%s%s%s",
+       Log_Log("TCP", "TCP_GetPacket: <Local>:%i from [%s]:%i, Flags= %s%s%s%s%s%s%s%s",
+               ntohs(hdr->SourcePort),
+               IPStack_PrintAddress(Interface->Type, Address),
+               ntohs(hdr->DestPort),
                (hdr->Flags & TCP_FLAG_CWR) ? "CWR " : "",
                (hdr->Flags & TCP_FLAG_ECE) ? "ECE " : "",
                (hdr->Flags & TCP_FLAG_URG) ? "URG " : "",
@@ -183,8 +176,6 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                        // Is this in an established connection?
                        for( conn = srv->Connections; conn; conn = conn->Next )
                        {
-                               Log_Log("TCP", "TCP_GetPacket: conn->Interface(%p) == Interface(%p)",
-                                       conn->Interface, Interface);
                                // Check that it is coming in on the same interface
                                if(conn->Interface != Interface)        continue;
 
@@ -424,11 +415,15 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head
                // Is this packet the next expected packet?
                if( sequence_num == Connection->NextSequenceRcv )
                {
+                        int    rv;
                        // Ooh, Goodie! Add it to the recieved list
-                       TCP_INT_AppendRecieved(Connection,
+                       rv = TCP_INT_AppendRecieved(Connection,
                                (Uint8*)Header + (Header->DataOffset>>4)*4,
                                dataLen
                                );
+                       if(rv != 0) {
+                               break;
+                       }
                        Log_Log("TCP", "0x%08x += %i", Connection->NextSequenceRcv, dataLen);
                        Connection->NextSequenceRcv += dataLen;
                        
@@ -619,16 +614,19 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head
  * \param Data Packet contents
  * \param Length       Length of \a Data
  */
-void TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length)
+int TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length)
 {
        Mutex_Acquire( &Connection->lRecievedPackets );
+
        if(Connection->RecievedBuffer->Length + Length > Connection->RecievedBuffer->Space )
        {
-               Log_Error("TCP", "Buffer filled, packet dropped (%s)",
-               //      TCP_INT_DumpConnection(Connection)
-                       ""
+               VFS_MarkAvaliable(&Connection->Node, 1);
+               Log_Error("TCP", "Buffer filled, packet dropped (:%i) - %i + %i > %i",
+                       Connection->LocalPort, Connection->RecievedBuffer->Length, Length,
+                       Connection->RecievedBuffer->Space
                        );
-               return ;
+               Mutex_Release( &Connection->lRecievedPackets );
+               return 1;
        }
        
        RingBuffer_Write( Connection->RecievedBuffer, Data, Length );
@@ -636,6 +634,7 @@ void TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t
        VFS_MarkAvaliable(&Connection->Node, 1);
        
        Mutex_Release( &Connection->lRecievedPackets );
+       return 0;
 }
 
 /**

UCC git Repository :: git.ucc.asn.au