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.

182 lines
5.4 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-1993 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //** TCPDEB.C - TCP debug code.
  7. //
  8. // This file contains the code for various TCP specific debug routines.
  9. //
  10. #include "precomp.h"
  11. #include "tcp.h"
  12. #include "tcpsend.h"
  13. #include "tlcommon.h"
  14. #if DBG
  15. ULONG TCPDebug = TCP_DEBUG_CANCEL;
  16. //* CheckRBList - Check a list of RBs for the correct size.
  17. //
  18. // A routine to walk a list of RBs, making sure the size is what we think
  19. // it it.
  20. //
  21. // Input: RBList - List of RBs to check.
  22. // Size - Size RBs should be.
  23. //
  24. // Returns: Nothing.
  25. //
  26. void
  27. CheckRBList(IPRcvBuf * RBList, uint Size)
  28. {
  29. uint SoFar = 0;
  30. IPRcvBuf *List = RBList;
  31. while (List != NULL) {
  32. SoFar += List->ipr_size;
  33. List = List->ipr_next;
  34. }
  35. ASSERT(Size == SoFar);
  36. }
  37. //* CheckTCBRcv - Check receives on a TCB.
  38. //
  39. // Check the receive state of a TCB.
  40. //
  41. // Input: CheckTCB - TCB to check.
  42. //
  43. // Returns: Nothing.
  44. //
  45. void
  46. CheckTCBRcv(TCB * CheckTCB)
  47. {
  48. CTEStructAssert(CheckTCB, tcb);
  49. ASSERT(!(CheckTCB->tcb_flags & FLOW_CNTLD) ||
  50. (CheckTCB->tcb_sendwin == 0));
  51. if ((CheckTCB->tcb_fastchk & ~TCP_FLAG_IN_RCV) == TCP_FLAG_ACK) {
  52. ASSERT(CheckTCB->tcb_slowcount == 0);
  53. ASSERT(CheckTCB->tcb_state == TCB_ESTAB);
  54. ASSERT(CheckTCB->tcb_raq == NULL);
  55. //ASSERT(!(CheckTCB->tcb_flags & TCP_SLOW_FLAGS));
  56. ASSERT(!CLOSING(CheckTCB));
  57. } else {
  58. ASSERT(CheckTCB->tcb_slowcount != 0);
  59. ASSERT((CheckTCB->tcb_state != TCB_ESTAB) ||
  60. (CheckTCB->tcb_raq != NULL) ||
  61. (CheckTCB->tcb_flags & TCP_SLOW_FLAGS) ||
  62. (CheckTCB->tcb_fastchk & TCP_FLAG_RST_WHILE_SYN) ||
  63. CLOSING(CheckTCB));
  64. }
  65. }
  66. //* CheckTCBSends - Check the send status of a TCB.
  67. //
  68. // A routine to check the send status of a TCB. We make sure that all
  69. // of the SendReqs make sense, as well as making sure that the send seq.
  70. // variables in the TCB are consistent.
  71. //
  72. // Input: CheckTCB - TCB to check.
  73. //
  74. // Returns: Nothing.
  75. //
  76. void
  77. CheckTCBSends(TCB *CheckTCB)
  78. {
  79. Queue *End, *Current; // End and current elements.
  80. TCPSendReq *CurrentTSR; // Current send req we're examining.
  81. uint Unacked; // Number of unacked bytes.
  82. PNDIS_BUFFER CurrentBuffer;
  83. uint FoundSendReq;
  84. CTEStructAssert(CheckTCB, tcb);
  85. // Don't check on unsynchronized TCBs.
  86. if (!SYNC_STATE(CheckTCB->tcb_state)) {
  87. return;
  88. }
  89. ASSERT(SEQ_LTE(CheckTCB->tcb_senduna, CheckTCB->tcb_sendnext));
  90. ASSERT(SEQ_LTE(CheckTCB->tcb_sendnext, CheckTCB->tcb_sendmax));
  91. ASSERT(!(CheckTCB->tcb_flags & FIN_OUTSTANDING) ||
  92. (CheckTCB->tcb_sendnext == CheckTCB->tcb_sendmax));
  93. if ((CheckTCB->tcb_fastchk & TCP_FLAG_REQUEUE_FROM_SEND_AND_DISC)) {
  94. ASSERT(CheckTCB->tcb_unacked == 0);
  95. return;
  96. }
  97. if (CheckTCB->tcb_unacked == 0){
  98. ASSERT(CheckTCB->tcb_cursend == NULL);
  99. ASSERT(CheckTCB->tcb_sendsize == 0);
  100. }
  101. if (CheckTCB->tcb_sendbuf != NULL) {
  102. ASSERT(CheckTCB->tcb_sendofs < NdisBufferLength(CheckTCB->tcb_sendbuf));
  103. }
  104. FoundSendReq = (CheckTCB->tcb_cursend == NULL) ? TRUE : FALSE;
  105. End = QEND(&CheckTCB->tcb_sendq);
  106. Current = QHEAD(&CheckTCB->tcb_sendq);
  107. Unacked = 0;
  108. while (Current != End) {
  109. CurrentTSR = STRUCT_OF(TCPSendReq, QSTRUCT(TCPReq, Current, tr_q), tsr_req);
  110. CTEStructAssert(CurrentTSR, tsr);
  111. if (CurrentTSR == CheckTCB->tcb_cursend)
  112. FoundSendReq = TRUE;
  113. ASSERT(CurrentTSR->tsr_unasize <= CurrentTSR->tsr_size);
  114. CurrentBuffer = CurrentTSR->tsr_buffer;
  115. ASSERT(CurrentBuffer != NULL);
  116. ASSERT(CurrentTSR->tsr_offset < NdisBufferLength(CurrentBuffer));
  117. // All send requests after the current should have zero offsets.
  118. //
  119. if (CheckTCB->tcb_cursend &&
  120. FoundSendReq && (CurrentTSR != CheckTCB->tcb_cursend)) {
  121. ASSERT(0 == CurrentTSR->tsr_offset);
  122. }
  123. Unacked += CurrentTSR->tsr_unasize;
  124. Current = QNEXT(Current);
  125. }
  126. ASSERT(FoundSendReq);
  127. if (!CheckTCB->tcb_unacked &&
  128. ((CheckTCB->tcb_senduna == CheckTCB->tcb_sendmax) ||
  129. (CheckTCB->tcb_senduna == CheckTCB->tcb_sendmax - 1)) &&
  130. ((CheckTCB->tcb_sendnext == CheckTCB->tcb_sendmax) ||
  131. (CheckTCB->tcb_sendnext == CheckTCB->tcb_sendmax - 1)) &&
  132. (CheckTCB->tcb_fastchk & TCP_FLAG_SEND_AND_DISC)) {
  133. if (!EMPTYQ(&CheckTCB->tcb_sendq)) {
  134. Current = QHEAD(&CheckTCB->tcb_sendq);
  135. CurrentTSR = STRUCT_OF(TCPSendReq, QSTRUCT(TCPReq, Current, tr_q),
  136. tsr_req);
  137. ASSERT(CurrentTSR->tsr_flags & TSR_FLAG_SEND_AND_DISC);
  138. }
  139. }
  140. if (!(CheckTCB->tcb_flags & FIN_SENT) &&
  141. !(CheckTCB->tcb_state == TCB_FIN_WAIT2) &&
  142. !(CheckTCB->tcb_fastchk & TCP_FLAG_REQUEUE_FROM_SEND_AND_DISC)) {
  143. ASSERT(Unacked == CheckTCB->tcb_unacked);
  144. ASSERT((CheckTCB->tcb_sendmax - CheckTCB->tcb_senduna) <= (int)Unacked);
  145. }
  146. }
  147. #endif