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.

407 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. rtmmgmt.c
  5. Abstract:
  6. Routines used to perform various management
  7. functions on the Routing Table Manager v2.
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 17-Aug-1998
  10. Revision History:
  11. --*/
  12. #include "pchrtm.h"
  13. #pragma hdrstop
  14. #include "rtmmgmt.h"
  15. DWORD
  16. WINAPI
  17. RtmGetInstances (
  18. IN OUT PUINT NumInstances,
  19. OUT PRTM_INSTANCE_INFO InstanceInfos
  20. )
  21. /*++
  22. Routine Description:
  23. Enumerates all active RTM instances with their infos.
  24. Arguments:
  25. NumInstances - Num of Instance Info slots in the input
  26. buffer is passed in, and the total number
  27. of active RTM instances is returned.
  28. RtmInstances - Instance Infos that are active in RTMv2.
  29. Return Value:
  30. Status of the operation
  31. --*/
  32. {
  33. PINSTANCE_INFO Instance;
  34. PLIST_ENTRY Instances, p;
  35. UINT i, j;
  36. DWORD Status;
  37. CHECK_FOR_RTM_API_INITIALIZED();
  38. TraceEnter("RtmGetInstances");
  39. ACQUIRE_INSTANCES_READ_LOCK();
  40. //
  41. // Get next instance in table and copy info to output
  42. //
  43. for (i = j = 0; (i < INSTANCE_TABLE_SIZE) && (j < *NumInstances); i++)
  44. {
  45. Instances = &RtmGlobals.InstanceTable[i];
  46. for (p = Instances->Flink; p != Instances; p = p->Flink)
  47. {
  48. Instance = CONTAINING_RECORD(p, INSTANCE_INFO, InstTableLE);
  49. // Copy all relevant Instance information to output
  50. InstanceInfos[j].RtmInstanceId = Instance->RtmInstanceId;
  51. InstanceInfos[j].NumAddressFamilies = Instance->NumAddrFamilies;
  52. if (++j == *NumInstances)
  53. {
  54. break;
  55. }
  56. }
  57. }
  58. Status = (*NumInstances >= RtmGlobals.NumInstances)
  59. ? NO_ERROR
  60. : ERROR_INSUFFICIENT_BUFFER;
  61. *NumInstances = RtmGlobals.NumInstances;
  62. RELEASE_INSTANCES_READ_LOCK();
  63. TraceLeave("RtmGetInstances");
  64. return Status;
  65. }
  66. VOID
  67. CopyAddrFamilyInfo(
  68. IN USHORT RtmInstanceId,
  69. IN PADDRFAM_INFO AddrFamilyBlock,
  70. OUT PRTM_ADDRESS_FAMILY_INFO AddrFamilyInfo
  71. )
  72. /*++
  73. Routine Description:
  74. Copies all public information from an address family
  75. to the output buffer.
  76. Arguments:
  77. RtmInstanceId - Instance for this addr family info
  78. AddrFamilyBlock - Actual address family info block
  79. AddrFamilyInfo - Address family info is copied here
  80. Return Value:
  81. None
  82. Locks :
  83. The global instances lock is held to get a consistent
  84. view of the address family info in the instance.
  85. --*/
  86. {
  87. TraceEnter("CopyAddrFamilyInfo");
  88. AddrFamilyInfo->RtmInstanceId = RtmInstanceId;
  89. AddrFamilyInfo->AddressFamily = AddrFamilyBlock->AddressFamily;
  90. AddrFamilyInfo->ViewsSupported = AddrFamilyBlock->ViewsSupported;
  91. AddrFamilyInfo->MaxHandlesInEnum = AddrFamilyBlock->MaxHandlesInEnum;
  92. AddrFamilyInfo->MaxNextHopsInRoute = AddrFamilyBlock->MaxNextHopsInRoute;
  93. AddrFamilyInfo->MaxOpaquePtrs = AddrFamilyBlock->MaxOpaquePtrs;
  94. AddrFamilyInfo->NumOpaquePtrs = AddrFamilyBlock->NumOpaquePtrs;
  95. AddrFamilyInfo->NumEntities = AddrFamilyBlock->NumEntities;
  96. AddrFamilyInfo->NumDests = AddrFamilyBlock->NumDests;
  97. AddrFamilyInfo->NumRoutes = AddrFamilyBlock->NumRoutes;
  98. AddrFamilyInfo->MaxChangeNotifs = AddrFamilyBlock->MaxChangeNotifs;
  99. AddrFamilyInfo->NumChangeNotifs = AddrFamilyBlock->NumChangeNotifs;
  100. TraceLeave("CopyAddrFamilyInfo");
  101. return;
  102. }
  103. DWORD
  104. WINAPI
  105. RtmGetInstanceInfo (
  106. IN USHORT RtmInstanceId,
  107. OUT PRTM_INSTANCE_INFO InstanceInfo,
  108. IN OUT PUINT NumAddrFamilies,
  109. OUT PRTM_ADDRESS_FAMILY_INFO AddrFamilyInfos OPTIONAL
  110. )
  111. /*++
  112. Routine Description:
  113. Get config and run time information of an RTM instance.
  114. Arguments:
  115. RtmInstanceId - ID identifying the RTM instance,
  116. InstanceInfo - Buffer to return supported address families,
  117. NumAddrFamilies - Number of input address family info slots,
  118. Actual number of address families is retd.
  119. AddrFamilyInfos - Address family infos are copied here.
  120. Return Value:
  121. Status of the operation
  122. --*/
  123. {
  124. PINSTANCE_INFO Instance;
  125. PADDRFAM_INFO AddrFamilyBlock;
  126. PLIST_ENTRY AddrFamilies, q;
  127. UINT i;
  128. DWORD Status;
  129. CHECK_FOR_RTM_API_INITIALIZED();
  130. TraceEnter("RtmGetInstanceInfo");
  131. ACQUIRE_INSTANCES_READ_LOCK();
  132. do
  133. {
  134. //
  135. // Search for the instance with input instance id
  136. //
  137. Status = GetInstance(RtmInstanceId, FALSE, &Instance);
  138. if (Status != NO_ERROR)
  139. {
  140. break;
  141. }
  142. //
  143. // Copy RTM instance information to output
  144. //
  145. InstanceInfo->RtmInstanceId = RtmInstanceId;
  146. InstanceInfo->NumAddressFamilies = Instance->NumAddrFamilies;
  147. //
  148. // Copy address family infomation if reqd
  149. //
  150. if (ARGUMENT_PRESENT(AddrFamilyInfos))
  151. {
  152. if (*NumAddrFamilies < Instance->NumAddrFamilies)
  153. {
  154. Status = ERROR_INSUFFICIENT_BUFFER;
  155. }
  156. //
  157. // Copy info for as many addr families as possible
  158. //
  159. AddrFamilies = &Instance->AddrFamilyTable;
  160. for (q = AddrFamilies->Flink, i = 0;
  161. (q != AddrFamilies) && (i < *NumAddrFamilies);
  162. q = q->Flink)
  163. {
  164. AddrFamilyBlock =CONTAINING_RECORD(q, ADDRFAM_INFO, AFTableLE);
  165. CopyAddrFamilyInfo(RtmInstanceId,
  166. AddrFamilyBlock,
  167. &AddrFamilyInfos[i++]);
  168. }
  169. }
  170. *NumAddrFamilies = Instance->NumAddrFamilies;
  171. }
  172. while (FALSE);
  173. RELEASE_INSTANCES_READ_LOCK();
  174. TraceLeave("RtmGetInstanceInfo");
  175. return Status;
  176. }
  177. DWORD
  178. WINAPI
  179. RtmGetAddressFamilyInfo (
  180. IN USHORT RtmInstanceId,
  181. IN USHORT AddressFamily,
  182. OUT PRTM_ADDRESS_FAMILY_INFO AddrFamilyInfo,
  183. IN OUT PUINT NumEntities,
  184. OUT PRTM_ENTITY_INFO EntityInfos OPTIONAL
  185. )
  186. /*++
  187. Routine Description:
  188. Get config and run time information of an address family
  189. in an RTM instance.
  190. Arguments:
  191. RtmInstanceId - ID identifying the RTM instance
  192. AddressFamily - Address family that we are interested in
  193. AddrFamilyInfo - Buffer to return output information in
  194. NumEntities - Number of slots in the EntityIds buffer and
  195. filled with num of regd entities on return.
  196. EntityInfos - IDs of all registered entities is retd here.
  197. Return Value:
  198. Status of the operation
  199. --*/
  200. {
  201. PINSTANCE_INFO Instance;
  202. PADDRFAM_INFO AddrFamilyBlock;
  203. PENTITY_INFO Entity;
  204. PLIST_ENTRY Entities, r;
  205. UINT i, j;
  206. DWORD Status;
  207. CHECK_FOR_RTM_API_INITIALIZED();
  208. TraceEnter("RtmGetAddressFamilyInfo");
  209. ACQUIRE_INSTANCES_READ_LOCK();
  210. do
  211. {
  212. //
  213. // Search for an instance with the input RtmInstanceId
  214. //
  215. Status = GetInstance(RtmInstanceId, FALSE, &Instance);
  216. if (Status != NO_ERROR)
  217. {
  218. break;
  219. }
  220. //
  221. // Search for an address family info with input family
  222. //
  223. Status = GetAddressFamily(Instance,
  224. AddressFamily,
  225. FALSE,
  226. &AddrFamilyBlock);
  227. if (Status != NO_ERROR)
  228. {
  229. break;
  230. }
  231. //
  232. // Copy relevant address family information
  233. //
  234. CopyAddrFamilyInfo(RtmInstanceId, AddrFamilyBlock, AddrFamilyInfo);
  235. //
  236. // Is caller interested in entity info too ?
  237. //
  238. if (ARGUMENT_PRESENT(EntityInfos))
  239. {
  240. if (*NumEntities < AddrFamilyBlock->NumEntities)
  241. {
  242. Status = ERROR_INSUFFICIENT_BUFFER;
  243. }
  244. //
  245. // Copy all relevant entity information to output
  246. //
  247. for (i = j = 0; (i < ENTITY_TABLE_SIZE) && (j < *NumEntities); i++)
  248. {
  249. Entities = &AddrFamilyBlock->EntityTable[i];
  250. for (r = Entities->Flink; r != Entities; r = r->Flink)
  251. {
  252. Entity = CONTAINING_RECORD(r, ENTITY_INFO, EntityTableLE);
  253. EntityInfos[j].RtmInstanceId = RtmInstanceId;
  254. EntityInfos[j].AddressFamily = AddressFamily;
  255. EntityInfos[j].EntityId = Entity->EntityId;
  256. if (++j == *NumEntities)
  257. {
  258. break;
  259. }
  260. }
  261. }
  262. }
  263. *NumEntities = AddrFamilyBlock->NumEntities;
  264. }
  265. while (FALSE);
  266. RELEASE_INSTANCES_READ_LOCK();
  267. TraceLeave("RtmGetAddressFamilyInfo");
  268. return Status;
  269. }