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.

257 lines
5.0 KiB

  1. /*++
  2. Copyright(c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. brdgbuf.h
  5. Abstract:
  6. Ethernet MAC level bridge.
  7. Buffer management section
  8. PUBLIC header
  9. Author:
  10. Mark Aiken
  11. (original bridge by Jameel Hyder)
  12. Environment:
  13. Kernel mode driver
  14. Revision History:
  15. Feb 2000 - Original version
  16. --*/
  17. #include "brdgpkt.h"
  18. // ===========================================================================
  19. //
  20. // DECLARATIONS
  21. //
  22. // ===========================================================================
  23. typedef enum
  24. {
  25. BrdgOwnCopyPacket,
  26. BrdgOwnWrapperPacket,
  27. BrdgNotOwned
  28. } PACKET_OWNERSHIP;
  29. // ===========================================================================
  30. //
  31. // PROTOTYPES
  32. //
  33. // ===========================================================================
  34. NTSTATUS
  35. BrdgBufDriverInit();
  36. VOID
  37. BrdgBufCleanup();
  38. PNDIS_PACKET
  39. BrdgBufGetBaseCopyPacket(
  40. OUT PPACKET_INFO *pppi
  41. );
  42. VOID
  43. BrdgBufFreeWrapperPacket(
  44. IN PNDIS_PACKET pPacket,
  45. IN PPACKET_INFO ppi,
  46. IN PADAPT pQuotaOwner
  47. );
  48. VOID
  49. BrdgBufFreeBaseCopyPacket(
  50. IN PNDIS_PACKET pPacket,
  51. IN PPACKET_INFO ppi
  52. );
  53. VOID
  54. BrdgBufFreeBaseWrapperPacket(
  55. IN PNDIS_PACKET pPacket,
  56. IN PPACKET_INFO ppi
  57. );
  58. BOOLEAN
  59. BrdgBufAssignBasePacketQuota(
  60. IN PNDIS_PACKET pPacket,
  61. IN PADAPT pAdapt
  62. );
  63. VOID
  64. BrdgBufReleaseBasePacketQuota(
  65. IN PNDIS_PACKET pPacket,
  66. IN PADAPT pAdapt
  67. );
  68. PNDIS_PACKET
  69. BrdgBufGetWrapperPacket(
  70. OUT PPACKET_INFO *pppi,
  71. IN PADAPT pAdapt
  72. );
  73. NDIS_STATUS
  74. BrdgBufChainCopyBuffers(
  75. IN PNDIS_PACKET pTargetPacket,
  76. IN PNDIS_PACKET pSourcePacket
  77. );
  78. PACKET_OWNERSHIP
  79. BrdgBufGetPacketOwnership(
  80. IN PNDIS_PACKET pPacket
  81. );
  82. VOID
  83. BrdgBufGetStatistics(
  84. PBRIDGE_BUFFER_STATISTICS pStats
  85. );
  86. // ===========================================================================
  87. //
  88. // INLINES
  89. //
  90. // ===========================================================================
  91. //
  92. // Retrieves the first NDIS_BUFFER chained to a given packet (NULL if none)
  93. //
  94. __forceinline
  95. PNDIS_BUFFER
  96. BrdgBufPacketHeadBuffer(
  97. IN PNDIS_PACKET pPacket
  98. )
  99. {
  100. PNDIS_BUFFER pBuffer;
  101. SAFEASSERT( pPacket != NULL );
  102. NdisQueryPacket( pPacket, NULL, NULL, &pBuffer, NULL );
  103. return pBuffer;
  104. }
  105. //
  106. // Retrieves the total size of all buffers chained to a packet
  107. //
  108. __forceinline
  109. UINT
  110. BrdgBufTotalPacketSize(
  111. IN PNDIS_PACKET pPacket
  112. )
  113. {
  114. UINT size;
  115. SAFEASSERT( pPacket != NULL );
  116. NdisQueryPacket( pPacket, NULL, NULL, NULL, &size );
  117. return size;
  118. }
  119. //
  120. // Retrieves the virtual address of the data in the first buffer chained
  121. // to a packet (holds the Ethernet header)
  122. //
  123. __forceinline
  124. PVOID
  125. BrdgBufGetPacketHeader(
  126. IN PNDIS_PACKET pPacket
  127. )
  128. {
  129. PNDIS_BUFFER pBuffer;
  130. PVOID pHeader;
  131. UINT Length;
  132. SAFEASSERT( pPacket != NULL );
  133. pBuffer = BrdgBufPacketHeadBuffer( pPacket );
  134. SAFEASSERT( pBuffer != NULL );
  135. NdisQueryBufferSafe( pBuffer, &pHeader, &Length, NormalPagePriority );
  136. SAFEASSERT( pHeader != NULL );
  137. return pHeader;
  138. }
  139. //
  140. // Unchains and frees all buffers chained to a given packet
  141. //
  142. __forceinline
  143. VOID
  144. BrdgBufUnchainCopyBuffers(
  145. IN PNDIS_PACKET pPacket
  146. )
  147. {
  148. PNDIS_BUFFER pCurBuf;
  149. NdisUnchainBufferAtFront( pPacket, &pCurBuf );
  150. while( pCurBuf != NULL )
  151. {
  152. NdisFreeBuffer( pCurBuf );
  153. NdisUnchainBufferAtFront( pPacket, &pCurBuf );
  154. }
  155. }
  156. //
  157. // Determines whether this packet was allocated from our copy pool
  158. //
  159. __forceinline
  160. BOOLEAN
  161. BrdgBufIsCopyPacket(
  162. IN PNDIS_PACKET pPacket
  163. )
  164. {
  165. PACKET_OWNERSHIP Own = BrdgBufGetPacketOwnership(pPacket);
  166. return (BOOLEAN)(Own == BrdgOwnCopyPacket);
  167. }
  168. //
  169. // Determines whether this packet was allocated from our wrapper pool
  170. //
  171. __forceinline
  172. BOOLEAN
  173. BrdgBufIsWrapperPacket(
  174. IN PNDIS_PACKET pPacket
  175. )
  176. {
  177. PACKET_OWNERSHIP Own = BrdgBufGetPacketOwnership(pPacket);
  178. return (BOOLEAN)(Own == BrdgOwnWrapperPacket);
  179. }
  180. //
  181. // Initializes an ADAPTER_QUOTA structure
  182. //
  183. __forceinline
  184. VOID
  185. BrdgBufInitializeQuota(
  186. IN PADAPTER_QUOTA pQuota
  187. )
  188. {
  189. pQuota->UsedPackets[0] = pQuota->UsedPackets[1] = 0L;
  190. }
  191. // DO NOT use this variable directly outside of BrdgBuf.c
  192. extern NDIS_HANDLE gWrapperBufferPoolHandle;
  193. //
  194. // Allocates an NDIS_BUFFER from our pool
  195. //
  196. __forceinline
  197. PNDIS_BUFFER
  198. BrdgBufAllocateBuffer(
  199. IN PVOID p,
  200. IN UINT len
  201. )
  202. {
  203. PNDIS_BUFFER pBuf;
  204. NDIS_STATUS Status;
  205. NdisAllocateBuffer( &Status, &pBuf, gWrapperBufferPoolHandle, p, len );
  206. if( Status != NDIS_STATUS_SUCCESS )
  207. {
  208. THROTTLED_DBGPRINT(BUF, ("Failed to allocate a MDL in BrdgBufAllocateBuffer: %08x\n", Status));
  209. return NULL;
  210. }
  211. return pBuf;
  212. }