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.

267 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. rtmrout.h
  5. Abstract:
  6. Contains definitions for RTM objects like
  7. destinations, routes and next hops.
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 21-Aug-1998
  10. Revision History:
  11. --*/
  12. #ifndef __ROUTING_RTMROUT_H__
  13. #define __ROUTING_RTMROUT_H__
  14. //
  15. // Forward declarations for various Info Blocks
  16. //
  17. typedef struct _DEST_INFO DEST_INFO;
  18. typedef struct _ROUTE_INFO ROUTE_INFO;
  19. typedef struct _NEXTHOP_INFO NEXTHOP_INFO;
  20. //
  21. // Address Family independent dest structure
  22. //
  23. typedef struct _DEST_INFO
  24. {
  25. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  26. SINGLE_LIST_ENTRY ChangeListLE; // Linkage on the list of changed dests
  27. LOOKUP_LINKAGE LookupLinkage; // Linkage into owning lookup structure
  28. PVOID DestLock; // Dynamic lock that protects this dest
  29. DWORD DestMarkedBits; // Bit N set => Nth CN has marked dest
  30. DWORD DestChangedBits; // Bit N set => Nth CN has a change
  31. DWORD DestOnQueueBits; // Bit N set => Dest on Nth CN's queue
  32. UINT NumRoutes; // Number of routes to destination
  33. LIST_ENTRY RouteList; // A list of routes to destination
  34. PVOID *OpaqueInfoPtrs; // Array of Opaque Info Pointers
  35. RTM_NET_ADDRESS DestAddress; // Network Address unique to this dest
  36. FILETIME LastChanged; // Last time destination was modified
  37. USHORT State; // State of the destination
  38. USHORT HoldRefCount; // RefCount != 0 => Dest In Holddown
  39. RTM_VIEW_SET BelongsToViews; // View that this dest belongs too
  40. RTM_VIEW_SET ToHoldInViews; // Views in which holddown will apply
  41. struct
  42. { //
  43. ROUTE_INFO *BestRoute; // Best route to dest in each view
  44. ROUTE_INFO *HoldRoute; // The holddown route in each view
  45. ULONG HoldTime; // Time for which route is in held
  46. } ViewInfo[1]; //
  47. }
  48. DEST_INFO, *PDEST_INFO;
  49. //
  50. // Destination State
  51. //
  52. #define DEST_STATE_CREATED 0
  53. #define DEST_STATE_DELETED 1
  54. //
  55. // Context used in timing out a route
  56. //
  57. typedef struct _ROUTE_TIMER
  58. {
  59. HANDLE Timer; // Handle to the timer used for expiry
  60. PVOID Route; // Route being expired by this timer
  61. }
  62. ROUTE_TIMER, *PROUTE_TIMER;
  63. //
  64. // Address Family Independent route structure
  65. //
  66. typedef struct _ROUTE_INFO
  67. {
  68. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  69. LIST_ENTRY DestLE; // Linkage on list of routes on dest
  70. LIST_ENTRY RouteListLE; // Linkage on an entity's route list
  71. PROUTE_TIMER TimerContext; // Timer used to age-out or holddown
  72. RTM_ROUTE_INFO RouteInfo; // Part exposed directly to the owner
  73. }
  74. ROUTE_INFO, *PROUTE_INFO;
  75. //
  76. // Node in the next hop tree of which all the
  77. // next-hops with a particular addr hang off
  78. //
  79. typedef struct _NEXTHOP_LIST
  80. {
  81. LOOKUP_LINKAGE LookupLinkage; // Linkage into owning lookup structure
  82. LIST_ENTRY NextHopsList; // Head of the list of next hops
  83. }
  84. NEXTHOP_LIST, *PNEXTHOP_LIST;
  85. //
  86. // Address Family Independent next-hop structure
  87. //
  88. typedef struct _NEXTHOP_INFO
  89. {
  90. OBJECT_HEADER ObjectHeader; // Signature, Type and Reference Count
  91. LIST_ENTRY NextHopsLE; // Linkage into holding nexthops list
  92. RTM_NEXTHOP_INFO NextHopInfo; // Part exposed directly to the owner
  93. }
  94. NEXTHOP_INFO, *PNEXTHOP_INFO;
  95. //
  96. // Macros for acquiring various locks defined in this file
  97. //
  98. #define ACQUIRE_DEST_READ_LOCK(Dest) \
  99. ACQUIRE_DYNAMIC_READ_LOCK(&Dest->DestLock)
  100. #define RELEASE_DEST_READ_LOCK(Dest) \
  101. RELEASE_DYNAMIC_READ_LOCK(&Dest->DestLock)
  102. #define ACQUIRE_DEST_WRITE_LOCK(Dest) \
  103. ACQUIRE_DYNAMIC_WRITE_LOCK(&Dest->DestLock)
  104. #define RELEASE_DEST_WRITE_LOCK(Dest) \
  105. RELEASE_DYNAMIC_WRITE_LOCK(&Dest->DestLock)
  106. //
  107. // Macros for comparing two routes using their preferences
  108. //
  109. BOOL
  110. __inline
  111. IsPrefEqual (
  112. IN PRTM_ROUTE_INFO RouteInfo1,
  113. IN PRTM_ROUTE_INFO RouteInfo2
  114. )
  115. {
  116. return ((RouteInfo1->PrefInfo.Metric == RouteInfo2->PrefInfo.Metric) &&
  117. (RouteInfo1->PrefInfo.Preference == RouteInfo2->PrefInfo.Preference));
  118. }
  119. LONG
  120. __inline
  121. ComparePref (
  122. IN PRTM_ROUTE_INFO RouteInfo1,
  123. IN PRTM_ROUTE_INFO RouteInfo2
  124. )
  125. {
  126. // Lower preference means "more preferred"
  127. if (RouteInfo1->PrefInfo.Preference < RouteInfo2->PrefInfo.Preference)
  128. { return +1; }
  129. else
  130. if (RouteInfo1->PrefInfo.Preference > RouteInfo2->PrefInfo.Preference)
  131. { return -1; }
  132. else
  133. if (RouteInfo1->PrefInfo.Metric < RouteInfo2->PrefInfo.Metric)
  134. { return +1; }
  135. else
  136. if (RouteInfo1->PrefInfo.Metric > RouteInfo2->PrefInfo.Metric)
  137. { return -1; }
  138. return 0;
  139. }
  140. //
  141. // Dest, Route, NextHop Helper Functions
  142. //
  143. DWORD
  144. CreateDest (
  145. IN PADDRFAM_INFO AddrFamilyInfo,
  146. IN PRTM_NET_ADDRESS DestAddress,
  147. OUT PDEST_INFO *Dest
  148. );
  149. DWORD
  150. DestroyDest (
  151. IN PDEST_INFO Dest
  152. );
  153. DWORD
  154. CreateRoute (
  155. IN PENTITY_INFO Entity,
  156. IN PRTM_ROUTE_INFO RouteInfo,
  157. OUT PROUTE_INFO *Route
  158. );
  159. VOID
  160. ComputeRouteInfoChange(
  161. IN PRTM_ROUTE_INFO OldRouteInfo,
  162. IN PRTM_ROUTE_INFO NewRouteInfo,
  163. IN ULONG PrefChanged,
  164. OUT PULONG RouteInfoChanged,
  165. OUT PULONG ForwardingInfoChanged
  166. );
  167. VOID
  168. CopyToRoute (
  169. IN PENTITY_INFO Entity,
  170. IN PRTM_ROUTE_INFO RouteInfo,
  171. IN PROUTE_INFO Route
  172. );
  173. DWORD
  174. DestroyRoute (
  175. IN PROUTE_INFO Route
  176. );
  177. DWORD
  178. CreateNextHop (
  179. IN PENTITY_INFO Entity,
  180. IN PRTM_NEXTHOP_INFO NextHopInfo,
  181. OUT PNEXTHOP_INFO *NextHop
  182. );
  183. VOID
  184. CopyToNextHop (
  185. IN PENTITY_INFO Entity,
  186. IN PRTM_NEXTHOP_INFO NextHopInfo,
  187. IN PNEXTHOP_INFO NextHop
  188. );
  189. DWORD
  190. DestroyNextHop (
  191. IN PNEXTHOP_INFO NextHop
  192. );
  193. DWORD
  194. FindNextHop (
  195. IN PENTITY_INFO Entity,
  196. IN PRTM_NEXTHOP_INFO NextHopInfo,
  197. OUT PLOOKUP_CONTEXT Context OPTIONAL,
  198. OUT PLIST_ENTRY *NextHopLE
  199. );
  200. #endif //__ROUTING_RTMROUT_H__