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.

355 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. intrface.c
  5. Abstract:
  6. Provides interface for managing cluster netinterfaces
  7. Author:
  8. John Vert (jvert) 30-Jan-1996
  9. Charlie Wickham (charlwi) 5-Jun-1997
  10. Rod Gamache (rodga) 9-Jun-1997
  11. Revision History:
  12. copied from network.c
  13. --*/
  14. #include "clusapip.h"
  15. HNETINTERFACE
  16. WINAPI
  17. OpenClusterNetInterface(
  18. IN HCLUSTER hCluster,
  19. IN LPCWSTR lpszInterfaceName
  20. )
  21. /*++
  22. Routine Description:
  23. Opens a handle to the specified network interface
  24. Arguments:
  25. hCluster - Supplies a handle to the cluster
  26. lpszInterfaceName - Supplies the name of the netinterface to be opened
  27. Return Value:
  28. non-NULL - returns an open handle to the specified netinterface.
  29. NULL - The operation failed. Extended error status is available
  30. using GetLastError()
  31. --*/
  32. {
  33. PCLUSTER Cluster;
  34. PCNETINTERFACE NetInterface;
  35. error_status_t Status = ERROR_SUCCESS;
  36. //
  37. // get a pointer to the cluster struct, allocate space for the netinterface
  38. // structure and the supplied name.
  39. //
  40. Cluster = (PCLUSTER)hCluster;
  41. NetInterface = LocalAlloc(LMEM_FIXED, sizeof(CNETINTERFACE));
  42. if (NetInterface == NULL) {
  43. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  44. return(NULL);
  45. }
  46. NetInterface->Name = LocalAlloc(LMEM_FIXED, (lstrlenW(lpszInterfaceName)+1)*sizeof(WCHAR));
  47. if (NetInterface->Name == NULL) {
  48. LocalFree(NetInterface);
  49. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  50. return(NULL);
  51. }
  52. //
  53. // init the netinterface struct and call clussvc to open the netinterface
  54. //
  55. lstrcpyW(NetInterface->Name, lpszInterfaceName);
  56. NetInterface->Cluster = Cluster;
  57. InitializeListHead(&NetInterface->NotifyList);
  58. WRAP_NULL(NetInterface->hNetInterface,
  59. (ApiOpenNetInterface(Cluster->RpcBinding,
  60. lpszInterfaceName,
  61. &Status)),
  62. &Status,
  63. Cluster);
  64. if ((NetInterface->hNetInterface == NULL) || (Status != ERROR_SUCCESS)) {
  65. LocalFree(NetInterface->Name);
  66. LocalFree(NetInterface);
  67. SetLastError(Status);
  68. return(NULL);
  69. }
  70. //
  71. // Link newly opened netinterface onto the cluster structure.
  72. //
  73. EnterCriticalSection(&Cluster->Lock);
  74. InsertHeadList(&Cluster->NetInterfaceList, &NetInterface->ListEntry);
  75. LeaveCriticalSection(&Cluster->Lock);
  76. return ((HNETINTERFACE)NetInterface);
  77. }
  78. BOOL
  79. WINAPI
  80. CloseClusterNetInterface(
  81. IN HNETINTERFACE hNetInterface
  82. )
  83. /*++
  84. Routine Description:
  85. Closes a network interface handle returned from OpenClusterNetInterface
  86. Arguments:
  87. hNetInterface - Supplies the netinterface handle
  88. Return Value:
  89. TRUE - The operation was successful.
  90. FALSE - The operation failed. Extended error status is available
  91. using GetLastError()
  92. --*/
  93. {
  94. PCNETINTERFACE NetInterface;
  95. PCLUSTER Cluster;
  96. NetInterface = (PCNETINTERFACE)hNetInterface;
  97. Cluster = (PCLUSTER)NetInterface->Cluster;
  98. //
  99. // Unlink netinterface from cluster list.
  100. //
  101. EnterCriticalSection(&Cluster->Lock);
  102. RemoveEntryList(&NetInterface->ListEntry);
  103. //
  104. // Remove any notifications posted against this netinterface.
  105. //
  106. RundownNotifyEvents(&NetInterface->NotifyList, NetInterface->Name);
  107. //if the cluster is dead and the reconnect has failed,
  108. //the group->hnetinterface might be NULL if s_apiopennetinterface for
  109. //this group failed on a reconnect
  110. //the cluster may be dead and hinterface may be non null, say
  111. //if reconnectnetinterfaces succeeded but say the reconnect networks
  112. //failed
  113. // At reconnect, the old context is saved in the obsolete
  114. // list for deletion when the cluster handle is closed or when
  115. // the next call is made
  116. if ((Cluster->Flags & CLUS_DEAD) && (NetInterface->hNetInterface))
  117. {
  118. RpcSmDestroyClientContext(&NetInterface->hNetInterface);
  119. LeaveCriticalSection(&Cluster->Lock);
  120. goto FnExit;
  121. }
  122. LeaveCriticalSection(&Cluster->Lock);
  123. //
  124. // Close RPC context handle
  125. //
  126. ApiCloseNetInterface(&NetInterface->hNetInterface);
  127. FnExit:
  128. //
  129. // Free memory allocations
  130. //
  131. LocalFree(NetInterface->Name);
  132. LocalFree(NetInterface);
  133. //
  134. // Give the cluster a chance to clean up in case this
  135. // netinterface was the only thing keeping it around.
  136. //
  137. CleanupCluster(Cluster);
  138. return(TRUE);
  139. }
  140. CLUSTER_NETINTERFACE_STATE
  141. WINAPI
  142. GetClusterNetInterfaceState(
  143. IN HNETINTERFACE hNetInterface
  144. )
  145. /*++
  146. Routine Description:
  147. Returns the network interface's current state
  148. Arguments:
  149. hNetInterface - Supplies a handle to a cluster netinterface
  150. Return Value:
  151. Returns the current state of the network interface.
  152. If the function fails, the return value is -1. Extended error
  153. status is available using GetLastError()
  154. --*/
  155. {
  156. PCNETINTERFACE NetInterface;
  157. CLUSTER_NETINTERFACE_STATE State;
  158. DWORD Status;
  159. NetInterface = (PCNETINTERFACE)hNetInterface;
  160. WRAP(Status,
  161. (ApiGetNetInterfaceState( NetInterface->hNetInterface,
  162. (LPDWORD)&State )), // cast for win64 warning
  163. NetInterface->Cluster);
  164. if (Status == ERROR_SUCCESS) {
  165. return(State);
  166. } else {
  167. SetLastError(Status);
  168. return( ClusterNetInterfaceStateUnknown );
  169. }
  170. }
  171. DWORD
  172. WINAPI
  173. GetClusterNetInterface(
  174. IN HCLUSTER hCluster,
  175. IN LPCWSTR lpszNodeName,
  176. IN LPCWSTR lpszNetworkName,
  177. OUT LPWSTR lpszInterfaceName,
  178. IN OUT LPDWORD lpcchInterfaceName
  179. )
  180. /*++
  181. Routine Description:
  182. Gets the name of a node's interface to a network in the cluster.
  183. Arguments:
  184. hCluster - Supplies a handle to the cluster
  185. lpszNodeName - Supplies the node name of the node in the cluster
  186. lpszNetworkName - Supplies the name of the cluster network
  187. lpszInterfaceName - Returns the name of the network interface
  188. lpcchInterfaceName - Points to a variable that specifies the size, in
  189. characters, of the buffer pointed to by the lpszInterfaceName
  190. parameter. This size should include the terminating null
  191. character. When the function returns, the variable pointed to
  192. by lpcchInterfaceName contains the number of characters that
  193. would be stored in the buffer if it were large enough. The count
  194. returned does not include the terminating null character.
  195. Return Value:
  196. If the function succeeds, the return value is ERROR_SUCCESS.
  197. If the function fails, the return value is an error value.
  198. --*/
  199. {
  200. DWORD Status;
  201. DWORD Length;
  202. PCLUSTER Cluster;
  203. LPWSTR Name = NULL;
  204. Cluster = GET_CLUSTER(hCluster);
  205. WRAP(Status,
  206. (ApiGetNetInterface(Cluster->RpcBinding,
  207. lpszNodeName,
  208. lpszNetworkName,
  209. &Name)),
  210. Cluster);
  211. if (Status != ERROR_SUCCESS) {
  212. return(Status);
  213. }
  214. MylstrcpynW(lpszInterfaceName, Name, *lpcchInterfaceName);
  215. Length = lstrlenW(Name);
  216. if (*lpcchInterfaceName < (Length + 1)) {
  217. if (lpszInterfaceName == NULL) {
  218. Status = ERROR_SUCCESS;
  219. } else {
  220. Status = ERROR_MORE_DATA;
  221. }
  222. }
  223. *lpcchInterfaceName = Length;
  224. MIDL_user_free(Name);
  225. return(Status);
  226. }
  227. HCLUSTER
  228. WINAPI
  229. GetClusterFromNetInterface(
  230. IN HNETINTERFACE hNetInterface
  231. )
  232. /*++
  233. Routine Description:
  234. Returns the cluster handle from the associated network interface handle.
  235. Arguments:
  236. hNetInterface - Supplies the network interface.
  237. Return Value:
  238. Handle to the cluster associated with the network interface handle.
  239. --*/
  240. {
  241. DWORD nStatus;
  242. PCNETINTERFACE NetInterface = (PCNETINTERFACE)hNetInterface;
  243. HCLUSTER hCluster = (HCLUSTER)NetInterface->Cluster;
  244. nStatus = AddRefToClusterHandle( hCluster );
  245. if ( nStatus != ERROR_SUCCESS ) {
  246. SetLastError( nStatus );
  247. hCluster = NULL;
  248. }
  249. return( hCluster );
  250. } // GetClusterFromNetInterface()