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.

293 lines
6.8 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: protocol.c
  5. //
  6. // History:
  7. // V Raman June-25-1997 Created.
  8. //
  9. // Routines that manipulate protocol entries
  10. //============================================================================
  11. #include "pchmgm.h"
  12. #pragma hdrstop
  13. //----------------------------------------------------------------------------
  14. // CreateProtocolEntry
  15. //
  16. // This function creates, initializes and inserts a new protocol entry in the
  17. // the list of protocols registered with MGM.
  18. //
  19. // Assumes that the protocol list is already locked.
  20. //----------------------------------------------------------------------------
  21. DWORD
  22. CreateProtocolEntry(
  23. PLIST_ENTRY pleProtocolList,
  24. DWORD dwProtocolId,
  25. DWORD dwComponentId,
  26. PROUTING_PROTOCOL_CONFIG prpcConfig,
  27. PPROTOCOL_ENTRY * pppeEntry
  28. )
  29. {
  30. DWORD dwErr = NO_ERROR;
  31. PPROTOCOL_ENTRY ppe = NULL;
  32. do
  33. {
  34. //
  35. // Allocate new protocol entry.
  36. //
  37. ppe = MGM_ALLOC( sizeof( PROTOCOL_ENTRY ) );
  38. if ( ppe == NULL )
  39. {
  40. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  41. TRACE1(
  42. ANY,
  43. "CreateProtocolEntry : Could not allocate protocol entry %x",
  44. dwErr
  45. );
  46. LOGERR0( HEAP_ALLOC_FAILED, dwErr );
  47. break;
  48. }
  49. //
  50. // Initialize protocol entry
  51. //
  52. InitializeListHead( &ppe-> leProtocolList );
  53. ppe-> dwProtocolId = dwProtocolId;
  54. ppe-> dwComponentId = dwComponentId;
  55. ppe-> dwIfCount = 0;
  56. CopyMemory(
  57. &ppe-> rpcProtocolConfig, prpcConfig,
  58. sizeof( ROUTING_PROTOCOL_CONFIG )
  59. );
  60. ppe-> dwSignature = MGM_PROTOCOL_SIGNATURE;
  61. //
  62. // Insert into protocol list
  63. //
  64. InsertTailList( pleProtocolList, &ppe-> leProtocolList );
  65. *pppeEntry = ppe;
  66. dwErr = NO_ERROR;
  67. } while ( FALSE );
  68. return dwErr;
  69. }
  70. //----------------------------------------------------------------------------
  71. // GetProtocolEntry
  72. //
  73. // This function retrieves an entry from the list of protocols registered
  74. // with MGM.
  75. //
  76. // Assumes that the protocol list is already locked.
  77. //----------------------------------------------------------------------------
  78. PPROTOCOL_ENTRY
  79. GetProtocolEntry(
  80. PLIST_ENTRY pleProtocolList,
  81. DWORD dwProtocolId,
  82. DWORD dwComponentId
  83. )
  84. {
  85. BOOL bFound = FALSE;
  86. PLIST_ENTRY ple = NULL;
  87. PPROTOCOL_ENTRY ppe = NULL;
  88. //
  89. // Scan protocol list and find entry
  90. //
  91. for ( ple = pleProtocolList-> Flink;
  92. ple != pleProtocolList;
  93. ple = ple-> Flink )
  94. {
  95. ppe = CONTAINING_RECORD( ple, PROTOCOL_ENTRY, leProtocolList );
  96. if ( ppe-> dwProtocolId == dwProtocolId &&
  97. ppe-> dwComponentId == dwComponentId )
  98. {
  99. bFound = TRUE;
  100. break;
  101. }
  102. }
  103. return bFound ? ppe : NULL;
  104. }
  105. //----------------------------------------------------------------------------
  106. // DeleteProtocolEntry
  107. //
  108. // This function deletes a protocol entry from the list of registered
  109. // protocols. All the interface owned by this protocol should have been
  110. // released before this funtion is called.
  111. //
  112. // Assumes that the protocol list is already locked.
  113. //----------------------------------------------------------------------------
  114. VOID
  115. DeleteProtocolEntry(
  116. PPROTOCOL_ENTRY ppeEntry
  117. )
  118. {
  119. //
  120. // remove protocol entry from list
  121. //
  122. RemoveEntryList( &ppeEntry-> leProtocolList );
  123. MGM_FREE( ppeEntry );
  124. }
  125. //----------------------------------------------------------------------------
  126. // DeleteProtocolList
  127. //
  128. // This function deletes a protocol entry from the list of registered
  129. // protocols. All the interface owned by this protocol should have been
  130. // released before this funtion is called.
  131. //
  132. // Assumes that the protocol list is already locked.
  133. //----------------------------------------------------------------------------
  134. VOID
  135. DeleteProtocolList(
  136. PLIST_ENTRY pleProtocolList
  137. )
  138. {
  139. PLIST_ENTRY ple = NULL;
  140. PPROTOCOL_ENTRY ppe = NULL;
  141. while ( !IsListEmpty( pleProtocolList ) )
  142. {
  143. ple = pleProtocolList-> Flink;
  144. ppe = CONTAINING_RECORD( ple, PROTOCOL_ENTRY, leProtocolList );
  145. DeleteProtocolEntry( ppe );
  146. }
  147. }
  148. //----------------------------------------------------------------------------
  149. // VerifyProtocolHandle
  150. //
  151. // This function verifies that the specified pointer points to a valid
  152. // protocol entry
  153. //
  154. // Assumes that the protocol list is already locked.
  155. //----------------------------------------------------------------------------
  156. DWORD
  157. VerifyProtocolHandle(
  158. PPROTOCOL_ENTRY ppeEntry
  159. )
  160. {
  161. DWORD dwErr = NO_ERROR;
  162. try
  163. {
  164. if ( ppeEntry-> dwSignature != MGM_PROTOCOL_SIGNATURE )
  165. {
  166. dwErr = ERROR_INVALID_PARAMETER;
  167. TRACE0( ANY, "Invalid protocol handle" );
  168. LOGERR0( INVALID_PROTOCOL_HANDLE, dwErr );
  169. }
  170. }
  171. except ( GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
  172. EXCEPTION_EXECUTE_HANDLER :
  173. EXCEPTION_CONTINUE_SEARCH )
  174. {
  175. dwErr = ERROR_INVALID_PARAMETER;
  176. TRACE0( ANY, "Invalid protocol handle" );
  177. LOGERR0( INVALID_PROTOCOL_HANDLE, dwErr );
  178. }
  179. return dwErr;
  180. }
  181. //----------------------------------------------------------------------------
  182. // FindIgmpProtocolEntry
  183. //
  184. // Find the protocol entry for IGMP
  185. //----------------------------------------------------------------------------
  186. PPROTOCOL_ENTRY
  187. GetIgmpProtocolEntry(
  188. PLIST_ENTRY pleProtocolList
  189. )
  190. {
  191. BOOL bFound = FALSE;
  192. PLIST_ENTRY ple = NULL;
  193. PPROTOCOL_ENTRY ppe = NULL;
  194. //
  195. // Scan protocol list and find entry
  196. //
  197. for ( ple = pleProtocolList-> Flink;
  198. ple != pleProtocolList;
  199. ple = ple-> Flink )
  200. {
  201. ppe = CONTAINING_RECORD( ple, PROTOCOL_ENTRY, leProtocolList );
  202. if ( IS_PROTOCOL_IGMP( ppe ) )
  203. {
  204. bFound = TRUE;
  205. break;
  206. }
  207. }
  208. return bFound ? ppe : NULL;
  209. }