- Log_Log("TCP", "TCP_GetPacket: Opening Connection");
- // Open a new connection (well, check that it's a SYN)
- if(hdr->Flags != TCP_FLAG_SYN) {
- Log_Log("TCP", "TCP_GetPacket: Packet is not a SYN");
- return ;
- }
-
- // TODO: Check for halfopen max
-
- conn = calloc(1, sizeof(tTCPConnection));
- conn->State = TCP_ST_SYN_RCVD;
- conn->LocalPort = srv->Port;
- conn->RemotePort = ntohs(hdr->SourcePort);
- conn->Interface = Interface;
-
- switch(Interface->Type)
- {
- case 4: conn->RemoteIP.v4 = *(tIPv4*)Address; break;
- case 6: conn->RemoteIP.v6 = *(tIPv6*)Address; break;
- }
-
- conn->RecievedBuffer = RingBuffer_Create( TCP_RECIEVE_BUFFER_SIZE );
-
- conn->NextSequenceRcv = ntohl( hdr->SequenceNumber ) + 1;
- conn->NextSequenceSend = rand();
-
- // Create node
- conn->Node.NumACLs = 1;
- conn->Node.ACLs = &gVFS_ACL_EveryoneRW;
- conn->Node.ImplPtr = conn;
- conn->Node.ImplInt = srv->NextID ++;
- conn->Node.Type = &gTCP_ClientNodeType; // TODO: Special type for the server end?
-
- // Hmm... Theoretically, this lock will never have to wait,
- // as the interface is locked to the watching thread, and this
- // runs in the watching thread. But, it's a good idea to have
- // it, just in case
- // Oh, wait, there is a case where a wildcard can be used
- // (srv->Interface == NULL) so having the lock is a good idea
- SHORTLOCK(&srv->lConnections);
- if( !srv->Connections )
- srv->Connections = conn;
- else
- srv->ConnectionsTail->Next = conn;
- srv->ConnectionsTail = conn;
- if(!srv->NewConnections)
- srv->NewConnections = conn;
- VFS_MarkAvaliable( &srv->Node, 1 );
- SHORTREL(&srv->lConnections);
-
- // Send the SYN ACK
- hdr->Flags |= TCP_FLAG_ACK;
- hdr->AcknowlegementNumber = htonl(conn->NextSequenceRcv);
- hdr->SequenceNumber = htonl(conn->NextSequenceSend);
- hdr->DestPort = hdr->SourcePort;
- hdr->SourcePort = htons(srv->Port);
- hdr->DataOffset = (sizeof(tTCPHeader)/4) << 4;
- TCP_SendPacket( conn, sizeof(tTCPHeader), hdr );
- conn->NextSequenceSend ++;
+ // Check Source Port
+ Log_Log("TCP", "TCP_GetPacket: conn->RemotePort(%i) == hdr->SourcePort(%i)",
+ conn->RemotePort, ntohs(hdr->SourcePort));
+ if(conn->RemotePort != ntohs(hdr->SourcePort)) continue;
+
+ // Check Source IP
+ Log_Debug("TCP", "TCP_GetPacket: conn->RemoteIP(%s)",
+ IPStack_PrintAddress(conn->Interface->Type, &conn->RemoteIP));
+ Log_Debug("TCP", " == Address(%s)",
+ IPStack_PrintAddress(conn->Interface->Type, Address));
+ if( IPStack_CompareAddress(conn->Interface->Type, &conn->RemoteIP, Address, -1) == 0 )
+ continue ;
+
+ Log_Log("TCP", "TCP_GetPacket: Matches connection %p", conn);
+ // We have a response!
+ TCP_INT_HandleConnectionPacket(conn, hdr, Length);
+
+ return;
+ }
+
+ Log_Log("TCP", "TCP_GetPacket: Opening Connection");
+ // Open a new connection (well, check that it's a SYN)
+ if(hdr->Flags != TCP_FLAG_SYN) {
+ Log_Log("TCP", "TCP_GetPacket: Packet is not a SYN");