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.

380 lines
12 KiB

  1. /*++
  2. Copyright (c) 1997-1998 Microsoft Corporation
  3. Module Name:
  4. rtmregn.h
  5. Abstract:
  6. Private defns relating to the registration
  7. and de-registration of entities with RTMv2
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 17-Aug-1998
  10. Revision History:
  11. --*/
  12. #ifndef __ROUTING_RTMREGN_H__
  13. #define __ROUTING_RTMREGN_H__
  14. //
  15. // Forward declarations for various Info Blocks
  16. //
  17. typedef struct _ADDRFAM_INFO ADDRFAM_INFO;
  18. //
  19. // Info related to an RTM instance
  20. //
  21. typedef struct _INSTANCE_INFO
  22. {
  23. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  24. USHORT RtmInstanceId; // Unique ID for this RTM instance
  25. LIST_ENTRY InstTableLE; // Linkage on global table of instances
  26. UINT NumAddrFamilies; // Address Family Specific Info Blocks
  27. LIST_ENTRY AddrFamilyTable; // on this instance (like IPv4 n IPv6)
  28. }
  29. INSTANCE_INFO, *PINSTANCE_INFO;
  30. //
  31. // Info related to an address family in an RTM instance
  32. //
  33. #define ENTITY_TABLE_SIZE 16
  34. typedef struct _ADDRFAM_INFO
  35. {
  36. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  37. USHORT AddressFamily; // Address Family for this info block
  38. UINT AddressSize; // Address size in this address family
  39. PINSTANCE_INFO Instance; // Back pointer to the owning instance
  40. LIST_ENTRY AFTableLE; // Linkage on table of AFs on instance
  41. RTM_VIEW_SET ViewsSupported; // Views supported by this addr family
  42. UINT NumberOfViews; // Num. of views supported by this AF
  43. RTM_VIEW_ID ViewIdFromIndex[RTM_MAX_VIEWS];
  44. // View Id -> Its Index in Dest mapping
  45. RTM_VIEW_ID ViewIndexFromId[RTM_MAX_VIEWS];
  46. // View Index in Dest -> Its Id mapping
  47. UINT MaxHandlesInEnum; // Max. number of handles returned in
  48. // any RTMv2 call that returns handles
  49. UINT MaxNextHopsInRoute;// Max. number of equal cost next-hops
  50. UINT MaxOpaquePtrs; //
  51. UINT NumOpaquePtrs; // Directory of opaque info ptr offsets
  52. PVOID *OpaquePtrsDir; //
  53. UINT NumEntities; // Table of all the registered entities
  54. LIST_ENTRY EntityTable[ENTITY_TABLE_SIZE];
  55. LIST_ENTRY DeregdEntities; // Table of all de-registered entities
  56. READ_WRITE_LOCK RouteTableLock; // Protects the route table of routes
  57. BOOL RoutesLockInited; // Was the above lock initialized ?
  58. PVOID RouteTable; // Table of dests and routes on this AF
  59. LONG NumDests; // Number of dests in the route table
  60. LONG NumRoutes; // Number of routes in the route table
  61. // [Use interlocked ops as no locking]
  62. HANDLE RouteTimerQueue; // List of route timers being used
  63. HANDLE NotifTimerQueue; // List of notification timers used
  64. READ_WRITE_LOCK ChangeNotifsLock; // Protects change notification info
  65. BOOL NotifsLockInited; // Was the above lock initialized ?
  66. UINT MaxChangeNotifs; //
  67. UINT NumChangeNotifs; // Directory of change notifications
  68. PVOID *ChangeNotifsDir; //
  69. DWORD ChangeNotifRegns; // Mask of regd change notifications
  70. DWORD CNsForMarkedDests;// Mask of CNs requesing changes on
  71. // only destinations marked by them
  72. DWORD CNsForView[RTM_MAX_VIEWS];
  73. // CNs interested in a certain view
  74. DWORD CNsForChangeType[RTM_NUM_CHANGE_TYPES];
  75. // CNs interested in a change type
  76. CRITICAL_SECTION NotifsTimerLock; // Lock the protects ops on CN timer
  77. BOOL TimerLockInited; // Was the above lock initialized ?
  78. HANDLE ChangeNotifTimer; // Timer used to process changes list
  79. LONG NumChangedDests; // Num of destinations on change list
  80. // [Use interlocked ops as no locking]
  81. struct
  82. {
  83. LONG ChangesListInUse; // Is this change list in use ?
  84. CRITICAL_SECTION ChangesListLock; // Protects list of changed dests
  85. BOOL ChangesLockInited; // Was above lock initialized ?
  86. SINGLE_LIST_ENTRY ChangedDestsHead; // Head of list of changed dests
  87. PSINGLE_LIST_ENTRY ChangedDestsTail; // Pointer to tail of above list
  88. }
  89. ChangeLists[NUM_CHANGED_DEST_LISTS]; // Multiple chng lists for concurrency
  90. }
  91. ADDRFAM_INFO, *PADDRFAM_INFO;
  92. //
  93. // Entity Registration Info Block
  94. //
  95. typedef struct _ENTITY_INFO
  96. {
  97. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  98. RTM_ENTITY_ID EntityId; // Entity Proto ID and Instance
  99. // that make a unique Entity Id
  100. PADDRFAM_INFO OwningAddrFamily; // Back pointer to the owning AF
  101. LIST_ENTRY EntityTableLE; // Linkage on AF's table of entities
  102. HANDLE BlockingEvent; // Event used to block ops on entity
  103. ULONG State; // See ENTITY_STATE_* values below
  104. INT OpaquePtrOffset; // Offset of reserved opaque ptr or -1
  105. READ_WRITE_LOCK RouteListsLock; // Protects all route lists of entity
  106. BOOL ListsLockInited; // Was the above lock initialized ?
  107. CRITICAL_SECTION OpenHandlesLock; // Protects list of enums and notifs
  108. BOOL HandlesLockInited;// Was the above lock initialized ?
  109. LIST_ENTRY OpenHandles; // List of all enums & change notifs
  110. READ_WRITE_LOCK NextHopTableLock; // Protects the next hop table.
  111. BOOL NextHopsLockInited;// Was the above lock initialized ?
  112. PVOID NextHopTable; // Table of next-hops that all
  113. // routes of this entity share
  114. ULONG NumNextHops; // Number of next-hops in this table
  115. READ_WRITE_LOCK EntityMethodsLock;// Used to block all methods
  116. // on owned dests and routes
  117. BOOL MethodsLockInited;// Was above lock initialized ?
  118. RTM_EVENT_CALLBACK EventCallback; // Entity Register/De-register
  119. // event inform callback
  120. RTM_ENTITY_EXPORT_METHODS
  121. EntityMethods; // Method set exported to get
  122. // entity specific information
  123. }
  124. ENTITY_INFO, *PENTITY_INFO;
  125. #define ENTITY_STATE_REGISTERED 0x00000000
  126. #define ENTITY_STATE_DEREGISTERED 0x00000001
  127. //
  128. // Common Header for all open blocks
  129. // ( pointed to by active handles )
  130. //
  131. typedef struct _OPEN_HEADER
  132. {
  133. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  134. UCHAR HandleType; // Type of handle for this open block
  135. #if DBG_HDL
  136. LIST_ENTRY HandlesLE; // On list of handles opened by entity
  137. #endif
  138. }
  139. OPEN_HEADER, *POPEN_HEADER;
  140. //
  141. // Macros for acquiring various locks defined in this file
  142. //
  143. #define ACQUIRE_ROUTE_TABLE_READ_LOCK(AF) \
  144. ACQUIRE_READ_LOCK(&AF->RouteTableLock)
  145. #define RELEASE_ROUTE_TABLE_READ_LOCK(AF) \
  146. RELEASE_READ_LOCK(&AF->RouteTableLock)
  147. #define ACQUIRE_ROUTE_TABLE_WRITE_LOCK(AF) \
  148. ACQUIRE_WRITE_LOCK(&AF->RouteTableLock)
  149. #define RELEASE_ROUTE_TABLE_WRITE_LOCK(AF) \
  150. RELEASE_WRITE_LOCK(&AF->RouteTableLock)
  151. #define ACQUIRE_NOTIFICATIONS_READ_LOCK(AF) \
  152. ACQUIRE_READ_LOCK(&AF->ChangeNotifsLock);
  153. #define RELEASE_NOTIFICATIONS_READ_LOCK(AF) \
  154. RELEASE_READ_LOCK(&AF->ChangeNotifsLock);
  155. #define ACQUIRE_NOTIFICATIONS_WRITE_LOCK(AF) \
  156. ACQUIRE_WRITE_LOCK(&AF->ChangeNotifsLock);
  157. #define RELEASE_NOTIFICATIONS_WRITE_LOCK(AF) \
  158. RELEASE_WRITE_LOCK(&AF->ChangeNotifsLock);
  159. #define ACQUIRE_NOTIF_TIMER_LOCK(AF) \
  160. ACQUIRE_LOCK(&AF->NotifsTimerLock)
  161. #define RELEASE_NOTIF_TIMER_LOCK(AF) \
  162. RELEASE_LOCK(&AF->NotifsTimerLock)
  163. #define ACQUIRE_CHANGED_DESTS_LIST_LOCK(AF, ListN) \
  164. ACQUIRE_LOCK(&AF->ChangeLists[ListN].ChangesListLock)
  165. #define RELEASE_CHANGED_DESTS_LIST_LOCK(AF, ListN) \
  166. RELEASE_LOCK(&AF->ChangeLists[ListN].ChangesListLock)
  167. #define ACQUIRE_ROUTE_LISTS_READ_LOCK(Entity) \
  168. ACQUIRE_READ_LOCK(&Entity->RouteListsLock)
  169. #define RELEASE_ROUTE_LISTS_READ_LOCK(Entity) \
  170. RELEASE_READ_LOCK(&Entity->RouteListsLock)
  171. #define ACQUIRE_ROUTE_LISTS_WRITE_LOCK(Entity) \
  172. ACQUIRE_WRITE_LOCK(&Entity->RouteListsLock)
  173. #define RELEASE_ROUTE_LISTS_WRITE_LOCK(Entity) \
  174. RELEASE_WRITE_LOCK(&Entity->RouteListsLock)
  175. #define ACQUIRE_OPEN_HANDLES_LOCK(Entity) \
  176. ACQUIRE_LOCK(&Entity->OpenHandlesLock)
  177. #define RELEASE_OPEN_HANDLES_LOCK(Entity) \
  178. RELEASE_LOCK(&Entity->OpenHandlesLock)
  179. #define ACQUIRE_NHOP_TABLE_READ_LOCK(Entity) \
  180. ACQUIRE_READ_LOCK(&Entity->NextHopTableLock)
  181. #define RELEASE_NHOP_TABLE_READ_LOCK(Entity) \
  182. RELEASE_READ_LOCK(&Entity->NextHopTableLock)
  183. #define ACQUIRE_NHOP_TABLE_WRITE_LOCK(Entity) \
  184. ACQUIRE_WRITE_LOCK(&Entity->NextHopTableLock)
  185. #define RELEASE_NHOP_TABLE_WRITE_LOCK(Entity) \
  186. RELEASE_WRITE_LOCK(&Entity->NextHopTableLock)
  187. #define ACQUIRE_ENTITY_METHODS_READ_LOCK(Entity) \
  188. ACQUIRE_READ_LOCK(&Entity->NextHopTableLock)
  189. #define RELEASE_ENTITY_METHODS_READ_LOCK(Entity) \
  190. RELEASE_READ_LOCK(&Entity->NextHopTableLock)
  191. #define ACQUIRE_ENTITY_METHODS_WRITE_LOCK(Entity) \
  192. ACQUIRE_WRITE_LOCK(&Entity->NextHopTableLock)
  193. #define RELEASE_ENTITY_METHODS_WRITE_LOCK(Entity) \
  194. RELEASE_WRITE_LOCK(&Entity->NextHopTableLock)
  195. //
  196. // Registration Helper Functions
  197. //
  198. DWORD
  199. CreateInstance (
  200. IN USHORT InstanceId,
  201. OUT PINSTANCE_INFO *NewInstance
  202. );
  203. DWORD
  204. GetInstance (
  205. IN USHORT RtmInstanceId,
  206. IN BOOL ImplicitCreate,
  207. OUT PINSTANCE_INFO *RtmInstance
  208. );
  209. DWORD
  210. DestroyInstance (
  211. IN PINSTANCE_INFO Instance
  212. );
  213. DWORD
  214. CreateAddressFamily (
  215. IN PINSTANCE_INFO Instance,
  216. IN USHORT AddressFamily,
  217. OUT PADDRFAM_INFO *NewAddrFamilyInfo
  218. );
  219. DWORD
  220. GetAddressFamily (
  221. IN PINSTANCE_INFO Instance,
  222. IN USHORT AddressFamily,
  223. IN BOOL ImplicitCreate,
  224. OUT PADDRFAM_INFO *AddrFamilyInfo
  225. );
  226. DWORD
  227. DestroyAddressFamily (
  228. IN PADDRFAM_INFO AddrFamilyInfo
  229. );
  230. DWORD
  231. CreateEntity (
  232. IN PADDRFAM_INFO AddressFamily,
  233. IN PRTM_ENTITY_INFO EntityInfo,
  234. IN BOOL ReserveOpaquePtr,
  235. IN PRTM_ENTITY_EXPORT_METHODS ExportMethods,
  236. IN RTM_EVENT_CALLBACK EventCallback,
  237. OUT PENTITY_INFO *NewEntity
  238. );
  239. DWORD
  240. GetEntity (
  241. IN PADDRFAM_INFO AddrFamilyInfo,
  242. IN ULONGLONG EntityId,
  243. IN BOOL ImplicitCreate,
  244. IN PRTM_ENTITY_INFO RtmEntityInfo OPTIONAL,
  245. IN BOOL ReserveOpaquePtr OPTIONAL,
  246. IN PRTM_ENTITY_EXPORT_METHODS ExportMethods OPTIONAL,
  247. IN RTM_EVENT_CALLBACK EventCallback OPTIONAL,
  248. OUT PENTITY_INFO *EntityInfo
  249. );
  250. DWORD
  251. DestroyEntity (
  252. IN PENTITY_INFO Entity
  253. );
  254. VOID
  255. InformEntitiesOfEvent (
  256. IN PLIST_ENTRY EntityTable,
  257. IN RTM_EVENT_TYPE EventType,
  258. IN PENTITY_INFO EntityThis
  259. );
  260. VOID
  261. CleanupAfterDeregister (
  262. IN PENTITY_INFO Entity
  263. );
  264. #endif //__ROUTING_RTMREGN_H__