ReactOS 0.4.15-dev-7953-g1f49173
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)
 
VOID FlushSendQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
VOID FlushShutdownQueue (PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
 
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 10 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 {
45 }
46 else
47 {
49 }
50}
static VOID BucketCompletionWorker(PVOID Context)
Definition: event.c:23
struct _CONNECTION_ENDPOINT * AssociatedEndpoint
Definition: titypes.h:231
#define ReferenceObject(Object)
Definition: titypes.h:14
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:61

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

◆ FlushAllQueues()

VOID FlushAllQueues ( PCONNECTION_ENDPOINT  Connection,
NTSTATUS  Status 
)

Definition at line 157 of file event.c.

158{
159 // flush receive queue
160 FlushReceiveQueue(Connection, Status);
161
162 /* We completed the reads successfully but we need to return failure now */
163 if (Status == STATUS_SUCCESS)
164 {
166 }
167
168 // flush listen queue
169 FlushListenQueue(Connection, Status);
170
171 // flush send queue
172 FlushSendQueue(Connection, Status);
173
174 // flush connect queue
175 FlushConnectQueue(Connection, Status);
176
177 // flush shutdown queue
178 FlushShutdownQueue(Connection, Status);
179}
VOID FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:116
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
VOID FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:136
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:53
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:74
Status
Definition: gdiplustypes.h:25
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by TCPClose(), and TCPFinEventHandler().

◆ FlushConnectQueue()

VOID FlushConnectQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 116 of file event.c.

117{
118 PTDI_BUCKET Bucket;
120
121 ASSERT_TCPIP_OBJECT_LOCKED(Connection);
122
123 while (!IsListEmpty(&Connection->ConnectRequest))
124 {
125 Entry = RemoveHeadList(&Connection->ConnectRequest);
127
128 Bucket->Status = Status;
129 Bucket->Information = 0;
130
131 CompleteBucket(Connection, Bucket, FALSE);
132 }
133}
#define FALSE
Definition: types.h:117
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY ConnectRequest
Definition: titypes.h:250
Definition: typedefs.h:120
NTSTATUS Status
Definition: titypes.h:233
ULONG Information
Definition: titypes.h:234
#define ASSERT_TCPIP_OBJECT_LOCKED(Object)
Definition: titypes.h:51
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by FlushAllQueues().

◆ FlushListenQueue()

VOID FlushListenQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 136 of file event.c.

137{
138 PTDI_BUCKET Bucket;
140
141 ASSERT_TCPIP_OBJECT_LOCKED(Connection);
142
143 while (!IsListEmpty(&Connection->ListenRequest))
144 {
145 Entry = RemoveHeadList(&Connection->ListenRequest);
147
148 Bucket->Status = Status;
149 Bucket->Information = 0;
150
152 CompleteBucket(Connection, Bucket, FALSE);
153 }
154}
LIST_ENTRY ListenRequest
Definition: titypes.h:251
#define DereferenceObject(Object)
Definition: titypes.h:24

Referenced by FlushAllQueues().

◆ FlushReceiveQueue()

VOID FlushReceiveQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 53 of file event.c.

54{
55 PTDI_BUCKET Bucket;
57
59
60 while (!IsListEmpty(&Connection->ReceiveRequest))
61 {
62 Entry = RemoveHeadList(&Connection->ReceiveRequest);
63
65
66 Bucket->Information = 0;
67 Bucket->Status = Status;
68
69 CompleteBucket(Connection, Bucket, FALSE);
70 }
71}
LIST_ENTRY ReceiveRequest
Definition: titypes.h:252

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushSendQueue()

VOID FlushSendQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 74 of file event.c.

75{
76 PTDI_BUCKET Bucket;
78
80
81 while (!IsListEmpty(&Connection->SendRequest))
82 {
83 Entry = RemoveHeadList(&Connection->SendRequest);
84
86
87 Bucket->Information = 0;
88 Bucket->Status = Status;
89
90 CompleteBucket(Connection, Bucket, FALSE);
91 }
92}
LIST_ENTRY SendRequest
Definition: titypes.h:253

