diff --git a/reactos/drivers/lib/ip/makefile b/reactos/drivers/lib/ip/makefile index e94ed93aa8a..eb277a19015 100644 --- a/reactos/drivers/lib/ip/makefile +++ b/reactos/drivers/lib/ip/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.6 2004/11/07 20:37:20 arty Exp $ +# $Id: makefile,v 1.7 2004/11/14 21:28:21 arty Exp $ PATH_TO_TOP = ../../.. @@ -32,6 +32,7 @@ TARGET_OBJECTS = \ network/loopback.o \ network/memtrack.o \ network/neighbor.o \ + network/ports.o \ network/prefix.o \ network/receive.o \ network/route.o \ diff --git a/reactos/drivers/lib/ip/network/ports.c b/reactos/drivers/lib/ip/network/ports.c new file mode 100644 index 00000000000..f17cb1ee16f --- /dev/null +++ b/reactos/drivers/lib/ip/network/ports.c @@ -0,0 +1,60 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS TCP/IP protocol driver + * FILE: tcpip/ports.c + * PURPOSE: Port allocation + * PROGRAMMERS: arty (ayerkes@speakeasy.net) + * REVISIONS: + * arty 20041114 Created + */ + +#include "precomp.h" + +VOID PortsStartup( PPORT_SET PortSet, + UINT StartingPort, + UINT PortsToManage ) { + PortSet->StartingPort = StartingPort; + PortSet->PortsToOversee = PortsToManage; + PortSet->ProtoBitBuffer = + PoolAllocateBuffer( (PortSet->PortsToOversee + 7) / 8 ); + RtlInitializeBitMap( &PortSet->ProtoBitmap, + PortSet->ProtoBitBuffer, + PortSet->PortsToOversee ); + ExInitializeFastMutex( &PortSet->Mutex ); +} + +VOID PortsShutdown( PPORT_SET PortSet ) { + PoolFreeBuffer( PortSet->ProtoBitBuffer ); +} + +VOID DeallocatePort( PPORT_SET PortSet, ULONG Port ) { + RtlClearBits( &PortSet->ProtoBitmap, + PortSet->StartingPort + Port, 1 ); +} + +BOOLEAN AllocatePort( PPORT_SET PortSet, ULONG Port ) { + BOOLEAN Clear; + + Port -= PortSet->StartingPort; + + ExAcquireFastMutex( &PortSet->Mutex ); + Clear = RtlAreBitsClear( &PortSet->ProtoBitmap, Port, 1 ); + if( Clear ) RtlSetBits( &PortSet->ProtoBitmap, Port, 1 ); + ExReleaseFastMutex( &PortSet->Mutex ); + + return Clear; +} + +ULONG AllocateAnyPort( PPORT_SET PortSet ) { + ULONG AllocatedPort; + + ExAcquireFastMutex( &PortSet->Mutex ); + AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, 0 ); + if( AllocatedPort != (ULONG)-1 ) { + RtlSetBits( &PortSet->ProtoBitmap, AllocatedPort, 1 ); + AllocatedPort += PortSet->StartingPort; + } + ExReleaseFastMutex( &PortSet->Mutex ); + + return AllocatedPort; +} diff --git a/reactos/drivers/lib/ip/transport/datagram/datagram.c b/reactos/drivers/lib/ip/transport/datagram/datagram.c index 18e36ae0f1b..eff40d26241 100644 --- a/reactos/drivers/lib/ip/transport/datagram/datagram.c +++ b/reactos/drivers/lib/ip/transport/datagram/datagram.c @@ -67,19 +67,18 @@ VOID DGDeliverData( while ((CurrentEntry != &AddrFile->ReceiveQueue) && (!Found)) { Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry); - if (AddrIsEqual(Address, &Current->RemoteAddress)) + + if (!Current->RemotePort || + AddrIsEqual(Address, &Current->RemoteAddress)) { Found = TRUE; - - if (Found) - { - /* FIXME: Maybe we should check if the buffer of this - receive request is large enough and if not, search - for another */ - - /* Remove the request from the queue */ - RemoveEntryList(&Current->ListEntry); - break; - } + /* FIXME: Maybe we should check if the buffer of this + receive request is large enough and if not, search + for another */ + + /* Remove the request from the queue */ + RemoveEntryList(&Current->ListEntry); + break; + } CurrentEntry = CurrentEntry->Flink; } @@ -95,9 +94,8 @@ VOID DGDeliverData( DataSize ); /* Complete the receive request */ - (*Current->Complete)(Current->Context, STATUS_SUCCESS, DataSize); - - exFreePool(Current); + Current->Complete(Current->Context, STATUS_SUCCESS, DataSize); + exFreePool( Current ); } } else if (AddrFile->RegisteredReceiveDatagramHandler)