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.

816 lines
18 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. qosmapi.c
  5. Abstract:
  6. The file contains IP router manager API
  7. implementations for the Qos Mgr.
  8. Revision History:
  9. --*/
  10. #include "pchqosm.h"
  11. #pragma hdrstop
  12. DWORD
  13. APIENTRY
  14. RegisterProtocol(
  15. IN OUT PMPR_ROUTING_CHARACTERISTICS RoutingChar,
  16. IN OUT PMPR_SERVICE_CHARACTERISTICS ServiceChar
  17. )
  18. /*++
  19. Routine Description:
  20. Initializes some global data structures in Qos Mgr.
  21. We initialize some variables here instead of in
  22. QosmDllStartup as it might not be safe to perform
  23. some operations in the context of DLL's DLLMain.
  24. We also export the appropriate callbacks to RM.
  25. This function is called when RM loads the protocol.
  26. Arguments:
  27. None
  28. Return Value:
  29. Status of the operation
  30. --*/
  31. {
  32. if(RoutingChar->dwProtocolId != MS_IP_QOSMGR)
  33. {
  34. return ERROR_NOT_SUPPORTED;
  35. }
  36. if ((RoutingChar->fSupportedFunctionality
  37. & (RF_ROUTING|RF_DEMAND_UPDATE_ROUTES)) !=
  38. (RF_ROUTING|RF_DEMAND_UPDATE_ROUTES))
  39. {
  40. return ERROR_NOT_SUPPORTED;
  41. }
  42. RoutingChar->fSupportedFunctionality =
  43. (RF_ROUTING | RF_DEMAND_UPDATE_ROUTES);
  44. //
  45. // Since we are not a service advertiser (and IPX thing)
  46. //
  47. ServiceChar->fSupportedFunctionality = 0;
  48. RoutingChar->pfnStartProtocol = StartProtocol;
  49. RoutingChar->pfnStartComplete = StartComplete;
  50. RoutingChar->pfnStopProtocol = StopProtocol;
  51. RoutingChar->pfnGetGlobalInfo = GetGlobalInfo;
  52. RoutingChar->pfnSetGlobalInfo = SetGlobalInfo;
  53. RoutingChar->pfnQueryPower = NULL;
  54. RoutingChar->pfnSetPower = NULL;
  55. RoutingChar->pfnAddInterface = AddInterface;
  56. RoutingChar->pfnDeleteInterface = DeleteInterface;
  57. RoutingChar->pfnInterfaceStatus = InterfaceStatus;
  58. RoutingChar->pfnGetInterfaceInfo = GetInterfaceInfo;
  59. RoutingChar->pfnSetInterfaceInfo = SetInterfaceInfo;
  60. RoutingChar->pfnGetEventMessage = GetEventMessage;
  61. RoutingChar->pfnUpdateRoutes = UpdateRoutes;
  62. RoutingChar->pfnConnectClient = NULL;
  63. RoutingChar->pfnDisconnectClient = NULL;
  64. RoutingChar->pfnGetNeighbors = NULL;
  65. RoutingChar->pfnGetMfeStatus = NULL;
  66. RoutingChar->pfnMibCreateEntry = MibCreateEntry;
  67. RoutingChar->pfnMibDeleteEntry = MibDeleteEntry;
  68. RoutingChar->pfnMibGetEntry = MibGetEntry;
  69. RoutingChar->pfnMibSetEntry = MibSetEntry;
  70. RoutingChar->pfnMibGetFirstEntry = MibGetFirstEntry;
  71. RoutingChar->pfnMibGetNextEntry = MibGetNextEntry;
  72. RoutingChar->pfnMibSetTrapInfo = MibSetTrapInfo;
  73. RoutingChar->pfnMibGetTrapInfo = MibGetTrapInfo;
  74. return NO_ERROR;
  75. }
  76. DWORD
  77. WINAPI
  78. StartProtocol (
  79. IN HANDLE NotificationEvent,
  80. IN PSUPPORT_FUNCTIONS SupportFunctions,
  81. IN LPVOID GlobalInfo,
  82. IN ULONG InfoVer,
  83. IN ULONG InfoSize,
  84. IN ULONG InfoCnt
  85. )
  86. {
  87. PIPQOS_GLOBAL_CONFIG GlobalConfig;
  88. DWORD Status;
  89. UNREFERENCED_PARAMETER(InfoVer);
  90. UNREFERENCED_PARAMETER(InfoCnt);
  91. TraceEnter("StartProtocol");
  92. GlobalConfig = (IPQOS_GLOBAL_CONFIG *) GlobalInfo;
  93. do
  94. {
  95. //
  96. // Copy RM support functions to global var
  97. //
  98. Globals.SupportFunctions = *SupportFunctions;
  99. //
  100. // First update your global configuration
  101. //
  102. Status = QosmSetGlobalInfo(GlobalConfig,
  103. InfoSize);
  104. if (Status != NO_ERROR)
  105. {
  106. break;
  107. }
  108. //
  109. // Update state to "initialization done"
  110. //
  111. Globals.State = IPQOSMGR_STATE_RUNNING;
  112. }
  113. while (FALSE);
  114. TraceLeave("StartProtocol");
  115. return Status;
  116. }
  117. DWORD
  118. WINAPI
  119. StartComplete (
  120. VOID
  121. )
  122. {
  123. TraceEnter("StartComplete");
  124. TraceLeave("StartComplete");
  125. return NO_ERROR;
  126. }
  127. DWORD
  128. WINAPI
  129. StopProtocol (
  130. VOID
  131. )
  132. {
  133. TraceEnter("StopProtocol");
  134. TraceLeave("StopProtocol");
  135. return NO_ERROR;
  136. }
  137. DWORD
  138. WINAPI
  139. GetGlobalInfo (
  140. IN PVOID GlobalInfo,
  141. IN OUT PULONG BufferSize,
  142. OUT PULONG InfoVer,
  143. OUT PULONG InfoSize,
  144. OUT PULONG InfoCnt
  145. )
  146. {
  147. DWORD Status;
  148. UNREFERENCED_PARAMETER(InfoVer);
  149. UNREFERENCED_PARAMETER(InfoCnt);
  150. #if 1
  151. *InfoVer = *InfoCnt = 1;
  152. #endif
  153. Trace2(ENTER, "GetGlobalInfo: Info: %p, Size: %08x",
  154. GlobalInfo,
  155. BufferSize);
  156. Status = QosmGetGlobalInfo(GlobalInfo,
  157. BufferSize,
  158. InfoSize);
  159. Trace1(LEAVE, "GetGlobalInfo Returned: %u", Status);
  160. return Status;
  161. }
  162. DWORD
  163. WINAPI
  164. SetGlobalInfo (
  165. IN PVOID GlobalInfo,
  166. IN ULONG InfoVer,
  167. IN ULONG InfoSize,
  168. IN ULONG InfoCnt
  169. )
  170. {
  171. DWORD Status;
  172. Trace2(ENTER, "SetGlobalInfo: Info: %p, Size: %08x",
  173. GlobalInfo,
  174. InfoSize);
  175. Status = QosmSetGlobalInfo(GlobalInfo,
  176. InfoSize);
  177. Trace1(LEAVE, "GetGlobalInfo: Returned %u", Status);
  178. return Status;
  179. }
  180. DWORD
  181. WINAPI
  182. AddInterface (
  183. IN LPWSTR InterfaceName,
  184. IN ULONG InterfaceIndex,
  185. IN NET_INTERFACE_TYPE InterfaceType,
  186. IN DWORD MediaType,
  187. IN WORD AccessType,
  188. IN WORD ConnectionType,
  189. IN PVOID InterfaceInfo,
  190. IN ULONG InfoVer,
  191. IN ULONG InfoSize,
  192. IN ULONG InfoCnt
  193. )
  194. {
  195. PQOSMGR_INTERFACE_ENTRY Interface, NextInterface;
  196. PIPQOS_IF_CONFIG InterfaceConfig;
  197. PLIST_ENTRY p;
  198. BOOL LockInited;
  199. DWORD Status;
  200. UNREFERENCED_PARAMETER(InfoVer);
  201. UNREFERENCED_PARAMETER(InfoCnt);
  202. TraceEnter("AddInterface");
  203. //
  204. // Validate input parameters before creating 'if'
  205. //
  206. if ((!InterfaceName) || (!InterfaceInfo))
  207. {
  208. return ERROR_INVALID_PARAMETER;
  209. }
  210. InterfaceConfig = (PIPQOS_IF_CONFIG) InterfaceInfo;
  211. Interface = NULL;
  212. LockInited = FALSE;
  213. ACQUIRE_GLOBALS_WRITE_LOCK();
  214. do
  215. {
  216. //
  217. // Search for an interface with this index
  218. //
  219. for (p = Globals.IfList.Flink;
  220. p != &Globals.IfList;
  221. p = p->Flink)
  222. {
  223. NextInterface =
  224. CONTAINING_RECORD(p, QOSMGR_INTERFACE_ENTRY, ListByIndexLE);
  225. if (NextInterface->InterfaceIndex >= InterfaceIndex)
  226. {
  227. break;
  228. }
  229. }
  230. if ((p != &Globals.IfList) &&
  231. (NextInterface->InterfaceIndex == InterfaceIndex))
  232. {
  233. Status = ERROR_ALREADY_EXISTS;
  234. break;
  235. }
  236. //
  237. // Allocate a new interface structure
  238. //
  239. Interface = AllocNZeroMemory(sizeof(QOSMGR_INTERFACE_ENTRY));
  240. if (Interface == NULL)
  241. {
  242. Status = ERROR_NOT_ENOUGH_MEMORY;
  243. break;
  244. }
  245. //
  246. // Fill the interface info from input
  247. //
  248. Interface->InterfaceIndex = InterfaceIndex;
  249. wcscpy(Interface->InterfaceName,
  250. InterfaceName);
  251. //
  252. // Initialize lock to guard this interface
  253. //
  254. try
  255. {
  256. CREATE_READ_WRITE_LOCK(&Interface->InterfaceLock);
  257. LockInited = TRUE;
  258. }
  259. except(EXCEPTION_EXECUTE_HANDLER)
  260. {
  261. Status = GetLastError();
  262. Trace1(ANY,
  263. "AddInterface: Failed to create read/write lock %x",
  264. Status);
  265. LOGERR0(CREATE_RWL_FAILED, Status);
  266. break;
  267. }
  268. Interface->Flags = InterfaceType;
  269. Interface->State = InterfaceConfig->QosState;
  270. Interface->NumFlows = 0;
  271. InitializeListHead(&Interface->FlowList);
  272. //
  273. // Fill in the TC information for this IF
  274. //
  275. QosmOpenTcInterface(Interface);
  276. //
  277. // Update state to reflect the intf config
  278. //
  279. Status = QosmSetInterfaceInfo(Interface,
  280. InterfaceConfig,
  281. InfoSize);
  282. if (Status != NO_ERROR)
  283. {
  284. break;
  285. }
  286. //
  287. // Insert interface on sorted global list
  288. //
  289. InsertTailList(p, &Interface->ListByIndexLE);
  290. Globals.NumIfs++;
  291. }
  292. while (FALSE);
  293. RELEASE_GLOBALS_WRITE_LOCK();
  294. if (Status != NO_ERROR)
  295. {
  296. //
  297. // Some error occurred - clean up and return
  298. //
  299. if (Interface->TciIfHandle)
  300. {
  301. TcCloseInterface(Interface->TciIfHandle);
  302. }
  303. if (LockInited)
  304. {
  305. DELETE_READ_WRITE_LOCK(&Interface->InterfaceLock);
  306. }
  307. if (Interface)
  308. {
  309. FreeMemory(Interface);
  310. }
  311. }
  312. TraceLeave("AddInterface");
  313. return Status;
  314. }
  315. DWORD
  316. WINAPI
  317. DeleteInterface (
  318. IN ULONG InterfaceIndex
  319. )
  320. {
  321. PQOSMGR_INTERFACE_ENTRY Interface;
  322. PLIST_ENTRY p;
  323. DWORD Status;
  324. TraceEnter("DeleteInterface");
  325. ACQUIRE_GLOBALS_WRITE_LOCK();
  326. do
  327. {
  328. //
  329. // Search for an interface with this index
  330. //
  331. for (p = Globals.IfList.Flink;
  332. p != &Globals.IfList;
  333. p = p->Flink)
  334. {
  335. Interface =
  336. CONTAINING_RECORD(p, QOSMGR_INTERFACE_ENTRY, ListByIndexLE);
  337. if (Interface->InterfaceIndex == InterfaceIndex)
  338. {
  339. break;
  340. }
  341. }
  342. if (p == &Globals.IfList)
  343. {
  344. Status = ERROR_NOT_FOUND;
  345. break;
  346. }
  347. //
  348. // Delete the interface from the global list
  349. //
  350. RemoveEntryList(&Interface->ListByIndexLE);
  351. Globals.NumIfs--;
  352. //
  353. // Free any handles associated with this if
  354. //
  355. if (Interface->TciIfHandle)
  356. {
  357. TcCloseInterface(Interface->TciIfHandle);
  358. }
  359. //
  360. // Free all memory allocated to the interface
  361. //
  362. DELETE_READ_WRITE_LOCK(&Interface->InterfaceLock);
  363. if (Interface->InterfaceConfig)
  364. {
  365. FreeMemory(Interface->InterfaceConfig);
  366. }
  367. FreeMemory(Interface);
  368. Status = NO_ERROR;
  369. }
  370. while (FALSE);
  371. RELEASE_GLOBALS_WRITE_LOCK();
  372. TraceLeave("DeleteInterface");
  373. return Status;
  374. }
  375. DWORD
  376. WINAPI
  377. InterfaceStatus (
  378. IN ULONG InterfaceIndex,
  379. IN BOOL InterfaceActive,
  380. IN DWORD StatusType,
  381. IN PVOID StatusInfo
  382. )
  383. {
  384. TraceEnter("InterfaceStatus");
  385. TraceLeave("InterfaceStatus");
  386. return NO_ERROR;
  387. }
  388. DWORD
  389. WINAPI
  390. GetInterfaceInfo (
  391. IN ULONG InterfaceIndex,
  392. IN PVOID InterfaceInfo,
  393. IN OUT PULONG BufferSize,
  394. OUT PULONG InfoVer,
  395. OUT PULONG InfoSize,
  396. OUT PULONG InfoCnt
  397. )
  398. {
  399. PQOSMGR_INTERFACE_ENTRY Interface;
  400. PLIST_ENTRY p;
  401. DWORD Status;
  402. UNREFERENCED_PARAMETER(InfoVer);
  403. UNREFERENCED_PARAMETER(InfoCnt);
  404. #if 1
  405. *InfoVer = *InfoCnt = 1;
  406. #endif
  407. Trace3(ENTER, "GetInterfaceInfo: Index: %5u, Info: %p, Size: %08x",
  408. InterfaceIndex,
  409. InterfaceInfo,
  410. BufferSize);
  411. ACQUIRE_GLOBALS_READ_LOCK();
  412. do
  413. {
  414. //
  415. // Search for an interface with this index
  416. //
  417. for (p = Globals.IfList.Flink;
  418. p != &Globals.IfList;
  419. p = p->Flink)
  420. {
  421. Interface =
  422. CONTAINING_RECORD(p, QOSMGR_INTERFACE_ENTRY, ListByIndexLE);
  423. if (Interface->InterfaceIndex == InterfaceIndex)
  424. {
  425. break;
  426. }
  427. }
  428. if (p == &Globals.IfList)
  429. {
  430. Status = ERROR_NOT_FOUND;
  431. break;
  432. }
  433. //
  434. // Get the interface info from the interface
  435. //
  436. Status = QosmGetInterfaceInfo(Interface,
  437. InterfaceInfo,
  438. BufferSize,
  439. InfoSize);
  440. }
  441. while (FALSE);
  442. RELEASE_GLOBALS_READ_LOCK();
  443. Trace1(LEAVE, "GetInterfaceInfo: Returned %u", Status);
  444. return Status;
  445. }
  446. DWORD
  447. WINAPI
  448. SetInterfaceInfo (
  449. IN ULONG InterfaceIndex,
  450. IN PVOID InterfaceInfo,
  451. IN ULONG InfoVer,
  452. IN ULONG InfoSize,
  453. IN ULONG InfoCnt
  454. )
  455. {
  456. PQOSMGR_INTERFACE_ENTRY Interface;
  457. PLIST_ENTRY p;
  458. DWORD Status;
  459. UNREFERENCED_PARAMETER(InfoVer);
  460. UNREFERENCED_PARAMETER(InfoCnt);
  461. Trace3(ENTER, "SetInterfaceInfo: Index: %5u, Info: %p, Size: %08x",
  462. InterfaceIndex,
  463. InterfaceInfo,
  464. InfoSize);
  465. ACQUIRE_GLOBALS_READ_LOCK();
  466. do
  467. {
  468. //
  469. // Search for an interface with this index
  470. //
  471. for (p = Globals.IfList.Flink;
  472. p != &Globals.IfList;
  473. p = p->Flink)
  474. {
  475. Interface =
  476. CONTAINING_RECORD(p, QOSMGR_INTERFACE_ENTRY, ListByIndexLE);
  477. if (Interface->InterfaceIndex == InterfaceIndex)
  478. {
  479. break;
  480. }
  481. }
  482. if (p == &Globals.IfList)
  483. {
  484. Status = ERROR_NOT_FOUND;
  485. break;
  486. }
  487. //
  488. // Set the interface info on the interface
  489. //
  490. Status = QosmSetInterfaceInfo(Interface,
  491. InterfaceInfo,
  492. InfoSize);
  493. }
  494. while (FALSE);
  495. RELEASE_GLOBALS_READ_LOCK();
  496. Trace1(LEAVE, "SetInterfaceInfo: Returned %u", Status);
  497. return Status;
  498. }
  499. DWORD
  500. WINAPI
  501. GetEventMessage (
  502. OUT ROUTING_PROTOCOL_EVENTS *Event,
  503. OUT MESSAGE *Result
  504. )
  505. {
  506. TraceEnter("GetEventMessage");
  507. TraceLeave("GetEventMessage");
  508. return ERROR_NO_MORE_ITEMS;
  509. }
  510. DWORD
  511. WINAPI
  512. UpdateRoutes (
  513. IN ULONG InterfaceIndex
  514. )
  515. {
  516. TraceEnter("UpdateRoutes");
  517. TraceLeave("UpdateRoutes");
  518. return NO_ERROR;
  519. }
  520. DWORD
  521. WINAPI
  522. MibCreateEntry (
  523. IN ULONG InputDataSize,
  524. IN PVOID InputData
  525. )
  526. {
  527. TraceEnter("MibCreateEntry");
  528. TraceLeave("MibCreateEntry");
  529. return NO_ERROR;
  530. }
  531. DWORD
  532. WINAPI
  533. MibDeleteEntry (
  534. IN ULONG InputDataSize,
  535. IN PVOID InputData
  536. )
  537. {
  538. TraceEnter("MibDeleteEntry");
  539. TraceLeave("MibDeleteEntry");
  540. return NO_ERROR;
  541. }
  542. DWORD
  543. WINAPI
  544. MibGetEntry (
  545. IN ULONG InputDataSize,
  546. IN PVOID InputData,
  547. OUT PULONG OutputDataSize,
  548. OUT PVOID OutputData
  549. )
  550. {
  551. TraceEnter("MibGetEntry");
  552. TraceLeave("MibGetEntry");
  553. return ERROR_INVALID_PARAMETER;
  554. }
  555. DWORD
  556. WINAPI
  557. MibSetEntry (
  558. IN ULONG InputDataSize,
  559. IN PVOID InputData
  560. )
  561. {
  562. TraceEnter("MibSetEntry");
  563. TraceLeave("MibSetEntry");
  564. return NO_ERROR;
  565. }
  566. DWORD
  567. WINAPI
  568. MibGetFirstEntry (
  569. IN ULONG InputDataSize,
  570. IN PVOID InputData,
  571. OUT PULONG OutputDataSize,
  572. OUT PVOID OutputData
  573. )
  574. {
  575. TraceEnter("MibGetFirstEntry");
  576. TraceLeave("MibGetFirstEntry");
  577. return ERROR_INVALID_PARAMETER;
  578. }
  579. DWORD
  580. WINAPI
  581. MibGetNextEntry (
  582. IN ULONG InputDataSize,
  583. IN PVOID InputData,
  584. OUT PULONG OutputDataSize,
  585. OUT PVOID OutputData
  586. )
  587. {
  588. TraceEnter("MibGetNextEntry");
  589. TraceLeave("MibGetNextEntry");
  590. return NO_ERROR;
  591. }
  592. DWORD
  593. WINAPI
  594. MibSetTrapInfo (
  595. IN HANDLE Event,
  596. IN ULONG InputDataSize,
  597. IN PVOID InputData,
  598. OUT PULONG OutputDataSize,
  599. OUT PVOID OutputData
  600. )
  601. {
  602. TraceEnter("MibSetTrapInfo");
  603. TraceLeave("MibSetTrapInfo");
  604. return NO_ERROR;
  605. }
  606. DWORD
  607. WINAPI
  608. MibGetTrapInfo (
  609. IN ULONG InputDataSize,
  610. IN PVOID InputData,
  611. OUT PULONG OutputDataSize,
  612. OUT PVOID OutputData
  613. )
  614. {
  615. TraceEnter("MibGetTrapInfo");
  616. TraceLeave("MibGetTrapInfo");
  617. return ERROR_NO_MORE_ITEMS;
  618. }