Referenced by FlushAllQueues(), and TCPDisconnect().

◆ FlushShutdownQueue()

VOID FlushShutdownQueue ( PCONNECTION_ENDPOINT  Connection,
const NTSTATUS  Status 
)

Definition at line 95 of file event.c.

96{
97 PTDI_BUCKET Bucket;
99
100 ASSERT_TCPIP_OBJECT_LOCKED(Connection);
101
102 while (!IsListEmpty(&Connection->ShutdownRequest))
103 {
104 Entry = RemoveHeadList(&Connection->ShutdownRequest);
105
107
108 Bucket->Information = 0;
109 Bucket->Status = Status;
110
111 CompleteBucket(Connection, Bucket, FALSE);
112 }
113}
LIST_ENTRY ShutdownRequest
Definition: titypes.h:254

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

◆ HandleSignalledConnection()

VOID HandleSignalledConnection ( PCONNECTION_ENDPOINT  Connection)

◆ LibTCPDumpPcb()

void LibTCPDumpPcb ( PVOID  SocketContext)

Definition at line 36 of file tcp.c.

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

Referenced by LogActiveObjects().

◆ TCPAbortListenForSocket()

BOOLEAN TCPAbortListenForSocket ( PCONNECTION_ENDPOINT  Listener,
PCONNECTION_ENDPOINT  Connection 
)

Definition at line 107 of file accept.c.

110{
111 PLIST_ENTRY ListEntry;
112 PTDI_BUCKET Bucket;
114
115 LockObject(Listener);
116
117 ListEntry = Listener->ListenRequest.Flink;
118 while (ListEntry != &Listener->ListenRequest)
119 {
120 Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry);
121
122 if (Bucket->AssociatedEndpoint == Connection)
123 {
125 RemoveEntryList( &Bucket->Entry );
126 ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
127 Found = TRUE;
128 break;
129 }
130
131 ListEntry = ListEntry->Flink;
132 }
133
134 UnlockObject(Listener);
135
136 return Found;
137}
unsigned char BOOLEAN
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
return Found
Definition: dirsup.c:1270
#define TRUE
Definition: types.h:120
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY Entry
Definition: titypes.h:230
#define UnlockObject(Object)
Definition: titypes.h:44
#define LockObject(Object)
Definition: titypes.h:34

Referenced by DispCancelListenRequest().

◆ TCPAccept()

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

Definition at line 139 of file accept.c.

144{
146 PTDI_BUCKET Bucket;
147
148 LockObject(Listener);
149
150 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
151
152 if (Bucket)
153 {
154 Bucket->AssociatedEndpoint = Connection;
156
159 InsertTailList( &Listener->ListenRequest, &Bucket->Entry );
161 }
162 else
164
165 UnlockObject(Listener);
166
167 return Status;
168}
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
pRequest Complete(RequestStatus)
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
TDI_REQUEST Request
Definition: titypes.h:232
PVOID RequestContext
Definition: tdi.h:55
PVOID RequestNotifyObject
Definition: tdi.h:54

Referenced by DispTdiListen().

◆ TCPAddSegment()

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

◆ TCPAllocateConnectionEndpoint()

PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint ( PVOID  ClientContext)

