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.

193 lines
5.6 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-1993 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //** TCPDELIV.H - TCP data delivery definitions.
  7. //
  8. // This file contains the definitions for structures used by the data
  9. // delivery code.
  10. //
  11. extern void FreeRcvReq(struct TCPRcvReq *FreedReq);
  12. extern uint IndicateData(struct TCB *RcvTCB, uint RcvFlags, IPRcvBuf *InBuffer,
  13. uint Size);
  14. extern uint BufferData(struct TCB *RcvTCB, uint RcvFlags, IPRcvBuf *InBuffer,
  15. uint Size);
  16. extern uint PendData(struct TCB *RcvTCB, uint RcvFlags, IPRcvBuf *InBuffer,
  17. uint Size);
  18. extern void IndicatePendingData(struct TCB *RcvTCB, struct TCPRcvReq *RcvReq,
  19. CTELockHandle TCBHandle);
  20. extern void HandleUrgent(struct TCB *RcvTCB, struct TCPRcvInfo *RcvInfo,
  21. IPRcvBuf *RcvBuf, uint *Size);
  22. extern TDI_STATUS TdiReceive(PTDI_REQUEST Request, ushort *Flags,
  23. uint *RcvLength, PNDIS_BUFFER Buffer);
  24. extern IPRcvBuf *FreePartialRB(IPRcvBuf *RB, uint Size);
  25. extern void FreeRBChain(IPRcvBuf * RBChain);
  26. extern void PushData(struct TCB *PushTCB, BOOLEAN PushAll);
  27. extern HANDLE TcprBufferPool;
  28. #if !MILLEN
  29. #define TCP_FIXED_SIZE_IPR_SIZE 1460
  30. #define TCP_UNUSED_PEND_BUF_LIMIT 2920
  31. extern HANDLE TcprBufferPool;
  32. #ifdef DBG
  33. extern ULONG SlistAllocates, NPPAllocates;
  34. #endif
  35. // This data structure embeds the generic IPRcvBuf structure as well as holds
  36. // a pointer to the TCB for which this buffer has been allocated for.
  37. //
  38. typedef struct _TCPRcvBuf{
  39. IPRcvBuf tcpr_ipr;
  40. PVOID tcpr_tcb;
  41. } TCPRcvBuf, *PTCPRcvBuf;
  42. // This macro calculates the unused bytes in a TcpRcvBuf structure.
  43. //
  44. #define IPR_BUF_UNUSED_BYTES(_Tcpr) \
  45. (TCP_FIXED_SIZE_IPR_SIZE - (_Tcpr)->tcpr_ipr.ipr_size - \
  46. ((PCHAR)((_Tcpr)->tcpr_ipr.ipr_buffer) - (PCHAR)(_Tcpr) - sizeof(TCPRcvBuf)))
  47. //* InitTcpIpr - Initializes the IPRcvBuffer.
  48. //
  49. // Input: Tcpr - Pointer to the TCPRcvBuf.
  50. // BufferSize - Number of bytes that are used.
  51. // PendTCB - Pointer to the TCB for which this allocation is being made.
  52. //
  53. // Returns: None.
  54. //
  55. __inline void
  56. InitTcpIpr(TCPRcvBuf *Tcpr, ULONG BufferSize, TCB* PendTCB)
  57. {
  58. Tcpr->tcpr_ipr.ipr_owner = IPR_OWNER_TCP;
  59. Tcpr->tcpr_ipr.ipr_next = NULL;
  60. Tcpr->tcpr_ipr.ipr_buffer = (PUCHAR) Tcpr + sizeof(TCPRcvBuf);
  61. Tcpr->tcpr_ipr.ipr_size = BufferSize;
  62. Tcpr->tcpr_tcb = PendTCB;
  63. }
  64. //* AllocTcpIpr - Allocates the IPRcvBuffer from NPP.
  65. //
  66. // A utility routine to allocate a TCP owned IPRcvBuffer. This routine
  67. // allocates the IPR from NPP and initializes appropriate fields.
  68. //
  69. // Input: BufferSize - Size of data to buffer.
  70. // Tag - Tag to be used if allocation is done from NPP.
  71. //
  72. // Returns: Pointer to allocated IPR.
  73. //
  74. __inline IPRcvBuf *
  75. AllocTcpIpr(ULONG BufferSize, ULONG Tag)
  76. {
  77. TCPRcvBuf *Tcpr;
  78. ULONG AllocateSize;
  79. // Real size that we need.
  80. AllocateSize = BufferSize + sizeof(TCPRcvBuf);
  81. Tcpr = CTEAllocMemLow(AllocateSize, Tag);
  82. if (Tcpr != NULL) {
  83. #ifdef DBG
  84. InterlockedIncrement((PLONG)&NPPAllocates);
  85. #endif
  86. InitTcpIpr(Tcpr, BufferSize, NULL);
  87. }
  88. return &Tcpr->tcpr_ipr;
  89. }
  90. //* AllocTcpIprFromSlist - Allocates the IPRcvBuffer from NPP.
  91. //
  92. // A utility routine to allocate a TCP owned IPRcvBuffer. This routine
  93. // allocates the IPR from an SLIST and initializes appropriate fields.
  94. //
  95. // Input: Tcb - Pointer to the TCB for which this allocation is being made.
  96. // BufferSize - Size of data buffer required.
  97. // Tag - Tag to be used if allocation is done from NPP.
  98. //
  99. // Returns: Pointer to allocated IPR.
  100. //
  101. __inline IPRcvBuf *
  102. AllocTcpIprFromSlist(TCB* PendTCB, ULONG BufferSize, ULONG Tag)
  103. {
  104. TCPRcvBuf* Tcpr;
  105. LOGICAL FromList;
  106. if ((BufferSize <= TCP_FIXED_SIZE_IPR_SIZE) &&
  107. (PendTCB->tcb_unusedpendbuf + TCP_FIXED_SIZE_IPR_SIZE
  108. - BufferSize <= TCP_UNUSED_PEND_BUF_LIMIT)) {
  109. Tcpr = PplAllocate(TcprBufferPool, &FromList);
  110. if (NULL != Tcpr) {
  111. #ifdef DBG
  112. InterlockedIncrement((PLONG)&SlistAllocates);
  113. #endif
  114. // Set up IPR fields appropriately.
  115. InitTcpIpr(Tcpr, BufferSize, PendTCB);
  116. ASSERT(PendTCB->tcb_unusedpendbuf >= 0);
  117. PendTCB->tcb_unusedpendbuf += (short)IPR_BUF_UNUSED_BYTES(Tcpr);
  118. ASSERT(PendTCB->tcb_unusedpendbuf <= TCP_UNUSED_PEND_BUF_LIMIT);
  119. return &Tcpr->tcpr_ipr;
  120. }
  121. }
  122. return AllocTcpIpr(BufferSize, Tag);
  123. }
  124. //* FreeTcpIpr - Frees the IPRcvBuffer..
  125. //
  126. // A utility routine to free a TCP owned IPRcvBuffer.
  127. //
  128. // Input: Ipr - Pointer the IPR.
  129. //
  130. // Returns: None.
  131. //
  132. __inline VOID
  133. FreeTcpIpr(IPRcvBuf *Ipr)
  134. {
  135. TCB *PendTCB;
  136. PTCPRcvBuf Tcpr = (PTCPRcvBuf)Ipr;
  137. if (Tcpr->tcpr_tcb) {
  138. PendTCB = (TCB*)(Tcpr->tcpr_tcb);
  139. ASSERT(PendTCB->tcb_unusedpendbuf <= TCP_UNUSED_PEND_BUF_LIMIT);
  140. PendTCB->tcb_unusedpendbuf -= (short)IPR_BUF_UNUSED_BYTES(Tcpr);
  141. ASSERT(PendTCB->tcb_unusedpendbuf >= 0);
  142. PplFree(TcprBufferPool, Tcpr);
  143. #ifdef DBG
  144. InterlockedDecrement((PLONG)&SlistAllocates);
  145. #endif
  146. } else {
  147. CTEFreeMem(Tcpr);
  148. #ifdef DBG
  149. InterlockedDecrement((PLONG)&NPPAllocates);
  150. #endif
  151. }
  152. }
  153. #else // MILLEN
  154. IPRcvBuf *AllocTcpIpr(ULONG BufferSize, ULONG Tag);
  155. VOID FreeTcpIpr(IPRcvBuf *Ipr);
  156. #endif // MILLEN