From 4ec1a851b94251af29c37808e9a916f8b0c602f7 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Thu, 30 Sep 2004 05:44:10 +0000 Subject: [PATCH] Changes to the interface to componentized ip library. This commit is where the ambiguously linked library starts being used in km. There are further cleanups i need to do, but hopefully having this checked in will help others who are eager to help work on it. svn path=/trunk/; revision=11126 --- reactos/drivers/net/tcpip/datalink/loopback.c | 1 - reactos/drivers/net/tcpip/include/loopback.h | 2 - reactos/drivers/net/tcpip/include/memtrack.h | 14 --- reactos/drivers/net/tcpip/include/tcp.h | 35 ++++-- reactos/drivers/net/tcpip/makefile | 51 +++------ reactos/drivers/net/tcpip/tcpip/dispatch.c | 50 ++++---- reactos/drivers/net/tcpip/tcpip/fileobjs.c | 108 ++++++++++++++---- 7 files changed, 147 insertions(+), 114 deletions(-) diff --git a/reactos/drivers/net/tcpip/datalink/loopback.c b/reactos/drivers/net/tcpip/datalink/loopback.c index cbe06d91245..22db515d0d1 100644 --- a/reactos/drivers/net/tcpip/datalink/loopback.c +++ b/reactos/drivers/net/tcpip/datalink/loopback.c @@ -10,7 +10,6 @@ #include "precomp.h" - WORK_QUEUE_ITEM LoopWorkItem; PIP_INTERFACE Loopback = NULL; /* Indicates wether the loopback interface is currently transmitting */ diff --git a/reactos/drivers/net/tcpip/include/loopback.h b/reactos/drivers/net/tcpip/include/loopback.h index e5c31c49ff1..02ba55f8723 100644 --- a/reactos/drivers/net/tcpip/include/loopback.h +++ b/reactos/drivers/net/tcpip/include/loopback.h @@ -9,10 +9,8 @@ #include - extern PIP_INTERFACE Loopback; - NDIS_STATUS LoopRegisterAdapter( PNDIS_STRING AdapterName, PLAN_ADAPTER *Adapter); diff --git a/reactos/drivers/net/tcpip/include/memtrack.h b/reactos/drivers/net/tcpip/include/memtrack.h index 72121cbd058..93726567f87 100644 --- a/reactos/drivers/net/tcpip/include/memtrack.h +++ b/reactos/drivers/net/tcpip/include/memtrack.h @@ -14,20 +14,6 @@ #ifdef MEMTRACK #define MTMARK() TrackDumpFL(__FILE__, __LINE__) -#define NdisAllocateBuffer(x,y,z,a,b) { \ - NdisAllocateBuffer(x,y,z,a,b); \ - if( *x == NDIS_STATUS_SUCCESS ) { \ - Track(NDIS_BUFFER_TAG, *y); \ - } \ -} -#define NdisAllocatePacket(x,y,z) { \ - NdisAllocatePacket(x,y,z); \ - if( *x == NDIS_STATUS_SUCCESS ) { \ - Track(NDIS_PACKET_TAG, *y); \ - } \ -} -#define NdisFreePacket(x) { Untrack(x); NdisFreePacket(x); } -#define NdisFreeBuffer(x) { Untrack(x); NdisFreeBuffer(x); } #define exAllocatePool(x,y) ExAllocatePoolX(x,y,__FILE__,__LINE__) #define exAllocatePoolWithTag(x,y,z) ExAllocatePoolX(x,y,__FILE__,__LINE__) #define exFreePool(x) ExFreePoolX(x,__FILE__,__LINE__) diff --git a/reactos/drivers/net/tcpip/include/tcp.h b/reactos/drivers/net/tcpip/include/tcp.h index b8468b3ab4b..1be257de1d8 100644 --- a/reactos/drivers/net/tcpip/include/tcp.h +++ b/reactos/drivers/net/tcpip/include/tcp.h @@ -81,6 +81,12 @@ typedef struct _SLEEPING_THREAD { #define SRF_SYN TCP_SYN #define SRF_FIN TCP_FIN +PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext ); +VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection ); + +NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection, + UINT Family, UINT Type, UINT Proto ); + PTCP_SEGMENT TCPCreateSegment( PIP_PACKET IPPacket, PTCPv4_HEADER TCPHeader, @@ -95,30 +101,35 @@ VOID TCPAddSegment( PULONG Acknowledged); NTSTATUS TCPConnect( - PTDI_REQUEST Request, + PCONNECTION_ENDPOINT Connection, PTDI_CONNECTION_INFORMATION ConnInfo, - PTDI_CONNECTION_INFORMATION ReturnInfo); + PTDI_CONNECTION_INFORMATION ReturnInfo, + PTCP_COMPLETION_ROUTINE Complete, + PVOID Context); NTSTATUS TCPListen( - PTDI_REQUEST Request, - UINT Backlog ); + PCONNECTION_ENDPOINT Connection, + UINT Backlog, + PTCP_COMPLETION_ROUTINE Complete, + PVOID Context); NTSTATUS TCPReceiveData( - PTDI_REQUEST Request, + PCONNECTION_ENDPOINT Connection, PNDIS_BUFFER Buffer, ULONG ReceiveLength, + PULONG BytesReceived, ULONG ReceiveFlags, - PULONG BytesReceived); + PTCP_COMPLETION_ROUTINE Complete, + PVOID Context); NTSTATUS TCPSendData( - PTDI_REQUEST Request, - PNDIS_BUFFER Buffer, + PCONNECTION_ENDPOINT Connection, + PCHAR Buffer, ULONG DataSize, - ULONG Flags, - PULONG DataUsed); + PULONG DataUsed, + ULONG Flags); -NTSTATUS TCPClose -( PTDI_REQUEST Request ); +NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection ); PVOID TCPPrepareInterface( PIP_INTERFACE IF ); diff --git a/reactos/drivers/net/tcpip/makefile b/reactos/drivers/net/tcpip/makefile index 2dd47379841..b4c062c3c10 100644 --- a/reactos/drivers/net/tcpip/makefile +++ b/reactos/drivers/net/tcpip/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.22 2004/09/25 21:32:56 arty Exp $ +# $Id: makefile,v 1.23 2004/09/30 05:44:10 arty Exp $ PATH_TO_TOP = ../../.. @@ -20,46 +20,31 @@ TARGET_CFLAGS = \ -I$(PATH_TO_TOP)/w32api/include \ -I$(PATH_TO_TOP)/include -TARGET_DDKLIBS = ndis.a \ +TARGET_DDKLIBS = \ $(PATH_TO_TOP)/dk/w32/lib/oskittcp.a \ - $(PATH_TO_TOP)/dk/w32/lib/rosrtl.a + $(PATH_TO_TOP)/dk/w32/lib/ip.a \ + $(PATH_TO_TOP)/dk/w32/lib/rosrtl.a \ + ndis.a -TARGET_CLEAN = \ - tcpip/*.o \ - datalink/*.o \ - network/*.o \ - transport/datagram/*.o \ - transport/rawip/*.o \ - transport/tcp/*.o \ - transport/udp/*.o +TARGET_CLEAN = tcpip/*.o datalink/*.o -TCPIP_OBJECTS = tcpip/main.o tcpip/address.o tcpip/checksum.o \ - tcpip/dispatch.o tcpip/fileobjs.o \ - tcpip/pool.o tcpip/routines.o tcpip/interface.o \ - tcpip/memtrack.o tcpip/irp.o +TCPIP_OBJECTS = tcpip/main.o \ + tcpip/dispatch.o \ + tcpip/fileobjs.o \ + tcpip/pool.o \ + tcpip/irp.o INFO_OBJECTS = tcpip/info.o tcpip/ninfo.o tcpip/tinfo.o tcpip/iinfo.o -DATALINK_OBJECTS = datalink/arp.o datalink/lan.o datalink/loopback.o -NETWORK_OBJECTS = network/icmp.o network/ip.o network/neighbor.o \ - network/receive.o network/route.o network/router.o \ - network/transmit.o network/prefix.o -DATAGRAM_OBJECTS = transport/datagram/datagram.o -RAWIP_OBJECTS = transport/rawip/rawip.o -TCP_OBJECTS = transport/tcp/tcp.o transport/tcp/event.o transport/tcp/if.o -UDP_OBJECTS = transport/udp/udp.o -ARCH_OBJECTS = tcpip/i386/checksum.o +DATALINK_OBJECTS = datalink/lan.o datalink/loopback.o TARGET_OBJECTS = \ $(TCPIP_OBJECTS) \ $(INFO_OBJECTS) \ - $(DATALINK_OBJECTS) \ - $(NETWORK_OBJECTS) \ - $(DATAGRAM_OBJECTS) \ - $(RAWIP_OBJECTS) \ - $(TCP_OBJECTS) \ - $(FREEBSD_OBJECTS) \ - $(REACTOS_OBJECTS) \ - $(UDP_OBJECTS) \ - $(ARCH_OBJECTS) \ + $(DATALINK_OBJECTS) + +preall: all + +$(PATH_TO_TOP)/dk/w32/lib/ipkernel.a: + $(MAKE) -C $(PATH_TO_TOP)/drivers/lib/ip include $(PATH_TO_TOP)/rules.mak diff --git a/reactos/drivers/net/tcpip/tcpip/dispatch.c b/reactos/drivers/net/tcpip/tcpip/dispatch.c index 12bd63f3adc..6115da87801 100644 --- a/reactos/drivers/net/tcpip/tcpip/dispatch.c +++ b/reactos/drivers/net/tcpip/tcpip/dispatch.c @@ -345,7 +345,6 @@ NTSTATUS DispTdiConnect( PTDI_REQUEST_KERNEL Parameters; PTRANSPORT_CONTEXT TranContext; PIO_STACK_LOCATION IrpSp; - TDI_REQUEST Request; NTSTATUS Status; TI_DbgPrint(DEBUG_IRP, ("Called.\n")); @@ -368,11 +367,6 @@ NTSTATUS DispTdiConnect( Parameters = (PTDI_REQUEST_KERNEL)&IrpSp->Parameters; - /* Initialize a connect request */ - Request.Handle.ConnectionContext = TranContext->Handle.ConnectionContext; - Request.RequestNotifyObject = DispDataRequestComplete; - Request.RequestContext = Irp; - #if 0 Status = TCPBind( Connection, &Connection->SocketContext, @@ -384,9 +378,11 @@ NTSTATUS DispTdiConnect( #endif Status = TCPConnect( - &Request, + TranContext->Handle.ConnectionContext, Parameters->RequestConnectionInformation, - Parameters->ReturnConnectionInformation); + Parameters->ReturnConnectionInformation, + DispDataRequestComplete, + Irp ); TI_DbgPrint(MAX_TRACE, ("TCP Connect returned %08x\n", Status)); @@ -561,7 +557,9 @@ NTSTATUS DispTdiListen( Parameters = (PTDI_REQUEST_KERNEL)&IrpSp->Parameters; - Status = TCPListen( Request, 1024 /* BACKLOG */ ); + Status = TCPListen( Request->Handle.ConnectionContext, 1024 /* BACKLOG */, + DispDataRequestComplete, + Irp ); return Status; } @@ -663,7 +661,6 @@ NTSTATUS DispTdiReceive( PIO_STACK_LOCATION IrpSp; PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo; PTRANSPORT_CONTEXT TranContext; - TDI_REQUEST Request; NTSTATUS Status; ULONG BytesReceived; @@ -686,9 +683,6 @@ NTSTATUS DispTdiReceive( } /* Initialize a receive request */ - Request.Handle.ConnectionContext = TranContext->Handle.ConnectionContext; - Request.RequestNotifyObject = DispDataRequestComplete; - Request.RequestContext = Irp; Status = DispPrepareIrpForCancel( IrpSp->FileObject->FsContext, Irp, @@ -697,11 +691,13 @@ NTSTATUS DispTdiReceive( if (NT_SUCCESS(Status)) { Status = TCPReceiveData( - &Request, - (PNDIS_BUFFER)Irp->MdlAddress, - ReceiveInfo->ReceiveLength, - ReceiveInfo->ReceiveFlags, - &BytesReceived); + TranContext->Handle.ConnectionContext, + (PNDIS_BUFFER)Irp->MdlAddress, + ReceiveInfo->ReceiveLength, + &BytesReceived, + ReceiveInfo->ReceiveFlags, + DispDataRequestComplete, + Irp); if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, BytesReceived); @@ -796,7 +792,6 @@ NTSTATUS DispTdiSend( PIO_STACK_LOCATION IrpSp; PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo; PTRANSPORT_CONTEXT TranContext; - TDI_REQUEST Request; NTSTATUS Status; ULONG BytesReceived; @@ -818,10 +813,6 @@ NTSTATUS DispTdiSend( return STATUS_INVALID_CONNECTION; } - /* Initialize a receive request */ - Request.Handle.ConnectionContext = TranContext->Handle.ConnectionContext; - Request.RequestNotifyObject = DispDataRequestComplete; - Request.RequestContext = Irp; Status = DispPrepareIrpForCancel( IrpSp->FileObject->FsContext, Irp, @@ -829,13 +820,18 @@ NTSTATUS DispTdiSend( TI_DbgPrint(MID_TRACE,("TCPIP<<< Got an MDL: %x\n", Irp->MdlAddress)); if (NT_SUCCESS(Status)) { + PCHAR Data; + UINT Len; + + NdisQueryBuffer( Irp->MdlAddress, &Data, &Len ); + TI_DbgPrint(MID_TRACE,("About to TCPSendData\n")); Status = TCPSendData( - &Request, - (PNDIS_BUFFER)Irp->MdlAddress, + TranContext->Handle.ConnectionContext, + Data, ReceiveInfo->ReceiveLength, - ReceiveInfo->ReceiveFlags, - &BytesReceived); + &BytesReceived, + ReceiveInfo->ReceiveFlags); if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, BytesReceived); diff --git a/reactos/drivers/net/tcpip/tcpip/fileobjs.c b/reactos/drivers/net/tcpip/tcpip/fileobjs.c index ddeda9e8bcd..26a0edaa04a 100644 --- a/reactos/drivers/net/tcpip/tcpip/fileobjs.c +++ b/reactos/drivers/net/tcpip/tcpip/fileobjs.c @@ -19,6 +19,86 @@ KSPIN_LOCK AddressFileListLock; LIST_ENTRY ConnectionEndpointListHead; KSPIN_LOCK ConnectionEndpointListLock; +/* + * FUNCTION: Searches through address file entries to find the first match + * ARGUMENTS: + * Address = IP address + * Port = Port number + * Protocol = Protocol number + * SearchContext = Pointer to search context + * RETURNS: + * Pointer to address file, NULL if none was found + */ +PADDRESS_FILE AddrSearchFirst( + PIP_ADDRESS Address, + USHORT Port, + USHORT Protocol, + PAF_SEARCH SearchContext) +{ + SearchContext->Address = Address; + SearchContext->Port = Port; + SearchContext->Next = AddressFileListHead.Flink; + SearchContext->Protocol = Protocol; + + return AddrSearchNext(SearchContext); +} + +/* + * FUNCTION: Searches through address file entries to find next match + * ARGUMENTS: + * SearchContext = Pointer to search context + * RETURNS: + * Pointer to address file, NULL if none was found + */ +PADDRESS_FILE AddrSearchNext( + PAF_SEARCH SearchContext) +{ + PLIST_ENTRY CurrentEntry; + PIP_ADDRESS IPAddress; + KIRQL OldIrql; + PADDRESS_FILE Current = NULL; + BOOLEAN Found = FALSE; + + if (IsListEmpty(SearchContext->Next)) + return NULL; + + CurrentEntry = SearchContext->Next; + + KeAcquireSpinLock(&AddressFileListLock, &OldIrql); + + while (CurrentEntry != &AddressFileListHead) { + Current = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry); + + IPAddress = Current->ADE->Address; + + TI_DbgPrint(DEBUG_ADDRFILE, ("Comparing: ((%d, %d, %s), (%d, %d, %s)).\n", + WN2H(Current->Port), + Current->Protocol, + A2S(IPAddress), + WN2H(SearchContext->Port), + SearchContext->Protocol, + A2S(SearchContext->Address))); + + /* See if this address matches the search criteria */ + if (((Current->Port == SearchContext->Port) && + (Current->Protocol == SearchContext->Protocol) && + (AddrIsEqual(IPAddress, SearchContext->Address))) || + (AddrIsUnspecified(IPAddress))) { + /* We've found a match */ + Found = TRUE; + break; + } + CurrentEntry = CurrentEntry->Flink; + } + + KeReleaseSpinLock(&AddressFileListLock, OldIrql); + + if (Found) { + SearchContext->Next = CurrentEntry->Flink; + return Current; + } else + return NULL; +} VOID AddrFileFree( PVOID Object) @@ -435,30 +515,8 @@ NTSTATUS FileOpenConnection( TI_DbgPrint(MID_TRACE, ("Called.\n")); - Connection = ExAllocatePool(NonPagedPool, sizeof(CONNECTION_ENDPOINT)); - if (!Connection) - return STATUS_INSUFFICIENT_RESOURCES; - - TI_DbgPrint(DEBUG_CPOINT, ("Connection point file object allocated at (0x%X).\n", Connection)); - - RtlZeroMemory(Connection, sizeof(CONNECTION_ENDPOINT)); - - /* Initialize spin lock that protects the connection endpoint file object */ - KeInitializeSpinLock(&Connection->Lock); - InitializeListHead(&Connection->ConnectRequest); - InitializeListHead(&Connection->ListenRequest); - InitializeListHead(&Connection->ReceiveRequest); - - /* Reference the object */ - Connection->RefCount = 1; - - /* Save client context pointer */ - Connection->ClientContext = ClientContext; - Status = OskitTCPSocket( Connection, - &Connection->SocketContext, - AF_INET, - SOCK_STREAM, - IPPROTO_TCP ); + + Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP ); DbgPrint("STATUS from OSKITTCP was %08x\n", Status); /* Initialize received segments queue */ @@ -501,7 +559,7 @@ NTSTATUS FileCloseConnection( Connection = Request->Handle.ConnectionContext; - TCPClose(Request); + TCPClose(Connection); DeleteConnectionEndpoint(Connection); TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));