Definition at line 107 of file tcp.c.

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 */
122 InitializeListHead(&Connection->ListenRequest);
124 InitializeListHead(&Connection->SendRequest);
126 InitializeListHead(&Connection->PacketQueue);
127
128 /* Initialize disconnect timer */
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}
#define NULL
Definition: types.h:112
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define DEBUG_CPOINT
Definition: debug.h:33
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define CONN_ENDPT_TAG
Definition: tags.h:10
PDEVICE_OBJECT TCPDeviceObject
Definition: main.c:20
VOID ConnectionFree(PVOID Object)
Definition: tcp.c:90
VOID NTAPI DisconnectTimeoutDpc(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: tcp.c:80
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY ConnectionEndpointListHead
Definition: fileobjs.c:25
KSPIN_LOCK ConnectionEndpointListLock
Definition: fileobjs.c:26
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ PVOID ClientContext
Definition: netioddk.h:55
LIST_ENTRY PacketQueue
Definition: titypes.h:256
PIO_WORKITEM DisconnectWorkItem
Definition: titypes.h:261
ERESOURCE Resource
Definition: titypes.h:245
LIST_ENTRY ListEntry
Definition: titypes.h:242
OBJECT_FREE_ROUTINE Free
Definition: titypes.h:244
KTIMER DisconnectTimer
Definition: titypes.h:259
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
struct _CONNECTION_ENDPOINT * PCONNECTION_ENDPOINT
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

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

◆ TCPAllocatePort()

UINT TCPAllocatePort ( const UINT  HintPort)

Definition at line 636 of file tcp.c.

637{
638 if (HintPort)
639 {
640 if (AllocatePort(&TCPPorts, HintPort))
641 return HintPort;
642 else
643 {
644 TI_DbgPrint(MID_TRACE,("We got a hint port but couldn't allocate it\n"));
645 return (UINT)-1;
646 }
647 }
648 else
649 return AllocatePortFromRange( &TCPPorts, 1024, 5000 );
650}
#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
PORT_SET TCPPorts
Definition: tcp.c:17
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}
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:267
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: tcp.c:856
struct _TDI_CONNECTION_INFORMATION * PTDI_CONNECTION_INFORMATION
#define TDI_QUERY_ACCEPT
Definition: tdi.h:132
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:172

Referenced by TCPAcceptEventHandler().

◆ TCPClose()

NTSTATUS TCPClose ( PCONNECTION_ENDPOINT  Connection)

