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.

154 lines
4.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 debug code.
  14. //
  15. // This file contains the code for various TCP specific debug routines.
  16. //
  17. #include "oscfg.h"
  18. #include "ndis.h"
  19. #include "ip6imp.h"
  20. #include "ip6def.h"
  21. #include "tdi.h"
  22. #include "queue.h"
  23. #include "transprt.h"
  24. #include "tcp.h"
  25. #include "tcpsend.h"
  26. #if DBG
  27. ULONG TCPDebug = 0;
  28. //* CheckPacketList - Check a list of packets for the correct size.
  29. //
  30. // A routine to walk a chain of packets, making sure the size
  31. // is what we think it is.
  32. //
  33. void // Returns: Nothing.
  34. CheckPacketList(
  35. IPv6Packet *Chain, // List of packets to check.
  36. uint Size) // Total size all packets should sum to.
  37. {
  38. uint SoFar = 0;
  39. while (Chain != NULL) {
  40. SoFar += Chain->TotalSize;
  41. Chain = Chain->Next;
  42. }
  43. ASSERT(Size == SoFar);
  44. }
  45. //* CheckTCBRcv - Check receives on a TCB.
  46. //
  47. // Check the receive state of a TCB.
  48. //
  49. void // Returns: Nothing.
  50. CheckTCBRcv(
  51. TCB *CheckTCB) // TCB to check.
  52. {
  53. CHECK_STRUCT(CheckTCB, tcb);
  54. ASSERT(!(CheckTCB->tcb_flags & FLOW_CNTLD) ||
  55. (CheckTCB->tcb_sendwin == 0));
  56. if ((CheckTCB->tcb_fastchk & ~TCP_FLAG_IN_RCV) == TCP_FLAG_ACK) {
  57. ASSERT(CheckTCB->tcb_slowcount == 0);
  58. ASSERT(CheckTCB->tcb_state == TCB_ESTAB);
  59. ASSERT(CheckTCB->tcb_raq == NULL);
  60. ASSERT(!(CheckTCB->tcb_flags & TCP_SLOW_FLAGS));
  61. ASSERT(!CLOSING(CheckTCB));
  62. } else {
  63. ASSERT(CheckTCB->tcb_slowcount != 0);
  64. ASSERT((CheckTCB->tcb_state != TCB_ESTAB) ||
  65. (CheckTCB->tcb_raq != NULL) ||
  66. (CheckTCB->tcb_flags & TCP_SLOW_FLAGS) || CLOSING(CheckTCB));
  67. }
  68. }
  69. //* CheckTCBSends - Check the send status of a TCB.
  70. //
  71. // A routine to check the send status of a TCB. We make sure that all
  72. // of the SendReqs make sense, as well as making sure that the send seq.
  73. // variables in the TCB are consistent.
  74. //
  75. void // Returns: Nothing.
  76. CheckTCBSends(
  77. TCB *CheckTCB) // TCB to check.
  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. TCPSendReq *TCBTsr; // Current send on TCB.
  84. uint FoundSendReq;
  85. CHECK_STRUCT(CheckTCB, tcb);
  86. // Don't check on unsynchronized TCBs.
  87. if (!SYNC_STATE(CheckTCB->tcb_state))
  88. return;
  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_unacked == 0) {
  94. ASSERT(CheckTCB->tcb_cursend == NULL);
  95. ASSERT(CheckTCB->tcb_sendsize == 0);
  96. }
  97. if (CheckTCB->tcb_sendbuf != NULL)
  98. ASSERT(CheckTCB->tcb_sendofs <
  99. NdisBufferLength(CheckTCB->tcb_sendbuf));
  100. TCBTsr = CheckTCB->tcb_cursend;
  101. FoundSendReq = (TCBTsr == NULL) ? TRUE : FALSE;
  102. End = QEND(&CheckTCB->tcb_sendq);
  103. Current = QHEAD(&CheckTCB->tcb_sendq);
  104. Unacked = 0;
  105. while (Current != End) {
  106. CurrentTSR = CONTAINING_RECORD(QSTRUCT(TCPReq, Current, tr_q),
  107. TCPSendReq, tsr_req);
  108. CHECK_STRUCT(CurrentTSR, tsr);
  109. if (CurrentTSR == TCBTsr)
  110. FoundSendReq = TRUE;
  111. ASSERT(CurrentTSR->tsr_unasize <= CurrentTSR->tsr_size);
  112. CurrentBuffer = CurrentTSR->tsr_buffer;
  113. ASSERT(CurrentBuffer != NULL);
  114. ASSERT(CurrentTSR->tsr_offset < NdisBufferLength(CurrentBuffer));
  115. Unacked += CurrentTSR->tsr_unasize;
  116. Current = QNEXT(Current);
  117. }
  118. ASSERT(FoundSendReq);
  119. ASSERT(Unacked == CheckTCB->tcb_unacked);
  120. Unacked += ((CheckTCB->tcb_flags & FIN_SENT) ? 1 : 0);
  121. ASSERT((CheckTCB->tcb_sendmax - CheckTCB->tcb_senduna) <=
  122. (int) Unacked);
  123. }
  124. #endif