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.

206 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\rtmapi.c
  5. Abstract:
  6. The file contains RTMv2 API implementations.
  7. --*/
  8. #include "pchsample.h"
  9. #pragma hdrstop
  10. #ifdef DEBUG
  11. DWORD
  12. RTM_DisplayDestInfo(
  13. IN PRTM_DEST_INFO prdi)
  14. /*++
  15. Routine Description
  16. Displays an RTM_DEST_INFO object.
  17. Locks
  18. None
  19. Arguments
  20. prdi buffer containing the rtm dest info
  21. Return Value
  22. NO_ERROR always
  23. --*/
  24. {
  25. IPADDRESS ip;
  26. if (!prdi)
  27. return NO_ERROR;
  28. RTM_GetAddress(&ip, &(prdi->DestAddress));
  29. TRACE2(NETWORK, "RtmDestInfo Destination %s/%u",
  30. INET_NTOA(ip), (prdi->DestAddress).NumBits);
  31. return NO_ERROR;
  32. }
  33. #else
  34. #define DisplayRtmDestInfo(prdi)
  35. #endif // DEBUG
  36. DWORD
  37. RTM_NextHop (
  38. IN PRTM_DEST_INFO prdiDestination,
  39. OUT PDWORD pdwIfIndex,
  40. OUT PIPADDRESS pipNeighbor)
  41. /*++
  42. Routine Description
  43. Obtain the next hop for a destination (typically a data source or an RP).
  44. Locks
  45. None
  46. Arguments
  47. prdiDestination destination information obtained from rtm
  48. dwIfIndex next hop interface index
  49. pipNeighbor ip address of next hop neighbor
  50. Return Value
  51. NO_ERROR success
  52. Error Code o/w
  53. --*/
  54. {
  55. DWORD dwErr = NO_ERROR;
  56. PRTM_ROUTE_INFO prriRoute;
  57. RTM_NEXTHOP_INFO rniNextHop;
  58. BOOL bRoute, bNextHop;
  59. // flags indicating handles held
  60. bRoute = bNextHop = FALSE;
  61. do // breakout loop
  62. {
  63. // allocate route info structure
  64. MALLOC(&prriRoute,
  65. RTM_SIZE_OF_ROUTE_INFO(g_ce.rrpRtmProfile.MaxNextHopsInRoute),
  66. &dwErr);
  67. if (dwErr != NO_ERROR)
  68. break;
  69. // get route info (best route in mcast view)
  70. dwErr = RtmGetRouteInfo (
  71. g_ce.hRtmHandle,
  72. prdiDestination->ViewInfo[0].Route,
  73. prriRoute,
  74. NULL);
  75. if (dwErr != NO_ERROR)
  76. {
  77. TRACE1(ANY, "Error %u getting route", dwErr);
  78. break;
  79. }
  80. bRoute = TRUE;
  81. // get nexthop info (first next hop for now...)
  82. dwErr = RtmGetNextHopInfo(
  83. g_ce.hRtmHandle,
  84. prriRoute->NextHopsList.NextHops[0],
  85. &rniNextHop);
  86. if (dwErr != NO_ERROR)
  87. {
  88. TRACE1(ANY, "Error %u getting next hop", dwErr);
  89. break;
  90. }
  91. bNextHop = TRUE;
  92. // finally!!! THIS SHOULD NOT BE A REMOTE NEXT HOP!!!
  93. *(pdwIfIndex) = rniNextHop.InterfaceIndex;
  94. RTM_GetAddress(pipNeighbor,
  95. &(rniNextHop.NextHopAddress));
  96. } while (FALSE);
  97. if (dwErr != NO_ERROR)
  98. TRACE1(ANY, "Error %u obtaining next hop", dwErr);
  99. // release the handle to the next hop
  100. if (bNextHop)
  101. {
  102. if (RtmReleaseNextHopInfo(g_ce.hRtmHandle, &rniNextHop) != NO_ERROR)
  103. TRACE0(ANY, "Error releasing next hop, continuing...");
  104. }
  105. // release the handle to the route
  106. if (bRoute)
  107. {
  108. if (RtmReleaseRouteInfo(g_ce.hRtmHandle, prriRoute) != NO_ERROR)
  109. TRACE0(ANY, "Error releasing route, continuing...");
  110. }
  111. // deallocate route info structure
  112. if (prriRoute)
  113. FREE(prriRoute);
  114. return dwErr;
  115. }
  116. ////////////////////////////////////////
  117. // CALLBACKFUNCTIONS
  118. ////////////////////////////////////////
  119. DWORD
  120. APIENTRY
  121. RTM_CallbackEvent (
  122. IN RTM_ENTITY_HANDLE hRtmHandle, // registration handle
  123. IN RTM_EVENT_TYPE retEvent,
  124. IN PVOID pvContext1,
  125. IN PVOID pvContext2)
  126. /*++
  127. Routine Description
  128. Processes an RTMv2 event. Used to inform entities of new entities
  129. registering, entities deregistering, route expiration, route changes.
  130. Locks
  131. None (for now)
  132. Arguments
  133. retEvent rtmv2 event type
  134. Return Value
  135. NO_ERROR success
  136. Error Code o/w
  137. --*/
  138. {
  139. DWORD dwErr = NO_ERROR;
  140. TRACE1(ENTER, "Entering RTM_CallbackEvent: %u", retEvent);
  141. do // breakout loop
  142. {
  143. UNREFERENCED_PARAMETER(hRtmHandle);
  144. UNREFERENCED_PARAMETER(pvContext1);
  145. UNREFERENCED_PARAMETER(pvContext2);
  146. // only route change notifications are processed
  147. if (retEvent != RTM_CHANGE_NOTIFICATION)
  148. {
  149. dwErr = ERROR_NOT_SUPPORTED;
  150. break;
  151. }
  152. dwErr = NM_ProcessRouteChange();
  153. } while (FALSE);
  154. TRACE0(LEAVE, "Leaving RTM_CallbackEvent");
  155. return dwErr;
  156. }