From 756b72155cbcec50d6117329cf3132168a8713b1 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 4 Mar 2010 13:59:21 +0800 Subject: [PATCH 1/1] Bugfixing and testing TCP stack - Also fixed build process --- Kernel/Makefile.BuildNum | 2 +- Kernel/drv/kb.c | 2 +- Modules/IPStack/main.c | 9 +++++-- Modules/IPStack/tcp.c | 29 ++++++++++++++++------- Usermode/Applications/ifconfig_src/main.c | 2 +- Usermode/Libraries/crt0.o_src/Makefile | 5 ++++ 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 511226d0..a1e25812 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1467 +BUILD_NUM = 1479 diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index a546153d..aa807b53 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -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) { diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 37caba8c..7ec76899 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -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; diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index e79a2946..302e07eb 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -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; diff --git a/Usermode/Applications/ifconfig_src/main.c b/Usermode/Applications/ifconfig_src/main.c index eb8fa19d..1cff6d98 100644 --- a/Usermode/Applications/ifconfig_src/main.c +++ b/Usermode/Applications/ifconfig_src/main.c @@ -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; } diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index c039e72b..324836bf 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -11,5 +11,10 @@ ASFLAGS = -felf all: ../crt0.o +install: + +clean: + $(RM) ../crt0.o + ../crt0.o: crt0.asm $(AS) $(ASFLAGS) $< -o $@ -- 2.20.1