ReactOS  0.4.14-dev-583-g2a1ba2c
tcp.h File Reference
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for tcp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TCPv4_HEADER
 
struct  TCPv4_PSEUDO_HEADER
 
struct  _SLEEPING_THREAD
 
struct  _CLIENT_DATA
 

Macros

#define TCPOPT_END_OF_LIST   0x0
 
#define TCPOPT_NO_OPERATION   0x1
 
#define TCPOPT_MAX_SEG_SIZE   0x2
 
#define TCPOPTLEN_MAX_SEG_SIZE   0x4
 
#define TCP_DATA_OFFSET(DataOffset)   (((DataOffset) & 0xF0) >> (4-2))
 
#define TCP_MIN_RETRANSMISSION_TIMEOUT   1*1000 /* 1 tick */
 
#define TCP_MAX_RETRANSMISSION_TIMEOUT   1*60*1000 /* 1 tick */
 
#define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)   (((x)*8)/10) /* 0.8 */
 
#define TCP_BETA_RETRANSMISSION_TIMEOUT(x)   (((x)*16)/10) /* 1.6 */
 
#define SEL_CONNECT   1
 
#define SEL_FIN   2
 
#define SEL_RST   4
 
#define SEL_ABRT   8
 
#define SEL_READ   16
 
#define SEL_WRITE   32
 
#define SEL_ACCEPT   64
 
#define SEL_OOB   128
 
#define SEL_ERROR   256
 
#define SEL_FINOUT   512
 
#define FREAD   0x0001
 
#define FWRITE   0x0002
 
#define SRF_URG   TCP_URG
 
#define SRF_ACK   TCP_ACK
 
#define SRF_PSH   TCP_PSH
 
#define SRF_RST   TCP_RST
 
#define SRF_SYN   TCP_SYN
 
#define SRF_FIN   TCP_FIN
 

Typedefs

typedef VOID(* PTCP_COMPLETION_ROUTINE) (PVOID Context, NTSTATUS Status, ULONG Count)
 
typedef struct TCPv4_HEADER TCPv4_HEADER
 
typedef struct TCPv4_HEADERPTCPv4_HEADER
 
typedef struct TCPv4_PSEUDO_HEADER TCPv4_PSEUDO_HEADER
 
typedef struct TCPv4_PSEUDO_HEADERPTCPv4_PSEUDO_HEADER
 
typedef struct _SLEEPING_THREAD SLEEPING_THREAD
 
typedef struct _SLEEPING_THREADPSLEEPING_THREAD
 
typedef struct _CLIENT_DATA CLIENT_DATA
 
typedef struct _CLIENT_DATAPCLIENT_DATA
 

Functions

NTSTATUS TCPCheckPeerForAccept (PVOID Context, PTDI_REQUEST_KERNEL Request)
 
NTSTATUS TCPListen (PCONNECTION_ENDPOINT Connection, UINT Backlog)
 
BOOLEAN TCPAbortListenForSocket (PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection)
 
