Cleanup commit, fixes to UDP, TCP and ICMP
authorJohn Hodge <[email protected]>
Wed, 3 Mar 2010 07:28:43 +0000 (15:28 +0800)
committerJohn Hodge <[email protected]>
Wed, 3 Mar 2010 07:28:43 +0000 (15:28 +0800)
- Basicly cleaning up commented out code and potential bugs
- More work on TCP support

Kernel/Makefile.BuildNum
Modules/IPStack/icmp.c
Modules/IPStack/icmp.h
Modules/IPStack/tcp.c
Modules/IPStack/udp.c
Usermode/Applications/MultibootCheck_src/Makefile

index bc2c5c6..ef0be0a 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1461
+BUILD_NUM = 1464
index cdc7126..77bc691 100644 (file)
@@ -54,7 +54,7 @@ void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
                }
                if(hdr->ID != (Uint16)~hdr->Sequence) {
                        Warning("[ICMP ] ID and Sequence values do not match");
-                       return ;
+                       //return ;
                }
                gICMP_PingSlots[hdr->ID].bArrived = 1;
                break;
@@ -70,6 +70,7 @@ void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
                        Log("[ICMP ] Destination Unreachable (Code %i)", hdr->Code);
                        break;
                }
+//             IPv4_Unreachable( Interface, hdr->Code, htons(hdr->Length)-sizeof(tICMPHeader), hdr->Data );
                break;
        
        // -- 8: Echo Request
index a9594f8..8e78722 100644 (file)
@@ -16,6 +16,7 @@ struct sICMPHeader
        Uint16  Checksum;
        Uint16  ID;
        Uint16  Sequence;
+       Uint8   Data[];
 };
 
 // === CONSTANTS ===
index 9225ffa..9b3f8f4 100644 (file)
@@ -115,10 +115,10 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
        tTCPConnection  *conn;
 
        Log("[TCP  ] sizeof(tTCPHeader) = %i", sizeof(tTCPHeader));
+       Log("[TCP  ] SourcePort = %i", ntohs(hdr->SourcePort));
        Log("[TCP  ] DestPort = %i", ntohs(hdr->DestPort));
-       Log("[TCP  ] DestPort = %i", ntohs(hdr->DestPort));
-       Log("[TCP  ] SequenceNumber = %i", ntohl(hdr->SequenceNumber));
-       Log("[TCP  ] AcknowlegementNumber = %i", ntohl(hdr->AcknowlegementNumber));
+       Log("[TCP  ] SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
+       Log("[TCP  ] AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber));
        Log("[TCP  ] DataOffset = %i", hdr->DataOffset >> 4);
        Log("[TCP  ] Flags = {");
        Log("[TCP  ]   CWR = %B", !!(hdr->Flags & TCP_FLAG_CWR));
@@ -167,7 +167,51 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                        }
 
                        // Open a new connection (well, check that it's a SYN)
-                       //TODO
+                       if(hdr->Flags != TCP_FLAG_SYN) {
+                               Log("[TCP  ] Packet is not a SYN");
+                               continue;
+                       }
+                       
+                       conn = calloc(1, sizeof(tTCPConnection));
+                       conn->State = TCP_ST_HALFOPEN;
+                       conn->LocalPort = srv->Port;
+                       conn->RemotePort = 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->NextSequenceRcv = ntohl( hdr->SequenceNumber );
+                       conn->NextSequenceSend = rand();
+                       
+                       // Create node
+                       conn->Node.NumACLs = 1;
+                       conn->Node.ACLs = &gVFS_ACL_EveryoneRW;
+                       conn->Node.ImplInt = srv->NextID ++;
+                       conn->Node.Read = TCP_Client_Read;
+                       conn->Node.Write = TCP_Client_Write;
+                       //conn->Node.Close = TCP_SrvConn_Close;
+                       
+                       // 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
+                       LOCK(&srv->lConnections);
+                       conn->Next = srv->Connections;
+                       srv->Connections = conn;
+                       RELEASE(&srv->lConnections);
+
+                       // Send the SYN ACK
+                       Log("[TCP  ] TODO: Sending SYN ACK");
+                       hdr->Flags |= TCP_FLAG_ACK;
+                       hdr->AcknowlegementNumber = hdr->SequenceNumber;
+                       hdr->SequenceNumber = conn->NextSequenceSend;
+                       hdr->DestPort = hdr->SourcePort;
+                       hdr->SourcePort = srv->Port;
+                       TCP_SendPacket( conn, sizeof(tTCPHeader), hdr );
 
                        break;
                }
index 760c997..4ce447d 100644 (file)
@@ -11,6 +11,8 @@
 // === PROTOTYPES ===
 void   UDP_Initialise();
 void   UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
+void   UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer);
+void   UDP_SendPacket(tUDPChannel *Channel, void *Data, size_t Length);
 // --- Listening Server
 tVFS_Node      *UDP_Server_Init(tInterface *Interface);
 char   *UDP_Server_ReadDir(tVFS_Node *Node, int ID);
@@ -50,6 +52,7 @@ void UDP_Initialise()
 {
        IPStack_AddFile(&gUDP_ServerFile);
        IPStack_AddFile(&gUDP_ClientFile);
+       //IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket, UDP_Unreachable);
        IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket);
 }
 
@@ -69,9 +72,7 @@ int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, in
                chan = chan->Next)
        {
                if(chan->Interface != Interface)        continue;
-               //Log("[UDP  ] Local (0x%04x) == Dest (0x%04x)", chan->LocalPort, ntohs(hdr->DestPort));
                if(chan->LocalPort != ntohs(hdr->DestPort))     continue;
-               //Log("[UDP  ] Remote (0x%04x) == Source (0x%04x)", chan->RemotePort, ntohs(hdr->SourcePort));
                if(chan->RemotePort != ntohs(hdr->SourcePort))  continue;
                
                if(Interface->Type == 4) {
@@ -148,6 +149,14 @@ void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
        
 }
 
+/**
+ * \brief Handle an ICMP Unrechable Error
+ */
+void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer)
+{
+       
+}
+
 /**
  * \brief Send a packet
  * \param Channel      Channel to send the packet from
index 291376e..ac0dc41 100644 (file)
@@ -1,4 +1,4 @@
-# Project: cat\r
+# Project: Multiboot Check\r
 \r
 -include ../Makefile.cfg\r
 \r

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