Author: cgutman
Date: Mon Oct 27 00:16:14 2008
New Revision: 37011
URL:
http://svn.reactos.org/svn/reactos?rev=37011&view=rev
Log:
- Merge aicom-network-fixes up to r37010
- Most of the port allocation problems are now fixed
Modified:
trunk/reactos/drivers/network/tcpip/include/ports.h
trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c
trunk/reactos/lib/drivers/ip/network/ports.c
trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c
trunk/reactos/lib/drivers/ip/transport/udp/udp.c
Modified: trunk/reactos/drivers/network/tcpip/include/ports.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/include/ports.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/include/ports.h [iso-8859-1] Mon Oct 27 00:16:14
2008
@@ -16,7 +16,6 @@
PVOID ProtoBitBuffer;
UINT StartingPort;
UINT PortsToOversee;
- UINT LastAllocatedPort;
FAST_MUTEX Mutex;
} PORT_SET, *PPORT_SET;
Modified: trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] Mon Oct 27 00:16:14
2008
@@ -285,6 +285,14 @@
case IPPROTO_TCP:
AddrFile->Port =
TCPAllocatePort(Address->Address[0].Address[0].sin_port);
+
+ if (Address->Address[0].Address[0].sin_port &&
+ AddrFile->Port != Address->Address[0].Address[0].sin_port)
+ {
+ ExFreePool(AddrFile);
+ return STATUS_INVALID_PARAMETER;
+ }
+
AddrFile->Send = NULL; /* TCPSendData */
break;
@@ -292,6 +300,14 @@
TI_DbgPrint(MID_TRACE,("Allocating udp port\n"));
AddrFile->Port =
UDPAllocatePort(Address->Address[0].Address[0].sin_port);
+
+ if (Address->Address[0].Address[0].sin_port &&
+ AddrFile->Port != Address->Address[0].Address[0].sin_port)
+ {
+ ExFreePool(AddrFile);
+ return STATUS_INVALID_PARAMETER;
+ }
+
TI_DbgPrint(MID_TRACE,("Setting port %d (wanted %d)\n",
AddrFile->Port,
Address->Address[0].Address[0].sin_port));
Modified: trunk/reactos/lib/drivers/ip/network/ports.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/por…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/ports.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/ports.c [iso-8859-1] Mon Oct 27 00:16:14 2008
@@ -15,8 +15,7 @@
UINT PortsToManage ) {
PortSet->StartingPort = StartingPort;
PortSet->PortsToOversee = PortsToManage;
- PortSet->LastAllocatedPort = PortSet->StartingPort +
- PortSet->PortsToOversee - 1;
+
PortSet->ProtoBitBuffer =
PoolAllocateBuffer( (PortSet->PortsToOversee + 7) / 8 );
if(!PortSet->ProtoBitBuffer) return STATUS_INSUFFICIENT_RESOURCES;
@@ -43,8 +42,13 @@
BOOLEAN Clear;
Port = htons(Port);
- ASSERT(Port >= PortSet->StartingPort);
- ASSERT(Port < PortSet->StartingPort + PortSet->PortsToOversee);
+
+ if ((Port < PortSet->StartingPort) ||
+ (Port >= PortSet->StartingPort + PortSet->PortsToOversee))
+ {
+ return FALSE;
+ }
+
Port -= PortSet->StartingPort;
ExAcquireFastMutex( &PortSet->Mutex );
@@ -57,64 +61,41 @@
ULONG AllocateAnyPort( PPORT_SET PortSet ) {
ULONG AllocatedPort;
- ULONG Next;
-
- if (PortSet->StartingPort + PortSet->PortsToOversee <=
- PortSet->LastAllocatedPort + 1) {
- Next = PortSet->StartingPort;
- } else {
- Next = PortSet->LastAllocatedPort + 1;
- }
- Next -= PortSet->StartingPort;
ExAcquireFastMutex( &PortSet->Mutex );
- AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Next );
+ AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, 0 );
if( AllocatedPort != (ULONG)-1 ) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
- PortSet->LastAllocatedPort = AllocatedPort;
+ ExReleaseFastMutex( &PortSet->Mutex );
+ return htons(AllocatedPort);
}
ExReleaseFastMutex( &PortSet->Mutex );
- AllocatedPort = htons(AllocatedPort);
-
- ASSERT(AllocatedPort >= PortSet->StartingPort);
- ASSERT(AllocatedPort < PortSet->StartingPort + PortSet->PortsToOversee);
-
- return AllocatedPort;
+ return -1;
}
ULONG AllocatePortFromRange( PPORT_SET PortSet, ULONG Lowest, ULONG Highest ) {
ULONG AllocatedPort;
- ULONG Next;
- if (PortSet->StartingPort + PortSet->PortsToOversee <=
- PortSet->LastAllocatedPort + 1) {
- Next = PortSet->StartingPort;
- } else {
- Next = PortSet->LastAllocatedPort + 1;
+ if ((Lowest < PortSet->StartingPort) ||
+ (Highest >= PortSet->StartingPort + PortSet->PortsToOversee))
+ {
+ return -1;
}
- if (Next < Lowest || Highest <= Next) {
- Next = Lowest;
- }
- Next -= PortSet->StartingPort;
+
Lowest -= PortSet->StartingPort;
Highest -= PortSet->StartingPort;
ExAcquireFastMutex( &PortSet->Mutex );
- AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Next );
- if( AllocatedPort != (ULONG)-1 && AllocatedPort >= Lowest &&
- AllocatedPort <= Highest) {
+ AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Lowest );
+ if( AllocatedPort != (ULONG)-1 && AllocatedPort <= Highest) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
- PortSet->LastAllocatedPort = AllocatedPort;
+ ExReleaseFastMutex( &PortSet->Mutex );
+ return htons(AllocatedPort);
}
ExReleaseFastMutex( &PortSet->Mutex );
- AllocatedPort = htons(AllocatedPort);
-
- ASSERT(AllocatedPort >= PortSet->StartingPort);
- ASSERT(AllocatedPort < PortSet->StartingPort + PortSet->PortsToOversee);
-
- return AllocatedPort;
+ return -1;
}
Modified: trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/r…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/rawip/rawip.c [iso-8859-1] Mon Oct 27 00:16:14
2008
@@ -223,8 +223,10 @@
TI_DbgPrint(MID_TRACE,("About to get route to destination\n"));
- if(!(NCE = RouteGetRouteToDestination( &RemoteAddress )))
+ if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
+ FreeNdisPacket(Packet.NdisPacket);
return STATUS_UNSUCCESSFUL;
+ }
TI_DbgPrint(MID_TRACE,("About to send datagram\n"));
Modified: trunk/reactos/lib/drivers/ip/transport/udp/udp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/u…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/udp/udp.c [iso-8859-1] Mon Oct 27 00:16:14
2008
@@ -33,15 +33,19 @@
*/
{
PUDP_HEADER UDPHeader;
+ NTSTATUS Status;
TI_DbgPrint(MID_TRACE, ("Packet: %x NdisPacket %x\n",
IPPacket, IPPacket->NdisPacket));
- AddGenericHeaderIPv4
+ Status = AddGenericHeaderIPv4
( RemoteAddress, RemotePort,
LocalAddress, LocalPort,
IPPacket, DataLength, IPPROTO_UDP,
sizeof(UDP_HEADER), (PVOID *)&UDPHeader );
+
+ if (!NT_SUCCESS(Status))
+ return Status;
/* Build UDP header */
UDPHeader = (PUDP_HEADER)((ULONG_PTR)IPPacket->Data - sizeof(UDP_HEADER));
@@ -195,8 +199,10 @@
if( !NT_SUCCESS(Status) )
return Status;
- if(!(NCE = RouteGetRouteToDestination( &RemoteAddress )))
+ if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) {
+ FreeNdisPacket(Packet.NdisPacket);
return STATUS_UNSUCCESSFUL;
+ }
IPSendDatagram( &Packet, NCE, UDPSendPacketComplete, NULL );
@@ -305,7 +311,7 @@
NTSTATUS Status;
- Status = PortsStartup( &UDPPorts, 1, 0xfffe );
+ Status = PortsStartup( &UDPPorts, 1, UDP_STARTING_PORT + UDP_DYNAMIC_PORTS );
if( !NT_SUCCESS(Status) ) return Status;