mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
Added port allocation.
Datagram: only match a sender if a sender match was specified. svn path=/trunk/; revision=11660
This commit is contained in:
parent
e280e1272c
commit
b055a01bc8
3 changed files with 75 additions and 16 deletions
|
@ -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 \
|
||||
|
|
60
reactos/drivers/lib/ip/network/ports.c
Normal file
60
reactos/drivers/lib/ip/network/ports.c
Normal 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;
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue