Bugfixing and testing TCP stack
authorJohn Hodge <[email protected]>
Thu, 4 Mar 2010 05:59:21 +0000 (13:59 +0800)
committerJohn Hodge <[email protected]>
Thu, 4 Mar 2010 05:59:21 +0000 (13:59 +0800)
- Also fixed build process

Kernel/Makefile.BuildNum
Kernel/drv/kb.c
Modules/IPStack/main.c
Modules/IPStack/tcp.c
Usermode/Applications/ifconfig_src/main.c
Usermode/Libraries/crt0.o_src/Makefile

index 511226d..a1e2581 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1467
+BUILD_NUM = 1479
index a546153..aa807b5 100644 (file)
@@ -76,7 +76,7 @@ void KB_IRQHandler()
 
        scancode = inb(0x60); // Read from the keyboard's data buffer
 
-       Log("KB_IRQHandler: scancode = 0x%02x", scancode);
+       //Log("KB_IRQHandler: scancode = 0x%02x", scancode);
 
        // Ignore ACKs
        if(scancode == 0xFA) {
index 37caba8..7ec7689 100644 (file)
@@ -92,6 +92,7 @@ int IPStack_Install(char **Arguments)
  */
 int IPStack_AddFile(tSocketFile *File)
 {
+       Log("IPStack_AddFile: %s", File->Name);
        File->Next = gIP_FileTemplates;
        gIP_FileTemplates = File;
        return 0;
@@ -224,7 +225,10 @@ int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data)
 char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos)
 {
        tSocketFile     *file = gIP_FileTemplates;
-       while(Pos-- && file)    file = file->Next;
+       while(Pos-- && file) {
+               Log("IPStack_Iface_ReadDir: %s", file->Name);
+               file = file->Next;
+       }
        
        if(!file)       return NULL;
        
@@ -242,6 +246,7 @@ tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name)
        for(;file;file = file->Next)
        {
                if( strcmp(file->Name, Name) == 0 )     break;
+               Log("IPStack_Iface_FindDir: strcmp('%s', '%s')", file->Name, Name);
        }
        if(!file)       return NULL;
        
@@ -506,7 +511,7 @@ int IPStack_AddInterface(char *Device)
        iface->Node.ImplPtr = iface;
        iface->Node.ImplInt = giIP_NextIfaceId++;
        iface->Node.Flags = VFS_FFLAG_DIRECTORY;
-       iface->Node.Size = 0;
+       iface->Node.Size = -1;
        iface->Node.NumACLs = 1;
        iface->Node.ACLs = &gVFS_ACL_EveryoneRX;
        iface->Node.ReadDir = IPStack_Iface_ReadDir;