NTSTATUS TCPAccept (PTDI_REQUEST Request, PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
 
PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint (PVOID ClientContext)
 
VOID TCPFreeConnectionEndpoint (PCONNECTION_ENDPOINT Connection)
 
NTSTATUS TCPSocket (PCONNECTION_ENDPOINT Connection, UINT Family, UINT Type, UINT Proto)
 
VOID HandleSignalledConnection (PCONNECTION_ENDPOINT Connection)
 
PTCP_SEGMENT TCPCreateSegment (PIP_PACKET IPPacket, PTCPv4_HEADER TCPHeader, ULONG SegmentLength)
 
VOID TCPFreeSegment (PTCP_SEGMENT Segment)
 
VOID TCPAddSegment (PCONNECTION_ENDPOINT Connection, PTCP_SEGMENT Segment, PULONG Acknowledged)
 
NTSTATUS TCPConnect (PCONNECTION_ENDPOINT Connection, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
 
NTSTATUS TCPDisconnect (PCONNECTION_ENDPOINT Connection, UINT Flags, PLARGE_INTEGER Timeout, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
 
NTSTATUS TCPReceiveData (PCONNECTION_ENDPOINT Connection, PNDIS_BUFFER Buffer, ULONG ReceiveLength, PULONG BytesReceived, ULONG ReceiveFlags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
 
NTSTATUS TCPSendData (PCONNECTION_ENDPOINT Connection, PCHAR Buffer, ULONG DataSize, PULONG DataUsed, ULONG Flags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
 
NTSTATUS TCPClose (PCONNECTION_ENDPOINT Connection)
 
NTSTATUS TCPTranslateError (const INT8 err)
 
UINT TCPAllocatePort (const UINT HintPort)
 
VOID TCPFreePort (const UINT Port)
 
NTSTATUS TCPGetSockAddress (PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS TransportAddress, BOOLEAN RemoteAddress)
 
NTSTATUS TCPStartup (VOID)
 
NTSTATUS TCPShutdown (VOID)
 
BOOLEAN TCPRemoveIRP (PCONNECTION_ENDPOINT Connection, PIRP Irp)
 
NTSTATUS TCPSetNoDelay (PCONNECTION_ENDPOINT Connection, BOOLEAN Set)
 
VOID TCPUpdateInterfaceLinkStatus (PIP_INTERFACE IF)
 
VOID TCPUpdateInterfaceIPInformation (PIP_INTERFACE IF)
 
VOID FlushListenQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushConnectQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushReceiveQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
 
VOID FlushSendQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
 
VOID FlushShutdownQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
 
VOID FlushAllQueues (PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
 
VOID CompleteBucket (PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
 
void LibTCPDumpPcb (PVOID SocketContext)
 
NTSTATUS TCPGetSocketStatus (PCONNECTION_ENDPOINT Connection, PULONG State)
 

Variables

LONG TCP_IPIdentification
 
CLIENT_DATA ClientInfo
 

Macro Definition Documentation

◆ FREAD

#define FREAD   0x0001

Definition at line 84 of file tcp.h.

◆ FWRITE

#define FWRITE   0x0002

Definition at line 85 of file tcp.h.

◆ SEL_ABRT

#define SEL_ABRT   8

Definition at line 76 of file tcp.h.

◆ SEL_ACCEPT

#define SEL_ACCEPT   64

Definition at line 79 of file tcp.h.

◆ SEL_CONNECT

#define SEL_CONNECT   1

Definition at line 73 of file tcp.h.

◆ SEL_ERROR

#define SEL_ERROR   256

Definition at line 81 of file tcp.h.

◆ SEL_FIN

#define SEL_FIN   2

Definition at line 74 of file tcp.h.

◆ SEL_FINOUT

#define SEL_FINOUT   512

Definition at line 82 of file tcp.h.

◆ SEL_OOB

#define SEL_OOB   128

Definition at line 80 of file tcp.h.

◆ SEL_READ

#define SEL_READ   16

Definition at line 77 of file tcp.h.

◆ SEL_RST

#define SEL_RST   4

Definition at line 75 of file tcp.h.

◆ SEL_WRITE

#define SEL_WRITE   32

Definition at line 78 of file tcp.h.

◆ SRF_ACK

#define SRF_ACK   TCP_ACK

Definition at line 90 of file tcp.h.

◆ SRF_FIN

#define SRF_FIN   TCP_FIN

Definition at line 94 of file tcp.h.

◆ SRF_PSH

#define SRF_PSH   TCP_PSH

Definition at line 91 of file tcp.h.

◆ SRF_RST

#define SRF_RST   TCP_RST

Definition at line 92 of file tcp.h.

◆ SRF_SYN

#define SRF_SYN   TCP_SYN

Definition at line 93 of file tcp.h.

◆ SRF_URG

#define SRF_URG   TCP_URG

Definition at line 89 of file tcp.h.

◆ TCP_ALPHA_RETRANSMISSION_TIMEOUT

#define TCP_ALPHA_RETRANSMISSION_TIMEOUT (   x)    (((x)*8)/10) /* 0.8 */

Definition at line 68 of file tcp.h.

◆ TCP_BETA_RETRANSMISSION_TIMEOUT

#define TCP_BETA_RETRANSMISSION_TIMEOUT (   x)    (((x)*16)/10) /* 1.6 */

Definition at line 71 of file tcp.h.

◆ TCP_DATA_OFFSET

#define TCP_DATA_OFFSET (   DataOffset)    (((DataOffset) & 0xF0) >> (4-2))

Definition at line 34 of file tcp.h.

◆ TCP_MAX_RETRANSMISSION_TIMEOUT

#define TCP_MAX_RETRANSMISSION_TIMEOUT   1*60*1000 /* 1 tick */

Definition at line 65 of file tcp.h.

◆ TCP_MIN_RETRANSMISSION_TIMEOUT

#define TCP_MIN_RETRANSMISSION_TIMEOUT   1*1000 /* 1 tick */

Definition at line 62 of file tcp.h.

◆ TCPOPT_END_OF_LIST

#define TCPOPT_END_OF_LIST   0x0

Definition at line 27 of file tcp.h.

◆ TCPOPT_MAX_SEG_SIZE

#define TCPOPT_MAX_SEG_SIZE   0x2

Definition at line 29 of file tcp.h.

◆ TCPOPT_NO_OPERATION

#define TCPOPT_NO_OPERATION   0x1

Definition at line 28 of file tcp.h.

◆ TCPOPTLEN_MAX_SEG_SIZE

#define TCPOPTLEN_MAX_SEG_SIZE   0x4

Definition at line 31 of file tcp.h.

Typedef Documentation

◆ CLIENT_DATA

◆ PCLIENT_DATA

◆ PSLEEPING_THREAD

◆ PTCP_COMPLETION_ROUTINE

typedef VOID(* PTCP_COMPLETION_ROUTINE) (PVOID Context, NTSTATUS Status, ULONG Count)

Definition at line 11 of file tcp.h.

◆ PTCPv4_HEADER

◆ PTCPv4_PSEUDO_HEADER

◆ SLEEPING_THREAD

◆ TCPv4_HEADER

◆ TCPv4_PSEUDO_HEADER

Function Documentation

◆ CompleteBucket()

VOID CompleteBucket ( PCONNECTION_ENDPOINT  Connection,
PTDI_BUCKET  Bucket,
const BOOLEAN  Synchronous 
)

Definition at line 38 of file event.c.

39 {
40  ReferenceObject(Connection);
41  Bucket->AssociatedEndpoint = Connection;
42  if (Synchronous)
43  {
44  BucketCompletionWorker(Bucket);
45  }
46  else
47  {
49  }
50 }
static VOID BucketCompletionWorker(PVOID Context)
Definition: event.c:23
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:65
#define ReferenceObject(Object)
Definition: titypes.h:14
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:251

Referenced by DisconnectTimeoutDpc(), FlushConnectQueue(), FlushListenQueue(), FlushReceiveQueue(), FlushSendQueue(), FlushShutdownQueue(), TCPAcceptEventHandler(), TCPConnectEventHandler(), TCPRecvEventHandler(), and TCPSendEventHandler().

◆ FlushAllQueues()

VOID FlushAllQueues ( PCONNECTION_ENDPOINT  Connection,
NTSTATUS  Status 
)

Definition at line 218 of file event.c.

219 {
220  ReferenceObject(Connection);
221 
222  // flush receive queue
223  FlushReceiveQueue(Connection, Status, TRUE);
224 
225  /* We completed the reads successfully but we need to return failure now */
226  if (Status == STATUS_SUCCESS)
227  {
229  }
230 
231  // flush listen queue
232  FlushListenQueue(Connection, Status);
233 
234  // flush send queue
235  FlushSendQueue(Connection, Status, TRUE);
236 
237  // flush connect queue
238  FlushConnectQueue(Connection, Status);
239 
240  // flush shutdown queue
241  FlushShutdownQueue(Connection, Status, TRUE);
242 
243  DereferenceObject(Connection);
244 }
VOID FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:196
#define TRUE
Definition: types.h:120
#define DereferenceObject(Object)
Definition: titypes.h:24
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:137
#define ReferenceObject(Object)
Definition: titypes.h:14
VOID FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:175
Status
Definition: gdiplustypes.h:24
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:53
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:95
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by TCPClose(), and TCPFinEventHandler().

◆ FlushConnectQueue()

VOID FlushConnectQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 175 of file event.c.

176 {
177  PTDI_BUCKET Bucket;
179 
180  ReferenceObject(Connection);
181 
182  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ConnectRequest, &Connection->Lock)))
183  {
184  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
185 
186  Bucket->Status = Status;
187  Bucket->Information = 0;
188 
189  CompleteBucket(Connection, Bucket, FALSE);
190  }
191 
192  DereferenceObject(Connection);
193 }
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
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
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ConnectRequest
Definition: titypes.h:271
NTSTATUS Status
Definition: titypes.h:253
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by FlushAllQueues().

◆ FlushListenQueue()

VOID FlushListenQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 196 of file event.c.

197 {
198  PTDI_BUCKET Bucket;
200 
201  ReferenceObject(Connection);
202 
203  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ListenRequest, &Connection->Lock)))
204  {
205  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
206 
207  Bucket->Status = Status;
208  Bucket->Information = 0;
209 
211  CompleteBucket(Connection, Bucket, FALSE);
212  }
213 
214  DereferenceObject(Connection);
215 }
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
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
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:251
LIST_ENTRY ListenRequest
Definition: titypes.h:272
NTSTATUS Status
Definition: titypes.h:253
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by FlushAllQueues().

◆ FlushReceiveQueue()

VOID FlushReceiveQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status,
const BOOLEAN  interlocked 
)

Definition at line 53 of file event.c.

