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.

296 lines
8.7 KiB

  1. /*********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /*********************************************************************/
  4. //***
  5. //
  6. // Filename: routerif.c
  7. //
  8. // Description: Handles calls to/from the router managers.
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include "util.h"
  14. #include "objects.h"
  15. #include "routerif.h"
  16. #include "rasapiif.h"
  17. //**
  18. //
  19. // Call: DDMConnectInterface
  20. //
  21. // Returns: NO_ERROR - Already connected
  22. // PENDING - Connection initiated successfully
  23. // error code - Connection initiation failure
  24. //
  25. // Description: Called by a router manager to intiate a connection.
  26. //
  27. DWORD
  28. DDMConnectInterface(
  29. IN HANDLE hDDMInterface,
  30. IN DWORD dwProtocolId
  31. )
  32. {
  33. DWORD dwRetCode = NO_ERROR;
  34. ROUTER_INTERFACE_OBJECT * pIfObject;
  35. DWORD dwTransportIndex=GetTransportIndex(dwProtocolId);
  36. RTASSERT( dwTransportIndex != (DWORD)-1 );
  37. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  38. do
  39. {
  40. pIfObject = IfObjectGetPointer( hDDMInterface );
  41. if ( pIfObject == (ROUTER_INTERFACE_OBJECT *)NULL )
  42. {
  43. dwRetCode = ERROR_INVALID_HANDLE;
  44. break;
  45. }
  46. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  47. "DDMConnectInterface:Called by protocol=0x%x,State=%d,Interface=%ws",
  48. dwProtocolId, pIfObject->State, pIfObject->lpwsInterfaceName );
  49. switch( pIfObject->State )
  50. {
  51. case RISTATE_CONNECTED:
  52. if ( pIfObject->Transport[dwTransportIndex].fState &
  53. RITRANSPORT_CONNECTED )
  54. {
  55. dwRetCode = ERROR_ALREADY_CONNECTED;
  56. }
  57. else
  58. {
  59. dwRetCode = ERROR_PROTOCOL_NOT_CONFIGURED;
  60. }
  61. break;
  62. case RISTATE_CONNECTING:
  63. dwRetCode = PENDING;
  64. break;
  65. case RISTATE_DISCONNECTED:
  66. //
  67. // Initiate a connection
  68. //
  69. dwRetCode = RasConnectionInitiate( pIfObject, FALSE );
  70. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  71. "RasConnectionInitiate: To %ws dwRetCode=%d",
  72. pIfObject->lpwsInterfaceName, dwRetCode );
  73. if ( dwRetCode == NO_ERROR )
  74. {
  75. dwRetCode = PENDING;
  76. }
  77. else
  78. {
  79. LPWSTR lpwsAudit[1];
  80. lpwsAudit[0] = pIfObject->lpwsInterfaceName;
  81. DDMLogErrorString( ROUTERLOG_CONNECTION_FAILURE,
  82. 1, lpwsAudit, dwRetCode, 1 );
  83. }
  84. break;
  85. }
  86. } while( FALSE );
  87. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  88. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  89. "DDMConnectInterface: dwRetCode=%d", dwRetCode );
  90. return( dwRetCode );
  91. }
  92. //**
  93. //
  94. // Call: DDMDisconnectInterface
  95. //
  96. // Returns: NO_ERROR - Already disconnected
  97. // PENDING - Disconnection initiated successfully
  98. // error code - Disconnection initiation failure
  99. //
  100. // Description: Called by a router manager to intiate a disconnection.
  101. //
  102. DWORD
  103. DDMDisconnectInterface(
  104. IN HANDLE hDDMInterface,
  105. IN DWORD dwProtocolId
  106. )
  107. {
  108. DWORD dwRetCode = NO_ERROR;
  109. ROUTER_INTERFACE_OBJECT * pIfObject;
  110. HCONN hConnection;
  111. DWORD dwTransportIndex=GetTransportIndex(dwProtocolId);
  112. PCONNECTION_OBJECT pConnObj;
  113. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  114. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  115. do
  116. {
  117. pIfObject = IfObjectGetPointer( hDDMInterface );
  118. if ( pIfObject == (ROUTER_INTERFACE_OBJECT *)NULL )
  119. {
  120. dwRetCode = ERROR_INVALID_HANDLE;
  121. break;
  122. }
  123. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  124. "DDMDisconnectInterface:Called by protocol=0x%x,State=%d,Interface=%ws",
  125. dwProtocolId, pIfObject->State, pIfObject->lpwsInterfaceName );
  126. if ( dwTransportIndex != -1 )
  127. {
  128. pIfObject->Transport[dwTransportIndex].fState &=
  129. ~RITRANSPORT_CONNECTED;
  130. }
  131. switch( pIfObject->State )
  132. {
  133. case RISTATE_DISCONNECTED:
  134. //
  135. // Already disconnected
  136. //
  137. dwRetCode = NO_ERROR;
  138. break;
  139. case RISTATE_CONNECTING:
  140. //
  141. // Disconnect only if all transports are disconnected
  142. //
  143. if ( !IfObjectAreAllTransportsDisconnected( pIfObject ) )
  144. {
  145. break;
  146. }
  147. //
  148. // Abort locally initiated connections
  149. //
  150. if ( pIfObject->fFlags & IFFLAG_LOCALLY_INITIATED )
  151. {
  152. pIfObject->fFlags |= IFFLAG_DISCONNECT_INITIATED;
  153. if ( pIfObject->hRasConn != (HRASCONN)NULL )
  154. {
  155. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  156. "DDMDisconnectInterface: %d hanging up 0x%x",
  157. __LINE__,
  158. pIfObject->hRasConn);
  159. RasHangUp( pIfObject->hRasConn );
  160. }
  161. IfObjectDisconnected( pIfObject );
  162. //
  163. // We need to notify router managers that the connection has
  164. // failed since the administrator has cancelled the connection
  165. // while in connecting state. This is usually called in the
  166. // RasConnectCallback routine, but we my not be actually
  167. // connecting at this time so we cannot rely on the callback
  168. // to do this.
  169. //
  170. IfObjectNotifyOfReachabilityChange(
  171. pIfObject,
  172. FALSE,
  173. INTERFACE_CONNECTION_FAILURE );
  174. //
  175. // Immediately go back to reachable state since it was the
  176. // admin that disconnected the line
  177. //
  178. IfObjectNotifyOfReachabilityChange(
  179. pIfObject,
  180. TRUE,
  181. INTERFACE_CONNECTION_FAILURE );
  182. }
  183. else
  184. {
  185. //
  186. // Not yet connected, we do not support abort
  187. //
  188. dwRetCode = ERROR_INTERFACE_NOT_CONNECTED;
  189. }
  190. break;
  191. case RISTATE_CONNECTED:
  192. //
  193. // Initiate a disconnection if all other routers are disconnected
  194. //
  195. if ( !IfObjectAreAllTransportsDisconnected( pIfObject ) )
  196. {
  197. break;
  198. }
  199. if ( pIfObject->fFlags & IFFLAG_LOCALLY_INITIATED )
  200. {
  201. pIfObject->fFlags |= IFFLAG_DISCONNECT_INITIATED;
  202. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  203. "DDMDisconnectInterface: %d disconnecting 0x%x",
  204. __LINE__, pIfObject->hRasConn);
  205. RasHangUp( pIfObject->hRasConn );
  206. }
  207. pConnObj = ConnObjGetPointer( pIfObject->hConnection );
  208. if ( pConnObj != (PCONNECTION_OBJECT)NULL )
  209. {
  210. if((pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED) &&
  211. (pIfObject->fFlags & IFFLAG_LOCALLY_INITIATED))
  212. {
  213. pConnObj->fFlags |= CONN_OBJ_DISCONNECT_INITIATED;
  214. }
  215. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  216. "DDMDisconnectInterface: disconnecting connobj");
  217. ConnObjDisconnect( pConnObj );
  218. }
  219. break;
  220. }
  221. } while( FALSE );
  222. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  223. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  224. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  225. "DDMDisconnectInterface: dwRetCode=%d", dwRetCode );
  226. return( dwRetCode );
  227. }