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.

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