54 {
55  PTDI_BUCKET Bucket;
57 
58  ReferenceObject(Connection);
59 
60  if (interlocked)
61  {
62  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ReceiveRequest, &Connection->Lock)))
63  {
65 
67  ("Completing Receive request: %x %x\n",
68  Bucket->Request, Status));
69 
70  Bucket->Status = Status;
71  Bucket->Information = 0;
72 
73  CompleteBucket(Connection, Bucket, FALSE);
74  }
75  }
76  else
77  {
78  while (!IsListEmpty(&Connection->ReceiveRequest))
79  {
80  Entry = RemoveHeadList(&Connection->ReceiveRequest);
81 
83 
84  Bucket->Information = 0;
85  Bucket->Status = Status;
86 
87  CompleteBucket(Connection, Bucket, FALSE);
88  }
89  }
90 
91  DereferenceObject(Connection);
92 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
LIST_ENTRY ReceiveRequest
Definition: titypes.h:273
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS Status
Definition: titypes.h:253
TDI_REQUEST Request
Definition: titypes.h:252
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushSendQueue()

VOID FlushSendQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status,
const BOOLEAN  interlocked 
)

Definition at line 95 of file event.c.

96 {
97  PTDI_BUCKET Bucket;
99 
100  ReferenceObject(Connection);
101 
102  if (interlocked)
103  {
104  while ((Entry = ExInterlockedRemoveHeadList(&Connection->SendRequest, &Connection->Lock)))
105  {
106  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
107 
109  ("Completing Send request: %x %x\n",
110  Bucket->Request, Status));
111 
112  Bucket->Status = Status;
113  Bucket->Information = 0;
114 
115  CompleteBucket(Connection, Bucket, FALSE);
116  }
117  }
118  else
119  {
120  while (!IsListEmpty(&Connection->SendRequest))
121  {
122  Entry = RemoveHeadList(&Connection->SendRequest);
123 
125 
126  Bucket->Information = 0;
127  Bucket->Status = Status;
128 
129  CompleteBucket(Connection, Bucket, FALSE);
130  }
131  }
132 
133  DereferenceObject(Connection);
134 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
LIST_ENTRY SendRequest
Definition: titypes.h:274
NTSTATUS Status
Definition: titypes.h:253
TDI_REQUEST Request
Definition: titypes.h:252
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushShutdownQueue()

VOID FlushShutdownQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status,
const BOOLEAN  interlocked 
)

Definition at line 137 of file event.c.

138 {
139  PTDI_BUCKET Bucket;
141 
142  ReferenceObject(Connection);
143 
144  if (interlocked)
145  {
146  while ((Entry = ExInterlockedRemoveHeadList(&Connection->ShutdownRequest, &Connection->Lock)))
147  {
148  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
149 
150  Bucket->Status = Status;
151  Bucket->Information = 0;
152 
153  CompleteBucket(Connection, Bucket, FALSE);
154  }
155  }
156  else
157  {
158  while (!IsListEmpty(&Connection->ShutdownRequest))
159  {
160  Entry = RemoveHeadList(&Connection->ShutdownRequest);
161 
163 
164  Bucket->Information = 0;
165  Bucket->Status = Status;
166 
167  CompleteBucket(Connection, Bucket, FALSE);
168  }
169  }
170 
171  DereferenceObject(Connection);
172 }
KSPIN_LOCK Lock
Definition: titypes.h:265
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DereferenceObject(Object)
Definition: titypes.h:24
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
LIST_ENTRY ShutdownRequest
Definition: titypes.h:275
#define ReferenceObject(Object)
Definition: titypes.h:14
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS Status
Definition: titypes.h:253
base of all file and directory entries
Definition: entries.h:82
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
ULONG Information
Definition: titypes.h:254

Referenced by FlushAllQueues(), TCPDisconnect(), and TCPSendEventHandler().

◆ HandleSignalledConnection()

VOID HandleSignalledConnection ( PCONNECTION_ENDPOINT  Connection)

◆ LibTCPDumpPcb()

void LibTCPDumpPcb ( PVOID  SocketContext)

Definition at line 39 of file rostcp.c.

40 {
41  struct tcp_pcb *pcb = (struct tcp_pcb*)SocketContext;
42  unsigned int addr = ntohl(pcb->remote_ip.addr);
43 
44  DbgPrint("\tState: %s\n", tcp_state_str[pcb->state]);
45  DbgPrint("\tRemote: (%d.%d.%d.%d, %d)\n",
46  (addr >> 24) & 0xFF,
47  (addr >> 16) & 0xFF,
48  (addr >> 8) & 0xFF,
49  addr & 0xFF,
50  pcb->remote_port);
51 }
static const char *const tcp_state_str[]
Definition: rostcp.c:9
#define DbgPrint
Definition: loader.c:25
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID SocketContext
Definition: wsk.h:182
GLenum const GLvoid * addr
Definition: glext.h:9621
#define ntohl(x)
Definition: module.h:203

Referenced by LogActiveObjects().

◆ TCPAbortListenForSocket()

BOOLEAN TCPAbortListenForSocket ( PCONNECTION_ENDPOINT  Listener,
PCONNECTION_ENDPOINT  Connection 
)

Definition at line 104 of file accept.c.

106 {
107  PLIST_ENTRY ListEntry;
108  PTDI_BUCKET Bucket;
109  KIRQL OldIrql;
110  BOOLEAN Found = FALSE;
111 
112  LockObject(Listener, &OldIrql);
113 
114  ListEntry = Listener->ListenRequest.Flink;
115  while (ListEntry != &Listener->ListenRequest)
116  {
117  Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry);
118 
119  if (Bucket->AssociatedEndpoint == Connection)
120  {
122  RemoveEntryList( &Bucket->Entry );
123  ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
124  Found = TRUE;
125  break;
126  }
127 
128  ListEntry = ListEntry->Flink;
129  }
130 
131  UnlockObject(Listener, OldIrql);
132 
133  return Found;
134 }
#define TRUE
Definition: types.h:120
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
#define DereferenceObject(Object)
Definition: titypes.h:24
#define LockObject(Object, Irql)
Definition: titypes.h:34
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
unsigned char BOOLEAN
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
LIST_ENTRY Entry
Definition: titypes.h:250
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:251
LIST_ENTRY ListenRequest
Definition: titypes.h:272
base of all file and directory entries
Definition: entries.h:82

Referenced by DispCancelListenRequest().

◆ TCPAccept()

NTSTATUS TCPAccept ( PTDI_REQUEST  Request,
PCONNECTION_ENDPOINT  Listener,
PCONNECTION_ENDPOINT  Connection,
PTCP_COMPLETION_ROUTINE  Complete,
PVOID  Context 
)

Definition at line 136 of file accept.c.

141 {
143  PTDI_BUCKET Bucket;
144  KIRQL OldIrql;
145 
146  LockObject(Listener, &OldIrql);
147 
148  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
149 
150  if (Bucket)
151  {
152  Bucket->AssociatedEndpoint = Connection;
154 
155  Bucket->Request.RequestNotifyObject = Complete;
156  Bucket->Request.RequestContext = Context;
157  InsertTailList( &Listener->ListenRequest, &Bucket->Entry );
159  }
160  else
162 
163  UnlockObject(Listener, OldIrql);
164 
165  return Status;
166 }
PVOID RequestContext
Definition: tdi.h:55
LONG NTSTATUS
Definition: precomp.h:26
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
#define InsertTailList(ListHead, Entry)
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID RequestNotifyObject
Definition: tdi.h:54
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
#define STATUS_PENDING
Definition: ntstatus.h:82
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define ReferenceObject(Object)
Definition: titypes.h:14
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:251
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
LIST_ENTRY ListenRequest
Definition: titypes.h:272
struct tagContext Context
Definition: acpixf.h:1030
TDI_REQUEST Request
Definition: titypes.h:252

