Author: cgutman
Date: Mon Aug 3 21:34:51 2009
New Revision: 42372
URL:
http://svn.reactos.org/svn/reactos?rev=42372&view=rev
Log:
- Fix some cleanup vs. close confusion
- Check if the search context address is unspecified
Modified:
trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c
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 Aug 3 21:34:51
2009
@@ -98,7 +98,8 @@
(Current->Protocol == SearchContext->Protocol) &&
(AddrIsEqual(IPAddress, SearchContext->Address) ||
AddrIsBroadcast(IPAddress, SearchContext->Address) ||
- AddrIsUnspecified(IPAddress))) {
+ AddrIsUnspecified(IPAddress) ||
+ AddrIsUnspecified(SearchContext->Address))) {
/* We've found a match */
Found = TRUE;
break;
@@ -139,25 +140,161 @@
}
-VOID DeleteAddress(PADDRESS_FILE AddrFile)
-/*
- * FUNCTION: Deletes an address file object
- * ARGUMENTS:
- * AddrFile = Pointer to address file object to delete
- */
+/*
+ * FUNCTION: Open an address file object
+ * ARGUMENTS:
+ * Request = Pointer to TDI request structure for this request
+ * Address = Pointer to address to be opened
+ * Protocol = Protocol on which to open the address
+ * Options = Pointer to option buffer
+ * RETURNS:
+ * Status of operation
+ */
+NTSTATUS FileOpenAddress(
+ PTDI_REQUEST Request,
+ PTA_IP_ADDRESS Address,
+ USHORT Protocol,
+ PVOID Options)
+{
+ IPv4_RAW_ADDRESS IPv4Address;
+ PADDRESS_FILE AddrFile;
+
+ TI_DbgPrint(MID_TRACE, ("Called (Proto %d).\n", Protocol));
+
+ AddrFile = exAllocatePool(NonPagedPool, sizeof(ADDRESS_FILE));
+ if (!AddrFile) {
+ TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ TI_DbgPrint(DEBUG_ADDRFILE, ("Address file object allocated at (0x%X).\n",
AddrFile));
+
+ RtlZeroMemory(AddrFile, sizeof(ADDRESS_FILE));
+
+ AddrFile->Free = AddrFileFree;
+
+ /* Make sure address is a local unicast address or 0 */
+ /* FIXME: IPv4 only */
+ AddrFile->Family = Address->Address[0].AddressType;
+ IPv4Address = Address->Address[0].Address[0].in_addr;
+ if (IPv4Address != 0 &&
+ !AddrLocateADEv4(IPv4Address, &AddrFile->Address)) {
+ exFreePool(AddrFile);
+ TI_DbgPrint(MIN_TRACE, ("Non-local address given (0x%X).\n",
DN2H(IPv4Address)));
+ return STATUS_INVALID_PARAMETER;
+ }
+ else
+ {
+ /* Bound to the default address ... Copy the address type */
+ AddrFile->Address.Type = IP_ADDRESS_V4;
+ }
+
+ TI_DbgPrint(MID_TRACE, ("Opening address %s for communication (P=%d
U=%d).\n",
+ A2S(&AddrFile->Address), Protocol, IPPROTO_UDP));
+
+ /* Protocol specific handling */
+ switch (Protocol) {
+ 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) ||
+ AddrFile->Port == 0xffff)
+ {
+ exFreePool(AddrFile);
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ AddrFile->Send = NULL; /* TCPSendData */
+ break;
+
+ case IPPROTO_UDP:
+ 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) ||
+ AddrFile->Port == 0xffff)
+ {
+ 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));
+ AddrFile->Send = UDPSendDatagram;
+ break;
+
+ case IPPROTO_ICMP:
+ AddrFile->Port = 0;
+ AddrFile->Send = ICMPSendDatagram;
+ break;
+
+ default:
+ /* Use raw IP for all other protocols */
+ AddrFile->Port = 0;
+ AddrFile->Send = RawIPSendDatagram;
+ break;
+ }
+
+ TI_DbgPrint(MID_TRACE, ("IP protocol number for address file object is
%d.\n",
+ Protocol));
+
+ TI_DbgPrint(MID_TRACE, ("Port number for address file object is %d.\n",
+ WN2H(AddrFile->Port)));
+
+ /* Set protocol */
+ AddrFile->Protocol = Protocol;
+
+ /* Initialize receive and transmit queues */
+ InitializeListHead(&AddrFile->ReceiveQueue);
+ InitializeListHead(&AddrFile->TransmitQueue);
+
+ /* Initialize spin lock that protects the address file object */
+ KeInitializeSpinLock(&AddrFile->Lock);
+
+ /* Set valid flag so the address can be used */
+ AF_SET_VALID(AddrFile);
+
+ /* Return address file object */
+ Request->Handle.AddressHandle = AddrFile;
+
+ /* Add address file to global list */
+ ExInterlockedInsertTailList(
+ &AddressFileListHead,
+ &AddrFile->ListEntry,
+ &AddressFileListLock);
+
+ TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
+
+ return STATUS_SUCCESS;
+}
+
+
+/*
+ * FUNCTION: Closes an address file object
+ * ARGUMENTS:
+ * Request = Pointer to TDI request structure for this request
+ * RETURNS:
+ * Status of operation
+ */
+NTSTATUS FileCloseAddress(
+ PTDI_REQUEST Request)
{
KIRQL OldIrql;
+ PADDRESS_FILE AddrFile;
+ NTSTATUS Status = STATUS_SUCCESS;
+ PDATAGRAM_SEND_REQUEST SendRequest;
+ PDATAGRAM_RECEIVE_REQUEST ReceiveRequest;
PLIST_ENTRY CurrentEntry;
PLIST_ENTRY NextEntry;
- PDATAGRAM_SEND_REQUEST SendRequest;
- PDATAGRAM_RECEIVE_REQUEST ReceiveRequest;
TI_DbgPrint(MID_TRACE, ("Called.\n"));
- /* Remove address file from the global list */
- TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
- RemoveEntryList(&AddrFile->ListEntry);
- TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
+ AddrFile = Request->Handle.AddressHandle;
TcpipAcquireSpinLock(&AddrFile->Lock, &OldIrql);
@@ -197,143 +334,9 @@
TcpipReleaseSpinLock(&AddrFile->Lock, OldIrql);
- (*AddrFile->Free)(AddrFile);
-
- TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
-}
-
-
-/*
- * FUNCTION: Open an address file object
- * ARGUMENTS:
- * Request = Pointer to TDI request structure for this request
- * Address = Pointer to address to be opened
- * Protocol = Protocol on which to open the address
- * Options = Pointer to option buffer
- * RETURNS:
- * Status of operation
- */
-NTSTATUS FileOpenAddress(
- PTDI_REQUEST Request,
- PTA_IP_ADDRESS Address,
- USHORT Protocol,
- PVOID Options)
-{
- IPv4_RAW_ADDRESS IPv4Address;
- PADDRESS_FILE AddrFile;
-
- TI_DbgPrint(MID_TRACE, ("Called (Proto %d).\n", Protocol));
-
- AddrFile = exAllocatePool(NonPagedPool, sizeof(ADDRESS_FILE));
- if (!AddrFile) {
- TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- TI_DbgPrint(DEBUG_ADDRFILE, ("Address file object allocated at (0x%X).\n",
AddrFile));
-
- RtlZeroMemory(AddrFile, sizeof(ADDRESS_FILE));
-
- AddrFile->Free = AddrFileFree;
-
- /* Make sure address is a local unicast address or 0 */
- /* FIXME: IPv4 only */
- AddrFile->Family = Address->Address[0].AddressType;
- IPv4Address = Address->Address[0].Address[0].in_addr;
- if (IPv4Address != 0 &&
- !AddrLocateADEv4(IPv4Address, &AddrFile->Address)) {
- exFreePool(AddrFile);
- TI_DbgPrint(MIN_TRACE, ("Non-local address given (0x%X).\n",
DN2H(IPv4Address)));
- return STATUS_INVALID_PARAMETER;
- }
- else
- {
- /* Bound to the default address ... Copy the address type */
- AddrFile->Address.Type = IP_ADDRESS_V4;
- }
-
- TI_DbgPrint(MID_TRACE, ("Opening address %s for communication (P=%d
U=%d).\n",
- A2S(&AddrFile->Address), Protocol, IPPROTO_UDP));
-
- /* Protocol specific handling */
- switch (Protocol) {
- 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) ||
- AddrFile->Port == 0xffff)
- {
- exFreePool(AddrFile);
- return STATUS_INVALID_PARAMETER;
- }
-
- AddrFile->Send = NULL; /* TCPSendData */
- break;
-
- case IPPROTO_UDP:
- 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) ||
- AddrFile->Port == 0xffff)
- {
- 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));
- AddrFile->Send = UDPSendDatagram;
- break;
-
- case IPPROTO_ICMP:
- AddrFile->Port = 0;
- AddrFile->Send = ICMPSendDatagram;
- break;
-
- default:
- /* Use raw IP for all other protocols */
- AddrFile->Port = 0;
- AddrFile->Send = RawIPSendDatagram;
- break;
- }
-
- TI_DbgPrint(MID_TRACE, ("IP protocol number for address file object is
%d.\n",
- Protocol));
-
- TI_DbgPrint(MID_TRACE, ("Port number for address file object is %d.\n",
- WN2H(AddrFile->Port)));
-
- /* Set protocol */
- AddrFile->Protocol = Protocol;
-
- /* Initialize receive and transmit queues */
- InitializeListHead(&AddrFile->ReceiveQueue);
- InitializeListHead(&AddrFile->TransmitQueue);
-
- /* Initialize spin lock that protects the address file object */
- KeInitializeSpinLock(&AddrFile->Lock);
-
- /* Set valid flag so the address can be used */
- AF_SET_VALID(AddrFile);
-
- /* Return address file object */
- Request->Handle.AddressHandle = AddrFile;
-
- /* Add address file to global list */
- ExInterlockedInsertTailList(
- &AddressFileListHead,
- &AddrFile->ListEntry,
- &AddressFileListLock);
-
- TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
-
- return STATUS_SUCCESS;
+ TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
+
+ return Status;
}
@@ -344,24 +347,21 @@
* RETURNS:
* Status of operation
*/
-NTSTATUS FileCloseAddress(
+NTSTATUS FileFreeAddress(
PTDI_REQUEST Request)
{
- KIRQL OldIrql;
PADDRESS_FILE AddrFile;
NTSTATUS Status = STATUS_SUCCESS;
+ KIRQL OldIrql;
+
+ AddrFile = Request->Handle.AddressHandle;
TI_DbgPrint(MID_TRACE, ("Called.\n"));
- AddrFile = Request->Handle.AddressHandle;
-
- TcpipAcquireSpinLock(&AddrFile->Lock, &OldIrql);
-
- /* Set address file object exclusive to us */
- AF_SET_BUSY(AddrFile);
- AF_CLR_VALID(AddrFile);
-
- TcpipReleaseSpinLock(&AddrFile->Lock, OldIrql);
+ /* Remove address file from the global list */
+ TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
+ RemoveEntryList(&AddrFile->ListEntry);
+ TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
/* Protocol specific handling */
switch (AddrFile->Protocol) {
@@ -380,30 +380,7 @@
break;
}
- TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
-
- return Status;
-}
-
-
-/*
- * FUNCTION: Closes an address file object
- * ARGUMENTS:
- * Request = Pointer to TDI request structure for this request
- * RETURNS:
- * Status of operation
- */
-NTSTATUS FileFreeAddress(
- PTDI_REQUEST Request)
-{
- PADDRESS_FILE AddrFile;
- NTSTATUS Status = STATUS_SUCCESS;
-
- AddrFile = Request->Handle.AddressHandle;
-
- TI_DbgPrint(MID_TRACE, ("Called.\n"));
-
- DeleteAddress(AddrFile);
+ (*AddrFile->Free)(AddrFile);
TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));