reactos/drivers/network/tcpip/include/tcp.h

219 lines
5.9 KiB
C
Raw Normal View History

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS TCP/IP protocol driver
* FILE: include/tcp.h
* PURPOSE: Transmission Control Protocol definitions
*/
#pragma once
typedef VOID
(*PTCP_COMPLETION_ROUTINE)( PVOID Context, NTSTATUS Status, ULONG Count );
/* TCPv4 header structure */
#include <pshpack1.h>
2004-03-04 Casper S. Hornstrup <chorns@users.sourceforge.net> * drivers/net/tcpip/tcpip/i386: New directory. * drivers/net/tcpip/tcpip/i386/checksum.S: New file. * drivers/net/tcpip/notes.txt: New file. * drivers/net/afd/afd/dispatch.c (AfdDispCompleteListen): Signal ACCEPT network event. (AfdDispEventSelect): Reference event handle. * drivers/net/afd/afd/tdi.c (TdiListen): Remove unused event. Move Iosb and RequestConnectionInfo to AFD_LISTEN_REQUEST structure. * drivers/net/afd/include/afd.h (AFDFCB): Replace EventObjects with EventObject of type PKEVENT. * drivers/net/tcpip/makefile (ARCH_OBJECTS): New variable. (TARGET_OBJECTS): Add ARCH_OBJECTS. * drivers/net/tcpip/include/address.h (AddrCloneAddress): New prototype. * drivers/net/tcpip/include/checksum.h (ChecksumFold, csum_partial): New prototype. (TCPv4Checksum): New macro. (CorrectChecksum): Rename to IPv4CorrectChecksum. (TCPv4CorrectChecksum): New macro. * drivers/net/tcpip/include/ip.h (IPv4_DF_MASK): New constant. * drivers/net/tcpip/include/tcp.h (TCP_XXX): Correct constants. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment): Prototype. * drivers/net/tcpip/include/titypes.h (TCP_SEND_REQUEST): Add SequenceNumber and AckNumber. (TCP_SEGMENT): New structure. (CONNECTION_ENDPOINT): Add ListenRequest and ReceivedSegments. * drivers/net/tcpip/network/transmit.c (SendFragments): Release memory for Data on failure. * drivers/net/tcpip/tcpip/address.c (AddrCloneAddress): New function. * drivers/net/tcpip/tcpip/checksum.c (ChecksumFold): Factor out folding from ChecksumCompute. * drivers/net/tcpip/tcpip/dispatch.c (DispTdiListen): Support asynchronous operation. * drivers/net/tcpip/tcpip/fileobjs.c (FileOpenAddress): Don't cast to PTDI_ADDRESS_IP. Initialize ReceivedSegments. * drivers/net/tcpip/tcpip/routines.c (DisplayIPHeader): New function. (DisplayIPPacket): Call DisplayIPHeader(). (DisplayTCPHeader): Change format strings. * drivers/net/tcpip/transport/tcp/tcp.c (IPIdentification, TCPSegmentList): Add. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment, TCPBuildAndTransmitSendRequest2, TCPiSelectISS, TCPiReceiveListen, TCPiReceiveSynSent, TCPiReceiveSynReceived, TCPiReceiveData): New function. (TCPiBuildPacket): Build segment. (TCPStartup): Initialize TCPSegmentList. (TCPShutdown): Cleanup TCPSegmentList. svn path=/trunk/; revision=8537
2004-03-04 20:45:39 +00:00
typedef struct TCPv4_HEADER {
USHORT SourcePort; /* Source port */
USHORT DestinationPort; /* Destination port */
ULONG SequenceNumber; /* Sequence number */
ULONG AckNumber; /* Acknowledgement number */
UCHAR DataOffset; /* Data offset; 32-bit words (leftmost 4 bits) */
UCHAR Flags; /* Control bits (rightmost 6 bits) */
USHORT Window; /* Maximum acceptable receive window */
USHORT Checksum; /* Checksum of segment */
USHORT Urgent; /* Pointer to urgent data */
} TCPv4_HEADER, *PTCPv4_HEADER;
#define TCPOPT_END_OF_LIST 0x0
#define TCPOPT_NO_OPERATION 0x1
#define TCPOPT_MAX_SEG_SIZE 0x2
#define TCPOPTLEN_MAX_SEG_SIZE 0x4
/* Data offset; 32-bit words (leftmost 4 bits); convert to bytes */
#define TCP_DATA_OFFSET(DataOffset)(((DataOffset) & 0xF0) >> (4-2))
/* TCPv4 pseudo header */
2004-03-04 Casper S. Hornstrup <chorns@users.sourceforge.net> * drivers/net/tcpip/tcpip/i386: New directory. * drivers/net/tcpip/tcpip/i386/checksum.S: New file. * drivers/net/tcpip/notes.txt: New file. * drivers/net/afd/afd/dispatch.c (AfdDispCompleteListen): Signal ACCEPT network event. (AfdDispEventSelect): Reference event handle. * drivers/net/afd/afd/tdi.c (TdiListen): Remove unused event. Move Iosb and RequestConnectionInfo to AFD_LISTEN_REQUEST structure. * drivers/net/afd/include/afd.h (AFDFCB): Replace EventObjects with EventObject of type PKEVENT. * drivers/net/tcpip/makefile (ARCH_OBJECTS): New variable. (TARGET_OBJECTS): Add ARCH_OBJECTS. * drivers/net/tcpip/include/address.h (AddrCloneAddress): New prototype. * drivers/net/tcpip/include/checksum.h (ChecksumFold, csum_partial): New prototype. (TCPv4Checksum): New macro. (CorrectChecksum): Rename to IPv4CorrectChecksum. (TCPv4CorrectChecksum): New macro. * drivers/net/tcpip/include/ip.h (IPv4_DF_MASK): New constant. * drivers/net/tcpip/include/tcp.h (TCP_XXX): Correct constants. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment): Prototype. * drivers/net/tcpip/include/titypes.h (TCP_SEND_REQUEST): Add SequenceNumber and AckNumber. (TCP_SEGMENT): New structure. (CONNECTION_ENDPOINT): Add ListenRequest and ReceivedSegments. * drivers/net/tcpip/network/transmit.c (SendFragments): Release memory for Data on failure. * drivers/net/tcpip/tcpip/address.c (AddrCloneAddress): New function. * drivers/net/tcpip/tcpip/checksum.c (ChecksumFold): Factor out folding from ChecksumCompute. * drivers/net/tcpip/tcpip/dispatch.c (DispTdiListen): Support asynchronous operation. * drivers/net/tcpip/tcpip/fileobjs.c (FileOpenAddress): Don't cast to PTDI_ADDRESS_IP. Initialize ReceivedSegments. * drivers/net/tcpip/tcpip/routines.c (DisplayIPHeader): New function. (DisplayIPPacket): Call DisplayIPHeader(). (DisplayTCPHeader): Change format strings. * drivers/net/tcpip/transport/tcp/tcp.c (IPIdentification, TCPSegmentList): Add. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment, TCPBuildAndTransmitSendRequest2, TCPiSelectISS, TCPiReceiveListen, TCPiReceiveSynSent, TCPiReceiveSynReceived, TCPiReceiveData): New function. (TCPiBuildPacket): Build segment. (TCPStartup): Initialize TCPSegmentList. (TCPShutdown): Cleanup TCPSegmentList. svn path=/trunk/; revision=8537
2004-03-04 20:45:39 +00:00
typedef struct TCPv4_PSEUDO_HEADER {
ULONG SourceAddress; /* Source address */
ULONG DestinationAddress; /* Destination address */
UCHAR Zero; /* Reserved */
UCHAR Protocol; /* Protocol */
USHORT TCPLength; /* Size of TCP segment */
} TCPv4_PSEUDO_HEADER, *PTCPv4_PSEUDO_HEADER;
#include <poppack.h>
typedef struct _SLEEPING_THREAD {
LIST_ENTRY Entry;
PVOID SleepToken;
KEVENT Event;
} SLEEPING_THREAD, *PSLEEPING_THREAD;
typedef struct _CLIENT_DATA {
BOOLEAN Unlocked;
KSPIN_LOCK Lock;
KIRQL OldIrql;
} CLIENT_DATA, *PCLIENT_DATA;
/* Retransmission timeout constants */
/* Lower bound for retransmission timeout in TCP timer ticks */
#define TCP_MIN_RETRANSMISSION_TIMEOUT 1*1000 /* 1 tick */
/* Upper bound for retransmission timeout in TCP timer ticks */
#define TCP_MAX_RETRANSMISSION_TIMEOUT 1*60*1000 /* 1 tick */
/* Smoothing factor */
#define TCP_ALPHA_RETRANSMISSION_TIMEOUT(x)(((x)*8)/10) /* 0.8 */
/* Delay variance factor */
#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
/* Datagram/segment send request flags */
#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
extern LONG TCP_IPIdentification;
extern CLIENT_DATA ClientInfo;
/* accept.c */
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 );
/* tcp.c */
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);
2004-03-04 Casper S. Hornstrup <chorns@users.sourceforge.net> * drivers/net/tcpip/tcpip/i386: New directory. * drivers/net/tcpip/tcpip/i386/checksum.S: New file. * drivers/net/tcpip/notes.txt: New file. * drivers/net/afd/afd/dispatch.c (AfdDispCompleteListen): Signal ACCEPT network event. (AfdDispEventSelect): Reference event handle. * drivers/net/afd/afd/tdi.c (TdiListen): Remove unused event. Move Iosb and RequestConnectionInfo to AFD_LISTEN_REQUEST structure. * drivers/net/afd/include/afd.h (AFDFCB): Replace EventObjects with EventObject of type PKEVENT. * drivers/net/tcpip/makefile (ARCH_OBJECTS): New variable. (TARGET_OBJECTS): Add ARCH_OBJECTS. * drivers/net/tcpip/include/address.h (AddrCloneAddress): New prototype. * drivers/net/tcpip/include/checksum.h (ChecksumFold, csum_partial): New prototype. (TCPv4Checksum): New macro. (CorrectChecksum): Rename to IPv4CorrectChecksum. (TCPv4CorrectChecksum): New macro. * drivers/net/tcpip/include/ip.h (IPv4_DF_MASK): New constant. * drivers/net/tcpip/include/tcp.h (TCP_XXX): Correct constants. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment): Prototype. * drivers/net/tcpip/include/titypes.h (TCP_SEND_REQUEST): Add SequenceNumber and AckNumber. (TCP_SEGMENT): New structure. (CONNECTION_ENDPOINT): Add ListenRequest and ReceivedSegments. * drivers/net/tcpip/network/transmit.c (SendFragments): Release memory for Data on failure. * drivers/net/tcpip/tcpip/address.c (AddrCloneAddress): New function. * drivers/net/tcpip/tcpip/checksum.c (ChecksumFold): Factor out folding from ChecksumCompute. * drivers/net/tcpip/tcpip/dispatch.c (DispTdiListen): Support asynchronous operation. * drivers/net/tcpip/tcpip/fileobjs.c (FileOpenAddress): Don't cast to PTDI_ADDRESS_IP. Initialize ReceivedSegments. * drivers/net/tcpip/tcpip/routines.c (DisplayIPHeader): New function. (DisplayIPPacket): Call DisplayIPHeader(). (DisplayTCPHeader): Change format strings. * drivers/net/tcpip/transport/tcp/tcp.c (IPIdentification, TCPSegmentList): Add. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment, TCPBuildAndTransmitSendRequest2, TCPiSelectISS, TCPiReceiveListen, TCPiReceiveSynSent, TCPiReceiveSynReceived, TCPiReceiveData): New function. (TCPiBuildPacket): Build segment. (TCPStartup): Initialize TCPSegmentList. (TCPShutdown): Cleanup TCPSegmentList. svn path=/trunk/; revision=8537
2004-03-04 20:45:39 +00:00
PTCP_SEGMENT TCPCreateSegment(
PIP_PACKET IPPacket,
PTCPv4_HEADER TCPHeader,
2004-03-04 Casper S. Hornstrup <chorns@users.sourceforge.net> * drivers/net/tcpip/tcpip/i386: New directory. * drivers/net/tcpip/tcpip/i386/checksum.S: New file. * drivers/net/tcpip/notes.txt: New file. * drivers/net/afd/afd/dispatch.c (AfdDispCompleteListen): Signal ACCEPT network event. (AfdDispEventSelect): Reference event handle. * drivers/net/afd/afd/tdi.c (TdiListen): Remove unused event. Move Iosb and RequestConnectionInfo to AFD_LISTEN_REQUEST structure. * drivers/net/afd/include/afd.h (AFDFCB): Replace EventObjects with EventObject of type PKEVENT. * drivers/net/tcpip/makefile (ARCH_OBJECTS): New variable. (TARGET_OBJECTS): Add ARCH_OBJECTS. * drivers/net/tcpip/include/address.h (AddrCloneAddress): New prototype. * drivers/net/tcpip/include/checksum.h (ChecksumFold, csum_partial): New prototype. (TCPv4Checksum): New macro. (CorrectChecksum): Rename to IPv4CorrectChecksum. (TCPv4CorrectChecksum): New macro. * drivers/net/tcpip/include/ip.h (IPv4_DF_MASK): New constant. * drivers/net/tcpip/include/tcp.h (TCP_XXX): Correct constants. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment): Prototype. * drivers/net/tcpip/include/titypes.h (TCP_SEND_REQUEST): Add SequenceNumber and AckNumber. (TCP_SEGMENT): New structure. (CONNECTION_ENDPOINT): Add ListenRequest and ReceivedSegments. * drivers/net/tcpip/network/transmit.c (SendFragments): Release memory for Data on failure. * drivers/net/tcpip/tcpip/address.c (AddrCloneAddress): New function. * drivers/net/tcpip/tcpip/checksum.c (ChecksumFold): Factor out folding from ChecksumCompute. * drivers/net/tcpip/tcpip/dispatch.c (DispTdiListen): Support asynchronous operation. * drivers/net/tcpip/tcpip/fileobjs.c (FileOpenAddress): Don't cast to PTDI_ADDRESS_IP. Initialize ReceivedSegments. * drivers/net/tcpip/tcpip/routines.c (DisplayIPHeader): New function. (DisplayIPPacket): Call DisplayIPHeader(). (DisplayTCPHeader): Change format strings. * drivers/net/tcpip/transport/tcp/tcp.c (IPIdentification, TCPSegmentList): Add. (TCPCreateSegment, TCPFreeSegment, TCPAddSegment, TCPBuildAndTransmitSendRequest2, TCPiSelectISS, TCPiReceiveListen, TCPiReceiveSynSent, TCPiReceiveSynReceived, TCPiReceiveData): New function. (TCPiBuildPacket): Build segment. (TCPStartup): Initialize TCPSegmentList. (TCPShutdown): Cleanup TCPSegmentList. svn path=/trunk/; revision=8537
2004-03-04 20:45:39 +00:00
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);
2003-12-25 Casper S. Hornstrup <chorns@users.sourceforge.net> * apps/utils/net/roshttpd/error.cpp (ReportErrorStr): Cast to wchar_t*, not __wchar_t*. * apps/utils/net/roshttpd/makefile (TARGET_CPPFLAGS): Add -Wno-deprecated. (TARGET_GCCLIBS): Add stdc++. * apps/utils/net/roshttpd/common/socket.cpp: Include <string.h>. * apps/utils/net/roshttpd/common/thread.cpp (CThread::CThread): Fix warning. * drivers/net/afd/afd/afd.c (ListenRequestLookasideList): New variable. (DriverEntry): Initialize ListenRequestLookasideList. * drivers/net/afd/afd/dispatch.c (AfdDispCompleteListen): New function. (AfdDispListen): Partial implement. * drivers/net/afd/afd/opnclose.c (AfdInitializeFCB): Initialize NewFCB->ListenRequestQueue. (AfdKillListenRequests): New function. (AfdClose): Call AfdKillListenRequests. * drivers/net/afd/afd/routines.c (DumpName): New function. * drivers/net/afd/afd/tdi.c (TdiAddressSizeFromType): New function. (TdiBuildConnectionInfo): Initialize ConnInfo->OptionsLength. (TdiBuildNullConnectionInfo): New function. (TdiOpenAddressFileIPv4, TdiOpenConnectionEndpointFile): EaName is 0-terminated. (TdiListen): New function. * drivers/net/afd/include/afd.h (AFDFCB): Add ListenRequestQueue. (AFD_LISTEN_REQUEST): New structure. (ListenRequestLookasideList): Declare. (DumpName, TdiListen): Add prototypes. * drivers/net/tcpip/datalink/lan.c (BindAdapter): Initialize AnsiAddress.Length and AnsiAddress.MaximumLength. * drivers/net/tcpip/include/debug.h: Define DEBUG_TCP. * drivers/net/tcpip/include/routines.h (DisplayTCPPacket): Add prototype. (DISPLAY_TCP_PACKET): Define. * drivers/net/tcpip/include/tcp.h (TCPListen): Add prototype. * drivers/net/tcpip/include/titypes.h (ADDRESS_FILE): Add Connection. * drivers/net/tcpip/network/ip.c (IPLocateNTEOnInterface): Cleanup. * drivers/net/tcpip/tcpip/address.c (AddrSearchNext): Port is in network byte order. * drivers/net/tcpip/tcpip/dispatch.c (DispTdiAssociateAddress): Initialize AddrFile->Connection. (DispTdiListen): Implement. * drivers/net/tcpip/tcpip/fileobjs.c (FileOpenAddress): Don't initialize AddrFile->Connections. * drivers/net/tcpip/tcpip/routines.c: Include <tcp.h>. (DisplayIPPacket): Enable. (DisplayTCPHeader, DisplayTCPPacket): New functions. * drivers/net/tcpip/transport/tcp/tcp.c: Include <routines.h>. (TCPListen, TCPiReceive): New functions. (TCPReceive): Partial implement. * lib/msafd/misc/helpers.c (CreateHelperDLLDatabase): Add {SOCK_STREAM,IPPROTO_TCP,0} and {SOCK_DGRAM,IPPROTO_UDP,0} mappings. * lib/ntdll/ldr/utils.c (LdrLoadDll): Print name of DLL if not found. * lib/ws2_32/include/ws2_32.h (Initialized): Declare. (WINSOCK_THREAD_BLOCK): Remove Initialized member. * (WSAINITIALIZED, WSASETINITIALIZED): Update. * lib/ws2_32/misc/catalog.c (CreateCatalog): Add {SOCK_STREAM,IPPROTO_TCP,0} and {SOCK_DGRAM,IPPROTO_UDP,0} mappings. (Initialized): New variable. (DllMain): Don't initialize p->Initialized. * ntoskrnl/dbg/kdb.c: Include <ctype.h>. * subsys/win32k/ntuser/message.c (NtUserDispatchMessage): Kill noisy message. svn path=/trunk/; revision=7232
2003-12-25 14:06:15 +00:00
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);