Definition at line 177 of file tcp.c.

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}
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:157
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
Definition: tcp.c:798
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

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 301 of file tcp.c.

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
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
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 UINT AllocatedPort;
374
375 /* We did, so we need to copy back the port */
377 if (!NT_SUCCESS(Status))
378 {
379 UnlockObject(Connection);
380 return Status;
381 }
382
383 /* Allocate the port in the port bitmap */
384 AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
385 /* This should never fail unless all ports are in use */
386 if (AllocatedPort == (UINT) -1)
387 {
388 DbgPrint("ERR: No more ports available.\n");
389 UnlockObject(Connection);
391 }
392 Connection->AddressFile->Port = AllocatedPort;
393 }
394
395 connaddr.addr = RemoteAddress.Address.IPv4Address;
396
397 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
398 if (!Bucket)
399 {
400 UnlockObject(Connection);
401 return STATUS_NO_MEMORY;
402 }
403
406
407 InsertTailList( &Connection->ConnectRequest, &Bucket->Entry );
408
409 UnlockObject(Connection);
410
412 &connaddr,
413 RemotePort));
414 if (!NT_SUCCESS(Status))
415 {
416 LockObject(Connection);
417 RemoveEntryList(&Bucket->Entry);
418 UnlockObject(Connection);
419 ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
420 }
421 TI_DbgPrint(DEBUG_TCP,("[IP, TCPConnect] Leaving. Status = 0x%x\n", Status));
422
423 return Status;
424}
NTSTATUS AddrBuildAddress(PTRANSPORT_ADDRESS TdiAddress, PIP_ADDRESS Address, PUSHORT Port)
Definition: address.c:184
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DEBUG_TCP
Definition: debug.h:28
PNEIGHBOR_CACHE_ENTRY RouteGetRouteToDestination(PIP_ADDRESS Destination)
Definition: router.c:300
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS Address, BOOLEAN GetRemote)
Definition: tcp.c:658
NTSTATUS TCPTranslateError(const err_t err)
Definition: tcp.c:267
NPAGED_LOOKASIDE_LIST TdiBucketLookasideList
Definition: tcp.c:26
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:636
err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: tcp.c:622
err_t LibTCPBind(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
Definition: tcp.c:415
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:704
#define STATUS_TOO_MANY_ADDRESSES
Definition: ntstatus.h:653
unsigned short USHORT
Definition: pedump.c:61
Definition: ip.h:23
union IP_ADDRESS::@1005 Address
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
Definition: neighbor.h:28
PIP_INTERFACE Interface
Definition: neighbor.h:33
USHORT Port
Definition: titypes.h:120
IP_ADDRESS Address
Definition: titypes.h:117
PADDRESS_FILE AddressFile
Definition: titypes.h:247
IP_ADDRESS Unicast
Definition: ip.h:159
void * PVOID
Definition: typedefs.h:50
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR LocalAddress
Definition: wsk.h:171

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 426 of file tcp.c.

434{
436 PTDI_BUCKET Bucket;
437 LARGE_INTEGER ActualTimeout;
438
439 TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Called\n"));
440
441 LockObject(Connection);
442
443 if (Connection->SocketContext)
444 {
446 {
447 if (IsListEmpty(&Connection->SendRequest))
448 {
449 ReferenceObject(Connection);
450 UnlockObject(Connection);
451 Status = TCPTranslateError(LibTCPShutdown(Connection, 0, 1));
452 LockObject(Connection);
453 DereferenceObject(Connection);
454 }
455 else if (Timeout && Timeout->QuadPart == 0)
456 {
458 ReferenceObject(Connection);
459 UnlockObject(Connection);
460 LibTCPShutdown(Connection, 0, 1);
461 LockObject(Connection);
462 DereferenceObject(Connection);
464 }
465 else
466 {
467 /* Use the timeout specified or 1 second if none was specified */
468 if (Timeout)
469 {
470 ActualTimeout = *Timeout;
471 }
472 else
473 {
474 ActualTimeout.QuadPart = -1000000;
475 }
476
477 /* We couldn't complete the request now because we need to wait for outstanding I/O */
478 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
479 if (!Bucket)
480 {
481 UnlockObject(Connection);
482 return STATUS_NO_MEMORY;
483 }
484
487
488 InsertTailList(&Connection->ShutdownRequest, &Bucket->Entry);
489
490 ReferenceObject(Connection);
491 if (KeSetTimer(&Connection->DisconnectTimer, ActualTimeout, &Connection->DisconnectDpc))
492 {
493 /* Timer was already in the queue. */
494 DereferenceObject(Connection);
495 }
496
498 }
499 }
500
501 if ((Flags & TDI_DISCONNECT_ABORT) || !Flags)
502 {
506 ReferenceObject(Connection);
507 UnlockObject(Connection);
508 Status = TCPTranslateError(LibTCPShutdown(Connection, 1, 1));
509 DereferenceObject(Connection);
510 }
511 else
512 {
513 UnlockObject(Connection);
514 }
515 }
516 else
517 {
518 UnlockObject(Connection);
519 /* We already got closed by the other side so just return success */
521 }
522
523 TI_DbgPrint(DEBUG_TCP,("[IP, TCPDisconnect] Leaving. Status = 0x%x\n", Status));
524
525 return Status;
526}
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:95
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:53
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:74
err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
Definition: tcp.c:717
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
static ULONG Timeout
Definition: ping.c:61
#define TDI_DISCONNECT_RELEASE
Definition: tdi.h:144
#define TDI_DISCONNECT_ABORT
Definition: tdi.h:143
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by DispTdiDisconnect().

◆ TCPFreeConnectionEndpoint()

VOID TCPFreeConnectionEndpoint ( PCONNECTION_ENDPOINT  Connection)

◆ TCPFreePort()

VOID TCPFreePort ( const UINT  Port)

Definition at line 652 of file tcp.c.

653{
655}
VOID DeallocatePort(PPORT_SET PortSet, ULONG Port)
Definition: ports.c:35
CPPORT Port[4]
Definition: headless.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 657 of file tcp.c.

661{
663 struct ip_addr ipaddr;
665
666 AddressIP->TAAddressCount = 1;
667 AddressIP->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
668 AddressIP->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
669
670 LockObject(Connection);
671
672 if (GetRemote)
673 {
675 &ipaddr,
676 &AddressIP->Address[0].Address[0].sin_port));
677 }
678 else
679 {
681 &ipaddr,
682 &AddressIP->Address[0].Address[0].sin_port));
683 }
684
685 UnlockObject(Connection);
686
687 AddressIP->Address[0].Address[0].in_addr = ipaddr.addr;
688
689 RtlZeroMemory(&AddressIP->Address[0].Address[0].sin_zero,
690 sizeof(AddressIP->Address[0].Address[0].sin_zero));
691
692 return Status;
693}
err_t LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
Definition: tcp.c:844
static WCHAR Address[46]
Definition: ping.c:68
struct _TA_ADDRESS_IP::_AddrIp Address[1]
LONG TAAddressCount
Definition: tdi.h:523
struct _TA_ADDRESS_IP * PTA_IP_ADDRESS

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

