ReactOS  0.4.15-dev-3207-ga415bd4
accept.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS TCP/IP protocol driver
4  * FILE: transport/tcp/accept.c
5  * PURPOSE: Transmission Control Protocol Listen/Accept code
6  * PROGRAMMERS: Art Yerkes (arty@users.sf.net)
7  * REVISIONS:
8  * arty 12/21/2004 Created
9  */
10 
11 #include "precomp.h"
12 
13 #include "rosip.h"
14 
16 
19 {
20  struct tcp_pcb *newpcb = (struct tcp_pcb*)Context;
22  PTDI_CONNECTION_INFORMATION WhoIsConnecting;
24  struct ip_addr ipaddr;
25 
26  if (Request->RequestFlags & TDI_QUERY_ACCEPT)
27  DbgPrint("TDI_QUERY_ACCEPT NOT SUPPORTED!!!\n");
28 
29  WhoIsConnecting = (PTDI_CONNECTION_INFORMATION)Request->ReturnConnectionInformation;
30  RemoteAddress = (PTA_IP_ADDRESS)WhoIsConnecting->RemoteAddress;
31 
32  RemoteAddress->TAAddressCount = 1;
33  RemoteAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
34  RemoteAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
35 
37  &ipaddr,
38  &RemoteAddress->Address[0].Address[0].sin_port));
39 
40  RemoteAddress->Address[0].Address[0].in_addr = ipaddr.addr;
41 
42  return Status;
43 }
44 
45 /* This listen is on a socket we keep as internal. That socket has the same
46  * lifetime as the address file */
48 {
50  struct ip_addr AddressToBind;
52 
53  ASSERT(Connection);
54 
55  LockObject(Connection);
56 
57  ASSERT_KM_POINTER(Connection->AddressFile);
58 
59  TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Called\n"));
60 
61  TI_DbgPrint(DEBUG_TCP, ("Connection->SocketContext %x\n",
62  Connection->SocketContext));
63 
64  AddressToBind.addr = Connection->AddressFile->Address.Address.IPv4Address;
65 
66  Status = TCPTranslateError(LibTCPBind(Connection,
67  &AddressToBind,
68  Connection->AddressFile->Port));
69 
70  if (NT_SUCCESS(Status))
71  {
72  /* Check if we had an unspecified port */
73  if (!Connection->AddressFile->Port)
74  {
75  /* We did, so we need to copy back the port */
77  if (NT_SUCCESS(Status))
78  {
79  /* Allocate the port in the port bitmap */
80  Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
81 
82  /* This should never fail */
83  ASSERT(Connection->AddressFile->Port != 0xFFFF);
84  }
85  }
86  }
87 
88  if (NT_SUCCESS(Status))
89  {
90  Connection->SocketContext = LibTCPListen(Connection, Backlog);
91  if (!Connection->SocketContext)
93  }
94 
95  UnlockObject(Connection);
96 
97  TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Leaving. Status = %x\n", Status));
98 
99  return Status;
100 }
101 
104  PCONNECTION_ENDPOINT Connection)
105 {
106  PLIST_ENTRY ListEntry;
107  PTDI_BUCKET Bucket;
108  BOOLEAN Found = FALSE;
109 
110  LockObject(Listener);
111 
112  ListEntry = Listener->ListenRequest.Flink;
113  while (ListEntry != &Listener->ListenRequest)
114  {
115  Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry);
116 
117  if (Bucket->AssociatedEndpoint == Connection)
118  {
120  RemoveEntryList( &Bucket->Entry );
121  ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
122  Found = TRUE;
123  break;
124  }
125 
126  ListEntry = ListEntry->Flink;
127  }
128 
129  UnlockObject(Listener);
130 
131  return Found;
132 }
133 
135  PCONNECTION_ENDPOINT Listener,
136  PCONNECTION_ENDPOINT Connection,
138  PVOID Context )
139 {
141  PTDI_BUCKET Bucket;
142 
143  LockObject(Listener);
144 
145  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
146 
147  if (Bucket)
148  {
149  Bucket->AssociatedEndpoint = Connection;
151 
153  Bucket->Request.RequestContext = Context;
154  InsertTailList( &Listener->ListenRequest, &Bucket->Entry );
156  }
157  else
159 
160  UnlockObject(Listener);
161 
162  return Status;
163 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
err_t LibTCPBind(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: rostcp.c:418
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST NPAGED_LOOKASIDE_LIST
PVOID RequestContext
Definition: tdi.h:55
#define DbgPrint
Definition: hal.h:12
#define TRUE
Definition: types.h:120
union IP_ADDRESS::@974 Address
LONG NTSTATUS
Definition: precomp.h:26
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:859
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
#define InsertTailList(ListHead, Entry)
NTSTATUS TCPAccept(PTDI_REQUEST Request, PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: accept.c:134
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PADDRESS_FILE AddressFile
Definition: titypes.h:247
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS TransportAddress, BOOLEAN RemoteAddress)
Definition: tcp.c:645
BOOLEAN TCPAbortListenForSocket(PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection)
Definition: accept.c:103
#define FALSE
Definition: types.h:117
pRequest Complete(RequestStatus)
PVOID RequestNotifyObject
Definition: tdi.h:54
unsigned char BOOLEAN
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:623
return Found
Definition: dirsup.c:1270
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID(* PTCP_COMPLETION_ROUTINE)(PVOID Context, NTSTATUS Status, ULONG Count)
Definition: tcp.h:11
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
#define ASSERT_KM_POINTER(_x)
Definition: debug.h:74
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
NTSTATUS TCPCheckPeerForAccept(PVOID Context, PTDI_REQUEST_KERNEL Request)
Definition: accept.c:17
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
#define TDI_QUERY_ACCEPT
Definition: tdi.h:132
#define UnlockObject(Object)
Definition: titypes.h:44
IP_ADDRESS Address
Definition: titypes.h:117
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
LIST_ENTRY ListenRequest
Definition: titypes.h:251
unsigned int UINT
Definition: ndis.h:50
NTSTATUS TCPListen(PCONNECTION_ENDPOINT Connection, UINT Backlog)
Definition: accept.c:47
struct tagContext Context
Definition: acpixf.h:1034
TDI_REQUEST Request
Definition: titypes.h:232
USHORT Port
Definition: titypes.h:120
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
u32_t addr
Definition: ip_addr.h:45
base of all file and directory entries
Definition: entries.h:82
PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
Definition: rostcp.c:472
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170
#define LockObject(Object)
Definition: titypes.h:34