From 33c558065ff8bb9efbb43cabca69bb6269466c08 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sun, 12 Dec 2004 11:48:04 +0000 Subject: [PATCH] - Fix receiving of loopback packets. - Fix recursive spinlock acquire in NBQueuePacket. - Don't pend connect requests if they're satisfied during the call. - Basic implementation of listen. svn path=/trunk/; revision=12039 --- reactos/drivers/lib/ip/network/loopback.c | 4 ++ reactos/drivers/lib/ip/network/neighbor.c | 16 +++++--- reactos/drivers/lib/ip/network/receive.c | 2 +- reactos/drivers/lib/ip/transport/tcp/tcp.c | 39 +++++++++++++------ .../drivers/lib/oskittcp/oskittcp/in_pcb.c | 2 + .../drivers/lib/oskittcp/oskittcp/interface.c | 8 +++- reactos/drivers/net/tcpip/tcpip/buffer.c | 1 + 7 files changed, 52 insertions(+), 20 deletions(-) diff --git a/reactos/drivers/lib/ip/network/loopback.c b/reactos/drivers/lib/ip/network/loopback.c index 639e174b9c6..e6511810740 100644 --- a/reactos/drivers/lib/ip/network/loopback.c +++ b/reactos/drivers/lib/ip/network/loopback.c @@ -39,11 +39,15 @@ VOID LoopTransmit( IPPacket.NdisPacket = NdisPacket; IPPacket.HeaderSize = 0; GetDataPtr( NdisPacket, 0, (PCHAR *)&IPPacket.Header, &IPPacket.TotalSize ); + IPPacket.Header += Offset; + IPPacket.ContigSize = IPPacket.TotalSize; + IPPacket.Position = Offset; TI_DbgPrint(MAX_TRACE, ("Doing receive (complete: %x, context %x, packet %x)\n", PC(NdisPacket)->DLComplete, Context, NdisPacket)); IPReceive(Context, &IPPacket); + DisplayIPPacket(&IPPacket); TI_DbgPrint(MAX_TRACE, ("Finished receive (complete: %x, context %x, packet %x)\n", PC(NdisPacket)->DLComplete, Context, NdisPacket)); diff --git a/reactos/drivers/lib/ip/network/neighbor.c b/reactos/drivers/lib/ip/network/neighbor.c index a6062aaedaf..49f650ff276 100644 --- a/reactos/drivers/lib/ip/network/neighbor.c +++ b/reactos/drivers/lib/ip/network/neighbor.c @@ -30,8 +30,9 @@ VOID NBSendPackets( PNEIGHBOR_CACHE_ENTRY NCE ) { PNEIGHBOR_PACKET Packet; /* Send any waiting packets */ - if( !IsListEmpty( &NCE->PacketQueue ) ) { - PacketEntry = RemoveHeadList( &NCE->PacketQueue ); + PacketEntry = ExInterlockedRemoveHeadList(&NCE->PacketQueue, + &NCE->Table->Lock); + if( PacketEntry != NULL ) { Packet = CONTAINING_RECORD( PacketEntry, NEIGHBOR_PACKET, Next ); TI_DbgPrint @@ -57,8 +58,9 @@ VOID NBFlushPacketQueue( PNEIGHBOR_CACHE_ENTRY NCE, PLIST_ENTRY PacketEntry; PNEIGHBOR_PACKET Packet; - while( !IsListEmpty( &NCE->PacketQueue ) ) { - PacketEntry = RemoveHeadList( &NCE->PacketQueue ); + PacketEntry = ExInterlockedRemoveHeadList(&NCE->PacketQueue, + &NCE->Table->Lock); + while( PacketEntry != NULL ) { Packet = CONTAINING_RECORD ( PacketEntry, NEIGHBOR_PACKET, Next ); @@ -78,6 +80,8 @@ VOID NBFlushPacketQueue( PNEIGHBOR_CACHE_ENTRY NCE, } PoolFreeBuffer( Packet ); + PacketEntry = ExInterlockedRemoveHeadList(&NCE->PacketQueue, + &NCE->Table->Lock); } } @@ -448,11 +452,11 @@ BOOLEAN NBQueuePacket( Packet->Packet = NdisPacket; InsertTailList( &NCE->PacketQueue, &Packet->Next ); + TcpipReleaseSpinLock(Lock, OldIrql); + if( NCE->State & NUD_CONNECTED ) NBSendPackets( NCE ); - TcpipReleaseSpinLock(Lock, OldIrql); - return TRUE; } diff --git a/reactos/drivers/lib/ip/network/receive.c b/reactos/drivers/lib/ip/network/receive.c index a5bb3395834..eeebcfd5de2 100644 --- a/reactos/drivers/lib/ip/network/receive.c +++ b/reactos/drivers/lib/ip/network/receive.c @@ -395,7 +395,7 @@ VOID ProcessFragment( /* If this is the first fragment, save the IP header */ if (FragFirst == 0) { TI_DbgPrint(DEBUG_IP, ("First fragment found. Header buffer is at (0x%X). " - "Header size is (%d).\n", IPDR->IPv4Header, IPPacket->HeaderSize)); + "Header size is (%d).\n", &IPDR->IPv4Header, IPPacket->HeaderSize)); RtlCopyMemory(&IPDR->IPv4Header, IPPacket->Header, IPPacket->HeaderSize); IPDR->HeaderSize = IPPacket->HeaderSize; diff --git a/reactos/drivers/lib/ip/transport/tcp/tcp.c b/reactos/drivers/lib/ip/transport/tcp/tcp.c index 394ae9da642..4dab97dfec7 100644 --- a/reactos/drivers/lib/ip/transport/tcp/tcp.c +++ b/reactos/drivers/lib/ip/transport/tcp/tcp.c @@ -427,7 +427,7 @@ NTSTATUS TCPConnect TcpipRecursiveMutexLeave( &TCPLock ); - if( Status == OSK_EINPROGRESS || Status == STATUS_SUCCESS ) + if( Status == OSK_EINPROGRESS ) return STATUS_PENDING; else return Status; @@ -496,26 +496,41 @@ NTSTATUS TCPListen UINT Backlog, PTCP_COMPLETION_ROUTINE Complete, PVOID Context) { - NTSTATUS Status; + NTSTATUS Status; + SOCKADDR_IN AddressToBind; - TI_DbgPrint(DEBUG_TCP,("TCPListen started\n")); + TI_DbgPrint(DEBUG_TCP,("TCPListen started\n")); - TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext %x\n", - Connection->SocketContext)); + TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext %x\n", + Connection->SocketContext)); - ASSERT(Connection); - ASSERT_KM_POINTER(Connection->SocketContext); + ASSERT(Connection); + ASSERT_KM_POINTER(Connection->SocketContext); + ASSERT_KM_POINTER(Connection->AddressFile); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); + TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - Status = TCPTranslateError( OskitTCPListen( Connection->SocketContext, + AddressToBind.sin_family = AF_INET; + memcpy( &AddressToBind.sin_addr, + &Connection->AddressFile->Address.Address.IPv4Address, + sizeof(AddressToBind.sin_addr) ); + AddressToBind.sin_port = Connection->AddressFile->Port; + + TI_DbgPrint(DEBUG_TCP,("AddressToBind - %x:%x\n", AddressToBind.sin_addr, AddressToBind.sin_port)); + + OskitTCPBind( Connection->SocketContext, + Connection, + &AddressToBind, + sizeof(AddressToBind) ); + + Status = TCPTranslateError( OskitTCPListen( Connection->SocketContext, Backlog ) ); - TcpipRecursiveMutexLeave( &TCPLock ); + TcpipRecursiveMutexLeave( &TCPLock ); - TI_DbgPrint(DEBUG_TCP,("TCPListen finished %x\n", Status)); + TI_DbgPrint(DEBUG_TCP,("TCPListen finished %x\n", Status)); - return Status; + return Status; } NTSTATUS TCPAccept diff --git a/reactos/drivers/lib/oskittcp/oskittcp/in_pcb.c b/reactos/drivers/lib/oskittcp/oskittcp/in_pcb.c index d5443145834..7d0f36b311c 100644 --- a/reactos/drivers/lib/oskittcp/oskittcp/in_pcb.c +++ b/reactos/drivers/lib/oskittcp/oskittcp/in_pcb.c @@ -150,6 +150,7 @@ in_pcbbind(inp, nam) if (lport) { struct inpcb *t; +#ifndef __REACTOS__ /* GROSS */ if (ntohs(lport) < IPPORT_RESERVED && (error = suser(p->p_ucred, &p->p_acflag))) { @@ -157,6 +158,7 @@ in_pcbbind(inp, nam) ("Leaving EACCESS\n")); return (EACCES); } +#endif t = in_pcblookup(head, zeroin_addr, 0, sin->sin_addr, lport, wild); if (t && (reuseport & t->inp_socket->so_options) == 0) diff --git a/reactos/drivers/lib/oskittcp/oskittcp/interface.c b/reactos/drivers/lib/oskittcp/oskittcp/interface.c index 60ba5e5dfbb..6dd4fb99a99 100644 --- a/reactos/drivers/lib/oskittcp/oskittcp/interface.c +++ b/reactos/drivers/lib/oskittcp/oskittcp/interface.c @@ -324,7 +324,13 @@ void OskitTCPReceiveDatagram( OSK_PCHAR Data, OSK_UINT Len, } int OskitTCPListen( void *socket, int backlog ) { - return solisten( socket, backlog ); + int error; + + OS_DbgPrint(OSK_MID_TRACE,("Called, socket = %08x\n", socket)); + error = solisten( socket, backlog ); + OS_DbgPrint(OSK_MID_TRACE,("Ending: %08x\n", error)); + + return error; } void OskitTCPSetAddress( void *socket, diff --git a/reactos/drivers/net/tcpip/tcpip/buffer.c b/reactos/drivers/net/tcpip/tcpip/buffer.c index b098b54e820..c9c4d463e80 100644 --- a/reactos/drivers/net/tcpip/tcpip/buffer.c +++ b/reactos/drivers/net/tcpip/tcpip/buffer.c @@ -370,6 +370,7 @@ NDIS_STATUS AllocatePacketWithBufferX( PNDIS_PACKET *NdisPacket, ExFreePool( NewData ); UntrackFL( File, Line, Packet ); FreeNdisPacket( Packet ); + return Status; } TrackWithTag(NDIS_BUFFER_TAG, Buffer, File, Line);