◆ TCPGetSocketStatus()

NTSTATUS TCPGetSocketStatus ( PCONNECTION_ENDPOINT  Connection,
PULONG  State 
)

Definition at line 749 of file tcp.c.

752{
753 if (!Connection)
754 return STATUS_UNSUCCESSFUL;
755
756 if (Connection->SocketContext == NULL)
757 return STATUS_UNSUCCESSFUL;
758
760 return STATUS_SUCCESS;
761}
void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State)
Definition: tcp.c:879
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

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;
52
53 ASSERT(Connection);
54
55 LockObject(Connection);
56
57 ASSERT_KM_POINTER(Connection->AddressFile);
58
59 TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Called\n"));
60
61 TI_DbgPrint(DEBUG_TCP, ("Connection->SocketContext %x\n",
62 Connection->SocketContext));
63
64 AddressToBind.addr = Connection->AddressFile->Address.Address.IPv4Address;
65
67 &AddressToBind,
68 Connection->AddressFile->Port));
69
70 if (NT_SUCCESS(Status))
71 {
72 /* Check if we had an unspecified port */
73 if (!Connection->AddressFile->Port)
74 {
75 /* We did, so we need to copy back the port */
77 if (NT_SUCCESS(Status))
78 {
79 /* Allocate the port in the port bitmap */
80 UINT AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port);
81 /* This should never fail unless all ports are in use */
82 if (AllocatedPort == (UINT) -1)
83 {
84 DbgPrint("ERR: No more ports available.\n");
85 UnlockObject(Connection);
87 }
88 Connection->AddressFile->Port = AllocatedPort;
89 }
90 }
91 }
92
93 if (NT_SUCCESS(Status))
94 {
95 Connection->SocketContext = LibTCPListen(Connection, Backlog);
96 if (!Connection->SocketContext)
98 }
99
100 UnlockObject(Connection);
101
102 TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Leaving. Status = %x\n", Status));
103
104 return Status;
105}
#define ASSERT_KM_POINTER(_x)
Definition: debug.h:74
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:636
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS TransportAddress, BOOLEAN RemoteAddress)
Definition: tcp.c:658
PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
Definition: tcp.c:469
#define ASSERT(a)
Definition: mode.c:44

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 528 of file tcp.c.

