Leaked source code of windows server 2003
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.

165 lines
6.5 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. //
  34. // Structure used for tracking abortive-disconnect requests.
  35. //
  36. typedef struct TCPAbortReq {
  37. RequestCompleteRoutine tar_rtn; // Completion routine.
  38. void* tar_context; // User context.
  39. } TCPAbortReq;
  40. #define MAX_CONN_PER_BLOCK 256
  41. //
  42. // Structure of a block of TCP connections.
  43. //
  44. typedef struct TCPConnBlock {
  45. KSPIN_LOCK cb_lock;
  46. uint cb_freecons;
  47. uint cb_nextfree;
  48. uint cb_blockid;
  49. uint cb_conninst;
  50. void *cb_conn[MAX_CONN_PER_BLOCK];
  51. } TCPConnBlock;
  52. //
  53. // Prototype for TCPConn (see below) done handlers.
  54. //
  55. typedef void (*ConnDoneRtn)(struct TCPConn *, KIRQL);
  56. //
  57. // Structure of a TCP Connection.
  58. // A TCP Connection points to a TCB and an address object.
  59. //
  60. typedef struct TCPConn {
  61. #if DBG
  62. ulong tc_sig;
  63. #endif
  64. Queue tc_q; // Linkage on AO.
  65. struct TCB *tc_tcb; // Pointer to TCB for connection.
  66. struct AddrObj *tc_ao; // Back pointer to AddrObj.
  67. uchar tc_inst; // Instance number.
  68. uchar tc_flags; // Flags for connection.
  69. ushort tc_refcnt; // Count of TCBs which reference this conn.
  70. void *tc_context; // User's context.
  71. RequestCompleteRoutine tc_rtn; // Completion routine.
  72. PVOID tc_rtncontext; // User context for completion routine.
  73. ConnDoneRtn tc_donertn; // Routine to call when refcnt goes to 0.
  74. uint tc_tcbflags; // Flags for TCB when it comes in.
  75. ulong tc_owningpid; // Owning process id
  76. uint tc_tcbkatime; // Initial keep alive time value for this conn.
  77. uint tc_tcbkainterval; // Keep alive interval for this conn.
  78. uint tc_window; // Default window for TCB.
  79. TCPConnBlock *tc_ConnBlock; // Containing block for this conn.
  80. uint tc_connid; // Cached dentifier for this conn.
  81. } TCPConn;
  82. #define tc_signature 0x20204354 // 'TC '
  83. #define CONN_CLOSING 1 // Connection is closing.
  84. #define CONN_DISACC 2 // Connection is disassociating.
  85. #define CONN_WINSET 4 // Window explictly set.
  86. #define CONN_INVALID (CONN_CLOSING | CONN_DISACC)
  87. #define CONN_INDEX(c) ((c) & 0xff)
  88. #define CONN_BLOCKID(c) (((c) & 0xffff00) >> 8)
  89. #define CONN_INST(c) ((uchar)((c) >> 24))
  90. #define MAKE_CONN_ID(index,block,instance) ((((uint)(instance)) << 24) | \
  91. (((uint)(block)) << 8) | \
  92. ((uint)(index)))
  93. #define INVALID_CONN_ID (ULONG)-1
  94. extern TCPConnBlock **ConnTable;
  95. typedef struct TCPAddrCheck {
  96. IPv6Addr SourceAddress;
  97. uint TickCount;
  98. } TCPAddrCheckElement;
  99. //
  100. // External definitions for TDI entry points.
  101. //
  102. extern TDI_STATUS TdiOpenConnection(PTDI_REQUEST Request, PVOID Context);
  103. extern TDI_STATUS TdiCloseConnection(PTDI_REQUEST Request);
  104. extern TDI_STATUS TdiAssociateAddress(PTDI_REQUEST Request, HANDLE AddrHandle);
  105. extern TDI_STATUS TdiDisAssociateAddress(PTDI_REQUEST Request);
  106. extern TDI_STATUS TdiConnect(PTDI_REQUEST Request, void *Timeout,
  107. PTDI_CONNECTION_INFORMATION RequestAddr,
  108. PTDI_CONNECTION_INFORMATION ReturnAddr);
  109. extern TDI_STATUS TdiListen(PTDI_REQUEST Request, ushort Flags,
  110. PTDI_CONNECTION_INFORMATION AcceptableAddr,
  111. PTDI_CONNECTION_INFORMATION ConnectedAddr);
  112. extern TDI_STATUS TdiAccept(PTDI_REQUEST Request,
  113. PTDI_CONNECTION_INFORMATION AcceptInfo,
  114. PTDI_CONNECTION_INFORMATION ConnectedInfo);
  115. extern TDI_STATUS TdiDisconnect(PTDI_REQUEST Request, void *TO, ushort Flags,
  116. PTDI_CONNECTION_INFORMATION DiscConnInfo,
  117. PTDI_CONNECTION_INFORMATION ReturnInfo,
  118. TCPAbortReq *AbortReq);
  119. extern struct TCPConnReq *GetConnReq(void);
  120. extern void FreeConnReq(struct TCPConnReq *FreedReq);
  121. extern void DerefTCB(struct TCB *DoneTCB, KIRQL Irql);
  122. extern void InitRCE(struct TCB *NewTCB);
  123. extern void AcceptConn(struct TCB *AcceptTCB, KIRQL Irql);
  124. extern void FreeConnID(TCPConn *Conn);
  125. extern void NotifyOfDisc(struct TCB *DiscTCB, TDI_STATUS Status,
  126. PKIRQL IrqlPtr);
  127. extern TCPConn *GetConnFromConnID(uint ConnID, KIRQL* Irql);
  128. extern void TryToCloseTCB(struct TCB *ClosedTCB, uchar Reason, KIRQL Irql);
  129. extern TDI_STATUS InitTCBFromConn(struct TCPConn *Conn, struct TCB *NewTCB,
  130. PTDI_CONNECTION_INFORMATION Addr,
  131. uint AOLocked);
  132. extern void PushData(struct TCB *PushTCB);
  133. extern TDI_STATUS MapIPError(IP_STATUS IPError, TDI_STATUS Default);
  134. extern void GracefulClose(struct TCB *CloseTCB, uint ToTimeWait, uint Notify,
  135. KIRQL Irql);
  136. extern void RemoveTCBFromConn(struct TCB *RemovedTCB);
  137. extern void InitAddrChecks();
  138. extern int ConnCheckPassed(IPv6Addr *Src, ulong Prt);
  139. extern void EnumerateConnectionList(uchar *Buffer, ulong BufferSize,
  140. ulong *EntriesReturned, ulong *EntriesAvailable);
  141. extern void GetRandomISN(SeqNum *Seq, uchar *TcbInvariants);