#include "precomp.h"
-
WORK_QUEUE_ITEM LoopWorkItem;
PIP_INTERFACE Loopback = NULL;
/* Indicates wether the loopback interface is currently transmitting */
#include <lan.h>
-
extern PIP_INTERFACE Loopback;
-
NDIS_STATUS LoopRegisterAdapter(
PNDIS_STRING AdapterName,
PLAN_ADAPTER *Adapter);
#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__)
#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,
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 );
-# $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 = ../../..
-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
PTDI_REQUEST_KERNEL Parameters;
PTRANSPORT_CONTEXT TranContext;
PIO_STACK_LOCATION IrpSp;
- TDI_REQUEST Request;
NTSTATUS Status;
TI_DbgPrint(DEBUG_IRP, ("Called.\n"));
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,
#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));
Parameters = (PTDI_REQUEST_KERNEL)&IrpSp->Parameters;
- Status = TCPListen( Request, 1024 /* BACKLOG */ );
+ Status = TCPListen( Request->Handle.ConnectionContext, 1024 /* BACKLOG */,
+ DispDataRequestComplete,
+ Irp );
return Status;
}
PIO_STACK_LOCATION IrpSp;
PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo;
PTRANSPORT_CONTEXT TranContext;
- TDI_REQUEST Request;
NTSTATUS Status;
ULONG BytesReceived;
}
/* Initialize a receive request */
- Request.Handle.ConnectionContext = TranContext->Handle.ConnectionContext;
- Request.RequestNotifyObject = DispDataRequestComplete;
- Request.RequestContext = Irp;
Status = DispPrepareIrpForCancel(
IrpSp->FileObject->FsContext,
Irp,
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);
PIO_STACK_LOCATION IrpSp;
PTDI_REQUEST_KERNEL_RECEIVE ReceiveInfo;
PTRANSPORT_CONTEXT TranContext;
- TDI_REQUEST Request;
NTSTATUS Status;
ULONG BytesReceived;
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,
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);
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)
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 */
Connection = Request->Handle.ConnectionContext;
- TCPClose(Request);
+ TCPClose(Connection);
DeleteConnectionEndpoint(Connection);
TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));