536{
537 PTDI_BUCKET Bucket;
538 PUCHAR DataBuffer;
539 UINT DataLen, Received;
541
542 TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Called for %d bytes (on socket %x)\n",
543 ReceiveLength, Connection->SocketContext));
544
545 NdisQueryBuffer(Buffer, &DataBuffer, &DataLen);
546
547 Status = LibTCPGetDataFromConnectionQueue(Connection, DataBuffer, DataLen, &Received);
548
549 if (Status == STATUS_PENDING)
550 {
551 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
552 if (!Bucket)
553 {
554 TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate bucket\n"));
555
556 return STATUS_NO_MEMORY;
557 }
558
561
562 LockObject(Connection);
563 InsertTailList( &Connection->ReceiveRequest, &Bucket->Entry );
564 UnlockObject(Connection);
565 TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Queued read irp\n"));
566
567 TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Leaving. Status = STATUS_PENDING\n"));
568
569 (*BytesReceived) = 0;
570 }
571 else
572 {
573 (*BytesReceived) = Received;
574 }
575
576 return Status;
577}
UINT Received
Definition: arping.c:40
Definition: bufpool.h:45
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
Definition: tcp.c:100
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by DispTdiReceive().

◆ TCPRemoveIRP()

BOOLEAN TCPRemoveIRP ( PCONNECTION_ENDPOINT  Connection,
PIRP  Irp 
)

Definition at line 695 of file tcp.c.

696{
698 PLIST_ENTRY ListHead[5];
699 PTDI_BUCKET Bucket;
700 UINT i = 0;
702
703 ListHead[0] = &Endpoint->SendRequest;
704 ListHead[1] = &Endpoint->ReceiveRequest;
705 ListHead[2] = &Endpoint->ConnectRequest;
706 ListHead[3] = &Endpoint->ListenRequest;
707 ListHead[4] = &Endpoint->ShutdownRequest;
708
709 LockObject(Endpoint);
710
711 for( i = 0; i < 5; i++ )
712 {
713 for( Entry = ListHead[i]->Flink;
714 Entry != ListHead[i];
715 Entry = Entry->Flink )
716 {
718 if( Bucket->Request.RequestContext == Irp )
719 {
720 RemoveEntryList( &Bucket->Entry );
721 ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket);
722 Found = TRUE;
723 break;
724 }
725 }
726 }
727
728 UnlockObject(Endpoint);
729
730 return Found;
731}
_In_ PIRP Irp
Definition: csq.h:116
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

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 579 of file tcp.c.

587{
589 PTDI_BUCKET Bucket;
590
591 ReferenceObject(Connection);
592
593 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Called for %d bytes (on socket %x)\n",
594 SendLength, Connection->SocketContext));
595
596 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection = %x\n", Connection));
597 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection->SocketContext = %x\n",
598 Connection->SocketContext));
599
601 BufferData,
602 SendLength,
603 BytesSent,
604 FALSE));
605
606 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Send: %x, %d\n", Status, SendLength));
607
608 /* Keep this request around ... there was no data yet */
609 if (Status == STATUS_PENDING)
610 {
611 /* Freed in TCPSocketState */
612 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
613 if (!Bucket)
614 {
615 DereferenceObject(Connection);
616 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Failed to allocate bucket\n"));
617 return STATUS_NO_MEMORY;
618 }
619
622
623 LockObject(Connection);
624 InsertTailList( &Connection->SendRequest, &Bucket->Entry );
625 TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Queued write irp\n"));
626 UnlockObject(Connection);
627 }
628
629
630 TI_DbgPrint(DEBUG_TCP, ("[IP, TCPSendData] Leaving. Status = %x\n", Status));
631 DereferenceObject(Connection);
632
633 return Status;
634}
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
Definition: tcp.c:557

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

◆ TCPSetNoDelay()

NTSTATUS TCPSetNoDelay ( PCONNECTION_ENDPOINT  Connection,
BOOLEAN  Set 
)

Definition at line 734 of file tcp.c.

737{
738 if (!Connection)
739 return STATUS_UNSUCCESSFUL;
740
741 if (Connection->SocketContext == NULL)
742 return STATUS_UNSUCCESSFUL;
743
744 LibTCPSetNoDelay(Connection->SocketContext, Set);
745 return STATUS_SUCCESS;
746}
void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set)
Definition: tcp.c:868
static BOOL Set
Definition: pageheap.c:10

Referenced by SetConnectionInfo().

◆ TCPShutdown()

