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.

198 lines
4.4 KiB

  1. /*++
  2. Copyright 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. qosmdsrv.c
  5. Abstract:
  6. Contains routines that are invoked by
  7. the QosMgr DLL to control diffserv.
  8. Revision History:
  9. --*/
  10. #include "pchqosm.h"
  11. #pragma hdrstop
  12. //
  13. // Traffic Control Handlers/Functionality
  14. //
  15. VOID
  16. TcNotifyHandler(
  17. IN HANDLE ClRegCtx,
  18. IN HANDLE ClIfcCtx,
  19. IN ULONG Event,
  20. IN HANDLE SubCode,
  21. IN ULONG BufSize,
  22. IN PVOID Buffer
  23. )
  24. {
  25. PQOSMGR_INTERFACE_ENTRY Interface;
  26. PLIST_ENTRY p;
  27. switch (Event)
  28. {
  29. case TC_NOTIFY_IFC_UP:
  30. //
  31. // New interface - check if we have this interface
  32. //
  33. break;
  34. case TC_NOTIFY_IFC_CLOSE:
  35. //
  36. // An existing interface has been closed by system
  37. //
  38. ACQUIRE_GLOBALS_READ_LOCK();
  39. do
  40. {
  41. //
  42. // Make sure that the interface still exists on list
  43. //
  44. for (p = Globals.IfList.Flink;
  45. p != &Globals.IfList;
  46. p = p->Flink)
  47. {
  48. Interface =
  49. CONTAINING_RECORD(p, QOSMGR_INTERFACE_ENTRY, ListByIndexLE);
  50. if (Interface == ClIfcCtx)
  51. {
  52. break;
  53. }
  54. }
  55. if (p == &Globals.IfList)
  56. {
  57. //
  58. // Must have been deleted in a parallel thread
  59. //
  60. break;
  61. }
  62. ACQUIRE_INTERFACE_WRITE_LOCK(Interface);
  63. Interface->TciIfHandle = NULL;
  64. //
  65. // This call would result in invalidating all flows
  66. // in the list as TciIfHandle is set to NULL above
  67. //
  68. QosmSetInterfaceInfo(Interface,
  69. Interface->InterfaceConfig,
  70. Interface->ConfigSize);
  71. RELEASE_INTERFACE_WRITE_LOCK(Interface);
  72. }
  73. while (FALSE);
  74. RELEASE_GLOBALS_READ_LOCK();
  75. break;
  76. }
  77. return;
  78. }
  79. DWORD
  80. QosmOpenTcInterface(
  81. IN PQOSMGR_INTERFACE_ENTRY Interface
  82. )
  83. {
  84. PTC_IFC_DESCRIPTOR CurrInterface;
  85. PTC_IFC_DESCRIPTOR Buffer;
  86. DWORD BufferSize;
  87. DWORD Status;
  88. //
  89. // First enumerate all interfaces and
  90. // get a interface with matching name
  91. //
  92. BufferSize = 0;
  93. Buffer = NULL;
  94. do
  95. {
  96. if (BufferSize)
  97. {
  98. //
  99. // Try to increase the buffer size
  100. //
  101. if (Buffer)
  102. {
  103. FreeMemory(Buffer);
  104. }
  105. Buffer = AllocMemory(BufferSize);
  106. if (!Buffer)
  107. {
  108. Status = ERROR_NOT_ENOUGH_MEMORY;
  109. break;
  110. }
  111. }
  112. Status = TcEnumerateInterfaces(Globals.TciHandle,
  113. &BufferSize,
  114. Buffer);
  115. }
  116. while (Status == ERROR_INSUFFICIENT_BUFFER);
  117. if (Status == NO_ERROR)
  118. {
  119. Status = ERROR_NOT_FOUND;
  120. //
  121. // Find the QOS interface with matching GUID
  122. //
  123. CurrInterface = Buffer;
  124. while (BufferSize > 0)
  125. {
  126. if (!_wcsicmp(CurrInterface->pInterfaceID,
  127. Interface->InterfaceName))
  128. {
  129. // Found the interface - copy qos name
  130. wcscpy(Interface->AlternateName,
  131. CurrInterface->pInterfaceName);
  132. // Open the interface and cache handle
  133. Status = TcOpenInterfaceW(Interface->AlternateName,
  134. Globals.TciHandle,
  135. Interface,
  136. &Interface->TciIfHandle);
  137. break;
  138. }
  139. BufferSize -= CurrInterface->Length;
  140. (PUCHAR) CurrInterface += CurrInterface->Length;
  141. }
  142. }
  143. if (Buffer)
  144. {
  145. FreeMemory(Buffer);
  146. }
  147. return Status;
  148. }