Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
6.1 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // TCP connection related definitions.
  14. //
  15. // This file contains the definitions for connection related structures,
  16. // such as the TCPConnReq structure.
  17. //
  18. #define INVALID_CONN_INDEX 0xffffff
  19. //
  20. // Structure used for tracking Connect/Listen/Accept/Disconnect requests.
  21. //
  22. typedef struct TCPConnReq {
  23. struct TCPReq tcr_req; // General request structure.
  24. #if DBG
  25. ulong tcr_sig;
  26. #endif
  27. struct _TDI_CONNECTION_INFORMATION *tcr_conninfo; // Where to return info.
  28. struct _TDI_CONNECTION_INFORMATION *tcr_addrinfo; // Where to return info.
  29. ushort tcr_flags; // Request flags.
  30. ushort tcr_timeout; // Timeout value.
  31. } TCPConnReq;
  32. #define tcr_signature 0x20524354 // 'TCR '
  33. #define MAX_CONN_PER_BLOCK 256
  34. //
  35. // Structure of a block of TCP connections.
  36. //
  37. typedef struct TCPConnBlock {
  38. KSPIN_LOCK cb_lock;
  39. uint cb_freecons;
  40. uint cb_nextfree;
  41. uint cb_blockid;
  42. uint cb_conninst;
  43. void *cb_conn[MAX_CONN_PER_BLOCK];
  44. } TCPConnBlock;
  45. //
  46. // Prototype for TCPConn (see below) done handlers.
  47. //
  48. typedef void (*ConnDoneRtn)(struct TCPConn *, KIRQL);
  49. //
  50. // Structure of a TCP Connection.
  51. // A TCP Connection points to a TCB and an address object.
  52. //
  53. typedef struct TCPConn {
  54. #if DBG
  55. ulong tc_sig;
  56. #endif
  57. Queue tc_q; // Linkage on AO.
  58. struct TCB *tc_tcb; // Pointer to TCB for connection.
  59. struct AddrObj *tc_ao; // Back pointer to AddrObj.
  60. uchar tc_inst; // Instance number.
  61. uchar tc_flags; // Flags for connection.
  62. ushort tc_refcnt; // Count of TCBs which reference this conn.
  63. void *tc_context; // User's context.
  64. RequestCompleteRoutine tc_rtn; // Completion routine.
  65. PVOID tc_rtncontext; // User context for completion routine.
  66. ConnDoneRtn tc_donertn; // Routine to call when refcnt goes to 0.
  67. uint tc_tcbflags; // Flags for TCB when it comes in.
  68. ulong tc_owningpid; // Owning process id
  69. uint tc_tcbkatime; // Initial keep alive time value for this conn.
  70. uint tc_tcbkainterval; // Keep alive interval for this conn.
  71. uint tc_window; // Default window for TCB.
  72. TCPConnBlock *tc_ConnBlock; // Containing block for this conn.
  73. uint tc_connid; // Cached dentifier for this conn.
  74. } TCPConn;
  75. #define tc_signature 0x20204354 // 'TC '
  76. #define CONN_CLOSING 1 // Connection is closing.
  77. #define CONN_DISACC 2 // Connection is disassociating.
  78. #define CONN_WINSET 4 // Window explictly set.
  79. #define CONN_INVALID (CONN_CLOSING | CONN_DISACC)
  80. #define CONN_INDEX(c) ((c) & 0xff)
  81. #define CONN_BLOCKID(c) (((c) & 0xffff00) >> 8)
  82. #define CONN_INST(c) ((uchar)((c) >> 24))
  83. #define MAKE_CONN_ID(index,block,instance) ((((uint)(instance)) << 24) | \
  84. (((uint)(block)) << 8) | \
  85. ((uint)(index)))
  86. #define INVALID_CONN_ID (ULONG)-1
  87. extern TCPConnBlock **ConnTable;
  88. typedef struct TCPAddrCheck {
  89. IPv6Addr SourceAddress;
  90. uint TickCount;
  91. } TCPAddrCheckElement;
  92. extern TCPAddrCheckElement *AddrCheckTable;
  93. //
  94. // External definitions for TDI entry points.
  95. //
  96. extern TDI_STATUS TdiOpenConnection(PTDI_REQUEST Request, PVOID Context);
  97. extern TDI_STATUS TdiCloseConnection(PTDI_REQUEST Request);
  98. extern TDI_STATUS TdiAssociateAddress(PTDI_REQUEST Request, HANDLE AddrHandle);
  99. extern TDI_STATUS TdiDisAssociateAddress(PTDI_REQUEST Request);
  100. extern TDI_STATUS TdiConnect(PTDI_REQUEST Request, void *Timeout,
  101. PTDI_CONNECTION_INFORMATION RequestAddr,
  102. PTDI_CONNECTION_INFORMATION ReturnAddr);
  103. extern TDI_STATUS TdiListen(PTDI_REQUEST Request, ushort Flags,
  104. PTDI_CONNECTION_INFORMATION AcceptableAddr,
  105. PTDI_CONNECTION_INFORMATION ConnectedAddr);
  106. extern TDI_STATUS TdiAccept(PTDI_REQUEST Request,
  107. PTDI_CONNECTION_INFORMATION AcceptInfo,
  108. PTDI_CONNECTION_INFORMATION ConnectedInfo);
  109. extern TDI_STATUS TdiDisconnect(PTDI_REQUEST Request, void *TO, ushort Flags,
  110. PTDI_CONNECTION_INFORMATION DiscConnInfo,
  111. PTDI_CONNECTION_INFORMATION ReturnInfo);
  112. extern struct TCPConnReq *GetConnReq(void);
  113. extern void FreeConnReq(struct TCPConnReq *FreedReq);
  114. extern void DerefTCB(struct TCB *DoneTCB, KIRQL Irql);
  115. extern void InitRCE(struct TCB *NewTCB);
  116. extern void AcceptConn(struct TCB *AcceptTCB, KIRQL Irql);
  117. extern void FreeConnID(TCPConn *Conn);
  118. extern void NotifyOfDisc(struct TCB *DiscTCB, TDI_STATUS Status);
  119. extern TCPConn *GetConnFromConnID(uint ConnID, KIRQL* Irql);
  120. extern void TryToCloseTCB(struct TCB *ClosedTCB, uchar Reason, KIRQL Irql);
  121. extern TDI_STATUS InitTCBFromConn(struct TCPConn *Conn, struct TCB *NewTCB,
  122. PTDI_CONNECTION_INFORMATION Addr,
  123. uint AOLocked);
  124. extern void PushData(struct TCB *PushTCB);
  125. extern TDI_STATUS MapIPError(IP_STATUS IPError, TDI_STATUS Default);
  126. extern void GracefulClose(struct TCB *CloseTCB, uint ToTimeWait, uint Notify,
  127. KIRQL Irql);
  128. extern void RemoveTCBFromConn(struct TCB *RemovedTCB);
  129. extern void InitAddrChecks();
  130. extern int ConnCheckPassed(IPv6Addr *Src, ulong Prt);
  131. extern void EnumerateConnectionList(uchar *Buffer, ulong BufferSize,
  132. ulong *EntriesReturned, ulong *EntriesAvailable);
  133. extern void GetRandomISN(SeqNum *Seq, uchar *TcbInvariants);