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.

118 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 2001-2002 Microsoft Corporation
  3. Module Name:
  4. elip6.c
  5. Abstract:
  6. This module contains the interface to the IPv6 stack.
  7. Required, since the IPv6 stack needs restart its protocol
  8. mechanisms on the link once authentication succeeds.
  9. Author:
  10. Mohit Talwar (mohitt) Fri Apr 20 12:05:23 2001
  11. --*/
  12. #include "pcheapol.h"
  13. #pragma hdrstop
  14. //
  15. // Ip6RenewInterface
  16. //
  17. // Description:
  18. //
  19. // Function called from within FSMAutheticated i.e. once authentication
  20. // has completed successfully. The IPv6 stack is instructed to restart
  21. // its protocol mechanism on the indicated interface.
  22. //
  23. // Arguments:
  24. // pwszInterface - Adapter name (GUID identifying the interface).
  25. //
  26. // Return values:
  27. // NO_ERROR on success, Error code o/w.
  28. //
  29. DWORD
  30. Ip6RenewInterface (
  31. IN WCHAR *pwszInterface
  32. )
  33. {
  34. HANDLE hIp6Device;
  35. IPV6_QUERY_INTERFACE Query;
  36. UINT BytesReturned;
  37. DWORD dwError = NO_ERROR;
  38. do
  39. {
  40. // We could make the hIp6Device handle a global/static variable.
  41. // The first successful call to CreateFileW in Ip6RenewInterface
  42. // would initialize it with a handle to the IPv6 Device. This would
  43. // be used for all subsequent DeviceIoControl requests.
  44. //
  45. // Since this function is not called in a thread safe environment,
  46. // we would need to perform an InterlockedCompareExchange after
  47. // calling CreateFileW. This is needed to ensure that no handles
  48. // are leaked. Also, since this service would have an open handle
  49. // to tcpip6.sys, we would not be able to unload that driver.
  50. //
  51. // For now, however, we keep things simple and open and close this
  52. // handle every time Ip6RenewInterface is called.
  53. hIp6Device = CreateFileW(
  54. WIN_IPV6_DEVICE_NAME,
  55. GENERIC_WRITE, // requires administrator privileges
  56. FILE_SHARE_READ | FILE_SHARE_WRITE,
  57. NULL, // security attributes
  58. OPEN_EXISTING,
  59. 0, // flags & attributes
  60. NULL); // template file
  61. if (hIp6Device == INVALID_HANDLE_VALUE)
  62. {
  63. dwError = GetLastError();
  64. TRACE1 (ANY, "Ip6RenewInterface: CreateFileW failed with error %ld",
  65. dwError);
  66. break;
  67. }
  68. // Pretend as though the interface was reconnected. This causes
  69. // IPv6 to resend Router Solicitation|Advertisement, Multicast
  70. // Listener Discovery, and Duplicate Address Detection messages.
  71. Query.Index = 0;
  72. if ((dwError = ElGuidFromString (&(Query.Guid), pwszInterface)) != NO_ERROR)
  73. {
  74. TRACE1 (ANY, "Ip6RenewInterface: ElGuidFromString failed with error %ld",
  75. dwError);
  76. break;
  77. }
  78. if (!DeviceIoControl(
  79. hIp6Device,
  80. IOCTL_IPV6_RENEW_INTERFACE,
  81. &Query,
  82. sizeof Query,
  83. NULL,
  84. 0,
  85. &BytesReturned,
  86. NULL))
  87. {
  88. dwError = GetLastError();
  89. TRACE1 (ANY, "Ip6RenewInterface: DeviceIoControl failed with error %ld",
  90. dwError);
  91. break;
  92. }
  93. }
  94. while (FALSE);
  95. if (hIp6Device != INVALID_HANDLE_VALUE)
  96. {
  97. CloseHandle(hIp6Device);
  98. }
  99. return dwError;
  100. }