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.

350 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. mibroute.c
  5. Abstract:
  6. The MIB handling functions for the Forwarding Group (Routes & Static Routes)
  7. Author:
  8. Stefan Solomon 05/02/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. DWORD
  14. MibGetRoute(PIPX_MIB_INDEX mip,
  15. PIPX_ROUTE Route,
  16. PULONG RouteSize)
  17. {
  18. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  19. *RouteSize = sizeof(IPX_ROUTE);
  20. return ERROR_INSUFFICIENT_BUFFER;
  21. }
  22. memcpy(Route->Network, mip->RoutingTableIndex.Network, 4);
  23. return(GetRoute(IPX_DEST_TABLE, Route));
  24. }
  25. DWORD
  26. MibGetFirstRoute(PIPX_MIB_INDEX mip,
  27. PIPX_ROUTE Route,
  28. PULONG RouteSize)
  29. {
  30. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  31. *RouteSize = sizeof(IPX_ROUTE);
  32. return ERROR_INSUFFICIENT_BUFFER;
  33. }
  34. return(GetFirstRoute(IPX_DEST_TABLE, Route));
  35. }
  36. DWORD
  37. MibGetNextRoute(PIPX_MIB_INDEX mip,
  38. PIPX_ROUTE Route,
  39. PULONG RouteSize)
  40. {
  41. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  42. *RouteSize = sizeof(IPX_ROUTE);
  43. return ERROR_INSUFFICIENT_BUFFER;
  44. }
  45. memcpy(Route->Network, mip->RoutingTableIndex.Network, 4);
  46. return(GetNextRoute(IPX_DEST_TABLE, Route));
  47. }
  48. DWORD
  49. MibCreateStaticRoute(PIPX_MIB_ROW MibRowp)
  50. {
  51. PIPX_ROUTE NewRoutep;
  52. IPX_ROUTE OldRoute;
  53. PICB icbp;
  54. IPX_STATIC_ROUTE_INFO strtinfo;
  55. DWORD rc;
  56. NewRoutep = &MibRowp->Route;
  57. OldRoute = *NewRoutep;
  58. ACQUIRE_DATABASE_LOCK;
  59. if((icbp = GetInterfaceByIndex(NewRoutep->InterfaceIndex)) == NULL) {
  60. RELEASE_DATABASE_LOCK;
  61. return ERROR_INVALID_PARAMETER;
  62. }
  63. // if this static route already exists, delete it
  64. if(GetRoute(IPX_STATIC_ROUTE_TABLE, &OldRoute) == NO_ERROR) {
  65. memcpy(&strtinfo.Network,
  66. OldRoute.Network,
  67. 4);
  68. strtinfo.TickCount = OldRoute.TickCount;
  69. strtinfo.HopCount = OldRoute.HopCount;
  70. memcpy(&strtinfo.NextHopMacAddress,
  71. OldRoute.NextHopMacAddress,
  72. 6);
  73. if(DeleteStaticRoute(OldRoute.InterfaceIndex,
  74. &strtinfo) != NO_ERROR) {
  75. RELEASE_DATABASE_LOCK;
  76. return ERROR_CAN_NOT_COMPLETE;
  77. }
  78. }
  79. memcpy(&strtinfo.Network,
  80. NewRoutep->Network,
  81. 4);
  82. strtinfo.TickCount = NewRoutep->TickCount;
  83. strtinfo.HopCount = NewRoutep->HopCount;
  84. memcpy(&strtinfo.NextHopMacAddress,
  85. NewRoutep->NextHopMacAddress,
  86. 6);
  87. rc = CreateStaticRoute(icbp, &strtinfo);
  88. RELEASE_DATABASE_LOCK;
  89. return rc;
  90. }
  91. DWORD
  92. MibDeleteStaticRoute(PIPX_MIB_ROW MibRowp)
  93. {
  94. PIPX_ROUTE Route;
  95. PICB icbp;
  96. IPX_STATIC_ROUTE_INFO strtinfo;
  97. DWORD rc;
  98. Route = &MibRowp->Route;
  99. ACQUIRE_DATABASE_LOCK;
  100. if((icbp = GetInterfaceByIndex(Route->InterfaceIndex)) == NULL) {
  101. RELEASE_DATABASE_LOCK;
  102. return ERROR_INVALID_PARAMETER;
  103. }
  104. memcpy(&strtinfo.Network,
  105. Route->Network,
  106. 4);
  107. strtinfo.TickCount = Route->TickCount;
  108. strtinfo.HopCount = Route->HopCount;
  109. memcpy(&strtinfo.NextHopMacAddress,
  110. Route->NextHopMacAddress,
  111. 6);
  112. rc = DeleteStaticRoute(Route->InterfaceIndex,
  113. &strtinfo);
  114. RELEASE_DATABASE_LOCK;
  115. return rc;
  116. }
  117. DWORD
  118. MibGetStaticRoute(PIPX_MIB_INDEX mip,
  119. PIPX_ROUTE Route,
  120. PULONG RouteSize)
  121. {
  122. DWORD rc;
  123. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  124. *RouteSize = sizeof(IPX_ROUTE);
  125. return ERROR_INSUFFICIENT_BUFFER;
  126. }
  127. Route->InterfaceIndex = mip->StaticRoutesTableIndex.InterfaceIndex;
  128. memcpy(Route->Network, mip->StaticRoutesTableIndex.Network, 4);
  129. return(GetRoute(IPX_STATIC_ROUTE_TABLE, Route));
  130. }
  131. DWORD
  132. MibGetFirstStaticRoute(PIPX_MIB_INDEX mip,
  133. PIPX_ROUTE Route,
  134. PULONG RouteSize)
  135. {
  136. ULONG InterfaceIndex;
  137. DWORD rc;
  138. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  139. *RouteSize = sizeof(IPX_ROUTE);
  140. return ERROR_INSUFFICIENT_BUFFER;
  141. }
  142. ACQUIRE_DATABASE_LOCK;
  143. if(EnumerateFirstInterfaceIndex(&InterfaceIndex)) {
  144. RELEASE_DATABASE_LOCK;
  145. return ERROR_NO_MORE_ITEMS;
  146. }
  147. RELEASE_DATABASE_LOCK;
  148. Route->InterfaceIndex = InterfaceIndex;
  149. rc = GetFirstRoute(IPX_STATIC_ROUTE_TABLE, Route);
  150. if(rc == NO_ERROR) {
  151. return rc;
  152. }
  153. // no more static routes for this interface. Find the next interface
  154. // which has static routes
  155. ACQUIRE_DATABASE_LOCK;
  156. while(rc != NO_ERROR)
  157. {
  158. if(EnumerateNextInterfaceIndex(&InterfaceIndex)) {
  159. rc = ERROR_NO_MORE_ITEMS;
  160. break;
  161. }
  162. else
  163. {
  164. Route->InterfaceIndex = InterfaceIndex;
  165. rc = GetFirstRoute(IPX_STATIC_ROUTE_TABLE, Route);
  166. }
  167. }
  168. RELEASE_DATABASE_LOCK;
  169. return rc;
  170. }
  171. DWORD
  172. MibGetNextStaticRoute(PIPX_MIB_INDEX mip,
  173. PIPX_ROUTE Route,
  174. PULONG RouteSize)
  175. {
  176. DWORD rc;
  177. ULONG InterfaceIndex;
  178. if((Route == NULL) || (*RouteSize < sizeof(IPX_ROUTE))) {
  179. *RouteSize = sizeof(IPX_ROUTE);
  180. return ERROR_INSUFFICIENT_BUFFER;
  181. }
  182. Route->InterfaceIndex = mip->StaticRoutesTableIndex.InterfaceIndex;
  183. memcpy(Route->Network, mip->StaticRoutesTableIndex.Network, 4);
  184. rc = GetNextRoute(IPX_STATIC_ROUTE_TABLE, Route);
  185. if(rc == NO_ERROR) {
  186. return rc;
  187. }
  188. // no more static routes for this interface. Find the next interface
  189. // which has static routes
  190. InterfaceIndex = mip->StaticRoutesTableIndex.InterfaceIndex;
  191. ACQUIRE_DATABASE_LOCK;
  192. while(rc != NO_ERROR)
  193. {
  194. if(EnumerateNextInterfaceIndex(&InterfaceIndex)) {
  195. rc = ERROR_NO_MORE_ITEMS;
  196. break;
  197. }
  198. else
  199. {
  200. Route->InterfaceIndex = InterfaceIndex;
  201. rc = GetFirstRoute(IPX_STATIC_ROUTE_TABLE, Route);
  202. }
  203. }
  204. RELEASE_DATABASE_LOCK;
  205. return rc;
  206. }
  207. DWORD
  208. MibSetStaticRoute(PIPX_MIB_ROW MibRowp)
  209. {
  210. PIPX_ROUTE NewRoutep;
  211. IPX_ROUTE OldRoute;
  212. PICB icbp;
  213. IPX_STATIC_ROUTE_INFO strtinfo;
  214. DWORD rc;
  215. NewRoutep = &MibRowp->Route;
  216. OldRoute = *NewRoutep;
  217. ACQUIRE_DATABASE_LOCK;
  218. if((icbp = GetInterfaceByIndex(OldRoute.InterfaceIndex)) == NULL) {
  219. RELEASE_DATABASE_LOCK;
  220. return ERROR_INVALID_PARAMETER;
  221. }
  222. // first, delete this route if it exists
  223. if(GetRoute(IPX_STATIC_ROUTE_TABLE, &OldRoute) != NO_ERROR) {
  224. // route doesn't exist
  225. RELEASE_DATABASE_LOCK;
  226. return ERROR_INVALID_PARAMETER;
  227. }
  228. memcpy(&strtinfo.Network,
  229. OldRoute.Network,
  230. 4);
  231. strtinfo.TickCount = OldRoute.TickCount;
  232. strtinfo.HopCount = OldRoute.HopCount;
  233. memcpy(&strtinfo.NextHopMacAddress,
  234. OldRoute.NextHopMacAddress,
  235. 6);
  236. if(DeleteStaticRoute(OldRoute.InterfaceIndex,
  237. &strtinfo) != NO_ERROR) {
  238. RELEASE_DATABASE_LOCK;
  239. return ERROR_CAN_NOT_COMPLETE;
  240. }
  241. memcpy(&strtinfo.Network,
  242. NewRoutep->Network,
  243. 4);
  244. strtinfo.TickCount = NewRoutep->TickCount;
  245. strtinfo.HopCount = NewRoutep->HopCount;
  246. memcpy(&strtinfo.NextHopMacAddress,
  247. NewRoutep->NextHopMacAddress,
  248. 6);
  249. // add it again with the new parameters
  250. rc = CreateStaticRoute(icbp,
  251. &strtinfo);
  252. RELEASE_DATABASE_LOCK;
  253. return rc;
  254. }