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.

169 lines
4.4 KiB

  1. #include "precomp.h"
  2. DWORD
  3. AddSetIpIpTunnelInfo(
  4. IN LPCWSTR pwszIfName,
  5. IN PIPINIP_CONFIG_INFO pInfo
  6. )
  7. {
  8. DWORD dwErr, dwType = 0;
  9. WCHAR rgwcNameBuffer[MAX_INTERFACE_NAME_LEN + 2];
  10. LPCWSTR pwszGuidName, pwszFriendlyName;
  11. BOOL bCreateIf, bCreatedMapping;
  12. PRTR_INFO_BLOCK_HEADER pIpInfo;
  13. MPR_IPINIP_INTERFACE_0 NameInfo;
  14. dwErr = GetInterfaceInfo(pwszIfName,
  15. &pIpInfo,
  16. NULL,
  17. &dwType);
  18. if(dwErr is NO_ERROR)
  19. {
  20. if(dwType is ROUTER_IF_TYPE_TUNNEL1)
  21. {
  22. dwErr = IpmontrSetInfoBlockInInterfaceInfo(pwszIfName,
  23. IP_IPINIP_CFG_INFO,
  24. (PBYTE)pInfo,
  25. sizeof(IPINIP_CONFIG_INFO),
  26. 1);
  27. if(dwErr isnot NO_ERROR)
  28. {
  29. DisplayMessage(g_hModule,
  30. EMSG_CANT_SET_IF_INFO,
  31. pwszIfName,
  32. dwErr);
  33. }
  34. }
  35. FREE_BUFFER(pIpInfo);
  36. return dwErr;
  37. }
  38. if((dwErr isnot ERROR_NO_SUCH_INTERFACE) and
  39. (dwErr isnot ERROR_TRANSPORT_NOT_PRESENT))
  40. {
  41. DisplayMessage(g_hModule,
  42. EMSG_CANT_GET_IF_INFO,
  43. pwszIfName,
  44. dwErr);
  45. return dwErr;
  46. }
  47. //
  48. // If we get ERROR_NO_SUCH_INTERFACE, we need to create the i/f in
  49. // the router, as well as adding it to IP
  50. //
  51. bCreateIf = (dwErr is ERROR_NO_SUCH_INTERFACE);
  52. //
  53. // Figure out if there is no friendly name <-> guid mapping.
  54. // Even if the interface is not added with the router, there could
  55. // be turds left in the name map. In case there is a friendly name
  56. // present, then the IfName passed to us is a GUID.
  57. //
  58. dwErr = MprConfigGetFriendlyName(g_hMprConfig,
  59. (LPWSTR)pwszIfName,
  60. rgwcNameBuffer,
  61. sizeof(rgwcNameBuffer));
  62. if(dwErr is NO_ERROR)
  63. {
  64. //
  65. // name mapping exists,
  66. //
  67. pwszGuidName = pwszIfName;
  68. pwszFriendlyName = rgwcNameBuffer;
  69. bCreatedMapping = FALSE;
  70. }
  71. else
  72. {
  73. //
  74. // no such name. this means the IfName passed to us is the
  75. // friendly name, so create a guid and map this name to it
  76. //
  77. if(UuidCreate(&(NameInfo.Guid)) isnot RPC_S_OK)
  78. {
  79. return ERROR_CAN_NOT_COMPLETE;
  80. }
  81. wcsncpy(NameInfo.wszFriendlyName,
  82. pwszIfName,
  83. MAX_INTERFACE_NAME_LEN);
  84. NameInfo.wszFriendlyName[MAX_INTERFACE_NAME_LEN] = UNICODE_NULL;
  85. //
  86. // Set the mapping
  87. //
  88. dwErr = MprSetupIpInIpInterfaceFriendlyNameCreate(g_pwszRouter,
  89. &NameInfo);
  90. if(dwErr isnot NO_ERROR)
  91. {
  92. return dwErr;
  93. }
  94. ConvertGuidToString(&(NameInfo.Guid),
  95. rgwcNameBuffer);
  96. pwszGuidName = rgwcNameBuffer;
  97. pwszFriendlyName = pwszIfName;
  98. bCreatedMapping = TRUE;
  99. }
  100. dwErr = CreateInterface(pwszFriendlyName,
  101. pwszGuidName,
  102. ROUTER_IF_TYPE_TUNNEL1,
  103. bCreateIf);
  104. if(dwErr isnot NO_ERROR)
  105. {
  106. DisplayMessage(g_hModule,
  107. EMSG_CANT_CREATE_IF,
  108. pwszIfName,
  109. dwErr);
  110. if(bCreatedMapping or bCreateIf)
  111. {
  112. MprSetupIpInIpInterfaceFriendlyNameDelete(g_pwszRouter,
  113. &(NameInfo.Guid));
  114. }
  115. return dwErr;
  116. }
  117. dwErr = IpmontrSetInfoBlockInInterfaceInfo(pwszGuidName,
  118. IP_IPINIP_CFG_INFO,
  119. (PBYTE)pInfo,
  120. sizeof(IPINIP_CONFIG_INFO),
  121. 1);
  122. if(dwErr isnot NO_ERROR)
  123. {
  124. DisplayMessage(g_hModule,
  125. EMSG_CANT_SET_IF_INFO,
  126. pwszIfName,
  127. dwErr);
  128. }
  129. return NO_ERROR;
  130. }