Referenced by DispTdiListen().

◆ TCPAddSegment()

VOID TCPAddSegment ( PCONNECTION_ENDPOINT  Connection,
PTCP_SEGMENT  Segment,
PULONG  Acknowledged 
)

◆ TCPAllocateConnectionEndpoint()

PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint ( PVOID  ClientContext)

Definition at line 86 of file tcp.c.

87 {
90 
91  if (!Connection)
92  return Connection;
93 
94  TI_DbgPrint(DEBUG_CPOINT, ("Connection point file object allocated at (0x%X).\n", Connection));
95 
96  RtlZeroMemory(Connection, sizeof(CONNECTION_ENDPOINT));
97 
98  /* Initialize spin lock that protects the connection endpoint file object */
99  KeInitializeSpinLock(&Connection->Lock);
100  InitializeListHead(&Connection->ConnectRequest);
101  InitializeListHead(&Connection->ListenRequest);
102  InitializeListHead(&Connection->ReceiveRequest);
103  InitializeListHead(&Connection->SendRequest);
104  InitializeListHead(&Connection->ShutdownRequest);
105  InitializeListHead(&Connection->PacketQueue);
106 
107  /* Initialize disconnect timer */
108  KeInitializeTimer(&Connection->DisconnectTimer);
109  KeInitializeDpc(&Connection->DisconnectDpc, DisconnectTimeoutDpc, Connection);
110 
111  /* Save client context pointer */
112  Connection->ClientContext = ClientContext;
113 
114  Connection->RefCount = 1;
115  Connection->Free = ConnectionFree;
116 
117  /* Add connection endpoint to global list */
119  &Connection->ListEntry,
121 
122  return Connection;
123 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
KSPIN_LOCK Lock
Definition: titypes.h:265
LIST_ENTRY ConnectionEndpointListHead
Definition: fileobjs.c:25
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
LIST_ENTRY PacketQueue
Definition: titypes.h:277
VOID ConnectionFree(PVOID Object)
Definition: tcp.c:72
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
VOID NTAPI DisconnectTimeoutDpc(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: tcp.c:29
OBJECT_FREE_ROUTINE Free
Definition: titypes.h:264
#define CONN_ENDPT_TAG
Definition: tags.h:10
_In_ PVOID ClientContext
Definition: netioddk.h:55
LIST_ENTRY ShutdownRequest
Definition: titypes.h:275
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
KTIMER DisconnectTimer
Definition: titypes.h:280
LIST_ENTRY ReceiveRequest
Definition: titypes.h:273
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY ConnectRequest
Definition: titypes.h:271
LIST_ENTRY ListenRequest
Definition: titypes.h:272
LIST_ENTRY SendRequest
Definition: titypes.h:274
#define DEBUG_CPOINT
Definition: debug.h:33
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
KSPIN_LOCK ConnectionEndpointListLock
Definition: fileobjs.c:26
LIST_ENTRY ListEntry
Definition: titypes.h:262

Referenced by DispTdiListen(), FileOpenConnection(), and TCPSocketObject::TCPSocketObject().

◆ TCPAllocatePort()

UINT TCPAllocatePort ( const UINT  HintPort)

Definition at line 580 of file tcp.c.

581 {
582  if (HintPort)
583  {
584  if (AllocatePort(&TCPPorts, HintPort))
585  return HintPort;
586  else
587  {
588  TI_DbgPrint(MID_TRACE,("We got a hint port but couldn't allocate it\n"));
589  return (UINT)-1;
590  }
591  }
592  else
593  return AllocatePortFromRange( &TCPPorts, 1024, 5000 );
594 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PORT_SET TCPPorts
Definition: tcp.c:17
#define MID_TRACE
Definition: debug.h:15
BOOLEAN AllocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:47
ULONG AllocatePortFromRange(PPORT_SET PortSet, ULONG Lowest, ULONG Highest)
Definition: ports.c:86
unsigned int UINT
Definition: ndis.h:50

Referenced by FileOpenAddress(), TCPConnect(), and TCPListen().

◆ TCPCheckPeerForAccept()

NTSTATUS TCPCheckPeerForAccept ( PVOID  Context,
PTDI_REQUEST_KERNEL  Request 
)

Definition at line 17 of file accept.c.

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 }
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:822
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
#define TDI_QUERY_ACCEPT
Definition: tdi.h:132
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170

Referenced by TCPAcceptEventHandler().

◆ TCPClose()

NTSTATUS TCPClose ( PCONNECTION_ENDPOINT  Connection)

Definition at line 150 of file tcp.c.

151 {
152  KIRQL OldIrql;
153 
154  LockObject(Connection, &OldIrql);
155 
156  FlushAllQueues(Connection, STATUS_CANCELLED);
157 
158  LibTCPClose(Connection, FALSE, TRUE);
159 
160  UnlockObject(Connection, OldIrql);
161 
162  DereferenceObject(Connection);
163 
164  return STATUS_SUCCESS;
165 }
#define TRUE
Definition: types.h:120
#define DereferenceObject(Object)
Definition: titypes.h:24
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:218
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: rostcp.c:764
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by FileCloseAddress(), FileCloseConnection(), main(), and TCPSocketObject::~TCPSocketObject().

◆ TCPConnect()

NTSTATUS TCPConnect ( PCONNECTION_ENDPOINT  Connection,
PTDI_CONNECTION_INFORMATION  ConnInfo,
PTDI_CONNECTION_INFORMATION  ReturnInfo,
PTCP_COMPLETION_ROUTINE  Complete,
PVOID  Context 
)

Definition at line 277 of file tcp.c.

282 {
284  struct ip_addr bindaddr, connaddr;
286  USHORT RemotePort;
288  PTDI_BUCKET Bucket;
290  KIRQL OldIrql;
291 
292  TI_DbgPrint(DEBUG_TCP,("[IP, TCPConnect] Called\n"));
293 
295  ((PTRANSPORT_ADDRESS)ConnInfo->RemoteAddress,
296  &RemoteAddress,
297  &RemotePort);
298 
299  if (!NT_SUCCESS(Status))
300  {
301  TI_DbgPrint(DEBUG_TCP, ("Could not AddrBuildAddress in TCPConnect\n"));
302  return Status;
303  }
304 
305  /* Freed in TCPSocketState */
307  ("Connecting to address %x:%x\n",
308  RemoteAddress.Address.IPv4Address,
309  RemotePort));
310 
311  LockObject(Connection, &OldIrql);
312 
313  if (!Connection->AddressFile)
314  {
315  UnlockObject(Connection, OldIrql);
317  }
318 
319  if (AddrIsUnspecified(&Connection->AddressFile->Address))
320  {
322  {
323  UnlockObject(Connection, OldIrql);
325  }
326 
327  bindaddr.addr = NCE->Interface->Unicast.Address.IPv4Address;
328  }
329  else
330  {
331  bindaddr.addr = Connection->AddressFile->Address.Address.IPv4Address;
332  }
333 
334  Status = TCPTranslateError(LibTCPBind(Connection,
335  &bindaddr,
336  Connection->AddressFile->Port));
337 
338  if (NT_SUCCESS(Status))
339  {
340  /* Copy bind address into connection */
341  Connection->AddressFile->Address.Address.IPv4Address = bindaddr.addr;
342  /* Check if we had an unspecified port */
343  if (!Connection->AddressFile->Port)
344  {
345  /* We did, so we need to copy back the port */
347  if (NT_SUCCESS(Status))
348  {
349  /* Allocate the port in the port bitmap */
350  Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
351 
352  /* This should never fail */
353  ASSERT(Connection->AddressFile->Port != 0xFFFF);
354  }
355  }
356 
357  if (NT_SUCCESS(Status))
358  {
359  connaddr.addr = RemoteAddress.Address.IPv4Address;
360 
361  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
362  if (!Bucket)
363  {
364  UnlockObject(Connection, OldIrql);
365  return STATUS_NO_MEMORY;
366  }
367 
368  Bucket->Request.RequestNotifyObject = (PVOID)Complete;
369  Bucket->Request.RequestContext = Context;
370 
371  InsertTailList( &Connection->ConnectRequest, &Bucket->Entry );
372 
374  &connaddr,
375  RemotePort));
376  }
377  }
378 
379  UnlockObject(Connection, OldIrql);
380 
381  TI_DbgPrint(DEBUG_TCP,("[IP, TCPConnect] Leaving. Status = 0x%x\n", Status));
382 
383  return Status;
384 }
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
#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:394
PVOID RequestContext
Definition: tdi.h:55
Definition: neighbor.h:28
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
#define InsertTailList(ListHead, Entry)
#define DEBUG_TCP
Definition: debug.h:28
#define LockObject(Object, Irql)
Definition: titypes.h:34
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:580
Definition: ip.h:23
PADDRESS_FILE AddressFile
Definition: titypes.h:268
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID RequestNotifyObject
Definition: tdi.h:54
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
IP_ADDRESS Unicast
Definition: ip.h:159
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
PIP_INTERFACE Interface
Definition: neighbor.h:33
unsigned short USHORT
Definition: pedump.c:61
IP_ADDRESS Address
Definition: titypes.h:136
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
LIST_ENTRY ConnectRequest
Definition: titypes.h:271
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS Address, BOOLEAN GetRemote)
Definition: tcp.c:602
struct tagContext Context
Definition: acpixf.h:1030
TDI_REQUEST Request
Definition: titypes.h:252
USHORT Port
Definition: titypes.h:139
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:690
NTSTATUS AddrBuildAddress(PTRANSPORT_ADDRESS TdiAddress, PIP_ADDRESS Address, PUSHORT Port)
Definition: address.c:184
err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: rostcp.c:601
union IP_ADDRESS::@990 Address
_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

