ReactOS  0.4.15-dev-3187-ge372f2b
tcp.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/tcp.c
5  * PURPOSE: Transmission Control Protocol
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * Art Yerkes (arty@users.sf.net)
8  * REVISIONS:
9  * CSH 01/08-2000 Created
10  * arty 12/21/2004 Added accept
11  */
12 
13 #include "precomp.h"
14 
18 
19 #include "lwip/pbuf.h"
20 #include "lwip/ip.h"
21 #include "lwip/init.h"
22 #include "lwip/arch.h"
23 
24 #include "rosip.h"
25 
27 
28 static
29 IO_WORKITEM_ROUTINE
31 
33 VOID
34 NTAPI
38 )
39 {
42  PTDI_BUCKET Bucket;
43 
44  /* We timed out waiting for pending sends so force it to shutdown */
45  TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
46 
47  LockObject(Connection);
48 
49  while (!IsListEmpty(&Connection->SendRequest))
50  {
51  Entry = RemoveHeadList(&Connection->SendRequest);
52 
54 
55  Bucket->Information = 0;
56  Bucket->Status = STATUS_FILE_CLOSED;
57 
58  CompleteBucket(Connection, Bucket, FALSE);
59  }
60 
61  while (!IsListEmpty(&Connection->ShutdownRequest))
62  {
63  Entry = RemoveHeadList( &Connection->ShutdownRequest );
64 
66 
67  Bucket->Status = STATUS_TIMEOUT;
68  Bucket->Information = 0;
69 
70  CompleteBucket(Connection, Bucket, FALSE);
71  }
72 
73  UnlockObject(Connection);
74 
75  DereferenceObject(Connection);
76 }
77 
78 VOID
79 NTAPI
84 {
86 
88 }
89 
91 {
93  KIRQL OldIrql;
94 
95  TI_DbgPrint(DEBUG_TCP, ("Freeing TCP Endpoint\n"));
96 
98  RemoveEntryList(&Connection->ListEntry);
100 
101  ExDeleteResourceLite(&Connection->Resource);
102  IoFreeWorkItem(Connection->DisconnectWorkItem);
103 
104  ExFreePoolWithTag( Connection, CONN_ENDPT_TAG );
105 }
106 
108 {
111 
112  if (!Connection)
113  return Connection;
114 
115  TI_DbgPrint(DEBUG_CPOINT, ("Connection point file object allocated at (0x%X).\n", Connection));
116 
117  RtlZeroMemory(Connection, sizeof(CONNECTION_ENDPOINT));
118 
119  /* Initialize spin lock that protects the connection endpoint file object */
120  ExInitializeResourceLite(&Connection->Resource);
121  InitializeListHead(&Connection->ConnectRequest);
122  InitializeListHead(&Connection->ListenRequest);
123  InitializeListHead(&Connection->ReceiveRequest);
124  InitializeListHead(&Connection->SendRequest);
125  InitializeListHead(&Connection->ShutdownRequest);
126  InitializeListHead(&Connection->PacketQueue);
127 
128  /* Initialize disconnect timer */
129  KeInitializeTimer(&Connection->DisconnectTimer);
130  KeInitializeDpc(&Connection->DisconnectDpc, DisconnectTimeoutDpc, Connection);
132  if (!Connection->DisconnectWorkItem)
133  {
134  ExDeleteResourceLite(&Connection->Resource);
135  ExFreePoolWithTag( Connection, CONN_ENDPT_TAG );
136  return NULL;
137  }
138 
139  /* Save client context pointer */
140  Connection->ClientContext = ClientContext;
141 
142  Connection->RefCount = 1;
143  Connection->Free = ConnectionFree;
144 
145  /* Add connection endpoint to global list */
147  &Connection->ListEntry,
149 
150  return Connection;
151 }
152 
154  UINT Family, UINT Type, UINT Proto )
155 {
157 
158  LockObject(Connection);
159 
160  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSocket] Called: Connection %x, Family %d, Type %d, "
161  "Proto %d, sizeof(CONNECTION_ENDPOINT) = %d\n",
162  Connection, Family, Type, Proto, sizeof(CONNECTION_ENDPOINT)));
163 
164  Connection->SocketContext = LibTCPSocket(Connection);
165  if (Connection->SocketContext)
167  else
169 
170  UnlockObject(Connection);
171 
172  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSocket] Leaving. Status = 0x%x\n", Status));
173 
174  return Status;
175 }
176 
178 {
179  LockObject(Connection);
180 
181  FlushAllQueues(Connection, STATUS_CANCELLED);
182 
183  UnlockObject(Connection);
184 
185  LibTCPClose(Connection, FALSE, TRUE);
186 
187  DereferenceObject(Connection);
188 
189  return STATUS_SUCCESS;
190 }
191 
193 /*
194  * FUNCTION: Receives and queues TCP data
195  * ARGUMENTS:
196  * IPPacket = Pointer to an IP packet that was received
197  * NOTES:
198  * This is the low level interface for receiving TCP data
199  */
200 {
201  TI_DbgPrint(DEBUG_TCP,("Sending packet %d (%d) to lwIP\n",
202  IPPacket->TotalSize,
203  IPPacket->HeaderSize));
204 
205  LibIPInsertPacket(Interface->TCPContext, IPPacket->Header, IPPacket->TotalSize);
206 }
207 
209 /*
210  * FUNCTION: Initializes the TCP subsystem
211  * RETURNS:
212  * Status of operation
213  */
214 {
216 
217  Status = PortsStartup( &TCPPorts, 1, 0xfffe );
218  if (!NT_SUCCESS(Status))
219  {
220  return Status;
221  }
222 
224  NULL,
225  NULL,
226  0,
227  sizeof(TDI_BUCKET),
229  0);
230 
231  /* Initialize our IP library */
232  LibIPInitialize();
233 
234  /* Register this protocol with IP layer */
236 
238 
239  return STATUS_SUCCESS;
240 }
241 
242 
244 /*
245  * FUNCTION: Shuts down the TCP subsystem
246  * RETURNS:
247  * Status of operation
248  */
249 {
250  if (!TCPInitialized)
251  return STATUS_SUCCESS;
252 
254 
255  LibIPShutdown();
256 
257  /* Deregister this protocol with IP layer */
259 
261 
263 
264  return STATUS_SUCCESS;
265 }
266 
268 {
270 
271  switch (err)
272  {
273  case ERR_OK: Status = STATUS_SUCCESS; return Status; //0
274  case ERR_MEM: Status = STATUS_INSUFFICIENT_RESOURCES; break; //-1
275  case ERR_BUF: Status = STATUS_BUFFER_TOO_SMALL; break; //-2
276  case ERR_TIMEOUT: Status = STATUS_TIMEOUT; break; // -3
277  case ERR_RTE: Status = STATUS_NETWORK_UNREACHABLE; break; //-4
278  case ERR_INPROGRESS: Status = STATUS_PENDING; return Status; //-5
279  case ERR_VAL: Status = STATUS_INVALID_PARAMETER; break; //-6
280  case ERR_WOULDBLOCK: Status = STATUS_CANT_WAIT; break; //-7
281  case ERR_USE: Status = STATUS_ADDRESS_ALREADY_EXISTS; break; //-8
282  case ERR_ISCONN: Status = STATUS_UNSUCCESSFUL; break; //-9 (FIXME)
283  case ERR_ABRT: Status = STATUS_LOCAL_DISCONNECT; break; //-10
284  case ERR_RST: Status = STATUS_REMOTE_DISCONNECT; break; //-11
285  case ERR_CLSD: Status = STATUS_FILE_CLOSED; break; //-12
286  case ERR_CONN: Status = STATUS_INVALID_CONNECTION; break; //-13
287  case ERR_ARG: Status = STATUS_INVALID_PARAMETER; break; //-14
288  case ERR_IF: Status = STATUS_UNEXPECTED_NETWORK_ERROR; break; //-15
289  default:
290  DbgPrint("Invalid error value: %d\n", err);
291  ASSERT(FALSE);
293  break;
294  }
295 
296  TI_DbgPrint(DEBUG_TCP,("TCP operation failed: 0x%x (%d)\n", Status, err));
297 
298  return Status;
299 }
300 
302 ( PCONNECTION_ENDPOINT Connection,
304  PTDI_CONNECTION_INFORMATION ReturnInfo,
306  PVOID Context )
307 {
309  struct ip_addr bindaddr, connaddr;
311  USHORT RemotePort;
313  PTDI_BUCKET Bucket;
315 
316  TI_DbgPrint(DEBUG_TCP,("[IP, TCPConnect] Called\n"));
317 
319  ((PTRANSPORT_ADDRESS)ConnInfo->RemoteAddress,
320  &RemoteAddress,
321  &RemotePort);
322 
323  if (!NT_SUCCESS(Status))
324  {
325  TI_DbgPrint(DEBUG_TCP, ("Could not AddrBuildAddress in TCPConnect\n"));
326  return Status;
327  }
328 
329  /* Freed in TCPSocketState */
331  ("Connecting to address %x:%x\n",
332  RemoteAddress.Address.IPv4Address,
333  RemotePort));
334 
335  LockObject(Connection);
336 
337  if (!Connection->AddressFile)
338  {
339  UnlockObject(Connection);
341  }
342 
343  if (AddrIsUnspecified(&Connection->AddressFile->Address))
344  {
346  {
347  UnlockObject(Connection);
349  }
350 
351  bindaddr.addr = NCE->Interface->Unicast.Address.IPv4Address;
352  }
353  else
354  {
355  bindaddr.addr = Connection->AddressFile->Address.Address.IPv4Address;
356  }
357 
358  Status = TCPTranslateError(LibTCPBind(Connection,
359  &bindaddr,
360  Connection->AddressFile->Port));
361 
362  if (!NT_SUCCESS(Status))
363  {
364  UnlockObject(Connection);
365  return Status;
366  }
367 
368  /* Copy bind address into connection */
369  Connection->AddressFile->Address.Address.IPv4Address = bindaddr.addr;
370  /* Check if we had an unspecified port */
371  if (!Connection->AddressFile->Port)
372  {
373  /* We did, so we need to copy back the port */
375  if (!NT_SUCCESS(Status))
376  {
377  UnlockObject(Connection);
378  return Status;
379  }
380 
381  /* Allocate the port in the port bitmap */
382  Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
383 
384  /* This should never fail */
385  ASSERT(Connection->AddressFile->Port != 0xFFFF);
386  }
387 
388  connaddr.addr = RemoteAddress.Address.IPv4Address;
389 
390  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
391  if (!Bucket)
392  {
393  UnlockObject(Connection);
394  return STATUS_NO_MEMORY;
395  }
396 
398  Bucket->Request.RequestContext = Context;
399 
400  InsertTailList( &Connection->ConnectRequest, &Bucket->Entry );
401 
402  UnlockObject(Connection);
403 
405  &connaddr,
406  RemotePort));
407 
408  TI_DbgPrint(DEBUG_TCP,("[IP, TCPConnect] Leaving. Status = 0x%x\n", Status));
409 
410  return Status;
411 }
412 
414 ( PCONNECTION_ENDPOINT Connection,
415  UINT Flags,
418  PTDI_CONNECTION_INFORMATION ReturnInfo,
420  PVOID Context )
421 {
423  PTDI_BUCKET Bucket;
424  LARGE_INTEGER ActualTimeout;
425 
426  TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Called\n"));
427 
428  LockObject(Connection);
429 
430  if (Connection->SocketContext)
431  {
433  {
434  if (IsListEmpty(&Connection->SendRequest))
435  {
436  ReferenceObject(Connection);
437  UnlockObject(Connection);
438  Status = TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
439  LockObject(Connection);
440  DereferenceObject(Connection);
441  }
442  else if (Timeout && Timeout->QuadPart == 0)
443  {
444  FlushSendQueue(Connection, STATUS_FILE_CLOSED);
445  ReferenceObject(Connection);
446  UnlockObject(Connection);
447  LibTCPShutdown(Connection, 0, 1);
448  LockObject(Connection);
449  DereferenceObject(Connection);
451  }
452  else
453  {
454  /* Use the timeout specified or 1 second if none was specified */
455  if (Timeout)
456  {
457  ActualTimeout = *Timeout;
458  }
459  else
460  {
461  ActualTimeout.QuadPart = -1000000;
462  }
463 
464  /* We couldn't complete the request now because we need to wait for outstanding I/O */
465  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
466  if (!Bucket)
467  {
468  UnlockObject(Connection);
469  return STATUS_NO_MEMORY;
470  }
471 
473  Bucket->Request.RequestContext = Context;
474 
475  InsertTailList(&Connection->ShutdownRequest, &Bucket->Entry);
476 
477  ReferenceObject(Connection);
478  if (KeSetTimer(&Connection->DisconnectTimer, ActualTimeout, &Connection->DisconnectDpc))
479  {
480  /* Timer was already in the queue. */
481  DereferenceObject(Connection);
482  }
483 
485  }
486  }
487 
488  if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
489  {
491  FlushSendQueue(Connection, STATUS_FILE_CLOSED);
493  ReferenceObject(Connection);
494  UnlockObject(Connection);
495  Status = TCPTranslateError(LibTCPShutdown(Connection, 1, 1));
496  DereferenceObject(Connection);
497  }
498  else
499  {
500  UnlockObject(Connection);
501  }
502  }
503  else
504  {
505  UnlockObject(Connection);
506  /* We already got closed by the other side so just return success */
508  }
509 
510  TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Leaving. Status = 0x%x\n", Status));
511 
512  return Status;
513 }
514 
516 ( PCONNECTION_ENDPOINT Connection,
518  ULONG ReceiveLength,
519  PULONG BytesReceived,
520  ULONG ReceiveFlags,
522  PVOID Context )
523 {
524  PTDI_BUCKET Bucket;
525  PUCHAR DataBuffer;
526  UINT DataLen, Received;
528 
529  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Called for %d bytes (on socket %x)\n",
530  ReceiveLength, Connection->SocketContext));
531 
532  NdisQueryBuffer(Buffer, &DataBuffer, &DataLen);
533 
534  Status = LibTCPGetDataFromConnectionQueue(Connection, DataBuffer, DataLen, &Received);
535 
536  if (Status == STATUS_PENDING)
537  {
538  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
539  if (!Bucket)
540  {
541  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate bucket\n"));
542 
543  return STATUS_NO_MEMORY;
544  }
545 
547  Bucket->Request.RequestContext = Context;
548 
549  LockObject(Connection);
550  InsertTailList( &Connection->ReceiveRequest, &Bucket->Entry );
551  UnlockObject(Connection);
552  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Queued read irp\n"));
553 
554  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Leaving. Status = STATUS_PENDING\n"));
555 
556  (*BytesReceived) = 0;
557  }
558  else
559  {
560  (*BytesReceived) = Received;
561  }
562 
563  return Status;
564 }
565 
567 ( PCONNECTION_ENDPOINT Connection,
568  PCHAR BufferData,
569  ULONG SendLength,
570  PULONG BytesSent,
571  ULONG Flags,
573  PVOID Context )
574 {
576  PTDI_BUCKET Bucket;
577 
578  ReferenceObject(Connection);
579 
580  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Called for %d bytes (on socket %x)\n",
581  SendLength, Connection->SocketContext));
582 
583  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection = %x\n", Connection));
584  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection->SocketContext = %x\n",
585  Connection->SocketContext));
586 
587  Status = TCPTranslateError(LibTCPSend(Connection,
588  BufferData,
589  SendLength,
590  BytesSent,
591  FALSE));
592 
593  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Send: %x, %d\n", Status, SendLength));
594 
595  /* Keep this request around ... there was no data yet */
596  if (Status == STATUS_PENDING)
597  {
598  /* Freed in TCPSocketState */
599  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
600  if (!Bucket)
601  {
602  DereferenceObject(Connection);
603  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Failed to allocate bucket\n"));
604  return STATUS_NO_MEMORY;
605  }
606 
608  Bucket->Request.RequestContext = Context;
609 
610  LockObject(Connection);
611  InsertTailList( &Connection->SendRequest, &Bucket->Entry );
612  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Queued write irp\n"));
613  UnlockObject(Connection);
614  }
615 
616 
617  TI_DbgPrint(DEBUG_TCP, ("[IP, TCPSendData] Leaving. Status = %x\n", Status));
618  DereferenceObject(Connection);
619 
620  return Status;
621 }
622 
623 UINT TCPAllocatePort(const UINT HintPort)
624 {
625  if (HintPort)
626  {
627  if (AllocatePort(&TCPPorts, HintPort))
628  return HintPort;
629  else
630  {
631  TI_DbgPrint(MID_TRACE,("We got a hint port but couldn't allocate it\n"));
632  return (UINT)-1;
633  }
634  }
635  else
636  return AllocatePortFromRange( &TCPPorts, 1024, 5000 );
637 }
638 
640 {
642 }
643 
645 ( PCONNECTION_ENDPOINT Connection,
647  BOOLEAN GetRemote )
648 {
650  struct ip_addr ipaddr;
652 
653  AddressIP->TAAddressCount = 1;
654  AddressIP->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
655  AddressIP->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
656 
657  LockObject(Connection);
658 
659  if (GetRemote)
660  {
662  &ipaddr,
663  &AddressIP->Address[0].Address[0].sin_port));
664  }
665  else
666  {
668  &ipaddr,
669  &AddressIP->Address[0].Address[0].sin_port));
670  }
671 
672  UnlockObject(Connection);
673 
674  AddressIP->Address[0].Address[0].in_addr = ipaddr.addr;
675 
676  RtlZeroMemory(&AddressIP->Address[0].Address[0].sin_zero,
677  sizeof(AddressIP->Address[0].Address[0].sin_zero));
678 
679  return Status;
680 }
681 
683 {
685  PLIST_ENTRY ListHead[5];
686  PTDI_BUCKET Bucket;
687  UINT i = 0;
688  BOOLEAN Found = FALSE;
689 
690  ListHead[0] = &Endpoint->SendRequest;
691  ListHead[1] = &Endpoint->ReceiveRequest;
692  ListHead[2] = &Endpoint->ConnectRequest;
693  ListHead[3] = &Endpoint->ListenRequest;
694  ListHead[4] = &Endpoint->ShutdownRequest;
695 
696  LockObject(Endpoint);
697 
698  for( i = 0; i < 5; i++ )
699  {
700  for( Entry = ListHead[i]->Flink;
701  Entry != ListHead[i];
702  Entry = Entry->Flink )
703  {
704  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
705  if( Bucket->Request.RequestContext == Irp )
706  {
707  RemoveEntryList( &Bucket->Entry );
708  ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
709  Found = TRUE;
710  break;
711  }
712  }
713  }
714 
715  UnlockObject(Endpoint);
716 
717  return Found;
718 }
719 
720 NTSTATUS
722  PCONNECTION_ENDPOINT Connection,
723  BOOLEAN Set)
724 {
725  if (!Connection)
726  return STATUS_UNSUCCESSFUL;
727 
728  if (Connection->SocketContext == NULL)
729  return STATUS_UNSUCCESSFUL;
730 
731  LibTCPSetNoDelay(Connection->SocketContext, Set);
732  return STATUS_SUCCESS;
733 }
734 
735 NTSTATUS
737  PCONNECTION_ENDPOINT Connection,
738  PULONG State)
739 {
740  if (!Connection)
741  return STATUS_UNSUCCESSFUL;
742 
743  if (Connection->SocketContext == NULL)
744  return STATUS_UNSUCCESSFUL;
745 
747  return STATUS_SUCCESS;
748 }
749 
750 /* EOF */
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
signed char * PCHAR
Definition: retypes.h:7
#define ERR_CONN
Definition: err.h:68
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
LONG TAAddressCount
Definition: tdi.h:523
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:556
CPPORT Port[4]
Definition: headless.c:35
VOID TCPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: tcp.c:192
#define ERR_ARG
Definition: err.h:70
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
PORT_SET TCPPorts
Definition: tcp.c:17
#define ERR_ISCONN
Definition: err.h:61
NTSTATUS TCPStartup(VOID)
Definition: tcp.c:208
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST NPAGED_LOOKASIDE_LIST
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:107
PVOID RequestContext
Definition: tdi.h:55
NTSTATUS PortsStartup(PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
Definition: ports.c:13
err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
Definition: rostcp.c:720
#define DbgPrint
Definition: hal.h:12
#define ERR_RTE
Definition: err.h:56
struct _Entry Entry
Definition: kefuncs.h:627
NTSTATUS TCPDisconnect(PCONNECTION_ENDPOINT Connection, UINT Flags, PLARGE_INTEGER Timeout, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:414
#define ERR_CLSD
Definition: err.h:67
Definition: neighbor.h:28
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
union IP_ADDRESS::@974 Address
LIST_ENTRY ConnectionEndpointListHead
Definition: fileobjs.c:25
#define ERR_USE
Definition: err.h:60
MDL * PNDIS_BUFFER
Definition: ndis.h:343
PTCP_PCB LibTCPSocket(void *arg)
Definition: rostcp.c:339
unsigned char * PUCHAR
Definition: retypes.h:3
void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State)
Definition: rostcp.c:882
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:560
LONG NTSTATUS
Definition: precomp.h:26
VOID TCPFreePort(const UINT Port)
Definition: tcp.c:639
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
void LibIPInsertPacket(void *ifarg, const void *const data, const u32_t size)
Definition: rosip.c:12
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:859
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint(PVOID ClientContext)
Definition: tcp.c:107
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:267
PDEVICE_OBJECT TCPDeviceObject
Definition: main.c:16
BOOLEAN TCPRemoveIRP(PCONNECTION_ENDPOINT Endpoint, PIRP Irp)
Definition: tcp.c:682
ERESOURCE Resource
Definition: titypes.h:245
#define InsertTailList(ListHead, Entry)
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
VOID TcpipReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL Irql)
Definition: lock.c:26
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:390
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID TcpipAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL Irql)
Definition: lock.c:18
LIST_ENTRY PacketQueue
Definition: titypes.h:256
VOID DeallocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:35
void LibIPInitialize(void)
Definition: rosip.c:35
static BOOL Set
Definition: pageheap.c:10
#define DEBUG_TCP
Definition: debug.h:28
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: ntstatus.h:654
#define DereferenceObject(Object)
Definition: titypes.h:24
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:53
#define _Use_decl_annotations_
Definition: ms_sal.h:275
#define ERR_TIMEOUT
Definition: err.h:55
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:623
Definition: ip.h:23
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
PADDRESS_FILE AddressFile
Definition: titypes.h:247
#define _Unreferenced_parameter_
Definition: specstrings.h:396
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:157
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
VOID ConnectionFree(PVOID Object)
Definition: tcp.c:90
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static int Family
Definition: ping.c:62
#define FALSE
Definition: types.h:117
#define STATUS_REMOTE_DISCONNECT
Definition: ntstatus.h:552
_In_ PIRP Irp
Definition: csq.h:116
pRequest Complete(RequestStatus)
long LONG
Definition: pedump.c:60
NTSTATUS TCPGetSocketStatus(PCONNECTION_ENDPOINT Connection, PULONG State)
Definition: tcp.c:736
static BOOLEAN TCPInitialized
Definition: tcp.c:16
#define ERR_VAL
Definition: err.h:58
PVOID RequestNotifyObject
Definition: tdi.h:54
#define TDI_BUCKET_TAG
Definition: tags.h:31
PVOID Header
Definition: ip.h:83
unsigned char BOOLEAN
static WCHAR Address[46]
Definition: ping.c:68
IP_ADDRESS Unicast
Definition: ip.h:159
#define _In_
Definition: ms_sal.h:308
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
s8_t err_t
Definition: err.h:47
BOOLEAN AllocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:47
NTSTATUS TCPSocket(PCONNECTION_ENDPOINT Connection, UINT Family, UINT Type, UINT Proto)
Definition: tcp.c:153
Definition: bufpool.h:45
struct _TA_ADDRESS_IP::_AddrIp Address[1]
VOID NTAPI DisconnectTimeoutDpc(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: tcp.c:80
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:801
return Found
Definition: dirsup.c:1270
void * PVOID
Definition: retypes.h:9
OBJECT_FREE_ROUTINE Free
Definition: titypes.h:244
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
KIRQL OldIrql
Definition: mm.h:1502
#define ERR_OK
Definition: err.h:52
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:74
NTSTATUS TCPShutdown(VOID)
Definition: tcp.c:243
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
#define CONN_ENDPT_TAG
Definition: tags.h:10
#define ASSERT(a)
Definition: mode.c:44
LONG TCP_IPIdentification
Definition: tcp.c:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ PVOID ClientContext
Definition: netioddk.h:55
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
UINT TotalSize
Definition: ip.h:86
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
Type
Definition: Type.h:6
LIST_ENTRY ShutdownRequest
Definition: titypes.h:254
ULONG AllocatePortFromRange(PPORT_SET PortSet, ULONG Lowest, ULONG Highest)
Definition: ports.c:86
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set)
Definition: rostcp.c:871
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR_RST
Definition: err.h:66
UINT HeaderSize
Definition: ip.h:84
Definition: ketypes.h:687
KTIMER DisconnectTimer
Definition: titypes.h:259
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252
NTSTATUS TCPClose(PCONNECTION_ENDPOINT Connection)
Definition: tcp.c:177
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:119
LIST_ENTRY Entry
Definition: titypes.h:230
#define err(...)
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIP_INTERFACE Interface
Definition: neighbor.h:33
static IO_WORKITEM_ROUTINE DisconnectWorker
Definition: tcp.c:30
static ULONG Timeout
Definition: ping.c:61
#define UnlockObject(Object)
Definition: titypes.h:44
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:361
unsigned short USHORT
Definition: pedump.c:61
IP_ADDRESS Address
Definition: titypes.h:117
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:103
#define ERR_MEM
Definition: fontsub.h:52
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define ERR_BUF
Definition: err.h:54
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
LIST_ENTRY ConnectRequest
Definition: titypes.h:250
void LibIPShutdown(void)
Definition: rosip.c:42
LIST_ENTRY ListenRequest
Definition: titypes.h:251
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
LIST_ENTRY SendRequest
Definition: titypes.h:253
PIO_WORKITEM DisconnectWorkItem
Definition: titypes.h:261
VOID PortsShutdown(PPORT_SET PortSet)
Definition: ports.c:31
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:551
#define ERR_INPROGRESS
Definition: err.h:57
#define ERR_WOULDBLOCK
Definition: err.h:59
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: ntstatus.h:432
NTSTATUS Status
Definition: titypes.h:233
#define DEBUG_CPOINT
Definition: debug.h:33
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS Address, BOOLEAN GetRemote)
Definition: tcp.c:645
struct tagContext Context
Definition: acpixf.h:1034
NTSTATUS TCPSetNoDelay(PCONNECTION_ENDPOINT Connection, BOOLEAN Set)
Definition: tcp.c:721
unsigned int ULONG
Definition: retypes.h:1
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
NTSTATUS TCPReceiveData(PCONNECTION_ENDPOINT Connection, PNDIS_BUFFER Buffer, ULONG ReceiveLength, PULONG BytesReceived, ULONG ReceiveFlags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:516
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ERR_ABRT
Definition: err.h:65
TDI_REQUEST Request
Definition: titypes.h:232
Definition: ip.h:77
USHORT Port
Definition: titypes.h:120
#define ERR_IF
Definition: err.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
KSPIN_LOCK ConnectionEndpointListLock
Definition: fileobjs.c:26
u32_t addr
Definition: ip_addr.h:45
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:704
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSTATUS AddrBuildAddress(PTRANSPORT_ADDRESS TdiAddress, PIP_ADDRESS Address, PUSHORT Port)
Definition: address.c:184
UINT Received
Definition: arping.c:40
err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: rostcp.c:625
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
err_t LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:847
LIST_ENTRY ListEntry
Definition: titypes.h:242
base of all file and directory entries
Definition: entries.h:82
NTSTATUS TCPConnect(PCONNECTION_ENDPOINT Connection, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:302
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG Information
Definition: titypes.h:234
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170
NTSTATUS TCPSendData(PCONNECTION_ENDPOINT Connection, PCHAR BufferData, ULONG SendLength, PULONG BytesSent, ULONG Flags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:567
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170
#define LockObject(Object)
Definition: titypes.h:34
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675