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.

755 lines
16 KiB

  1. /*++
  2. Copyright (c) 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. rtminfo.c
  5. Abstract:
  6. Contains routines for getting information
  7. on various objects pointed to by handles.
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 22-Aug-1998
  10. Revision History:
  11. --*/
  12. #include "pchrtm.h"
  13. #pragma hdrstop
  14. DWORD
  15. WINAPI
  16. RtmGetEntityInfo (
  17. IN RTM_ENTITY_HANDLE RtmRegHandle,
  18. IN RTM_ENTITY_HANDLE EntityHandle,
  19. OUT PRTM_ENTITY_INFO EntityInfo
  20. )
  21. /*++
  22. Routine Description:
  23. Retrieves information pertaining to a registered entity.
  24. Arguments:
  25. RtmRegHandle - RTM registration handle for calling entity,
  26. EntityHandle - RTM handle for entity whose info we want,
  27. EntityInfo - Block in which the entity info is returned.
  28. Return Value:
  29. Status of the operation
  30. --*/
  31. {
  32. PADDRFAM_INFO AddrFamilyInfo;
  33. PENTITY_INFO Entity;
  34. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  35. VALIDATE_ENTITY_HANDLE(EntityHandle, &Entity);
  36. //
  37. // Copy the entity information to output buffer
  38. //
  39. AddrFamilyInfo = Entity->OwningAddrFamily;
  40. EntityInfo->RtmInstanceId = AddrFamilyInfo->Instance->RtmInstanceId;
  41. EntityInfo->AddressFamily = AddrFamilyInfo->AddressFamily;
  42. EntityInfo->EntityId = Entity->EntityId;
  43. return NO_ERROR;
  44. }
  45. DWORD
  46. WINAPI
  47. RtmGetDestInfo (
  48. IN RTM_ENTITY_HANDLE RtmRegHandle,
  49. IN RTM_DEST_HANDLE DestHandle,
  50. IN ULONG ProtocolId,
  51. IN RTM_VIEW_SET TargetViews,
  52. OUT PRTM_DEST_INFO DestInfo
  53. )
  54. /*++
  55. Routine Description:
  56. Retrieves information for a destination in the route table
  57. Arguments:
  58. RtmRegHandle - RTM registration handle for calling entity,
  59. DestHandle - RTM handle for dest whose info we want,
  60. ProtocolId - Protocol whose best route info is retd,
  61. TargetViews - Views in which best route info is retd,
  62. DestInfo - Block in which the dest info is returned.
  63. Return Value:
  64. Status of the operation
  65. --*/
  66. {
  67. PENTITY_INFO Entity;
  68. PDEST_INFO Dest;
  69. VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  70. // VALIDATE_DEST_HANDLE(DestHandle, &Dest);
  71. Dest = DEST_FROM_HANDLE(DestHandle);
  72. if (!Dest)
  73. {
  74. return ERROR_INVALID_HANDLE;
  75. }
  76. ACQUIRE_DEST_READ_LOCK(Dest);
  77. GetDestInfo(Entity,
  78. Dest,
  79. ProtocolId,
  80. TargetViews,
  81. DestInfo);
  82. RELEASE_DEST_READ_LOCK(Dest);
  83. return NO_ERROR;
  84. }
  85. VOID
  86. GetDestInfo (
  87. IN PENTITY_INFO Entity,
  88. IN PDEST_INFO Dest,
  89. IN ULONG ProtocolId,
  90. IN RTM_VIEW_SET TargetViews,
  91. OUT PRTM_DEST_INFO DestInfo
  92. )
  93. /*++
  94. Routine Description:
  95. Retrieves information for a destination in the route table
  96. Arguments:
  97. Entity - RTM registration info for calling entity,
  98. Dest - Pointer to the dest whose info we want,
  99. ProtocolId - Protocol whose best route info is retd,
  100. TargetViews - Views in which best route info is retd,
  101. DestInfo - Block in which the dest info is returned.
  102. Return Value:
  103. None
  104. --*/
  105. {
  106. PENTITY_INFO Owner;
  107. PROUTE_INFO Route;
  108. RTM_VIEW_SET ViewsSeen;
  109. RTM_VIEW_SET ViewSet;
  110. RTM_VIEW_SET BelongsToViews;
  111. PLIST_ENTRY p;
  112. UINT i, j, k;
  113. // Limit caller's interest to set of views supported
  114. TargetViews &= Entity->OwningAddrFamily->ViewsSupported;
  115. //
  116. // Copy dest info to output and ref handles given out
  117. //
  118. DestInfo->DestHandle = MAKE_HANDLE_FROM_POINTER(Dest);
  119. REFERENCE_DEST(Dest, HANDLE_REF);
  120. CopyMemory(&DestInfo->DestAddress,
  121. &Dest->DestAddress,
  122. sizeof(RTM_NET_ADDRESS));
  123. DestInfo->LastChanged = Dest->LastChanged;
  124. DestInfo->BelongsToViews = Dest->BelongsToViews;
  125. //
  126. // Copy the holddown route out in all requested views
  127. //
  128. ViewSet = TargetViews;
  129. for (i = j = 0; ViewSet && (i < RTM_VIEW_MASK_SIZE); i++)
  130. {
  131. if (ViewSet & 0x01)
  132. {
  133. k = Entity->OwningAddrFamily->ViewIndexFromId[i];
  134. Route = Dest->ViewInfo[k].HoldRoute;
  135. //
  136. // Init view info and fill the holddown route
  137. //
  138. ZeroMemory(&DestInfo->ViewInfo[j], sizeof(DestInfo->ViewInfo[0]));
  139. DestInfo->ViewInfo[j].ViewId = i;
  140. if (Route)
  141. {
  142. DestInfo->ViewInfo[j].HoldRoute =
  143. MAKE_HANDLE_FROM_POINTER(Route);
  144. REFERENCE_ROUTE(Route, HANDLE_REF);
  145. }
  146. j++;
  147. }
  148. ViewSet >>= 1;
  149. }
  150. // Keep track of total number of view info slots filled in
  151. DestInfo->NumberOfViews = j;
  152. //
  153. // Fill up information in all the views he is interested in
  154. //
  155. if (TargetViews & Dest->BelongsToViews)
  156. {
  157. // Resolve the protocol id if it is RTM_THIS_PROTOCOL
  158. if (ProtocolId == RTM_THIS_PROTOCOL)
  159. {
  160. ProtocolId = Entity->EntityId.EntityProtocolId;
  161. }
  162. ViewsSeen = 0;
  163. //
  164. // Copy best route in each view & ref handles given out
  165. //
  166. for (p = Dest->RouteList.Flink; p != &Dest->RouteList; p = p->Flink)
  167. {
  168. Route = CONTAINING_RECORD(p, ROUTE_INFO, DestLE);
  169. //
  170. // Make sure that this agrees with our protocol id
  171. //
  172. Owner = ENTITY_FROM_HANDLE(Route->RouteInfo.RouteOwner);
  173. if (ProtocolId != RTM_BEST_PROTOCOL)
  174. {
  175. if (Owner->EntityId.EntityProtocolId != ProtocolId)
  176. {
  177. continue;
  178. }
  179. }
  180. //
  181. // Does this route belong to any interested views
  182. //
  183. if ((TargetViews & Route->RouteInfo.BelongsToViews) == 0)
  184. {
  185. continue;
  186. }
  187. //
  188. // Update dest info in each view that route belongs to
  189. //
  190. BelongsToViews = Route->RouteInfo.BelongsToViews;
  191. ViewSet = TargetViews;
  192. for (i = j = 0; ViewSet && (i < RTM_VIEW_MASK_SIZE); i++)
  193. {
  194. if (ViewSet & 0x01)
  195. {
  196. if (BelongsToViews & 0x01)
  197. {
  198. //
  199. // Increment number of routes in this view
  200. //
  201. DestInfo->ViewInfo[j].NumRoutes++;
  202. //
  203. // If you not already seen this view (in
  204. // other words got the best route in it)
  205. // update the DestInfo for this view now
  206. //
  207. if (!(ViewsSeen & VIEW_MASK(i)))
  208. {
  209. DestInfo->ViewInfo[j].Route =
  210. MAKE_HANDLE_FROM_POINTER(Route);
  211. REFERENCE_ROUTE(Route, HANDLE_REF);
  212. DestInfo->ViewInfo[j].Owner =
  213. MAKE_HANDLE_FROM_POINTER(Owner);
  214. REFERENCE_ENTITY(Owner, HANDLE_REF);
  215. DestInfo->ViewInfo[j].DestFlags =
  216. Route->RouteInfo.Flags;
  217. }
  218. }
  219. j++;
  220. }
  221. ViewSet >>= 1;
  222. BelongsToViews >>= 1;
  223. }
  224. ViewsSeen |= Route->RouteInfo.BelongsToViews;
  225. }
  226. }
  227. return;
  228. }
  229. DWORD
  230. WINAPI
  231. RtmGetRouteInfo (
  232. IN RTM_ENTITY_HANDLE RtmRegHandle,
  233. IN RTM_ROUTE_HANDLE RouteHandle,
  234. OUT PRTM_ROUTE_INFO RouteInfo OPTIONAL,
  235. OUT PRTM_NET_ADDRESS DestAddress OPTIONAL
  236. )
  237. /*++
  238. Routine Description:
  239. Retrieves information for a route in the route table
  240. Arguments:
  241. RtmRegHandle - RTM registration handle for calling entity,
  242. RouteHandle - RTM handle for route whose info we want,
  243. RouteInfo - Block in which the route info is returned.
  244. Return Value:
  245. Status of the operation
  246. --*/
  247. {
  248. PENTITY_INFO Entity;
  249. PROUTE_INFO Route;
  250. PDEST_INFO Dest;
  251. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  252. #if 1
  253. Route = ROUTE_FROM_HANDLE(RouteHandle);
  254. if (!Route)
  255. {
  256. return ERROR_INVALID_HANDLE;
  257. }
  258. #else
  259. VALIDATE_ROUTE_HANDLE(RouteHandle, &Route);
  260. #endif
  261. Dest = DEST_FROM_HANDLE(Route->RouteInfo.DestHandle);
  262. // Get a consitent picture of the route
  263. ACQUIRE_DEST_READ_LOCK(Dest);
  264. if (ARGUMENT_PRESENT(RouteInfo))
  265. {
  266. GetRouteInfo(Dest, Route, RouteInfo);
  267. }
  268. RELEASE_DEST_READ_LOCK(Dest);
  269. // No lock reqd - dest addr is constant
  270. if (ARGUMENT_PRESENT(DestAddress))
  271. {
  272. CopyMemory(DestAddress, &Dest->DestAddress, sizeof(RTM_NET_ADDRESS));
  273. }
  274. return NO_ERROR;
  275. }
  276. VOID
  277. WINAPI
  278. GetRouteInfo (
  279. IN PDEST_INFO Dest,
  280. IN PROUTE_INFO Route,
  281. OUT PRTM_ROUTE_INFO RouteInfo
  282. )
  283. /*++
  284. Routine Description:
  285. Retrieves information for a route in the route table
  286. Arguments:
  287. Dest - Pointer to the destination of the route,
  288. Route - Pointer to the route whose info we want,
  289. RouteInfo - Block in which the route info is returned.
  290. Return Value:
  291. None
  292. --*/
  293. {
  294. PENTITY_INFO Entity;
  295. PNEXTHOP_INFO Neighbour;
  296. PNEXTHOP_INFO NextHop;
  297. UINT NumBytes;
  298. UINT i;
  299. //
  300. // Copy the route information to output buffer
  301. //
  302. NumBytes = sizeof(RTM_ROUTE_INFO) +
  303. sizeof(RTM_NEXTHOP_HANDLE) *
  304. (Route->RouteInfo.NextHopsList.NumNextHops - 1);
  305. CopyMemory(RouteInfo, &Route->RouteInfo, NumBytes);
  306. //
  307. // Reference handles that are given out in info
  308. //
  309. Entity = ENTITY_FROM_HANDLE(RouteInfo->RouteOwner);
  310. REFERENCE_ENTITY(Entity, HANDLE_REF);
  311. if (RouteInfo->Neighbour)
  312. {
  313. Neighbour = NEXTHOP_FROM_HANDLE(RouteInfo->Neighbour);
  314. REFERENCE_NEXTHOP(Neighbour, HANDLE_REF);
  315. }
  316. for (i = 0; i < RouteInfo->NextHopsList.NumNextHops; i++)
  317. {
  318. NextHop = NEXTHOP_FROM_HANDLE(RouteInfo->NextHopsList.NextHops[i]);
  319. REFERENCE_NEXTHOP(NextHop, HANDLE_REF);
  320. }
  321. REFERENCE_DEST(Dest, HANDLE_REF);
  322. return;
  323. }
  324. DWORD
  325. WINAPI
  326. RtmGetNextHopInfo (
  327. IN RTM_ENTITY_HANDLE RtmRegHandle,
  328. IN RTM_NEXTHOP_HANDLE NextHopHandle,
  329. OUT PRTM_NEXTHOP_INFO NextHopInfo
  330. )
  331. /*++
  332. Routine Description:
  333. Retrieves information for a next-hop in the route table
  334. Arguments:
  335. RtmRegHandle - RTM registration handle for calling entity,
  336. NextHopHandle - RTM handle for next-hop whose info we want,
  337. NextHopInfo - Block in which the next-hop info is returned.
  338. Return Value:
  339. Status of the operation
  340. --*/
  341. {
  342. PENTITY_INFO Entity;
  343. PNEXTHOP_INFO NextHop;
  344. PDEST_INFO Dest;
  345. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  346. VALIDATE_NEXTHOP_HANDLE(NextHopHandle, &NextHop);
  347. Entity = ENTITY_FROM_HANDLE(NextHop->NextHopInfo.NextHopOwner);
  348. ACQUIRE_NHOP_TABLE_READ_LOCK(Entity);
  349. //
  350. // Copy the next-hop information to output buffer
  351. //
  352. CopyMemory(NextHopInfo, &NextHop->NextHopInfo, sizeof(RTM_NEXTHOP_INFO));
  353. //
  354. // Reference handles that are given out in info
  355. //
  356. if (NextHop->NextHopInfo.RemoteNextHop)
  357. {
  358. Dest = DEST_FROM_HANDLE(NextHop->NextHopInfo.RemoteNextHop);
  359. REFERENCE_DEST(Dest, HANDLE_REF);
  360. }
  361. REFERENCE_ENTITY(Entity, HANDLE_REF);
  362. RELEASE_NHOP_TABLE_READ_LOCK(Entity);
  363. return NO_ERROR;
  364. }
  365. DWORD
  366. WINAPI
  367. RtmReleaseEntityInfo (
  368. IN RTM_ENTITY_HANDLE RtmRegHandle,
  369. IN PRTM_ENTITY_INFO EntityInfo
  370. )
  371. /*++
  372. Routine Description:
  373. Releases all handles present in the input info structure
  374. Arguments:
  375. RtmRegHandle - RTM registration handle for calling entity,
  376. EntityInfo - All handles in this info are de-referenced.
  377. Return Value:
  378. Status of the operation
  379. --*/
  380. {
  381. UNREFERENCED_PARAMETER(RtmRegHandle);
  382. UNREFERENCED_PARAMETER(EntityInfo);
  383. return NO_ERROR;
  384. }
  385. DWORD
  386. WINAPI
  387. RtmReleaseDestInfo (
  388. IN RTM_ENTITY_HANDLE RtmRegHandle,
  389. IN PRTM_DEST_INFO DestInfo
  390. )
  391. /*++
  392. Routine Description:
  393. Releases all handles present in the input info structure
  394. Arguments:
  395. RtmRegHandle - RTM registration handle for calling entity,
  396. DestInfo - All handles in this info are de-referenced.
  397. Return Value:
  398. Status of the operation
  399. --*/
  400. {
  401. PENTITY_INFO Entity;
  402. PENTITY_INFO Owner;
  403. PDEST_INFO Dest;
  404. PROUTE_INFO Route;
  405. UINT i;
  406. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  407. for (i = 0; i < DestInfo->NumberOfViews; i++)
  408. {
  409. //
  410. // If a best route, dereference it and its owner
  411. //
  412. if (DestInfo->ViewInfo[i].Route)
  413. {
  414. Route = ROUTE_FROM_HANDLE(DestInfo->ViewInfo[i].Route);
  415. DEREFERENCE_ROUTE(Route, HANDLE_REF);
  416. Owner = ENTITY_FROM_HANDLE(DestInfo->ViewInfo[i].Owner);
  417. DEREFERENCE_ENTITY(Owner, HANDLE_REF);
  418. }
  419. //
  420. // If we have a holddown route, dereference it
  421. //
  422. if (DestInfo->ViewInfo[i].HoldRoute)
  423. {
  424. Route = ROUTE_FROM_HANDLE(DestInfo->ViewInfo[i].HoldRoute);
  425. DEREFERENCE_ROUTE(Route, HANDLE_REF);
  426. }
  427. }
  428. Dest = DEST_FROM_HANDLE(DestInfo->DestHandle);
  429. DEREFERENCE_DEST(Dest, HANDLE_REF);
  430. return NO_ERROR;
  431. }
  432. DWORD
  433. WINAPI
  434. RtmReleaseRouteInfo (
  435. IN RTM_ENTITY_HANDLE RtmRegHandle,
  436. IN PRTM_ROUTE_INFO RouteInfo
  437. )
  438. /*++
  439. Routine Description:
  440. Releases all handles present in the input info structure
  441. Arguments:
  442. RtmRegHandle - RTM registration handle for calling entity,
  443. RouteInfo - All handles in this info are de-referenced.
  444. Return Value:
  445. Status of the operation
  446. --*/
  447. {
  448. PENTITY_INFO Entity;
  449. PDEST_INFO Dest;
  450. PNEXTHOP_INFO Neighbour;
  451. PNEXTHOP_INFO NextHop;
  452. UINT i;
  453. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  454. for (i = 0; i < RouteInfo->NextHopsList.NumNextHops; i++)
  455. {
  456. NextHop = NEXTHOP_FROM_HANDLE(RouteInfo->NextHopsList.NextHops[i]);
  457. DEREFERENCE_NEXTHOP(NextHop, HANDLE_REF);
  458. }
  459. if (RouteInfo->Neighbour)
  460. {
  461. Neighbour = NEXTHOP_FROM_HANDLE(RouteInfo->Neighbour);
  462. DEREFERENCE_NEXTHOP(Neighbour, HANDLE_REF);
  463. }
  464. Entity = ENTITY_FROM_HANDLE(RouteInfo->RouteOwner);
  465. DEREFERENCE_ENTITY(Entity, HANDLE_REF);
  466. Dest = DEST_FROM_HANDLE(RouteInfo->DestHandle);
  467. DEREFERENCE_DEST(Dest, HANDLE_REF);
  468. return NO_ERROR;
  469. }
  470. DWORD
  471. WINAPI
  472. RtmReleaseNextHopInfo (
  473. IN RTM_ENTITY_HANDLE RtmRegHandle,
  474. IN PRTM_NEXTHOP_INFO NextHopInfo
  475. )
  476. /*++
  477. Routine Description:
  478. Releases all handles present in the input info structure
  479. Arguments:
  480. RtmRegHandle - RTM registration handle for calling entity,
  481. NextHopInfo - All handles in this info are de-referenced.
  482. Return Value:
  483. Status of the operation
  484. --*/
  485. {
  486. PENTITY_INFO Entity;
  487. PDEST_INFO Dest;
  488. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  489. if (NextHopInfo->RemoteNextHop)
  490. {
  491. Dest = DEST_FROM_HANDLE(NextHopInfo->RemoteNextHop);
  492. if (Dest)
  493. {
  494. DEREFERENCE_DEST(Dest, HANDLE_REF);
  495. }
  496. }
  497. Entity = ENTITY_FROM_HANDLE(NextHopInfo->NextHopOwner);
  498. DEREFERENCE_ENTITY(Entity, HANDLE_REF);
  499. return NO_ERROR;
  500. }