Referenced by DispTdiConnect(), and TCPSocketObject::TCPSocketObject().

◆ TCPCreateSegment()

PTCP_SEGMENT TCPCreateSegment ( PIP_PACKET  IPPacket,
PTCPv4_HEADER  TCPHeader,
ULONG  SegmentLength 
)

◆ TCPDisconnect()

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 at line 387 of file tcp.c.

394 {
396  PTDI_BUCKET Bucket;
397  KIRQL OldIrql;
398  LARGE_INTEGER ActualTimeout;
399 
400  TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Called\n"));
401 
402  LockObject(Connection, &OldIrql);
403 
404  if (Connection->SocketContext)
405  {
407  {
408  if (IsListEmpty(&Connection->SendRequest))
409  {
410  Status = TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
411  }
412  else if (Timeout && Timeout->QuadPart == 0)
413  {
415  TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
417  }
418  else
419  {
420  /* Use the timeout specified or 1 second if none was specified */
421  if (Timeout)
422  {
423  ActualTimeout = *Timeout;
424  }
425  else
426  {
427  ActualTimeout.QuadPart = -1000000;
428  }
429 
430  /* We couldn't complete the request now because we need to wait for outstanding I/O */
431  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
432  if (!Bucket)
433  {
434  UnlockObject(Connection, OldIrql);
435  return STATUS_NO_MEMORY;
436  }
437 
438  Bucket->Request.RequestNotifyObject = (PVOID)Complete;
439  Bucket->Request.RequestContext = Context;
440 
441  InsertTailList(&Connection->ShutdownRequest, &Bucket->Entry);
442 
443  ReferenceObject(Connection);
444  if (KeCancelTimer(&Connection->DisconnectTimer))
445  {
446  DereferenceObject(Connection);
447  }
448  KeSetTimer(&Connection->DisconnectTimer, ActualTimeout, &Connection->DisconnectDpc);
449 
451  }
452  }
453 
454  if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
455  {
459  Status = TCPTranslateError(LibTCPShutdown(Connection, 1, 1));
460  }
461  }
462  else
463  {
464  /* We already got closed by the other side so just return success */
466  }
467 
468  UnlockObject(Connection, OldIrql);
469 
470  TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Leaving. Status = 0x%x\n", Status));
471 
472  return Status;
473 }
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
PVOID RequestContext
Definition: tdi.h:55
err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
Definition: rostcp.c:683
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define DEBUG_TCP
Definition: debug.h:28
#define DereferenceObject(Object)
Definition: titypes.h:24
#define LockObject(Object, Irql)
Definition: titypes.h:34
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PVOID RequestNotifyObject
Definition: tdi.h:54
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:53
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
void * PVOID
Definition: retypes.h:9
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:137
LIST_ENTRY ShutdownRequest
Definition: titypes.h:275
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KTIMER DisconnectTimer
Definition: titypes.h:280
#define ReferenceObject(Object)
Definition: titypes.h:14
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:95
static ULONG Timeout
Definition: ping.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
LIST_ENTRY SendRequest
Definition: titypes.h:274
struct tagContext Context
Definition: acpixf.h:1030
TDI_REQUEST Request
Definition: titypes.h:252
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
LONGLONG QuadPart
Definition: typedefs.h:112
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by DispTdiDisconnect().

◆ TCPFreeConnectionEndpoint()

VOID TCPFreeConnectionEndpoint ( PCONNECTION_ENDPOINT  Connection)

◆ TCPFreePort()

VOID TCPFreePort ( const UINT  Port)

Definition at line 596 of file tcp.c.

597 {
599 }
CPPORT Port[4]
Definition: headless.c:34
PORT_SET TCPPorts
Definition: tcp.c:17
VOID DeallocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:35

Referenced by AddrFileFree().

◆ TCPFreeSegment()

