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.

209 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. lookup.h
  5. Abstract:
  6. This module contains defines for a wrapper
  7. that integrates the trie lookup into TCPIP.
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 11-Dec-1997
  10. Revision History:
  11. --*/
  12. #pragma once
  13. #include "strie.h"
  14. #include "ftrie.h"
  15. // Global Externs
  16. extern Trie *RouteTable;
  17. // Wrapper Routines
  18. /*++
  19. Routine Description:
  20. Initializes the IP Route Table
  21. Arguments:
  22. None
  23. Return Value:
  24. STATUS_SUCCESS or Error Code
  25. --*/
  26. #define InitRouteTable(initflags, levelsBmp, fastTrieMem, slowTrieMem) \
  27. CreateTrie(levelsBmp, initflags, slowTrieMem, fastTrieMem, &RouteTable)
  28. /*++
  29. Routine Description:
  30. Searches for a route given a prefix
  31. The route returned is a Semi-Read-
  32. Only-Version. The following fields
  33. should be changed only by calling
  34. the InsRoute function -
  35. 1) Next,
  36. 2) Dest,
  37. 3) Mask,
  38. 4) Priority, &
  39. 5) Route Metric.
  40. Remaining fields can be changed by
  41. directly modifying returned route.
  42. Arguments:
  43. IN -
  44. Dest - Destination IP Addr
  45. Mask - Destination IP Mask
  46. FirstHop - IP Addr of Next Hop
  47. OutIF - Outgoing Interface
  48. bFindFirst - Do not Match IF / not (for FindSpecificRTE)
  49. fMatchFlags - Route fields to match (for FindMatchingRTE)
  50. OUT -
  51. PrevRTE - Value should be ignored
  52. Return Value:
  53. Matching RTE or NULL if not match
  54. --*/
  55. #define FindSpecificRTE(_Dest_, _Mask_, _FirstHop_, _OutIF_, _PrevRTE_, _bFindFirst_) \
  56. ((SearchRouteInTrie(RouteTable, _Dest_, _Mask_, _FirstHop_, _OutIF_, \
  57. (!_bFindFirst_ * MATCH_INTF) | MATCH_NHOP, _PrevRTE_) \
  58. == TRIE_SUCCESS) ? *_PrevRTE_ : NULL)
  59. #define FindMatchingRTE(_Dest_, _Mask_, _FirstHop_, _OutIF_, _PrevRTE_, _fMatchFlags_) \
  60. ((SearchRouteInTrie(RouteTable, _Dest_, _Mask_, _FirstHop_, _OutIF_, \
  61. _fMatchFlags_, _PrevRTE_) \
  62. == TRIE_SUCCESS) ? *_PrevRTE_ : NULL)
  63. /*
  64. Routine Description:
  65. Gets list of default routes in table.
  66. The routes returned are a Semi-Read-
  67. Only-Version. The following fields
  68. should be changed only by calling
  69. the InsRoute function -
  70. 1) Next,
  71. 2) Dest,
  72. 3) Mask,
  73. 4) Priority, &
  74. 5) Route Metric.
  75. Remaining fields can be changed by
  76. directly modifying returned route.
  77. Replaces::
  78. RouteTable[IPHash(0)] (or) RouteTable[0];
  79. Arguments:
  80. OUT -
  81. ppDefRoute - Ptr to Ptr to list of
  82. default routes.
  83. Return Value:
  84. Pointer to default routes, or NULL
  85. */
  86. #define GetDefaultGWs(_ppDefRoute_) \
  87. ((SearchRouteInTrie(RouteTable, 0, 0, 0, NULL, MATCH_NONE, \
  88. _ppDefRoute_) == TRIE_SUCCESS) ? *(_ppDefRoute_) : NULL)
  89. /*++
  90. Routine Description:
  91. Frees memory for a route and adjusts
  92. some global statistics
  93. Arguments:
  94. IN -
  95. RTE - The RTE to be freed
  96. Return Value:
  97. None
  98. --*/
  99. #define CleanupRTE(_RTE_) DeleteRTE(NULL, _RTE_);
  100. /*++
  101. Routine Description:
  102. Frees memory for a route
  103. Arguments:
  104. IN -
  105. RTE - The RTE to be freed
  106. Return Value:
  107. None
  108. --*/
  109. #define FreeRoute(_RTE_) FreeRouteInTrie(RouteTable, _RTE_);
  110. //
  111. // Wrapper Prototypes
  112. //
  113. UINT
  114. InsRoute(IPAddr Dest, IPMask Mask, IPAddr FirstHop, VOID *OutIF,
  115. UINT Metric, ULONG MatchFlags, RouteTableEntry **ppInsRTE,
  116. RouteTableEntry **ppOldBestRTE, RouteTableEntry **ppNewBestRTE);
  117. UINT
  118. DelRoute(IPAddr Dest, IPMask Mask, IPAddr FirstHop, VOID *OutIF,
  119. ULONG MatchFlags, RouteTableEntry **ppDelRTE,
  120. RouteTableEntry **ppOldBestRTE, RouteTableEntry **ppNewBestRTE);
  121. RouteTableEntry *
  122. FindRTE(IPAddr Dest, IPAddr Source, UINT Index, UINT MaxPri, UINT MinPri,
  123. UINT UnicastIf);
  124. RouteTableEntry *
  125. LookupRTE(IPAddr Dest, IPAddr Source, UINT MaxPri, UINT UnicastIf);
  126. RouteTableEntry *
  127. LookupForwardRTE(IPAddr Dest, IPAddr Source, BOOLEAN Multipath);
  128. UINT
  129. GetNextRoute(VOID *Context, Route **ppRoute);
  130. UINT
  131. GetNextDest(VOID *Context, Dest **ppDest);
  132. VOID
  133. SortRoutesInDest(Dest *pDest);
  134. VOID
  135. SortRoutesInDestByRTE(Route *pRTE);
  136. UINT
  137. RTValidateContext(VOID *Context, UINT *Valid);