From: John Hodge Date: Sun, 27 Feb 2011 10:46:15 +0000 (+0800) Subject: IPStack - Bugfixing (and testing IRC client) X-Git-Tag: rel0.10~197 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4dcdedff0ff1494189773c2d724f76a0291ca155;p=tpg%2Facess2.git IPStack - Bugfixing (and testing IRC client) --- diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 004497db..2b04a6a5 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -119,10 +119,64 @@ int IPStack_Install(char **Arguments) // Route for addrData/iBits, no next hop, default metric IPStack_AddRoute(iface->Name, iface->Address, iBits, NULL, 0); } + + continue; } - // I could also define routes using ,,, + // I could also define routes using ::[:] // Example: 1:00000000:0:0A000201 + if( '0' <= Arguments[i][0] && Arguments[i][0] <= '9' ) + { + // Define Interface + char *ifaceName, *network, *bits, *gateway; + + // Read definition + ifaceName = Arguments[i]; + + network = strchr(ifaceName, ':'); + if( !network ) { + Log_Warning("IPStack", ":::"); + continue; + } + *network = '\0'; network ++; + + bits = strchr(network, ':'); + if( !bits ) { + Log_Warning("IPStack", ":::"); + continue; + } + *bits = '\0'; bits ++; + + gateway = strchr(bits, ':'); + if( gateway ) { + *gateway = '\0'; gateway ++; + } + + // Define route + { + tVFS_Node *node = IPStack_Root_FindDir(NULL, ifaceName); + if( !node ) { + Log_Warning("IPStack", "Unknown interface '%s' in arg %i", ifaceName, i); + continue ; + } + tInterface *iface = node->ImplPtr; + + int size = IPStack_GetAddressSize(iface->Type); + Uint8 netData[size]; + Uint8 gwData[size]; + int iBits = atoi(bits); + + UnHex(netData, size, network); + if( gateway ) + UnHex(gwData, size, gateway); + else + memset(gwData, 0, size); + + IPStack_AddRoute(ifaceName, netData, iBits, gwData, 30); + } + + continue; + } } } diff --git a/Modules/IPStack/routing.c b/Modules/IPStack/routing.c index 6b8aa1a1..fd234da7 100644 --- a/Modules/IPStack/routing.c +++ b/Modules/IPStack/routing.c @@ -2,7 +2,7 @@ * Acess2 IP Stack * - Routing Tables */ -#define DEBUG 1 +#define DEBUG 0 #define VERSION VER2(0,10) #include #include diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index 51f6ae43..f292ea86 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -104,27 +104,27 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe tTCPListener *srv; tTCPConnection *conn; - Log_Log("TCP", "SourcePort = %i, DestPort = %i", + Log_Log("TCP", "TCP_GetPacket: SourcePort = %i, DestPort = %i", ntohs(hdr->SourcePort), ntohs(hdr->DestPort)); /* - Log_Log("TCP", "SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber)); - Log_Log("TCP", "AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber)); - Log_Log("TCP", "DataOffset = %i", hdr->DataOffset >> 4); - Log_Log("TCP", "Flags = {"); - Log_Log("TCP", " CWR = %B, ECE = %B", + Log_Log("TCP", "TCP_GetPacket: SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber)); + Log_Log("TCP", "TCP_GetPacket: AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber)); + Log_Log("TCP", "TCP_GetPacket: DataOffset = %i", hdr->DataOffset >> 4); + Log_Log("TCP", "TCP_GetPacket: Flags = {"); + Log_Log("TCP", "TCP_GetPacket: CWR = %B, ECE = %B", !!(hdr->Flags & TCP_FLAG_CWR), !!(hdr->Flags & TCP_FLAG_ECE)); - Log_Log("TCP", " URG = %B, ACK = %B", + Log_Log("TCP", "TCP_GetPacket: URG = %B, ACK = %B", !!(hdr->Flags & TCP_FLAG_URG), !!(hdr->Flags & TCP_FLAG_ACK)); - Log_Log("TCP", " PSH = %B, RST = %B", + Log_Log("TCP", "TCP_GetPacket: PSH = %B, RST = %B", !!(hdr->Flags & TCP_FLAG_PSH), !!(hdr->Flags & TCP_FLAG_RST)); - Log_Log("TCP", " SYN = %B, FIN = %B", + Log_Log("TCP", "TCP_GetPacket: SYN = %B, FIN = %B", !!(hdr->Flags & TCP_FLAG_SYN), !!(hdr->Flags & TCP_FLAG_FIN)); - Log_Log("TCP", "}"); - Log_Log("TCP", "WindowSize = %i", htons(hdr->WindowSize)); - Log_Log("TCP", "Checksum = 0x%x", htons(hdr->Checksum)); - Log_Log("TCP", "UrgentPointer = 0x%x", htons(hdr->UrgentPointer)); + Log_Log("TCP", "TCP_GetPacket: }"); + Log_Log("TCP", "TCP_GetPacket: WindowSize = %i", htons(hdr->WindowSize)); + Log_Log("TCP", "TCP_GetPacket: Checksum = 0x%x", htons(hdr->Checksum)); + Log_Log("TCP", "TCP_GetPacket: UrgentPointer = 0x%x", htons(hdr->UrgentPointer)); */ - Log_Log("TCP", "Flags = %s%s%s%s%s%s", + Log_Log("TCP", "TCP_GetPacket: Flags = %s%s%s%s%s%s", (hdr->Flags & TCP_FLAG_CWR) ? "CWR " : "", (hdr->Flags & TCP_FLAG_ECE) ? "ECE " : "", (hdr->Flags & TCP_FLAG_URG) ? "URG " : "", @@ -155,17 +155,17 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe // Check the destination port if(srv->Port != htons(hdr->DestPort)) continue; - Log_Log("TCP", "Matches server %p", srv); + Log_Log("TCP", "TCP_GetPacket: Matches server %p", srv); // Is this in an established connection? for( conn = srv->Connections; conn; conn = conn->Next ) { - Log_Log("TCP", "conn->Interface(%p) == Interface(%p)", + Log_Log("TCP", "TCP_GetPacket: conn->Interface(%p) == Interface(%p)", conn->Interface, Interface); // Check that it is coming in on the same interface if(conn->Interface != Interface) continue; // Check Source Port - Log_Log("TCP", "conn->RemotePort(%i) == hdr->SourcePort(%i)", + Log_Log("TCP", "TCP_GetPacket: conn->RemotePort(%i) == hdr->SourcePort(%i)", conn->RemotePort, ntohs(hdr->SourcePort)); if(conn->RemotePort != ntohs(hdr->SourcePort)) continue; @@ -175,17 +175,17 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe if(conn->Interface->Type == 4 && !IP4_EQU(conn->RemoteIP.v4, *(tIPv4*)Address)) continue; - Log_Log("TCP", "Matches connection %p", conn); + Log_Log("TCP", "TCP_GetPacket: Matches connection %p", conn); // We have a response! TCP_INT_HandleConnectionPacket(conn, hdr, Length); return; } - Log_Log("TCP", "Opening Connection"); + 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", "Packet is not a SYN"); + Log_Log("TCP", "TCP_GetPacket: Packet is not a SYN"); return ; } @@ -268,7 +268,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe } } - Log_Log("TCP", "No Match"); + Log_Log("TCP", "TCP_GetPacket: No Match"); } /** @@ -869,57 +869,59 @@ void TCP_StartConnection(tTCPConnection *Conn) int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data) { tTCPConnection *conn = Node->ImplPtr; + + ENTER("pNode iID pData", Node, ID, Data); switch(ID) { case 4: // Get/Set local port if(!Data) - return conn->LocalPort; + LEAVE_RET('i', conn->LocalPort); if(conn->State != TCP_ST_CLOSED) - return -1; + LEAVE_RET('i', -1); if(!CheckMem(Data, sizeof(Uint16))) - return -1; + LEAVE_RET('i', -1); if(Threads_GetUID() != 0 && *(Uint16*)Data < 1024) - return -1; + LEAVE_RET('i', -1); conn->LocalPort = *(Uint16*)Data; - return 0; + LEAVE_RET('i', conn->LocalPort); case 5: // Get/Set remote port - if(!Data) return conn->RemotePort; - if(conn->State != TCP_ST_CLOSED) return -1; - if(!CheckMem(Data, sizeof(Uint16))) return -1; + if(!Data) LEAVE_RET('i', conn->RemotePort); + if(conn->State != TCP_ST_CLOSED) LEAVE_RET('i', -1); + if(!CheckMem(Data, sizeof(Uint16))) LEAVE_RET('i', -1); conn->RemotePort = *(Uint16*)Data; - return conn->RemotePort; + LEAVE_RET('i', conn->RemotePort); case 6: // Set Remote IP if( conn->State != TCP_ST_CLOSED ) - return -1; + LEAVE_RET('i', -1); if( conn->Interface->Type == 4 ) { - if(!CheckMem(Data, sizeof(tIPv4))) return -1; + if(!CheckMem(Data, sizeof(tIPv4))) LEAVE_RET('i', -1); conn->RemoteIP.v4 = *(tIPv4*)Data; } else if( conn->Interface->Type == 6 ) { - if(!CheckMem(Data, sizeof(tIPv6))) return -1; + if(!CheckMem(Data, sizeof(tIPv6))) LEAVE_RET('i', -1); conn->RemoteIP.v6 = *(tIPv6*)Data; } - return 0; + LEAVE_RET('i', 0); case 7: // Connect if(conn->LocalPort == 0xFFFF) conn->LocalPort = TCP_GetUnusedPort(); if(conn->RemotePort == -1) - return 0; + LEAVE_RET('i', 0); TCP_StartConnection(conn); - return 1; + LEAVE_RET('i', 1); // Get recieve buffer length case 8: - return conn->RecievedBuffer->Length; + LEAVE_RET('i', conn->RecievedBuffer->Length); } return 0; @@ -930,6 +932,8 @@ void TCP_Client_Close(tVFS_Node *Node) tTCPConnection *conn = Node->ImplPtr; tTCPHeader packet; + ENTER("pNode", Node); + packet.SourcePort = htons(conn->LocalPort); packet.DestPort = htons(conn->RemotePort); packet.DataOffset = (sizeof(tTCPHeader)/4)*16; @@ -946,4 +950,6 @@ void TCP_Client_Close(tVFS_Node *Node) while( conn->State == TCP_ST_FIN_SENT ) Threads_Yield(); free(conn); + + LEAVE('-'); } diff --git a/Usermode/Applications/irc_src/main.c b/Usermode/Applications/irc_src/main.c index 4fce928b..b4892e79 100644 --- a/Usermode/Applications/irc_src/main.c +++ b/Usermode/Applications/irc_src/main.c @@ -52,11 +52,17 @@ int main(int argc, const char *argv[], const char *envp[]) } printf("Connection opened\n"); + ProcessIncoming(&srv); writef(srv.FD, "USER %s %s %s : %s\n", gsUsername, gsHostname, gsRemoteAddress, gsRealName); - writef(srv.FD, "NICK %s", gsNickname); + writef(srv.FD, "NICK %s\n", gsNickname); - ProcessIncoming(&srv); + printf("Processing\n"); + + for( ;; ) + { + ProcessIncoming(&srv); + } close(srv.FD); return 0; @@ -86,6 +92,8 @@ char *GetValue(char *Src, int *Ofs) char *ret = Src + pos; char *end; + if( !Src ) return NULL; + while( *ret == ' ' ) ret ++; end = strchr(ret, ' '); @@ -104,7 +112,7 @@ char *GetValue(char *Src, int *Ofs) */ void ParseServerLine(tServer *Server, char *Line) { - int pos; + int pos = 0; char *ident, *cmd; if( *Line == ':' ) { // Message @@ -143,10 +151,12 @@ void ProcessIncoming(tServer *Server) // process it line by line // ioctl#8 on a TCP client gets the number of bytes in the recieve buffer // - Used to avoid blocking - while( ioctl(Server->FD, 8, NULL) ) + #if NON_BLOCK_READ + while( (len = ioctl(Server->FD, 8, NULL)) > 0 ) { + #endif // Read data - len = read(Server->FD, BUFSIZ - Server->ReadPos, Server->InBuf + Server->ReadPos); + len = read(Server->FD, BUFSIZ - Server->ReadPos, &Server->InBuf[Server->ReadPos]); Server->InBuf[Server->ReadPos + len] = '\0'; // Break into lines @@ -161,13 +171,19 @@ void ProcessIncoming(tServer *Server) // Handle incomplete lines if( ptr - Server->InBuf < len + Server->ReadPos ) { - Server->ReadPos = ptr - Server->InBuf; + // Update the read position + // InBuf ReadPos ptr ReadPos+len + // | old | new used | new unused | + Server->ReadPos = len + Server->ReadPos - (ptr - Server->InBuf); + // Copy stuff back (moving "new unused" to the start of the buffer) memcpy(Server->InBuf, ptr, Server->ReadPos); } else { Server->ReadPos = 0; } + #if NON_BLOCK_READ } + #endif } /**