VOID TCPFreeSegment ( PTCP_SEGMENT  Segment)

◆ TCPGetSockAddress()

NTSTATUS TCPGetSockAddress ( PCONNECTION_ENDPOINT  Connection,
PTRANSPORT_ADDRESS  TransportAddress,
BOOLEAN  RemoteAddress 
)

Definition at line 602 of file tcp.c.

605 {
607  struct ip_addr ipaddr;
609  KIRQL OldIrql;
610 
611  AddressIP->TAAddressCount = 1;
612  AddressIP->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
613  AddressIP->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
614 
615  LockObject(Connection, &OldIrql);
616 
617  if (GetRemote)
618  {
620  &ipaddr,
621  &AddressIP->Address[0].Address[0].sin_port));
622  }
623  else
624  {
626  &ipaddr,
627  &AddressIP->Address[0].Address[0].sin_port));
628  }
629 
630  UnlockObject(Connection, OldIrql);
631 
632  AddressIP->Address[0].Address[0].in_addr = ipaddr.addr;
633 
634  RtlZeroMemory(&AddressIP->Address[0].Address[0].sin_zero,
635  sizeof(AddressIP->Address[0].Address[0].sin_zero));
636 
637  return Status;
638 }
LONG TAAddressCount
Definition: tdi.h:523
struct _TA_ADDRESS_IP * PTA_IP_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:822
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
static WCHAR Address[46]
Definition: ping.c:68
struct _TA_ADDRESS_IP::_AddrIp Address[1]
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
Status
Definition: gdiplustypes.h:24
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
err_t LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: rostcp.c:810

Referenced by InfoTdiQueryGetConnectionTcpTable(), TCPConnect(), and TCPListen().

◆ TCPGetSocketStatus()

NTSTATUS TCPGetSocketStatus ( PCONNECTION_ENDPOINT  Connection,
PULONG  State 
)

Definition at line 695 of file tcp.c.

698 {
699  if (!Connection)
700  return STATUS_UNSUCCESSFUL;
701 
702  if (Connection->SocketContext == NULL)
703  return STATUS_UNSUCCESSFUL;
704 
706  return STATUS_SUCCESS;
707 }
void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State)
Definition: rostcp.c:845
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by InfoTdiQueryGetConnectionTcpTable().

◆ TCPListen()

NTSTATUS TCPListen ( PCONNECTION_ENDPOINT  Connection,
UINT  Backlog 
)

Definition at line 47 of file accept.c.

48 {
50  struct ip_addr AddressToBind;
51  KIRQL OldIrql;
53 
54  ASSERT(Connection);
55 
56  LockObject(Connection, &OldIrql);
57 
58  ASSERT_KM_POINTER(Connection->AddressFile);
59 
60  TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Called\n"));
61 
62  TI_DbgPrint(DEBUG_TCP, ("Connection->SocketContext %x\n",
63  Connection->SocketContext));
64 
65  AddressToBind.addr = Connection->AddressFile->Address.Address.IPv4Address;
66 
67  Status = TCPTranslateError(LibTCPBind(Connection,
68  &AddressToBind,
69  Connection->AddressFile->Port));
70 
71  if (NT_SUCCESS(Status))
72  {
73  /* Check if we had an unspecified port */
74  if (!Connection->AddressFile->Port)
75  {
76  /* We did, so we need to copy back the port */
78  if (NT_SUCCESS(Status))
79  {
80  /* Allocate the port in the port bitmap */
81  Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
82 
83  /* This should never fail */
84  ASSERT(Connection->AddressFile->Port != 0xFFFF);
85  }
86  }
87  }
88 
89  if (NT_SUCCESS(Status))
90  {
91  Connection->SocketContext = LibTCPListen(Connection, Backlog);
92  if (!Connection->SocketContext)
94  }
95 
96  UnlockObject(Connection, OldIrql);
97 
98  TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Leaving. Status = %x\n", Status));
99 
100  return Status;
101 }
#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:394
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG_TCP
Definition: debug.h:28
#define LockObject(Object, Irql)
Definition: titypes.h:34
PADDRESS_FILE AddressFile
Definition: titypes.h:268
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS TransportAddress, BOOLEAN RemoteAddress)
Definition: tcp.c:602
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:580
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ASSERT_KM_POINTER(_x)
Definition: debug.h:74
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
IP_ADDRESS Address
Definition: titypes.h:136
USHORT Port
Definition: titypes.h:139
return STATUS_SUCCESS
Definition: btrfs.c:2938
union IP_ADDRESS::@990 Address
PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
Definition: rostcp.c:448
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:170

Referenced by DispTdiListen().

◆ TCPReceiveData()

NTSTATUS TCPReceiveData ( PCONNECTION_ENDPOINT  Connection,
PNDIS_BUFFER  Buffer,
ULONG  ReceiveLength,
PULONG  BytesReceived,
ULONG  ReceiveFlags,
PTCP_COMPLETION_ROUTINE  Complete,
PVOID  Context 
)

Definition at line 476 of file tcp.c.

483 {
484  PTDI_BUCKET Bucket;
485  PUCHAR DataBuffer;
486  UINT DataLen, Received;
488 
489  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Called for %d bytes (on socket %x)\n",
490  ReceiveLength, Connection->SocketContext));
491 
492  NdisQueryBuffer(Buffer, &DataBuffer, &DataLen);
493 
494  Status = LibTCPGetDataFromConnectionQueue(Connection, DataBuffer, DataLen, &Received);
495 
496  if (Status == STATUS_PENDING)
497  {
498  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
499  if (!Bucket)
500  {
501  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate bucket\n"));
502 
503  return STATUS_NO_MEMORY;
504  }
505 
506  Bucket->Request.RequestNotifyObject = Complete;
507  Bucket->Request.RequestContext = Context;
508 
509  ExInterlockedInsertTailList( &Connection->ReceiveRequest, &Bucket->Entry, &Connection->Lock );
510  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Queued read irp\n"));
511 
512  TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Leaving. Status = STATUS_PENDING\n"));
513 
514  (*BytesReceived) = 0;
515  }
516  else
517  {
518  (*BytesReceived) = Received;
519  }
520 
521  return Status;
522 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
KSPIN_LOCK Lock
Definition: titypes.h:265
unsigned char * PUCHAR
Definition: retypes.h:3
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG_TCP
Definition: debug.h:28
PVOID RequestNotifyObject
Definition: tdi.h:54
Definition: bufpool.h:45
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
#define STATUS_PENDING
Definition: ntstatus.h:82
LIST_ENTRY ReceiveRequest
Definition: titypes.h:273
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: rostcp.c:101
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
struct tagContext Context
Definition: acpixf.h:1030
TDI_REQUEST Request
Definition: titypes.h:252
UINT Received
Definition: arping.c:40

Referenced by DispTdiReceive().

◆ TCPRemoveIRP()

BOOLEAN TCPRemoveIRP ( PCONNECTION_ENDPOINT  Connection,
PIRP  Irp 
)

Definition at line 640 of file tcp.c.

