ReactOS  0.4.15-dev-309-g7c8d563
tcp.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS TCP/IP protocol driver
4  * FILE: include/tcp.h
5  * PURPOSE: Transmission Control Protocol definitions
6  */
7 
8 #pragma once
9 
10 typedef VOID
12 
13 /* TCPv4 header structure */
14 #include <pshpack1.h>
15 typedef struct TCPv4_HEADER {
16  USHORT SourcePort; /* Source port */
17  USHORT DestinationPort; /* Destination port */
18  ULONG SequenceNumber; /* Sequence number */
19  ULONG AckNumber; /* Acknowledgement number */
20  UCHAR DataOffset; /* Data offset; 32-bit words (leftmost 4 bits) */
21  UCHAR Flags; /* Control bits (rightmost 6 bits) */
22  USHORT Window; /* Maximum acceptable receive window */
23  USHORT Checksum; /* Checksum of segment */
24  USHORT Urgent; /* Pointer to urgent data */
26 
27 #define TCPOPT_END_OF_LIST 0x0
28 #define TCPOPT_NO_OPERATION 0x1
29 #define TCPOPT_MAX_SEG_SIZE 0x2
30 
31 #define TCPOPTLEN_MAX_SEG_SIZE 0x4
32 
33 /* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */
34 #define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2))
35 
36 
37 /* TCPv4 pseudo header */
38 typedef struct TCPv4_PSEUDO_HEADER {
39  ULONG SourceAddress; /* Source address */
40  ULONG DestinationAddress; /* Destination address */
41  UCHAR Zero; /* Reserved */
42  UCHAR Protocol; /* Protocol */
43  USHORT TCPLength; /* Size of TCP segment */
45 #include <poppack.h>
46 
47 typedef struct _SLEEPING_THREAD {
52 
53 typedef struct _CLIENT_DATA {
58 
59 /* Retransmission timeout constants */
60 
61 /* Lower bound for retransmission timeout in TCP timer ticks */
62 #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
63 
64 /* Upper bound for retransmission timeout in TCP timer ticks */
65 #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
66 
67 /* Smoothing factor */
68 #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
69 
70 /* Delay variance factor */
71 #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */
72 
73 #define SEL_CONNECT 1
74 #define SEL_FIN 2
75 #define SEL_RST 4
76 #define SEL_ABRT 8
77 #define SEL_READ 16
78 #define SEL_WRITE 32
79 #define SEL_ACCEPT 64
80 #define SEL_OOB 128
81 #define SEL_ERROR 256
82 #define SEL_FINOUT 512
83 
84 #define FREAD 0x0001
85 #define FWRITE 0x0002
86 
87 /* Datagram/segment send request flags */
88 
89 #define SRF_URG TCP_URG
90 #define SRF_ACK TCP_ACK
91 #define SRF_PSH TCP_PSH
92 #define SRF_RST TCP_RST
93 #define SRF_SYN TCP_SYN
94 #define SRF_FIN TCP_FIN
95 
97 extern CLIENT_DATA ClientInfo;
98 
99 /* accept.c */
102 NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog );
104  PCONNECTION_ENDPOINT Connection );
107  PCONNECTION_ENDPOINT Listener,
108  PCONNECTION_ENDPOINT Connection,
109  PTCP_COMPLETION_ROUTINE Complete,
110  PVOID Context );
111 
112 /* tcp.c */
115 
117  UINT Family, UINT Type, UINT Proto );
118 
120 
122  PIP_PACKET IPPacket,
124  ULONG SegmentLength);
125 
128 
130  PCONNECTION_ENDPOINT Connection,
132  PULONG Acknowledged);
133 
135  PCONNECTION_ENDPOINT Connection,
137  PTDI_CONNECTION_INFORMATION ReturnInfo,
138  PTCP_COMPLETION_ROUTINE Complete,
139  PVOID Context);
140 
142  PCONNECTION_ENDPOINT Connection,
143  UINT Flags,
146  PTDI_CONNECTION_INFORMATION ReturnInfo,
147  PTCP_COMPLETION_ROUTINE Complete,
148  PVOID Context);
149 
151  PCONNECTION_ENDPOINT Connection,
153  ULONG ReceiveLength,
154  PULONG BytesReceived,
155  ULONG ReceiveFlags,
156  PTCP_COMPLETION_ROUTINE Complete,
157  PVOID Context);
158 
160  PCONNECTION_ENDPOINT Connection,
161  PCHAR Buffer,
162  ULONG DataSize,
163  PULONG DataUsed,
164  ULONG Flags,
165  PTCP_COMPLETION_ROUTINE Complete,
166  PVOID Context);
167 
169 
171 
172 UINT TCPAllocatePort( const UINT HintPort );
173 
174 VOID TCPFreePort( const UINT Port );
175 
177 ( PCONNECTION_ENDPOINT Connection,
178  PTRANSPORT_ADDRESS TransportAddress,
180 
182  VOID);
183 
185  VOID);
186 
188 
190 
191 VOID
193 
194 VOID
196 
197 VOID
199 
200 VOID
202 
203 VOID
204 FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
205 
206 VOID
207 FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
208 
209 VOID
210 FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked);
211 
212 VOID
214 
215 VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous);
216 
217 void
219 
NTSTATUS TCPConnect(PCONNECTION_ENDPOINT Connection, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:277
signed char * PCHAR
Definition: retypes.h:7
VOID FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:196
signed char INT8
LONG TCP_IPIdentification
Definition: tcptest.cpp:24
CPPORT Port[4]
Definition: headless.c:34
struct TCPv4_HEADER TCPv4_HEADER
VOID TCPFreeSegment(PTCP_SEGMENT Segment)
Type
Definition: Type.h:6
KIRQL OldIrql
Definition: tcp.h:56
NTSTATUS TCPGetSocketStatus(PCONNECTION_ENDPOINT Connection, PULONG State)
Definition: tcp.c:695
NTSTATUS TCPListen(PCONNECTION_ENDPOINT Connection, UINT Backlog)
Definition: accept.c:47
ULONG SourceAddress
Definition: tcp.h:39
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS TCPReceiveData(PCONNECTION_ENDPOINT Connection, PNDIS_BUFFER Buffer, ULONG ReceiveLength, PULONG BytesReceived, ULONG ReceiveFlags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:476
MDL * PNDIS_BUFFER
Definition: ndis.h:343
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TCPSendData(PCONNECTION_ENDPOINT Connection, PCHAR Buffer, ULONG DataSize, PULONG DataUsed, ULONG Flags, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:525
BOOLEAN TCPAbortListenForSocket(PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection)
Definition: accept.c:104
VOID HandleSignalledConnection(PCONNECTION_ENDPOINT Connection)
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
NTSTATUS TCPSocket(PCONNECTION_ENDPOINT Connection, UINT Family, UINT Type, UINT Proto)
Definition: tcp.c:125
UCHAR DataOffset
Definition: tcp.h:20
USHORT Window
Definition: tcp.h:22
VOID TCPFreePort(const UINT Port)
Definition: tcp.c:596
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID SocketContext
Definition: wsk.h:182
NTSTATUS TCPCheckPeerForAccept(PVOID Context, PTDI_REQUEST_KERNEL Request)
Definition: accept.c:17
struct _SLEEPING_THREAD * PSLEEPING_THREAD
static BOOL Set
Definition: pageheap.c:10
KSPIN_LOCK Lock
Definition: tcp.h:55
UCHAR Flags
Definition: tcp.h:21
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
CLIENT_DATA ClientInfo
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status)
Definition: event.c:218
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS TCPGetSockAddress(PCONNECTION_ENDPOINT Connection, PTRANSPORT_ADDRESS TransportAddress, BOOLEAN RemoteAddress)
Definition: tcp.c:602
NTSTATUS TCPClose(PCONNECTION_ENDPOINT Connection)
Definition: tcp.c:150
static int Family
Definition: ping.c:62
VOID TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
Definition: if.c:81
long LONG
Definition: pedump.c:60
NTSTATUS TCPAccept(PTDI_REQUEST Request, PCONNECTION_ENDPOINT Listener, PCONNECTION_ENDPOINT Connection, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: accept.c:136
USHORT DestinationPort
Definition: tcp.h:17
unsigned char BOOLEAN
struct TCPv4_HEADER * PTCPv4_HEADER
UINT TCPAllocatePort(const UINT HintPort)
Definition: tcp.c:580
Definition: bufpool.h:45
VOID FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:53
VOID TCPAddSegment(PCONNECTION_ENDPOINT Connection, PTCP_SEGMENT Segment, PULONG Acknowledged)
VOID(* PTCP_COMPLETION_ROUTINE)(PVOID Context, NTSTATUS Status, ULONG Count)
Definition: tcp.h:11
_Inout_ PVOID Segment
Definition: exfuncs.h:893
_In_ PVOID ClientContext
Definition: netioddk.h:55
USHORT TCPLength
Definition: tcp.h:43
VOID FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:137
struct _CLIENT_DATA * PCLIENT_DATA
PTCP_SEGMENT TCPCreateSegment(PIP_PACKET IPPacket, PTCPv4_HEADER TCPHeader, ULONG SegmentLength)
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG AckNumber
Definition: tcp.h:19
USHORT Checksum
Definition: tcp.h:23
#define VOID
Definition: acefi.h:82
Definition: typedefs.h:118
struct TCPv4_PSEUDO_HEADER * PTCPv4_PSEUDO_HEADER
#define err(...)
UCHAR Zero
Definition: tcp.h:41
struct _CLIENT_DATA CLIENT_DATA
UCHAR Protocol
Definition: tcp.h:42
VOID FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status)
Definition: event.c:175
Status
Definition: gdiplustypes.h:24
NTSTATUS TCPTranslateError(const INT8 err)
Definition: tcp.c:242
VOID FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status, const BOOLEAN interlocked)
Definition: event.c:95
NTSTATUS TCPStartup(VOID)
Definition: tcp.c:183
void LibTCPDumpPcb(PVOID SocketContext)
Definition: rostcp.c:39
USHORT SourcePort
Definition: tcp.h:16
struct TCPv4_PSEUDO_HEADER TCPv4_PSEUDO_HEADER
static ULONG Timeout
Definition: ping.c:61
KEVENT Event
Definition: tcp.h:50
NTSTATUS TCPDisconnect(PCONNECTION_ENDPOINT Connection, UINT Flags, PLARGE_INTEGER Timeout, PTDI_CONNECTION_INFORMATION ConnInfo, PTDI_CONNECTION_INFORMATION ReturnInfo, PTCP_COMPLETION_ROUTINE Complete, PVOID Context)
Definition: tcp.c:387
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS TCPSetNoDelay(PCONNECTION_ENDPOINT Connection, BOOLEAN Set)
Definition: tcp.c:680
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
LIST_ENTRY Entry
Definition: tcp.h:48
ULONG SequenceNumber
Definition: tcp.h:18
BOOLEAN TCPRemoveIRP(PCONNECTION_ENDPOINT Connection, PIRP Irp)
Definition: tcp.c:640
BOOLEAN Unlocked
Definition: tcp.h:54
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous)
Definition: event.c:38
Definition: ip.h:77
VOID TCPFreeConnectionEndpoint(PCONNECTION_ENDPOINT Connection)
NTSTATUS TCPShutdown(VOID)
Definition: tcp.c:218
PVOID SleepToken
Definition: tcp.h:49
USHORT Urgent
Definition: tcp.h:24
VOID TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF)
Definition: if.c:145
PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint(PVOID ClientContext)
Definition: tcp.c:86
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
ULONG DestinationAddress
Definition: tcp.h:40
struct _SLEEPING_THREAD SLEEPING_THREAD
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170