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.

456 lines
11 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 "dimsvcp.h"
  13. #define DIM_VALNAME_INTERFACE TEXT("InterfaceInfo")
  14. #define DIM_VALNAME_GLOBALINFO TEXT("GlobalInfo")
  15. //**
  16. //
  17. // Call: DIMConnectInterface
  18. //
  19. // Returns: NO_ERROR - Already connected
  20. // PENDING - Connection initiated successfully
  21. // error code - Connection initiation failure
  22. //
  23. // Description: Called by a router manager to intiate a connection.
  24. //
  25. DWORD
  26. DIMConnectInterface(
  27. IN HANDLE hDIMInterface,
  28. IN DWORD dwProtocolId
  29. )
  30. {
  31. if ( ( gblDIMConfigInfo.ServiceStatus.dwCurrentState != SERVICE_RUNNING )
  32. ||
  33. ( !( gbldwDIMComponentsLoaded & DIM_DDM_LOADED ) ) )
  34. {
  35. return( ERROR_DDM_NOT_RUNNING );
  36. }
  37. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  38. {
  39. return( ERROR_DDM_NOT_RUNNING );
  40. }
  41. else
  42. {
  43. DWORD (*DDMConnectInterface)( HANDLE, DWORD ) =
  44. (DWORD(*)( HANDLE, DWORD ))GetDDMEntryPoint("DDMConnectInterface");
  45. if(NULL == DDMConnectInterface)
  46. {
  47. return ERROR_PROC_NOT_FOUND;
  48. }
  49. return( DDMConnectInterface( hDIMInterface, dwProtocolId ) );
  50. }
  51. }
  52. //**
  53. //
  54. // Call: DIMDisconnectInterface
  55. //
  56. // Returns: NO_ERROR - Already disconnected
  57. // PENDING - Disconnection initiated successfully
  58. // error code - Disconnection initiation failure
  59. //
  60. // Description: Called by a router manager to intiate a disconnection.
  61. //
  62. DWORD
  63. DIMDisconnectInterface(
  64. IN HANDLE hDIMInterface,
  65. IN DWORD dwProtocolId
  66. )
  67. {
  68. if ( gblDIMConfigInfo.ServiceStatus.dwCurrentState != SERVICE_RUNNING )
  69. {
  70. return( ERROR_DDM_NOT_RUNNING );
  71. }
  72. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  73. {
  74. return( ERROR_DDM_NOT_RUNNING );
  75. }
  76. else
  77. {
  78. DWORD (*DDMDisconnectInterface)( HANDLE, DWORD ) =
  79. (DWORD(*)(HANDLE,DWORD ))GetDDMEntryPoint("DDMDisconnectInterface");
  80. if(NULL == DDMDisconnectInterface)
  81. {
  82. return ERROR_PROC_NOT_FOUND;
  83. }
  84. return( DDMDisconnectInterface( hDIMInterface, dwProtocolId ) );
  85. }
  86. }
  87. //**
  88. //
  89. // Call: DIMSaveInterfaceInfo
  90. //
  91. // Returns: none
  92. //
  93. // Description: This call will make DIM store the interface information
  94. // into the registry.
  95. //
  96. DWORD
  97. DIMSaveInterfaceInfo(
  98. IN HANDLE hDIMInterface,
  99. IN DWORD dwProtocolId,
  100. IN LPVOID pInterfaceInfo,
  101. IN DWORD cbInterfaceInfoSize
  102. )
  103. {
  104. HKEY hKey = NULL;
  105. DWORD dwRetCode = NO_ERROR;
  106. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  107. if ((gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOP_PENDING)
  108. ||
  109. (gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOPPED) )
  110. {
  111. return( ERROR_DDM_NOT_RUNNING );
  112. }
  113. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  114. do
  115. {
  116. if ( ( pIfObject = IfObjectGetPointer( hDIMInterface ) ) == NULL )
  117. {
  118. dwRetCode = ERROR_INVALID_HANDLE;
  119. break;
  120. }
  121. dwRetCode = RegOpenAppropriateKey( pIfObject->lpwsInterfaceName,
  122. dwProtocolId,
  123. &hKey);
  124. if ( dwRetCode != NO_ERROR )
  125. {
  126. break;
  127. }
  128. dwRetCode = RegSetValueEx(
  129. hKey,
  130. DIM_VALNAME_INTERFACE,
  131. 0,
  132. REG_BINARY,
  133. pInterfaceInfo,
  134. cbInterfaceInfoSize );
  135. } while( FALSE );
  136. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  137. if ( hKey != NULL )
  138. {
  139. RegCloseKey( hKey );
  140. }
  141. return( dwRetCode );
  142. }
  143. //**
  144. //
  145. // Call: DIMRestoreInterfaceInfo
  146. //
  147. // Returns: none
  148. //
  149. // Description: This will make DIM get interface information from the registry
  150. //
  151. DWORD
  152. DIMRestoreInterfaceInfo(
  153. IN HANDLE hDIMInterface,
  154. IN DWORD dwProtocolId,
  155. IN LPVOID lpInterfaceInfo,
  156. IN LPDWORD lpcbInterfaceInfoSize
  157. )
  158. {
  159. DWORD dwType;
  160. HKEY hKey = NULL;
  161. DWORD dwRetCode = NO_ERROR;
  162. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  163. if ((gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOP_PENDING)
  164. ||
  165. (gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOPPED) )
  166. {
  167. return( ERROR_DDM_NOT_RUNNING );
  168. }
  169. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  170. do
  171. {
  172. if ( ( pIfObject = IfObjectGetPointer( hDIMInterface ) ) == NULL )
  173. {
  174. dwRetCode = ERROR_INVALID_HANDLE;
  175. break;
  176. }
  177. dwRetCode = RegOpenAppropriateKey( pIfObject->lpwsInterfaceName,
  178. dwProtocolId,
  179. &hKey);
  180. if ( dwRetCode != NO_ERROR )
  181. {
  182. break;
  183. }
  184. dwRetCode = RegQueryValueEx(
  185. hKey,
  186. DIM_VALNAME_INTERFACE,
  187. 0,
  188. &dwType,
  189. lpInterfaceInfo,
  190. lpcbInterfaceInfoSize );
  191. } while( FALSE );
  192. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  193. if ( hKey != NULL )
  194. {
  195. RegCloseKey( hKey );
  196. }
  197. if ( dwRetCode != NO_ERROR )
  198. {
  199. return( dwRetCode );
  200. }
  201. else if ( lpInterfaceInfo == NULL )
  202. {
  203. return( ERROR_BUFFER_TOO_SMALL );
  204. }
  205. else
  206. {
  207. return( NO_ERROR );
  208. }
  209. }
  210. //**
  211. //
  212. // Call: DIMSaveGlobalInfo
  213. //
  214. // Returns: none
  215. //
  216. // Description: This call will make DIM store the Global information
  217. // into the registry.
  218. //
  219. DWORD
  220. DIMSaveGlobalInfo(
  221. IN DWORD dwProtocolId,
  222. IN LPVOID pGlobalInfo,
  223. IN DWORD cbGlobalInfoSize
  224. )
  225. {
  226. HKEY hKey = NULL;
  227. DWORD dwRetCode = NO_ERROR;
  228. if ((gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOP_PENDING)
  229. ||
  230. (gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOPPED) )
  231. {
  232. return( ERROR_DDM_NOT_RUNNING );
  233. }
  234. do
  235. {
  236. dwRetCode = RegOpenAppropriateRMKey(dwProtocolId, &hKey);
  237. if ( dwRetCode != NO_ERROR )
  238. {
  239. break;
  240. }
  241. dwRetCode = RegSetValueEx(
  242. hKey,
  243. DIM_VALNAME_GLOBALINFO,
  244. 0,
  245. REG_BINARY,
  246. pGlobalInfo,
  247. cbGlobalInfoSize );
  248. } while( FALSE );
  249. if ( hKey != NULL )
  250. {
  251. RegCloseKey( hKey );
  252. }
  253. return( dwRetCode );
  254. }
  255. //**
  256. //
  257. // Call: DIMRouterStopped
  258. //
  259. // Returns: None
  260. //
  261. // Description: If the Router failed to start or stopped due to an error,
  262. // This call should be called with the dwError value set to
  263. // something other than NO_ERROR
  264. //
  265. VOID
  266. DIMRouterStopped(
  267. IN DWORD dwProtocolId,
  268. IN DWORD dwError
  269. )
  270. {
  271. DWORD dwTransportIndex = GetTransportIndex(dwProtocolId);
  272. RTASSERT( dwTransportIndex != (DWORD)-1 );
  273. gblRouterManagers[dwTransportIndex].fIsRunning = FALSE;
  274. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  275. "DIMRouterStopped called by protocol 0x%x", dwProtocolId );
  276. SetEvent( gblhEventRMState );
  277. }
  278. //**
  279. //
  280. // Call: DimUnloadRouterManagers
  281. //
  282. // Returns: none
  283. //
  284. // Description: Will block until all the router managers have unloaded
  285. //
  286. VOID
  287. DimUnloadRouterManagers(
  288. VOID
  289. )
  290. {
  291. DWORD dwIndex;
  292. DWORD dwRetCode;
  293. BOOL fAllRouterManagersStopped;
  294. if ( gblRouterManagers == NULL )
  295. {
  296. return;
  297. }
  298. for ( dwIndex = 0;
  299. dwIndex < gblDIMConfigInfo.dwNumRouterManagers;
  300. dwIndex++ )
  301. {
  302. if ( gblRouterManagers[dwIndex].fIsRunning )
  303. {
  304. dwRetCode = gblRouterManagers[dwIndex].DdmRouterIf.StopRouter();
  305. if ( ( dwRetCode != NO_ERROR ) && ( dwRetCode != PENDING ) )
  306. {
  307. gblRouterManagers[dwIndex].fIsRunning = FALSE;
  308. }
  309. }
  310. }
  311. do
  312. {
  313. fAllRouterManagersStopped = TRUE;
  314. for ( dwIndex = 0;
  315. dwIndex < gblDIMConfigInfo.dwNumRouterManagers;
  316. dwIndex++ )
  317. {
  318. if ( gblRouterManagers[dwIndex].fIsRunning == TRUE )
  319. {
  320. fAllRouterManagersStopped = FALSE;
  321. }
  322. }
  323. if ( fAllRouterManagersStopped )
  324. {
  325. TracePrintfExA(gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  326. "DimUnloadRouterManagers: fAllRouterManagersStopped");
  327. break;
  328. }
  329. WaitForSingleObject( gblhEventRMState, INFINITE );
  330. }while(TRUE);
  331. for ( dwIndex = 0;
  332. dwIndex < gblDIMConfigInfo.dwNumRouterManagers;
  333. dwIndex++ )
  334. {
  335. if ( gblRouterManagers[dwIndex].hModule != NULL )
  336. {
  337. FreeLibrary( gblRouterManagers[dwIndex].hModule );
  338. }
  339. }
  340. LOCAL_FREE( gblRouterManagers );
  341. gblRouterManagers = NULL;
  342. }
  343. //**
  344. //
  345. // Call: DIMInterfaceEnabled
  346. //
  347. // Returns: none
  348. //
  349. // Description: This will set the state of a certain transport for the interface
  350. //
  351. DWORD
  352. DIMInterfaceEnabled(
  353. IN HANDLE hDIMInterface,
  354. IN DWORD dwProtocolId,
  355. IN BOOL fEnabled
  356. )
  357. {
  358. DWORD dwRetCode = NO_ERROR;
  359. ROUTER_INTERFACE_OBJECT* pIfObject = NULL;
  360. DWORD dwTransportIndex = GetTransportIndex(dwProtocolId);
  361. if ((gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOP_PENDING)
  362. ||
  363. (gblDIMConfigInfo.ServiceStatus.dwCurrentState==SERVICE_STOPPED) )
  364. {
  365. return( ERROR_DDM_NOT_RUNNING );
  366. }
  367. RTASSERT( dwTransportIndex != (DWORD)-1 );
  368. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  369. do
  370. {
  371. if ( ( pIfObject = IfObjectGetPointer( hDIMInterface ) ) == NULL )
  372. {
  373. dwRetCode = ERROR_INVALID_HANDLE;
  374. break;
  375. }
  376. if ( fEnabled )
  377. {
  378. pIfObject->Transport[dwTransportIndex].fState|=RITRANSPORT_ENABLED;
  379. }
  380. else
  381. {
  382. pIfObject->Transport[dwTransportIndex].fState&=~RITRANSPORT_ENABLED;
  383. }
  384. } while( FALSE );
  385. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  386. return( dwRetCode );
  387. }