Added port allocation.

Datagram: only match a sender if a sender match was specified.

svn path=/trunk/; revision=11660
This commit is contained in:
Art Yerkes 2004-11-14 21:28:21 +00:00
parent e280e1272c
commit b055a01bc8
3 changed files with 75 additions and 16 deletions

View file

@ -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 \

View file

@ -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;
}

View file

@ -67,11 +67,10 @@ VOID DGDeliverData(
while ((CurrentEntry != &AddrFile->ReceiveQueue) && (!Found))
{
Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry);
if (AddrIsEqual(Address, &Current->RemoteAddress))
Found = TRUE;
if (Found)
{
if (!Current->RemotePort ||
AddrIsEqual(Address, &Current->RemoteAddress)) {
Found = TRUE;
/* FIXME: Maybe we should check if the buffer of this
receive request is large enough and if not, search
for another */
@ -95,8 +94,7 @@ VOID DGDeliverData(
DataSize );
/* Complete the receive request */
(*Current->Complete)(Current->Context, STATUS_SUCCESS, DataSize);
Current->Complete(Current->Context, STATUS_SUCCESS, DataSize);
exFreePool( Current );
}
}