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.

207 lines
10 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // EXTERNAL (SHARED) DEFINITIONS //
  3. // //
  4. // ( Any user mode app which wants to use this functionality should copy this section of the header file) //
  5. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. // WildCard definitions for Ip Address, Port and Protocol //
  7. #define UL_ANY 0xffffffff
  8. #define US_ANY 0xffff
  9. // Definitions for Direction (Send/Recv) //
  10. #define DIR_SEND 1
  11. #define DIR_RECV 2
  12. // Common InBuf structure: This is same for either type of request //
  13. // For wildcarding, use UL_ANY for ULONGs and US_ANY for USHORTs //
  14. // //
  15. // This will be layed out in the buffer in this fashion: //
  16. // +---------------------------------------------+ //
  17. // 0x00 | SrcIp (4) | SrcPort(2) Padding(2) | //
  18. // +---------------------------------------------+ //
  19. // 0x08 | DstIp (4) | DstPort(2) Padding(2) | //
  20. // +---------------------------------------------+ //
  21. // 0x10 | Proto(2)| Dir'n(2) | //
  22. // +---------+----------+ //
  23. typedef struct _TIMESTMP_REQ
  24. {
  25. ULONG SrcIp;
  26. USHORT SrcPort;
  27. ULONG DstIp;
  28. USHORT DstPort;
  29. USHORT Proto;
  30. USHORT Direction;
  31. } TIMESTMP_REQ, *PTIMESTMP_REQ;
  32. // 1. MARK_IN_BUF_RECORD: THIS WILL MARK THE TIMESTAMPS IN A BUFFER WITH IP-ID'S AND PACKET-SIZES //
  33. // //
  34. // This will be laid out in the buffer in this fashion: //
  35. // +---------------------------------------------+ //
  36. // 0x00 |IpId(2) Size(2) | Padding(4) | //
  37. // +---------------------------------------------+ //
  38. // 0x08 | TimeValue (8) | //
  39. // +---------------------------------------------+ //
  40. #define IOCTL_TIMESTMP_REGISTER_IN_BUF CTL_CODE( FILE_DEVICE_NETWORK, 23, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  41. #define IOCTL_TIMESTMP_DEREGISTER_IN_BUF CTL_CODE( FILE_DEVICE_NETWORK, 24, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  42. #define IOCTL_TIMESTMP_FINISH_BUFFERING CTL_CODE( FILE_DEVICE_NETWORK, 25, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  43. typedef struct _MARK_IN_BUF_RECORD
  44. {
  45. USHORT IpId;
  46. USHORT Size;
  47. UINT64 TimeValue;
  48. } MARK_IN_BUF_RECORD, *PMARK_IN_BUF_RECORD;
  49. // This is the MINIMUM size of the buffer that should be passed in with every request to copy //
  50. // timestamps colleced in the drivers internal buffer. Application should call this frequently //
  51. // to prevent driver buffer re-use //
  52. #define PACKET_STORE_SIZE (sizeof(MARK_IN_BUF_RECORD)*5000)
  53. // 2. MARK_IN_PKT_RECORD: THIS WILL MARK THE TIMESTAMPS IN THE PACKET ITSELF //
  54. // //
  55. // This will be laid out in the packet in this fashion: //
  56. // +---------------------------------------------+ //
  57. // 0x00 | Time Sent - App (8) | //
  58. // +---------------------------------------------+ //
  59. // 0x08 | Time Rcvd - App (8) | //
  60. // +---------------------------------------------+ //
  61. // 0x10 | Time Sent - OS (8) | //
  62. // +---------------------------------------------+ //
  63. // 0x18 | Time Rcvd - OS (8) | //
  64. // +---------------------------------------------+ //
  65. // 0x20 | Latency - App (8) | //
  66. // +---------------------------------------------+ //
  67. // 0x28 | BufferSize - App(4) | Seq No - App (4) | //
  68. // +---------------------------------------------+ //
  69. // //
  70. #define IOCTL_TIMESTMP_REGISTER_IN_PKT CTL_CODE( FILE_DEVICE_NETWORK, 21, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  71. #define IOCTL_TIMESTMP_DEREGISTER_IN_PKT CTL_CODE( FILE_DEVICE_NETWORK, 22, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  72. typedef struct _MARK_IN_PKT_RECORD
  73. {
  74. UINT64 TimeSent;
  75. UINT64 TimeReceived;
  76. UINT64 TimeSentWire;
  77. UINT64 TimeReceivedWire;
  78. UINT64 Latency;
  79. INT BufferSize;
  80. INT SequenceNumber;
  81. } MARK_IN_PKT_RECORD, *PMARK_IN_PKT_RECORD;
  82. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83. // INTERNAL TIMESTMP DEFINITIONS //
  84. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. #define IOCTL_PSCHED_ZAW_EVENT CTL_CODE( FILE_DEVICE_NETWORK, 20, METHOD_BUFFERED, FILE_ANY_ACCESS)
  86. #define MARK_NONE 0
  87. #define MARK_IN_PKT 1
  88. #define MARK_IN_BUF 2
  89. typedef struct _TS_ENTRY {
  90. LIST_ENTRY Linkage;
  91. ULONG SrcIp;
  92. USHORT SrcPort;
  93. ULONG DstIp;
  94. USHORT DstPort;
  95. USHORT Proto;
  96. USHORT Type;
  97. USHORT Direction;
  98. PFILE_OBJECT FileObject;
  99. PMARK_IN_BUF_RECORD pPacketStore;
  100. PMARK_IN_BUF_RECORD pPacketStoreHead;
  101. } TS_ENTRY, *PTS_ENTRY;
  102. extern LIST_ENTRY TsList;
  103. extern NDIS_SPIN_LOCK TsSpinLock;
  104. extern ULONG TsCount;
  105. VOID
  106. InitializeTimeStmp( PPSI_INFO Info );
  107. BOOL
  108. AddRequest( PFILE_OBJECT FileObject,
  109. ULONG SrcIp,
  110. USHORT SrcPort,
  111. ULONG DstIp,
  112. USHORT DstPort,
  113. USHORT Proto,
  114. USHORT Type,
  115. USHORT Direction);
  116. void
  117. RemoveRequest( PFILE_OBJECT FileObject,
  118. ULONG SrcIp,
  119. USHORT SrcPort,
  120. ULONG DstIp,
  121. USHORT DstPort,
  122. USHORT Proto);
  123. int
  124. CopyTimeStmps( PFILE_OBJECT FileObject, PVOID buf, ULONG Len);
  125. VOID
  126. UnloadTimeStmp();
  127. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  128. // COPIED TRANSPORT DEFINITIONS
  129. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. #define IPPROTO_TCP 6
  131. #define IPPROTO_UDP 17
  132. #define IP_MF_FLAG 0x0020
  133. #define IP_VERSION 0x40
  134. #define IP_VER_FLAG 0xF0
  135. #define TCP_OFFSET_MASK 0xf0
  136. #define TCP_HDR_SIZE(t) (uint)(((*(uchar *)&(t)->tcp_flags) & TCP_OFFSET_MASK) >> 2)
  137. #define IP_OFFSET_MASK ~0x00E0
  138. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  139. #define net_short(_x) _byteswap_ushort((USHORT)(_x))
  140. #else
  141. #define net_short(x) ((((x)&0xff) << 8) | (((x)&0xff00) >> 8))
  142. #endif
  143. typedef int SeqNum; // A sequence number.
  144. struct TCPHeader {
  145. ushort tcp_src; // Source port.
  146. ushort tcp_dest; // Destination port.
  147. SeqNum tcp_seq; // Sequence number.
  148. SeqNum tcp_ack; // Ack number.
  149. ushort tcp_flags; // Flags and data offset.
  150. ushort tcp_window; // Window offered.
  151. ushort tcp_xsum; // Checksum.
  152. ushort tcp_urgent; // Urgent pointer.
  153. };
  154. typedef struct TCPHeader TCPHeader;
  155. struct UDPHeader {
  156. ushort uh_src; // Source port.
  157. ushort uh_dest; // Destination port.
  158. ushort uh_length; // Length
  159. ushort uh_xsum; // Checksum.
  160. }; /* UDPHeader */
  161. typedef struct UDPHeader UDPHeader;
  162. //////////////////////////////////////////////////////////////////////////////////////////////////////////////