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.

217 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. routing\netsh\ip\ipmon\routing.c
  5. Abstract:
  6. Routing Command dispatcher.
  7. Revision History:
  8. Dave Thaler 3/03/99 Created
  9. --*/
  10. #include "precomp.h"
  11. const GUID g_RoutingGuid = ROUTING_GUID;
  12. const GUID g_NetshGuid = NETSH_ROOT_GUID;
  13. PWCHAR g_pwszRouter = NULL;
  14. HRESULT RouterReset(LPCTSTR pszMachineName);
  15. NS_CONTEXT_DUMP_FN RoutingDump;
  16. NS_CONTEXT_CONNECT_FN RoutingConnect;
  17. FN_HANDLE_CMD HandleRoutingReset;
  18. DWORD ParentVersion;
  19. BOOL g_bRoutingDirty = FALSE;
  20. CMD_ENTRY g_RoutingCmds[] =
  21. {
  22. CREATE_CMD_ENTRY(IP_RESET, HandleRoutingReset),
  23. };
  24. ULONG g_ulRoutingNumTopCmds = sizeof(g_RoutingCmds)/sizeof(CMD_ENTRY);
  25. DWORD
  26. WINAPI
  27. RoutingStartHelper(
  28. IN CONST GUID *pguidParent,
  29. IN DWORD dwVersion
  30. )
  31. {
  32. DWORD dwErr;
  33. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  34. ParentVersion = dwVersion;
  35. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  36. attMyAttributes.pwszContext = L"routing";
  37. attMyAttributes.guidHelper = g_RoutingGuid;
  38. attMyAttributes.dwVersion = 1;
  39. attMyAttributes.dwFlags = 0;
  40. attMyAttributes.ulNumTopCmds = g_ulRoutingNumTopCmds;
  41. attMyAttributes.pTopCmds = (CMD_ENTRY (*)[])&g_RoutingCmds;
  42. attMyAttributes.ulNumGroups = 0;
  43. attMyAttributes.pCmdGroups = NULL;
  44. attMyAttributes.pfnCommitFn = NULL; // RoutingCommit;
  45. attMyAttributes.pfnDumpFn = RoutingDump;
  46. attMyAttributes.pfnConnectFn = RoutingConnect;
  47. dwErr = RegisterContext( &attMyAttributes );
  48. return dwErr;
  49. }
  50. DWORD
  51. HandleRoutingReset(
  52. IN LPCWSTR pwszMachine,
  53. IN OUT LPWSTR *ppwcArguments,
  54. IN DWORD dwCurrentIndex,
  55. IN DWORD dwArgCount,
  56. IN DWORD dwFlags,
  57. IN LPCVOID pvData,
  58. OUT BOOL *pbDone
  59. )
  60. {
  61. // Call KennT's "router upgrade" function
  62. RouterReset( g_pwszRouter );
  63. return NO_ERROR;
  64. }
  65. DWORD
  66. ConnectToRouter(
  67. IN LPCWSTR pwszRouter
  68. )
  69. {
  70. DWORD rc;
  71. if (g_pwszRouter != pwszRouter)
  72. {
  73. if (g_hMprConfig)
  74. {
  75. MprConfigServerDisconnect(g_hMprConfig);
  76. g_hMprConfig = NULL;
  77. }
  78. if (g_hMprAdmin)
  79. {
  80. MprAdminServerDisconnect(g_hMprAdmin);
  81. g_hMprAdmin = NULL;
  82. }
  83. if (g_hMIBServer)
  84. {
  85. MprAdminMIBServerDisconnect(g_hMIBServer);
  86. g_hMIBServer = NULL;
  87. }
  88. if (g_pwszRouter)
  89. {
  90. FREE(g_pwszRouter);
  91. g_pwszRouter = NULL;
  92. }
  93. if (pwszRouter)
  94. {
  95. g_pwszRouter = MALLOC((wcslen(pwszRouter)+1)*sizeof(WCHAR));
  96. if (g_pwszRouter)
  97. {
  98. wcscpy(g_pwszRouter, pwszRouter);
  99. }
  100. else
  101. {
  102. return ERROR_NOT_ENOUGH_MEMORY;
  103. }
  104. }
  105. }
  106. if (!g_hMprConfig)
  107. {
  108. //
  109. // first time connecting to router config
  110. //
  111. rc = MprConfigServerConnect ((LPWSTR)pwszRouter,
  112. &g_hMprConfig);
  113. if (rc isnot NO_ERROR)
  114. {
  115. //
  116. // cannot connect to router config.
  117. //
  118. return ERROR_CONNECT_REMOTE_CONFIG;
  119. }
  120. }
  121. //
  122. // Check to see if router is running. If so, get the handles
  123. //
  124. do
  125. {
  126. if (MprAdminIsServiceRunning((LPWSTR)pwszRouter))
  127. {
  128. if (MprAdminServerConnect((LPWSTR)pwszRouter, &g_hMprAdmin) == NO_ERROR)
  129. {
  130. DEBUG("Got admin handle");
  131. if (MprAdminMIBServerConnect ((LPWSTR)pwszRouter,
  132. &g_hMIBServer) == NO_ERROR)
  133. {
  134. DEBUG("Got server handle");
  135. break;
  136. }
  137. else
  138. {
  139. MprAdminServerDisconnect (g_hMprAdmin);
  140. }
  141. }
  142. }
  143. g_hMprAdmin = g_hMIBServer = NULL;
  144. } while (FALSE);
  145. return NO_ERROR;
  146. }
  147. DWORD WINAPI
  148. RoutingConnect(
  149. IN LPCWSTR pwszRouter
  150. )
  151. {
  152. // If context info is dirty, reregister it
  153. if (g_bRoutingDirty)
  154. {
  155. RoutingStartHelper(NULL, ParentVersion);
  156. }
  157. return ConnectToRouter(pwszRouter);
  158. }
  159. DWORD
  160. RoutingDump(
  161. IN LPCWSTR pwszRouter,
  162. IN WCHAR **ppwcArguments,
  163. IN DWORD dwArgCount,
  164. IN PVOID pvData
  165. )
  166. {
  167. DWORD dwErr;
  168. dwErr = ConnectToRouter(pwszRouter);
  169. // Dump routing information
  170. DisplayMessage( g_hModule, DMP_ROUTING_HEADER_COMMENTS);
  171. DisplayMessageT(DMP_ROUTING_HEADER);
  172. DisplayMessageT(DMP_POPD);
  173. return NO_ERROR;
  174. }