index e79a294..302e07e 100644 (file)
@@ -92,7 +92,7 @@ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data )
        switch( Conn->Interface->Type )
        {
        case 4: // Append IPv4 Pseudo Header
-               buflen = 4 + 4 + 4 + ((Length+1)&1);
+               buflen = 4 + 4 + 4 + ((Length+1)&~1);
                buf = malloc( buflen );
                buf[0] = Conn->Interface->IP4.Address.L;
                buf[1] = Conn->RemoteIP.v4.L;
@@ -140,13 +140,17 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
        {
                for( srv = gTCP_Listeners; srv; srv = srv->Next )
                {
+                       Log("[TCP  ] Server %p, Port = 0x%04x", srv, srv->Port);
                        // Check if the server is active
                        if(srv->Port == 0)      continue;
                        // Check the interface
+                       Log("[TCP  ]  Interface = %p (== %p ?)", srv->Interface, Interface);
                        if(srv->Interface && srv->Interface != Interface)       continue;
                        // Check the destination port
-                       if(srv->Port != hdr->DestPort)  continue;
-
+                       Log("[TCP  ]  hdr->DestPort = 0x%04x", ntohs(hdr->DestPort));
+                       if(srv->Port != htons(hdr->DestPort))   continue;
+                       
+                       Log("[TCP  ] Matches");
                        // Is this in an established connection?
                        for( conn = srv->Connections; conn; conn = conn->Next )
                        {
@@ -154,7 +158,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                                if(conn->Interface != Interface)        continue;
 
                                // Check Source Port
-                               if(conn->RemotePort != hdr->SourcePort) continue;
+                               if(conn->RemotePort != ntohs(hdr->SourcePort))  continue;
 
                                // Check Source IP
                                if(conn->Interface->Type == 6 && !IP6_EQU(conn->RemoteIP.v6, *(tIPv6*)Address))
@@ -168,6 +172,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                                return;
                        }
 
+                       Log("[TCP  ] Opening Connection");
                        // Open a new connection (well, check that it's a SYN)
                        if(hdr->Flags != TCP_FLAG_SYN) {
                                Log("[TCP  ] Packet is not a SYN");
@@ -179,7 +184,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                        conn = calloc(1, sizeof(tTCPConnection));
                        conn->State = TCP_ST_HALFOPEN;
                        conn->LocalPort = srv->Port;
-                       conn->RemotePort = hdr->SourcePort;
+                       conn->RemotePort = ntohs(hdr->SourcePort);
                        conn->Interface = Interface;
                        
                        switch(Interface->Type)
@@ -212,9 +217,9 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                        Log("[TCP  ] TODO: Sending SYN ACK");
                        hdr->Flags |= TCP_FLAG_ACK;
                        hdr->AcknowlegementNumber = hdr->SequenceNumber;
-                       hdr->SequenceNumber = conn->NextSequenceSend;
+                       hdr->SequenceNumber = htonl(conn->NextSequenceSend);
                        hdr->DestPort = hdr->SourcePort;
-                       hdr->SourcePort = srv->Port;
+                       hdr->SourcePort = htonl(srv->Port);
                        TCP_SendPacket( conn, sizeof(tTCPHeader), hdr );
 
                        break;
@@ -230,7 +235,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
                        if(conn->Interface != Interface)        continue;
 
                        // Check Source Port
-                       if(conn->RemotePort != hdr->SourcePort) continue;
+                       if(conn->RemotePort != ntohs(hdr->SourcePort))  continue;
 
                        // Check Source IP
                        if(conn->Interface->Type == 6 && !IP6_EQU(conn->RemoteIP.v6, *(tIPv6*)Address))
@@ -429,6 +434,8 @@ tVFS_Node *TCP_Server_Init(tInterface *Interface)
        srv->NextID = 0;
        srv->Connections = NULL;
        srv->Next = NULL;
+       srv->Node.Flags = VFS_FFLAG_DIRECTORY;
+       srv->Node.Size = -1;
        srv->Node.ImplPtr = srv;
        srv->Node.NumACLs = 1;
        srv->Node.ACLs = &gVFS_ACL_EveryoneRW;
@@ -477,6 +484,9 @@ tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, char *Name)
        return NULL;
 }
 
+/**
+ * \brief Handle IOCtl calls
+ */
 int TCP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data)
 {
        tTCPListener    *srv = Node->ImplPtr;
@@ -507,6 +517,9 @@ int TCP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data)
                        srv->Port = TCP_GetUnusedPort();
                else    // Else, mark this as used
                        TCP_AllocatePort(srv->Port);
+               
+               Log("[TCP  ] Server %p listening on port %i", srv, srv->Port);
+               
                return srv->Port;
        }
        return 0;
index eb8fa19..1cff6d9 100644 (file)
@@ -125,7 +125,7 @@ int AddInterface( char *Device )
                return -1;
        }
        
-       printf("-- Added '"IPSTACK_ROOT"/ip%i' using device %s\n", ret, Device);
+       printf("-- Added '"IPSTACK_ROOT"/%i' using device %s\n", ret, Device);
        
        return ret;
 }
index c039e72..324836b 100644 (file)
@@ -11,5 +11,10 @@ ASFLAGS = -felf
 
 all: ../crt0.o
 
+install:
+
+clean:
+       $(RM) ../crt0.o
+
 ../crt0.o: crt0.asm
        $(AS) $(ASFLAGS) $< -o $@

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