1c2c66affSColin Finck /* 2c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory 3c2c66affSColin Finck * PROJECT: ReactOS TCP/IP protocol driver 4c2c66affSColin Finck * FILE: include/tcp.h 5c2c66affSColin Finck * PURPOSE: Transmission Control Protocol definitions 6c2c66affSColin Finck */ 7c2c66affSColin Finck 8c2c66affSColin Finck #pragma once 9c2c66affSColin Finck 10c2c66affSColin Finck typedef VOID 11c2c66affSColin Finck (*PTCP_COMPLETION_ROUTINE)( PVOID Context, NTSTATUS Status, ULONG Count ); 12c2c66affSColin Finck 13c2c66affSColin Finck /* TCPv4 header structure */ 14c2c66affSColin Finck #include <pshpack1.h> 15c2c66affSColin Finck typedef struct TCPv4_HEADER { 16c2c66affSColin Finck USHORT SourcePort; /* Source port */ 17c2c66affSColin Finck USHORT DestinationPort; /* Destination port */ 18c2c66affSColin Finck ULONG SequenceNumber; /* Sequence number */ 19c2c66affSColin Finck ULONG AckNumber; /* Acknowledgement number */ 20c2c66affSColin Finck UCHAR DataOffset; /* Data offset; 32-bit words (leftmost 4 bits) */ 21c2c66affSColin Finck UCHAR Flags; /* Control bits (rightmost 6 bits) */ 22c2c66affSColin Finck USHORT Window; /* Maximum acceptable receive window */ 23c2c66affSColin Finck USHORT Checksum; /* Checksum of segment */ 24c2c66affSColin Finck USHORT Urgent; /* Pointer to urgent data */ 25c2c66affSColin Finck } TCPv4_HEADER, *PTCPv4_HEADER; 26c2c66affSColin Finck 27c2c66affSColin Finck #define TCPOPT_END_OF_LIST 0x0 28c2c66affSColin Finck #define TCPOPT_NO_OPERATION 0x1 29c2c66affSColin Finck #define TCPOPT_MAX_SEG_SIZE 0x2 30c2c66affSColin Finck 31c2c66affSColin Finck #define TCPOPTLEN_MAX_SEG_SIZE 0x4 32c2c66affSColin Finck 33c2c66affSColin Finck /* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */ 34c2c66affSColin Finck #define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2)) 35c2c66affSColin Finck 36c2c66affSColin Finck 37c2c66affSColin Finck /* TCPv4 pseudo header */ 38c2c66affSColin Finck typedef struct TCPv4_PSEUDO_HEADER { 39c2c66affSColin Finck ULONG SourceAddress; /* Source address */ 40c2c66affSColin Finck ULONG DestinationAddress; /* Destination address */ 41c2c66affSColin Finck UCHAR Zero; /* Reserved */ 42c2c66affSColin Finck UCHAR Protocol; /* Protocol */ 43c2c66affSColin Finck USHORT TCPLength; /* Size of TCP segment */ 44c2c66affSColin Finck } TCPv4_PSEUDO_HEADER, *PTCPv4_PSEUDO_HEADER; 45c2c66affSColin Finck #include <poppack.h> 46c2c66affSColin Finck 47c2c66affSColin Finck typedef struct _SLEEPING_THREAD { 48c2c66affSColin Finck LIST_ENTRY Entry; 49c2c66affSColin Finck PVOID SleepToken; 50c2c66affSColin Finck KEVENT Event; 51c2c66affSColin Finck } SLEEPING_THREAD, *PSLEEPING_THREAD; 52c2c66affSColin Finck 53c2c66affSColin Finck typedef struct _CLIENT_DATA { 54c2c66affSColin Finck BOOLEAN Unlocked; 55c2c66affSColin Finck KSPIN_LOCK Lock; 56c2c66affSColin Finck KIRQL OldIrql; 57c2c66affSColin Finck } CLIENT_DATA, *PCLIENT_DATA; 58c2c66affSColin Finck 59c2c66affSColin Finck /* Retransmission timeout constants */ 60c2c66affSColin Finck 61c2c66affSColin Finck /* Lower bound for retransmission timeout in TCP timer ticks */ 62c2c66affSColin Finck #define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */ 63c2c66affSColin Finck 64c2c66affSColin Finck /* Upper bound for retransmission timeout in TCP timer ticks */ 65c2c66affSColin Finck #define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */ 66c2c66affSColin Finck 67c2c66affSColin Finck /* Smoothing factor */ 68c2c66affSColin Finck #define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */ 69c2c66affSColin Finck 70c2c66affSColin Finck /* Delay variance factor */ 71c2c66affSColin Finck #define TCP_BETA_RETRANSMISSION_TIMEOUT(x)(((x)*16)/10) /* 1.6 */ 72c2c66affSColin Finck 73c2c66affSColin Finck #define SEL_CONNECT 1 74c2c66affSColin Finck #define SEL_FIN 2 75c2c66affSColin Finck #define SEL_RST 4 76c2c66affSColin Finck #define SEL_ABRT 8 77c2c66affSColin Finck #define SEL_READ 16 78c2c66affSColin Finck #define SEL_WRITE 32 79c2c66affSColin Finck #define SEL_ACCEPT 64 80c2c66affSColin Finck #define SEL_OOB 128 81c2c66affSColin Finck #define SEL_ERROR 256 82c2c66affSColin Finck #define SEL_FINOUT 512 83c2c66affSColin Finck 84c2c66affSColin Finck #define FREAD 0x0001 85c2c66affSColin Finck #define FWRITE 0x0002 86c2c66affSColin Finck 87c2c66affSColin Finck /* Datagram/segment send request flags */ 88c2c66affSColin Finck 89c2c66affSColin Finck #define SRF_URG TCP_URG 90c2c66affSColin Finck #define SRF_ACK TCP_ACK 91c2c66affSColin Finck #define SRF_PSH TCP_PSH 92c2c66affSColin Finck #define SRF_RST TCP_RST 93c2c66affSColin Finck #define SRF_SYN TCP_SYN 94c2c66affSColin Finck #define SRF_FIN TCP_FIN 95c2c66affSColin Finck 96c2c66affSColin Finck extern LONG TCP_IPIdentification; 97c2c66affSColin Finck extern CLIENT_DATA ClientInfo; 98c2c66affSColin Finck 99c2c66affSColin Finck /* accept.c */ 100c2c66affSColin Finck NTSTATUS TCPCheckPeerForAccept(PVOID Context, 101c2c66affSColin Finck PTDI_REQUEST_KERNEL Request); 102c2c66affSColin Finck NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog ); 103c2c66affSColin Finck BOOLEAN TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener, 104c2c66affSColin Finck PCONNECTION_ENDPOINT Connection ); 105c2c66affSColin Finck NTSTATUS TCPAccept 106c2c66affSColin Finck ( PTDI_REQUEST Request, 107c2c66affSColin Finck PCONNECTION_ENDPOINT Listener, 108c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 109c2c66affSColin Finck PTCP_COMPLETION_ROUTINE Complete, 110c2c66affSColin Finck PVOID Context ); 111c2c66affSColin Finck 112c2c66affSColin Finck /* tcp.c */ 113c2c66affSColin Finck PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext ); 114c2c66affSColin Finck VOID TCPFreeConnectionEndpoint( PCONNECTION_ENDPOINT Connection ); 115c2c66affSColin Finck 116c2c66affSColin Finck NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection, 117c2c66affSColin Finck UINT Family, UINT Type, UINT Proto ); 118c2c66affSColin Finck 119c2c66affSColin Finck VOID HandleSignalledConnection(PCONNECTION_ENDPOINT Connection); 120c2c66affSColin Finck 121c2c66affSColin Finck PTCP_SEGMENT TCPCreateSegment( 122c2c66affSColin Finck PIP_PACKET IPPacket, 123c2c66affSColin Finck PTCPv4_HEADER TCPHeader, 124c2c66affSColin Finck ULONG SegmentLength); 125c2c66affSColin Finck 126c2c66affSColin Finck VOID TCPFreeSegment( 127c2c66affSColin Finck PTCP_SEGMENT Segment); 128c2c66affSColin Finck 129c2c66affSColin Finck VOID TCPAddSegment( 130c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 131c2c66affSColin Finck PTCP_SEGMENT Segment, 132c2c66affSColin Finck PULONG Acknowledged); 133c2c66affSColin Finck 134c2c66affSColin Finck NTSTATUS TCPConnect( 135c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 136c2c66affSColin Finck PTDI_CONNECTION_INFORMATION ConnInfo, 137c2c66affSColin Finck PTDI_CONNECTION_INFORMATION ReturnInfo, 138c2c66affSColin Finck PTCP_COMPLETION_ROUTINE Complete, 139c2c66affSColin Finck PVOID Context); 140c2c66affSColin Finck 141c2c66affSColin Finck NTSTATUS TCPDisconnect( 142c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 143c2c66affSColin Finck UINT Flags, 144c2c66affSColin Finck PLARGE_INTEGER Timeout, 145c2c66affSColin Finck PTDI_CONNECTION_INFORMATION ConnInfo, 146c2c66affSColin Finck PTDI_CONNECTION_INFORMATION ReturnInfo, 147c2c66affSColin Finck PTCP_COMPLETION_ROUTINE Complete, 148c2c66affSColin Finck PVOID Context); 149c2c66affSColin Finck 150c2c66affSColin Finck NTSTATUS TCPReceiveData( 151c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 152c2c66affSColin Finck PNDIS_BUFFER Buffer, 153c2c66affSColin Finck ULONG ReceiveLength, 154c2c66affSColin Finck PULONG BytesReceived, 155c2c66affSColin Finck ULONG ReceiveFlags, 156c2c66affSColin Finck PTCP_COMPLETION_ROUTINE Complete, 157c2c66affSColin Finck PVOID Context); 158c2c66affSColin Finck 159c2c66affSColin Finck NTSTATUS TCPSendData( 160c2c66affSColin Finck PCONNECTION_ENDPOINT Connection, 161c2c66affSColin Finck PCHAR Buffer, 162c2c66affSColin Finck ULONG DataSize, 163c2c66affSColin Finck PULONG DataUsed, 164c2c66affSColin Finck ULONG Flags, 165c2c66affSColin Finck PTCP_COMPLETION_ROUTINE Complete, 166c2c66affSColin Finck PVOID Context); 167c2c66affSColin Finck 168c2c66affSColin Finck NTSTATUS TCPClose( PCONNECTION_ENDPOINT Connection ); 169c2c66affSColin Finck 170c2c66affSColin Finck NTSTATUS TCPTranslateError( const INT8 err ); 171c2c66affSColin Finck 172c2c66affSColin Finck UINT TCPAllocatePort( const UINT HintPort ); 173c2c66affSColin Finck 174c2c66affSColin Finck VOID TCPFreePort( const UINT Port ); 175c2c66affSColin Finck 176c2c66affSColin Finck NTSTATUS TCPGetSockAddress 177c2c66affSColin Finck ( PCONNECTION_ENDPOINT Connection, 178c2c66affSColin Finck PTRANSPORT_ADDRESS TransportAddress, 179c2c66affSColin Finck BOOLEAN RemoteAddress ); 180c2c66affSColin Finck 181c2c66affSColin Finck NTSTATUS TCPStartup( 182c2c66affSColin Finck VOID); 183c2c66affSColin Finck 184c2c66affSColin Finck NTSTATUS TCPShutdown( 185c2c66affSColin Finck VOID); 186c2c66affSColin Finck 187c2c66affSColin Finck BOOLEAN TCPRemoveIRP( PCONNECTION_ENDPOINT Connection, PIRP Irp ); 188c2c66affSColin Finck 189c2c66affSColin Finck NTSTATUS TCPSetNoDelay(PCONNECTION_ENDPOINT Connection, BOOLEAN Set); 190c2c66affSColin Finck 191c2c66affSColin Finck VOID 192c2c66affSColin Finck TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF); 193c2c66affSColin Finck 194c2c66affSColin Finck VOID 195c2c66affSColin Finck TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF); 196c2c66affSColin Finck 197c2c66affSColin Finck VOID 198c2c66affSColin Finck FlushListenQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status); 199c2c66affSColin Finck 200c2c66affSColin Finck VOID 201c2c66affSColin Finck FlushConnectQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status); 202c2c66affSColin Finck 203c2c66affSColin Finck VOID 204*27fcfe66SJérôme Gardou FlushReceiveQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status); 205c2c66affSColin Finck 206c2c66affSColin Finck VOID 207*27fcfe66SJérôme Gardou FlushSendQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status); 208c2c66affSColin Finck 209c2c66affSColin Finck VOID 210*27fcfe66SJérôme Gardou FlushShutdownQueue(PCONNECTION_ENDPOINT Connection, const NTSTATUS Status); 211c2c66affSColin Finck 212c2c66affSColin Finck VOID 213c2c66affSColin Finck FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status); 214c2c66affSColin Finck 215c2c66affSColin Finck VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous); 216c2c66affSColin Finck 217c2c66affSColin Finck void 218c2c66affSColin Finck LibTCPDumpPcb(PVOID SocketContext); 21991b013d3SPierre Schweitzer 22091b013d3SPierre Schweitzer NTSTATUS TCPGetSocketStatus(PCONNECTION_ENDPOINT Connection, PULONG State); 221