NTSTATUS TCPShutdown ( VOID  )

Definition at line 243 of file tcp.c.

249{
250 if (!TCPInitialized)
251 return STATUS_SUCCESS;
252
254
256
257 /* Deregister this protocol with IP layer */
259
261
263
264 return STATUS_SUCCESS;
265}
#define IPPROTO_TCP
Definition: ip.h:196
VOID IPRegisterProtocol(UINT ProtocolNumber, IP_PROTOCOL_HANDLER Handler)
Definition: ip.c:386
VOID PortsShutdown(PPORT_SET PortSet)
Definition: ports.c:31
static BOOLEAN TCPInitialized
Definition: tcp.c:16
void LibIPShutdown(void)
Definition: ip.c:40
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170

Referenced by TiUnload().

◆ TCPSocket()

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

Definition at line 153 of file tcp.c.

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}
Type
Definition: Type.h:7
PTCP_PCB LibTCPSocket(void *arg)
Definition: tcp.c:336
static int Family
Definition: ping.c:62
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

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

◆ TCPStartup()

NTSTATUS TCPStartup ( VOID  )

Definition at line 208 of file tcp.c.

214{
216
217 Status = PortsStartup(&TCPPorts, 1, 0xffff);
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 */
233
234 /* Register this protocol with IP layer */
236
238
239 return STATUS_SUCCESS;
240}
NTSTATUS PortsStartup(PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
Definition: ports.c:13
#define TDI_BUCKET_TAG
Definition: tags.h:31
VOID TCPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket)
Definition: tcp.c:192
void LibIPInitialize(void)
Definition: ip.c:33
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

Referenced by DriverEntry().

◆ TCPTranslateError()

NTSTATUS TCPTranslateError ( const INT8  err)

Definition at line 267 of file tcp.c.

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}
#define ERR_ABRT
Definition: err.h:65
#define ERR_RST
Definition: err.h:66
#define ERR_ISCONN
Definition: err.h:61
#define ERR_MEM
Definition: err.h:53
#define ERR_USE
Definition: err.h:60
#define ERR_ARG
Definition: err.h:70
#define ERR_CONN
Definition: err.h:68
#define ERR_OK
Definition: err.h:52
#define ERR_RTE
Definition: err.h:56
#define ERR_WOULDBLOCK
Definition: err.h:59
#define ERR_VAL
Definition: err.h:58
#define ERR_INPROGRESS
Definition: err.h:57
#define ERR_BUF
Definition: err.h:54
#define ERR_TIMEOUT
Definition: err.h:55
#define ERR_CLSD
Definition: err.h:67
#define ERR_IF
Definition: err.h:72
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: ntstatus.h:654
#define STATUS_REMOTE_DISCONNECT
Definition: ntstatus.h:552
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:556
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: ntstatus.h:432
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:551
#define err(...)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69

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

◆ TCPUpdateInterfaceIPInformation()

VOID TCPUpdateInterfaceIPInformation ( PIP_INTERFACE  IF)

Definition at line 144 of file if.c.

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

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

◆ TCPUpdateInterfaceLinkStatus()

VOID TCPUpdateInterfaceLinkStatus ( PIP_INTERFACE  IF)

Definition at line 82 of file if.c.

83{
84 ULONG OperationalStatus;
85
86 GetInterfaceConnectionStatus(IF, &OperationalStatus);
87
88 if (OperationalStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
90 else
92}
#define MIB_IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:251
void netif_set_link_down(struct netif *netif)
Definition: netif.c:574
void netif_set_link_up(struct netif *netif)
Definition: netif.c:535
VOID GetInterfaceConnectionStatus(PIP_INTERFACE Interface, PULONG OperStatus)
Definition: interface.c:254
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ReconfigureAdapter(), and TCPInterfaceInit().

Variable Documentation

◆ ClientInfo

◆ TCP_IPIdentification

LONG TCP_IPIdentification
extern

Definition at line 15 of file tcp.c.