641 {
643  PLIST_ENTRY ListHead[5];
644  KIRQL OldIrql;
645  PTDI_BUCKET Bucket;
646  UINT i = 0;
647  BOOLEAN Found = FALSE;
648 
649  ListHead[0] = &Endpoint->SendRequest;
650  ListHead[1] = &Endpoint->ReceiveRequest;
651  ListHead[2] = &Endpoint->ConnectRequest;
652  ListHead[3] = &Endpoint->ListenRequest;
653  ListHead[4] = &Endpoint->ShutdownRequest;
654 
655  LockObject(Endpoint, &OldIrql);
656 
657  for( i = 0; i < 5; i++ )
658  {
659  for( Entry = ListHead[i]->Flink;
660  Entry != ListHead[i];
661  Entry = Entry->Flink )
662  {
663  Bucket = CONTAINING_RECORD( Entry, TDI_BUCKET, Entry );
664  if( Bucket->Request.RequestContext == Irp )
665  {
666  RemoveEntryList( &Bucket->Entry );
667  ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
668  Found = TRUE;
669  break;
670  }
671  }
672  }
673 
674  UnlockObject(Endpoint, OldIrql);
675 
676  return Found;
677 }
#define TRUE
Definition: types.h:120
PVOID RequestContext
Definition: tdi.h:55
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
#define LockObject(Object, Irql)
Definition: titypes.h:34
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
unsigned char BOOLEAN
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
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
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
LIST_ENTRY Entry
Definition: titypes.h:250
unsigned int UINT
Definition: ndis.h:50
TDI_REQUEST Request
Definition: titypes.h:252
base of all file and directory entries
Definition: entries.h:82

Referenced by DispCancelRequest().

◆ TCPSendData()

NTSTATUS TCPSendData ( PCONNECTION_ENDPOINT  Connection,
PCHAR  Buffer,
ULONG  DataSize,
PULONG  DataUsed,
ULONG  Flags,
PTCP_COMPLETION_ROUTINE  Complete,
PVOID  Context 
)

Definition at line 525 of file tcp.c.

532 {
534  PTDI_BUCKET Bucket;
535  KIRQL OldIrql;
536 
537  LockObject(Connection, &OldIrql);
538 
539  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Called for %d bytes (on socket %x)\n",
540  SendLength, Connection->SocketContext));
541 
542  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection = %x\n", Connection));
543  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection->SocketContext = %x\n",
544  Connection->SocketContext));
545 
546  Status = TCPTranslateError(LibTCPSend(Connection,
547  BufferData,
548  SendLength,
549  BytesSent,
550  FALSE));
551 
552  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Send: %x, %d\n", Status, SendLength));
553 
554  /* Keep this request around ... there was no data yet */
555  if (Status == STATUS_PENDING)
556  {
557  /* Freed in TCPSocketState */
558  Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
559  if (!Bucket)
560  {
561  UnlockObject(Connection, OldIrql);
562  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Failed to allocate bucket\n"));
563  return STATUS_NO_MEMORY;
564  }
565 
566  Bucket->Request.RequestNotifyObject = Complete;
567  Bucket->Request.RequestContext = Context;
568 
569  InsertTailList( &Connection->SendRequest, &Bucket->Entry );
570  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Queued write irp\n"));
571  }
572 
573  UnlockObject(Connection, OldIrql);
574 
575  TI_DbgPrint(DEBUG_TCP, ("[IP, TCPSendData] Leaving. Status = %x\n", Status));
576 
577  return Status;
578 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
PVOID RequestContext
Definition: tdi.h:55
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: rostcp.c:536
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:242
#define InsertTailList(ListHead, Entry)
#define DEBUG_TCP
Definition: debug.h:28
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID RequestNotifyObject
Definition: tdi.h:54
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
#define STATUS_PENDING
Definition: ntstatus.h:82
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY Entry
Definition: titypes.h:250
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
LIST_ENTRY SendRequest
Definition: titypes.h:274
struct tagContext Context
Definition: acpixf.h:1030
TDI_REQUEST Request
Definition: titypes.h:252

Referenced by DispTdiSend(), TCPSocketObject::recv(), and TCPSocketObject::send().

◆ TCPSetNoDelay()

NTSTATUS TCPSetNoDelay ( PCONNECTION_ENDPOINT  Connection,
BOOLEAN  Set 
)

Definition at line 680 of file tcp.c.

683 {
684  if (!Connection)
685  return STATUS_UNSUCCESSFUL;
686 
687  if (Connection->SocketContext == NULL)
688  return STATUS_UNSUCCESSFUL;
689 
690  LibTCPSetNoDelay(Connection->SocketContext, Set);
691  return STATUS_SUCCESS;
692 }
static BOOL Set
Definition: pageheap.c:10
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set)
Definition: rostcp.c:834
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SetConnectionInfo().

◆ TCPShutdown()

NTSTATUS TCPShutdown ( VOID  )

Definition at line 218 of file tcp.c.

224 {
225  if (!TCPInitialized)
226  return STATUS_SUCCESS;
227 
229 
230  LibIPShutdown();
231 
232  /* Deregister this protocol with IP layer */
234 
236 
238 
239  return STATUS_SUCCESS;
240 }
PORT_SET TCPPorts
Definition: tcp.c:17
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:390
static BOOLEAN TCPInitialized
Definition: tcp.c:16
smooth NULL
Definition: ftsmooth.c:416
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
void LibIPShutdown(void)
Definition: rosip.c:42
VOID PortsShutdown(PPORT_SET PortSet)
Definition: ports.c:31
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:174

Referenced by TiUnload().

◆ TCPSocket()

NTSTATUS TCPSocket ( PCONNECTION_ENDPOINT  Connection,
UINT  Family,
UINT  Type,
UINT  Proto 
)

Definition at line 125 of file tcp.c.

127 {
129  KIRQL OldIrql;
130 
131  LockObject(Connection, &OldIrql);
132 
133  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSocket] Called: Connection %x, Family %d, Type %d, "
134  "Proto %d, sizeof(CONNECTION_ENDPOINT) = %d\n",
135  Connection, Family, Type, Proto, sizeof(CONNECTION_ENDPOINT)));
136 
137  Connection->SocketContext = LibTCPSocket(Connection);
138  if (Connection->SocketContext)
140  else
142 
143  UnlockObject(Connection, OldIrql);
144 
145  TI_DbgPrint(DEBUG_TCP,("[IP, TCPSocket] Leaving. Status = 0x%x\n", Status));
146 
147  return Status;
148 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
PTCP_PCB LibTCPSocket(void *arg)
Definition: rostcp.c:342
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG_TCP
Definition: debug.h:28
#define LockObject(Object, Irql)
Definition: titypes.h:34
UCHAR KIRQL
Definition: env_spec_w32.h:591
static int Family
Definition: ping.c:62
#define UnlockObject(Object, OldIrql)
Definition: titypes.h:54
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DispTdiListen(), FileOpenConnection(), and TCPSocketObject::TCPSocketObject().

◆ TCPStartup()

NTSTATUS TCPStartup ( VOID  )

