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.

313 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Abstract:
  4. Netsh helper for IPv6
  5. --*/
  6. #include "precomp.h"
  7. GUID g_Ipv6Guid = IPV6MON_GUID;
  8. static const GUID g_IfGuid = IFMON_GUID;
  9. #define IPV6_HELPER_VERSION 1
  10. //
  11. // The helper's commands are broken into 2 sets
  12. // - The top level commands are those which deal with the helper
  13. // itself (meta commands) and others which take 0 arguments
  14. // - The rest of the commands are split into "command groups"
  15. // i.e, commands grouped by the VERB where the VERB is ADD, DELETE,
  16. // GET or SET. This is not for any technical reason - only for
  17. // staying with the semantics used in other helpers
  18. //
  19. // A command is described using a CMD_ENTRY structure. It requires the
  20. // command token, the handler, a short help message token and an extended
  21. // help message token. To make it easier to create we use the
  22. // CREATE_CMD_ENTRY macro. This, however puts restrictions on how the tokens
  23. // are named.
  24. //
  25. // The command groups are simply arrays of the CMD_ENTRY structure. The
  26. // top level commands are also grouped in a similar array.
  27. //
  28. // The info about a complete command group is put in a CMD_GROUP_ENTRY
  29. // structure, all of which are put in an array.
  30. //
  31. //
  32. // To add a command entry to a group, simply add the command to the appropriate
  33. // array
  34. // To add a command group - create and array and add its info to the
  35. // command group array
  36. //
  37. CMD_ENTRY g_Ipv6AddCmdTable[] =
  38. {
  39. CREATE_CMD_ENTRY(IPV6_ADD_6OVER4TUNNEL, HandleAdd6over4Tunnel),
  40. CREATE_CMD_ENTRY(IPV6_ADD_ADDRESS, HandleAddAddress),
  41. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_ADD_DNS, HandleAddDns),
  42. // CREATE_CMD_ENTRY(IPV6_ADD_DNS, HandleAddDns),
  43. CREATE_CMD_ENTRY(IPV6_ADD_PREFIXPOLICY, HandleAddPrefixPolicy),
  44. CREATE_CMD_ENTRY(IPV6_ADD_ROUTE, HandleAddRoute),
  45. CREATE_CMD_ENTRY(IPV6_ADD_V6V4TUNNEL, HandleAddV6V4Tunnel),
  46. };
  47. CMD_ENTRY g_Ipv6DelCmdTable[] =
  48. {
  49. CREATE_CMD_ENTRY(IPV6_DEL_ADDRESS, HandleDelAddress),
  50. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_DEL_DNS, HandleDelDns),
  51. // CREATE_CMD_ENTRY(IPV6_DEL_DNS, HandleDelDns),
  52. CREATE_CMD_ENTRY(IPV6_DEL_INTERFACE, HandleDelInterface),
  53. CREATE_CMD_ENTRY(IPV6_DEL_NEIGHBORS, HandleDelNeighbors),
  54. CREATE_CMD_ENTRY(IPV6_DEL_PREFIXPOLICY, HandleDelPrefixPolicy),
  55. CREATE_CMD_ENTRY(IPV6_DEL_ROUTE, HandleDelRoute),
  56. CREATE_CMD_ENTRY(IPV6_DEL_DESTINATIONCACHE, HandleDelDestinationCache),
  57. };
  58. CMD_ENTRY g_Ipv6SetCmdTable[] =
  59. {
  60. CREATE_CMD_ENTRY(IPV6_SET_ADDRESS, HandleSetAddress),
  61. CREATE_CMD_ENTRY(IPV6_SET_GLOBAL, HandleSetGlobal),
  62. CREATE_CMD_ENTRY(IPV6_SET_INTERFACE, HandleSetInterface),
  63. CREATE_CMD_ENTRY(IPV6_SET_MOBILITY, HandleSetMobility),
  64. CREATE_CMD_ENTRY(IPV6_SET_PREFIXPOLICY, HandleSetPrefixPolicy),
  65. CREATE_CMD_ENTRY(IPV6_SET_PRIVACY, HandleSetPrivacy),
  66. CREATE_CMD_ENTRY(IPV6_SET_ROUTE, HandleSetRoute),
  67. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_SET_STATE, HandleSetState),
  68. // CREATE_CMD_ENTRY(IPV6_SET_STATE, HandleSetState),
  69. #if TEREDO
  70. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_SET_TEREDO, HandleSetTeredo),
  71. // CREATE_CMD_ENTRY(IPV6_SET_TEREDO, HandleSetTeredo),
  72. #endif // TEREDO
  73. };
  74. CMD_ENTRY g_Ipv6ShowCmdTable[] =
  75. {
  76. CREATE_CMD_ENTRY(IPV6_SHOW_ADDRESS, HandleShowAddress),
  77. CREATE_CMD_ENTRY(IPV6_SHOW_BINDINGCACHEENTRIES, HandleShowBindingCacheEntries),
  78. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_SHOW_DNS, HandleShowDns),
  79. // CREATE_CMD_ENTRY(IPV6_SHOW_DNS, HandleShowDns),
  80. CREATE_CMD_ENTRY(IPV6_SHOW_GLOBAL, HandleShowGlobal),
  81. CREATE_CMD_ENTRY(IPV6_SHOW_INTERFACE, HandleShowInterface),
  82. CREATE_CMD_ENTRY(IPV6_SHOW_JOINS, HandleShowJoins),
  83. CREATE_CMD_ENTRY(IPV6_SHOW_MOBILITY, HandleShowMobility),
  84. CREATE_CMD_ENTRY(IPV6_SHOW_NEIGHBORS, HandleShowNeighbors),
  85. CREATE_CMD_ENTRY(IPV6_SHOW_PREFIXPOLICY, HandleShowPrefixPolicy),
  86. CREATE_CMD_ENTRY(IPV6_SHOW_PRIVACY, HandleShowPrivacy),
  87. CREATE_CMD_ENTRY(IPV6_SHOW_DESTINATIONCACHE, HandleShowDestinationCache),
  88. CREATE_CMD_ENTRY(IPV6_SHOW_ROUTES, HandleShowRoutes),
  89. CREATE_CMD_ENTRY(IPV6_SHOW_SITEPREFIXES, HandleShowSitePrefixes),
  90. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_SHOW_STATE, HandleShowState),
  91. // CREATE_CMD_ENTRY(IPV6_SHOW_STATE, HandleShowState),
  92. #if TEREDO
  93. CREATE_UNDOCUMENTED_CMD_ENTRY(IPV6_SHOW_TEREDO, HandleShowTeredo),
  94. // CREATE_CMD_ENTRY(IPV6_SHOW_TEREDO, HandleShowTeredo),
  95. #endif // TEREDO
  96. };
  97. CMD_GROUP_ENTRY g_Ipv6CmdGroups[] =
  98. {
  99. CREATE_CMD_GROUP_ENTRY(GROUP_ADD, g_Ipv6AddCmdTable),
  100. CREATE_CMD_GROUP_ENTRY(GROUP_DELETE, g_Ipv6DelCmdTable),
  101. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_Ipv6ShowCmdTable),
  102. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_Ipv6SetCmdTable),
  103. };
  104. ULONG g_ulNumGroups = sizeof(g_Ipv6CmdGroups)/sizeof(CMD_GROUP_ENTRY);
  105. CMD_ENTRY g_Ipv6TopCmds[] =
  106. {
  107. CREATE_CMD_ENTRY(IPV6_INSTALL, HandleInstall),
  108. CREATE_CMD_ENTRY(IPV6_RENEW, HandleRenew),
  109. CREATE_CMD_ENTRY(IPV6_RESET, HandleReset),
  110. CREATE_CMD_ENTRY(IPV6_UNINSTALL, HandleUninstall),
  111. };
  112. ULONG g_ulNumTopCmds = sizeof(g_Ipv6TopCmds)/sizeof(CMD_ENTRY);
  113. HANDLE g_hModule;
  114. PWCHAR g_pwszRouter = NULL;
  115. DWORD ParentVersion;
  116. BOOL g_bIfDirty = FALSE;
  117. ULONG g_ulInitCount;
  118. BOOL
  119. WINAPI
  120. Ipv6DllEntry(
  121. HINSTANCE hInstDll,
  122. DWORD fdwReason,
  123. LPVOID pReserved
  124. )
  125. {
  126. switch (fdwReason)
  127. {
  128. case DLL_PROCESS_ATTACH:
  129. {
  130. g_hModule = hInstDll;
  131. DisableThreadLibraryCalls(hInstDll);
  132. break;
  133. }
  134. case DLL_PROCESS_DETACH:
  135. {
  136. break;
  137. }
  138. default:
  139. {
  140. break;
  141. }
  142. }
  143. return TRUE;
  144. }
  145. DWORD
  146. WINAPI
  147. Ipv6Dump(
  148. IN LPCWSTR pwszRouter,
  149. IN OUT LPWSTR *ppwcArguments,
  150. IN DWORD dwArgCount,
  151. IN LPCVOID pvData
  152. )
  153. /*++
  154. Routine Description
  155. Used when dumping all contexts
  156. Arguments
  157. Return Value
  158. NO_ERROR
  159. --*/
  160. {
  161. DWORD dwErr;
  162. HANDLE hFile = (HANDLE)-1;
  163. DisplayMessage( g_hModule, DMP_IPV6_HEADER_COMMENTS );
  164. DisplayMessageT(DMP_IPV6_PUSHD);
  165. //
  166. // Dump persistent configuration information.
  167. //
  168. QueryGlobalParameters(FORMAT_DUMP, TRUE);
  169. ShowIpv6StateConfig(TRUE);
  170. ShowDnsServers(TRUE, NULL);
  171. QueryPrivacyParameters(FORMAT_DUMP, TRUE);
  172. QueryMobilityParameters(FORMAT_DUMP, TRUE);
  173. QueryPrefixPolicy(FORMAT_DUMP, TRUE);
  174. QueryRouteTable(FORMAT_DUMP, TRUE);
  175. QueryInterface(NULL, FORMAT_DUMP, TRUE);
  176. #if TEREDO
  177. ShowTeredo(FORMAT_DUMP);
  178. #endif // TEREDO
  179. DisplayMessageT(DMP_IPV6_POPD);
  180. DisplayMessage( g_hModule, DMP_IPV6_FOOTER_COMMENTS );
  181. return NO_ERROR;
  182. }
  183. DWORD
  184. WINAPI
  185. Ipv6StartHelper(
  186. IN CONST GUID *pguidParent,
  187. IN DWORD dwVersion
  188. )
  189. {
  190. DWORD dwErr;
  191. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  192. ParentVersion = dwVersion;
  193. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  194. attMyAttributes.pwszContext = L"ipv6";
  195. attMyAttributes.guidHelper = g_Ipv6Guid;
  196. attMyAttributes.dwVersion = IPV6_HELPER_VERSION;
  197. attMyAttributes.dwFlags = CMD_FLAG_LOCAL | CMD_FLAG_ONLINE;
  198. attMyAttributes.pfnDumpFn = Ipv6Dump;
  199. attMyAttributes.ulNumTopCmds= g_ulNumTopCmds;
  200. attMyAttributes.pTopCmds = (CMD_ENTRY (*)[])&g_Ipv6TopCmds;
  201. attMyAttributes.ulNumGroups = g_ulNumGroups;
  202. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_Ipv6CmdGroups;
  203. dwErr = RegisterContext( &attMyAttributes );
  204. return dwErr;
  205. }
  206. DWORD
  207. Ipv6UnInit(
  208. IN DWORD dwReserved
  209. )
  210. {
  211. if(InterlockedDecrement(&g_ulInitCount) isnot 0)
  212. {
  213. return NO_ERROR;
  214. }
  215. return NO_ERROR;
  216. }
  217. DWORD WINAPI
  218. InitHelperDll(
  219. IN DWORD dwNetshVersion,
  220. OUT PVOID pReserved
  221. )
  222. {
  223. DWORD dwErr;
  224. NS_HELPER_ATTRIBUTES attMyAttributes;
  225. WSADATA wsa;
  226. //
  227. // See if this is the first time we are being called
  228. //
  229. if (InterlockedIncrement(&g_ulInitCount) != 1)
  230. {
  231. return NO_ERROR;
  232. }
  233. dwErr = WSAStartup(MAKEWORD(2,0), &wsa);
  234. // Register helpers
  235. ZeroMemory( &attMyAttributes, sizeof(attMyAttributes) );
  236. attMyAttributes.guidHelper = g_Ipv6Guid;
  237. attMyAttributes.dwVersion = IPV6_HELPER_VERSION;
  238. attMyAttributes.pfnStart = Ipv6StartHelper;
  239. attMyAttributes.pfnStop = NULL;
  240. RegisterHelper( &g_IfGuid, &attMyAttributes );
  241. attMyAttributes.guidHelper = g_PpGuid;
  242. attMyAttributes.dwVersion = PORTPROXY_HELPER_VERSION;
  243. attMyAttributes.pfnStart = PpStartHelper;
  244. attMyAttributes.pfnStop = NULL;
  245. RegisterHelper( &g_IfGuid, &attMyAttributes );
  246. dwErr = Ipv6InstallSubContexts();
  247. if (dwErr isnot NO_ERROR)
  248. {
  249. Ipv6UnInit(0);
  250. return dwErr;
  251. }
  252. return NO_ERROR;
  253. }