mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
[IP] Allow 0xFFFF as Valid Network Port Number (#5074)
* Allow 0xFFFF as valid port number * Note possible reason for failure in TCPAllocatePort * Return NtStatus error on TCP/IP out-of-ports failure * Replace unavailable "ERR" with "DbgPrint"
This commit is contained in:
parent
1fdbc80e58
commit
874d317a71
3 changed files with 30 additions and 17 deletions
|
@ -77,10 +77,14 @@ NTSTATUS TCPListen(PCONNECTION_ENDPOINT Connection, UINT Backlog)
|
|||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
/* Allocate the port in the port bitmap */
|
||||
Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
|
||||
|
||||
/* This should never fail */
|
||||
ASSERT(Connection->AddressFile->Port != 0xFFFF);
|
||||
UINT AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
|
||||
/* This should never fail unless all ports are in use */
|
||||
if (AllocatedPort == (UINT) -1)
|
||||
{
|
||||
DbgPrint("ERR: No more ports available.\n");
|
||||
return STATUS_TOO_MANY_ADDRESSES;
|
||||
}
|
||||
Connection->AddressFile->Port = AllocatedPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ NTSTATUS TCPStartup(VOID)
|
|||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = PortsStartup( &TCPPorts, 1, 0xfffe );
|
||||
Status = PortsStartup(&TCPPorts, 1, 0xffff);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
|
@ -370,6 +370,8 @@ NTSTATUS TCPConnect
|
|||
/* Check if we had an unspecified port */
|
||||
if (!Connection->AddressFile->Port)
|
||||
{
|
||||
UINT AllocatedPort;
|
||||
|
||||
/* We did, so we need to copy back the port */
|
||||
Status = TCPGetSockAddress(Connection, (PTRANSPORT_ADDRESS)&LocalAddress, FALSE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
|
@ -379,10 +381,14 @@ NTSTATUS TCPConnect
|
|||
}
|
||||
|
||||
/* Allocate the port in the port bitmap */
|
||||
Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
|
||||
|
||||
/* This should never fail */
|
||||
ASSERT(Connection->AddressFile->Port != 0xFFFF);
|
||||
AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
|
||||
/* This should never fail unless all ports are in use */
|
||||
if (AllocatedPort == (UINT) -1)
|
||||
{
|
||||
DbgPrint("ERR: No more ports available.\n");
|
||||
return STATUS_TOO_MANY_ADDRESSES;
|
||||
}
|
||||
Connection->AddressFile->Port = AllocatedPort;
|
||||
}
|
||||
|
||||
connaddr.addr = RemoteAddress.Address.IPv4Address;
|
||||
|
|
|
@ -404,6 +404,7 @@ NTSTATUS FileOpenAddress(
|
|||
PVOID Options)
|
||||
{
|
||||
PADDRESS_FILE AddrFile;
|
||||
UINT AllocatedPort;
|
||||
|
||||
TI_DbgPrint(MID_TRACE, ("Called (Proto %d).\n", Protocol));
|
||||
|
||||
|
@ -472,14 +473,15 @@ NTSTATUS FileOpenAddress(
|
|||
if (Address->Address[0].Address[0].sin_port)
|
||||
{
|
||||
/* The client specified an explicit port so we force a bind to this */
|
||||
AddrFile->Port = TCPAllocatePort(Address->Address[0].Address[0].sin_port);
|
||||
AllocatedPort = TCPAllocatePort(Address->Address[0].Address[0].sin_port);
|
||||
|
||||
/* Check for bind success */
|
||||
if (AddrFile->Port == 0xffff)
|
||||
if (AllocatedPort == (UINT)-1)
|
||||
{
|
||||
ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG);
|
||||
return STATUS_ADDRESS_ALREADY_EXISTS;
|
||||
}
|
||||
AddrFile->Port = AllocatedPort;
|
||||
|
||||
/* Sanity check */
|
||||
ASSERT(Address->Address[0].Address[0].sin_port == AddrFile->Port);
|
||||
|
@ -487,14 +489,15 @@ NTSTATUS FileOpenAddress(
|
|||
else if (!AddrIsUnspecified(&AddrFile->Address))
|
||||
{
|
||||
/* The client is trying to bind to a local address so allocate a port now too */
|
||||
AddrFile->Port = TCPAllocatePort(0);
|
||||
AllocatedPort = TCPAllocatePort(0);
|
||||
|
||||
/* Check for bind success */
|
||||
if (AddrFile->Port == 0xffff)
|
||||
if (AllocatedPort == (UINT)-1)
|
||||
{
|
||||
ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG);
|
||||
return STATUS_ADDRESS_ALREADY_EXISTS;
|
||||
}
|
||||
AddrFile->Port = AllocatedPort;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -509,16 +512,16 @@ NTSTATUS FileOpenAddress(
|
|||
|
||||
case IPPROTO_UDP:
|
||||
TI_DbgPrint(MID_TRACE,("Allocating udp port\n"));
|
||||
AddrFile->Port =
|
||||
UDPAllocatePort(Address->Address[0].Address[0].sin_port);
|
||||
AllocatedPort = 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) ||
|
||||
AddrFile->Port == 0xffff)
|
||||
AllocatedPort != Address->Address[0].Address[0].sin_port) ||
|
||||
AllocatedPort == (UINT)-1)
|
||||
{
|
||||
ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG);
|
||||
return STATUS_ADDRESS_ALREADY_EXISTS;
|
||||
}
|
||||
AddrFile->Port = AllocatedPort;
|
||||
|
||||
TI_DbgPrint(MID_TRACE,("Setting port %d (wanted %d)\n",
|
||||
AddrFile->Port,
|
||||
|
|
Loading…
Reference in a new issue