Definition at line 183 of file tcp.c.

189 {
191 
192  Status = PortsStartup( &TCPPorts, 1, 0xfffe );
193  if (!NT_SUCCESS(Status))
194  {
195  return Status;
196  }
197 
199  NULL,
200  NULL,
201  0,
202  sizeof(TDI_BUCKET),
204  0);
205 
206  /* Initialize our IP library */
207  LibIPInitialize();
208 
209  /* Register this protocol with IP layer */
211 
213 
214  return STATUS_SUCCESS;
215 }
VOID TCPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: tcp.c:167
PORT_SET TCPPorts
Definition: tcp.c:17
#define TRUE
Definition: types.h:120
NTSTATUS PortsStartup(PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
Definition: ports.c:13
LONG NTSTATUS
Definition: precomp.h:26
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:390
void LibIPInitialize(void)
Definition: rosip.c:35
static BOOLEAN TCPInitialized
Definition: tcp.c:16
#define TDI_BUCKET_TAG
Definition: tags.h:31
smooth NULL
Definition: ftsmooth.c:416
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
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:222
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ TCPTranslateError()

NTSTATUS TCPTranslateError ( const INT8  err)

Definition at line 242 of file tcp.c.

243 {
245 
246  switch (err)
247  {
248  case ERR_OK: Status = STATUS_SUCCESS; return Status; //0
249  case ERR_MEM: Status = STATUS_INSUFFICIENT_RESOURCES; break; //-1
250  case ERR_BUF: Status = STATUS_BUFFER_TOO_SMALL; break; //-2
251  case ERR_TIMEOUT: Status = STATUS_TIMEOUT; break; // -3
252  case ERR_RTE: Status = STATUS_NETWORK_UNREACHABLE; break; //-4
253  case ERR_INPROGRESS: Status = STATUS_PENDING; return Status; //-5
254  case ERR_VAL: Status = STATUS_INVALID_PARAMETER; break; //-6
255  case ERR_WOULDBLOCK: Status = STATUS_CANT_WAIT; break; //-7
256  case ERR_USE: Status = STATUS_ADDRESS_ALREADY_EXISTS; break; //-8
257  case ERR_ISCONN: Status = STATUS_UNSUCCESSFUL; break; //-9 (FIXME)
258  case ERR_ABRT: Status = STATUS_LOCAL_DISCONNECT; break; //-10
259  case ERR_RST: Status = STATUS_REMOTE_DISCONNECT; break; //-11
260  case ERR_CLSD: Status = STATUS_FILE_CLOSED; break; //-12
261  case ERR_CONN: Status = STATUS_INVALID_CONNECTION; break; //-13
262  case ERR_ARG: Status = STATUS_INVALID_PARAMETER; break; //-14
263  case ERR_IF: Status = STATUS_UNEXPECTED_NETWORK_ERROR; break; //-15
264  default:
265  DbgPrint("Invalid error value: %d\n", err);
266  ASSERT(FALSE);
268  break;
269  }
270 
271  TI_DbgPrint(DEBUG_TCP,("TCP operation failed: 0x%x (%d)\n", Status, err));
272 
273  return Status;
274 }
#define ERR_CONN
Definition: err.h:68
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:542
#define ERR_ARG
Definition: err.h:70
#define ERR_ISCONN
Definition: err.h:61
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ERR_RTE
Definition: err.h:56
#define DbgPrint
Definition: loader.c:25
#define ERR_CLSD
Definition: err.h:67
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ERR_USE
Definition: err.h:60
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG_TCP
Definition: debug.h:28
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: ntstatus.h:640
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define ERR_TIMEOUT
Definition: err.h:55
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_REMOTE_DISCONNECT
Definition: ntstatus.h:538
#define ERR_VAL
Definition: err.h:58
#define ERR_OK
Definition: err.h:52
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ERR_RST
Definition: err.h:66
#define err(...)
Status
Definition: gdiplustypes.h:24
#define ERR_MEM
Definition: fontsub.h:52
#define ERR_BUF
Definition: err.h:54
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:537
#define ERR_INPROGRESS
Definition: err.h:57
#define ERR_WOULDBLOCK
Definition: err.h:59
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: ntstatus.h:418
#define ERR_ABRT
Definition: err.h:65
#define ERR_IF
Definition: err.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:690
#define STATUS_CANT_WAIT
Definition: ntstatus.h:438
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by TCPCheckPeerForAccept(), TCPConnectEventHandler(), TCPFinEventHandler(), TCPListen(), and TCPSendEventHandler().

◆ TCPUpdateInterfaceIPInformation()

VOID TCPUpdateInterfaceIPInformation ( PIP_INTERFACE  IF)

Definition at line 145 of file if.c.

146 {
147  struct ip_addr ipaddr;
148  struct ip_addr netmask;
149  struct ip_addr gw;
150 
151  gw.addr = 0;
152 
154  ADE_UNICAST,
155  (PULONG)&ipaddr.addr);
156 
158  ADE_ADDRMASK,
159  (PULONG)&netmask.addr);
160 
161  netif_set_addr(IF->TCPContext, &ipaddr, &netmask, &gw);
162 
163  if (ipaddr.addr != 0)
164  {
167  }
168  else
169  {
171  }
172 }
PVOID TCPContext
Definition: ip.h:169
void netif_set_default(struct netif *netif)
Definition: netif.c:430
void netif_set_up(struct netif *netif)
Definition: netif.c:453
#define ADE_ADDRMASK
Definition: ip.h:112
void netif_set_down(struct netif *netif)
Definition: netif.c:490
NTSTATUS GetInterfaceIPv4Address(PIP_INTERFACE Interface, ULONG Type, PULONG Address)
Definition: interface.c:19
unsigned int * PULONG
Definition: retypes.h:1
#define ADE_UNICAST
Definition: ip.h:110
u32_t addr
Definition: ip_addr.h:45
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Definition: netif.c:221

Referenced by IPAddInterfaceRoute(), ReconfigureAdapter(), and TCPInterfaceInit().

◆ TCPUpdateInterfaceLinkStatus()

VOID TCPUpdateInterfaceLinkStatus ( PIP_INTERFACE  IF)

Definition at line 81 of file if.c.

82 {
83 #if 0
84  ULONG OperationalStatus;
85 
86  GetInterfaceConnectionStatus(IF, &OperationalStatus);
87 
88  if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
90  else
92 #endif
93 }
PVOID TCPContext
Definition: ip.h:169
void netif_set_link_down(struct netif *netif)
Definition: netif.c:574
VOID GetInterfaceConnectionStatus(PIP_INTERFACE Interface, PULONG OperStatus)
Definition: interface.c:254
void netif_set_link_up(struct netif *netif)
Definition: netif.c:535
unsigned int ULONG
Definition: retypes.h:1
#define MIB_IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:251

Referenced by ReconfigureAdapter(), and TCPInterfaceInit().

Variable Documentation

◆ ClientInfo

◆ TCP_IPIdentification

LONG TCP_IPIdentification

Definition at line 24 of file tcptest.cpp.