X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Ftcp.c;h=4ef4bb3621ab27b2905227247432f48e23225655;hb=ec40992498997848492a6c2e9025df23c1327cd1;hp=3d4978b4fb5d2c3e34b9c258f25dca10db1d90d3;hpb=9122d035c4337d33bf0cc2212eeade4e42a367a2;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/tcp.c b/KernelLand/Modules/IPStack/tcp.c index 3d4978b4..4ef4bb36 100644 --- a/KernelLand/Modules/IPStack/tcp.c +++ b/KernelLand/Modules/IPStack/tcp.c @@ -8,7 +8,6 @@ #include "ipv6.h" #include "tcp.h" -#define USE_SELECT 1 #define HEXDUMP_INCOMING 0 #define HEXDUMP_OUTGOING 0 @@ -87,7 +86,7 @@ Uint32 gaTCP_PortBitmap[0x800]; */ void TCP_Initialise(void) { - giTCP_NextOutPort += rand()%32; + giTCP_NextOutPort += rand()%128; IPStack_AddFile(&gTCP_ServerFile); IPStack_AddFile(&gTCP_ClientFile); IPv4_RegisterCallback(IP4PROT_TCP, TCP_GetPacket); @@ -252,6 +251,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe } conn->NextSequenceRcv = ntohl( hdr->SequenceNumber ) + 1; + conn->HighestSequenceRcvd = conn->NextSequenceRcv; conn->NextSequenceSend = rand(); conn->Node.ImplInt = srv->NextID ++; @@ -334,6 +334,10 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head if( Connection->LastACKSequence != Connection->NextSequenceRcv ) TCP_INT_SendACK(Connection, "SYN"); Connection->NextSequenceRcv = ntohl(Header->SequenceNumber); + // TODO: Process HighestSequenceRcvd + // HACK! + if( Connection->HighestSequenceRcvd == 0 ) + Connection->HighestSequenceRcvd = Connection->NextSequenceRcv; Connection->LastACKSequence = Connection->NextSequenceRcv; } @@ -365,6 +369,8 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head case TCP_ST_SYN_SENT: if( Header->Flags & TCP_FLAG_SYN ) { + if( Connection->HighestSequenceRcvd == Connection->NextSequenceRcv ) + Connection->HighestSequenceRcvd ++; Connection->NextSequenceRcv ++; if( Header->Flags & TCP_FLAG_ACK ) @@ -422,17 +428,12 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head Log_Log("TCP", "ACK only packet"); return ; } - Connection->NextSequenceRcv ++; // TODO: Is this right? (empty packet counts as one byte) + // TODO: Is this right? (empty packet counts as one byte) + if( Connection->HighestSequenceRcvd == Connection->NextSequenceRcv ) + Connection->HighestSequenceRcvd ++; + Connection->NextSequenceRcv ++; Log_Log("TCP", "Empty Packet, inc and ACK the current sequence number"); TCP_INT_SendACK(Connection, "Empty"); - #if 0 - Header->DestPort = Header->SourcePort; - Header->SourcePort = htons(Connection->LocalPort); - Header->AcknowlegementNumber = htonl(Connection->NextSequenceRcv); - Header->SequenceNumber = htonl(Connection->NextSequenceSend); - Header->Flags |= TCP_FLAG_ACK; - TCP_SendPacket( Connection, Header, 0, NULL ); - #endif return ; } @@ -463,6 +464,8 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head break; } LOG("0x%08x += %i", Connection->NextSequenceRcv, dataLen); + if( Connection->HighestSequenceRcvd == Connection->NextSequenceRcv ) + Connection->HighestSequenceRcvd += dataLen; Connection->NextSequenceRcv += dataLen; // TODO: This should be moved out of the watcher thread, @@ -691,6 +694,7 @@ void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection) // Calculate length of contiguous bytes int length = Connection->HighestSequenceRcvd - Connection->NextSequenceRcv; Uint32 index = Connection->NextSequenceRcv % TCP_WINDOW_SIZE; + LOG("length=%i, index=%i", length, index); for( int i = 0; i < length; i ++ ) { int bit = index % 8; @@ -730,10 +734,10 @@ void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection) // Mark (now saved) bytes as invalid // - Align index - while(index % 8 && length) + while(index % 8 && length > 0) { Connection->FuturePacketData[index] = 0; - Connection->FuturePacketData[index/8] &= ~(1 << (index%8)); + Connection->FuturePacketValidBytes[index/8] &= ~(1 << (index%8)); index ++; if(index > TCP_WINDOW_SIZE) index -= TCP_WINDOW_SIZE; @@ -791,6 +795,8 @@ void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection) // Looks like we found one TCP_INT_AppendRecieved(Connection, pkt->Data, pkt->Length); + if( Connection->HighestSequenceRcvd == Connection->NextSequenceRcv ) + Connection->HighestSequenceRcvd += pkt->Length; Connection->NextSequenceRcv += pkt->Length; free(pkt); }