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.

789 lines
19 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. qoscfg.c
  5. Abstract:
  6. Fns to change configuration for IP QOS
  7. Revision History:
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. static IPQOS_GLOBAL_CONFIG
  12. g_ipqosGlobalDefault = {
  13. IPQOS_LOGGING_ERROR // Logging level
  14. };
  15. static BYTE* g_pIpqosGlobalDefault = (BYTE*)&g_ipqosGlobalDefault;
  16. static IPQOS_IF_CONFIG
  17. g_ipqosInterfaceDefault = {
  18. IPQOS_STATE_ENABLED,
  19. 0 // NULL flow list
  20. };
  21. static BYTE* g_pIpqosInterfaceDefault = (BYTE*)&g_ipqosInterfaceDefault;
  22. //
  23. // If one of the arguments is specified with a name tag
  24. // then all arguments must come with name tags.
  25. // If no name tags, then arguments are assumed to be in a certain order
  26. //
  27. DWORD
  28. MakeQosGlobalInfo(
  29. OUT PBYTE *ppbStart,
  30. OUT PDWORD pdwSize
  31. )
  32. /*++
  33. Routine Descqostion:
  34. Creates a QOS global info block.
  35. Arguments:
  36. ppbStart - Pointer to the info block
  37. pdwSize - Pointer to size of the info block
  38. Return Value:
  39. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  40. --*/
  41. {
  42. *pdwSize = sizeof(IPQOS_GLOBAL_CONFIG);
  43. *ppbStart = HeapAlloc(GetProcessHeap(), 0, *pdwSize);
  44. if (*ppbStart is NULL)
  45. {
  46. return ERROR_NOT_ENOUGH_MEMORY;
  47. }
  48. CopyMemory( *ppbStart, g_pIpqosGlobalDefault, *pdwSize);
  49. return NO_ERROR;
  50. }
  51. DWORD
  52. ShowQosGlobalInfo (
  53. HANDLE hFile
  54. )
  55. /*++
  56. Routine Descqostion:
  57. Displays QOS global config info
  58. Arguments:
  59. Return Value:
  60. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  61. --*/
  62. {
  63. VALUE_TOKEN vtLogLevelTable1[]
  64. = {IPQOS_LOGGING_NONE,TOKEN_OPT_VALUE_NONE,
  65. IPQOS_LOGGING_ERROR,TOKEN_OPT_VALUE_ERROR,
  66. IPQOS_LOGGING_WARN,TOKEN_OPT_VALUE_WARN,
  67. IPQOS_LOGGING_INFO,TOKEN_OPT_VALUE_INFO};
  68. VALUE_STRING vtLogLevelTable2[]
  69. = {IPQOS_LOGGING_NONE,STRING_LOGGING_NONE,
  70. IPQOS_LOGGING_ERROR,STRING_LOGGING_ERROR,
  71. IPQOS_LOGGING_WARN,STRING_LOGGING_WARN,
  72. IPQOS_LOGGING_INFO,STRING_LOGGING_INFO};
  73. PIPQOS_GLOBAL_CONFIG pigc = NULL;
  74. PTCHAR ptszLogLevel = NULL;
  75. DWORD dwBlkSize, dwCount, dwRes;
  76. do
  77. {
  78. dwRes = IpmontrGetInfoBlockFromGlobalInfo(MS_IP_QOSMGR,
  79. (PBYTE *) &pigc,
  80. &dwBlkSize,
  81. &dwCount);
  82. if (dwBlkSize is 0)
  83. {
  84. dwRes = ERROR_NOT_FOUND;
  85. }
  86. if ( dwRes isnot NO_ERROR )
  87. {
  88. break;
  89. }
  90. //
  91. // getting logging mode string
  92. //
  93. if (hFile)
  94. {
  95. dwRes = GetDisplayStringT(g_hModule,
  96. pigc->LoggingLevel,
  97. vtLogLevelTable1,
  98. NUM_VALUES_IN_TABLE(vtLogLevelTable1),
  99. &ptszLogLevel) ;
  100. }
  101. else
  102. {
  103. dwRes = GetDisplayString(g_hModule,
  104. pigc->LoggingLevel,
  105. vtLogLevelTable2,
  106. NUM_VALUES_IN_TABLE(vtLogLevelTable1),
  107. &ptszLogLevel) ;
  108. }
  109. if (dwRes != NO_ERROR)
  110. return dwRes ;
  111. if ( ptszLogLevel == NULL )
  112. {
  113. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  114. break;
  115. }
  116. if (hFile)
  117. {
  118. //
  119. // dump qos global info
  120. //
  121. // DisplayMessageT(DMP_QOS_GLOBAL_HEADER) ;
  122. // DisplayMessageT(DMP_QOS_UNINSTALL) ;
  123. DisplayMessageT(DMP_QOS_INSTALL) ;
  124. DisplayMessageT(DMP_QOS_SET_GLOBAL,
  125. ptszLogLevel);
  126. // DisplayMessageT(DMP_QOS_GLOBAL_FOOTER) ;
  127. }
  128. else
  129. {
  130. //
  131. // display qos global info
  132. //
  133. DisplayMessage(g_hModule,
  134. MSG_QOS_GLOBAL_INFO,
  135. ptszLogLevel);
  136. }
  137. dwRes = NO_ERROR;
  138. } while ( FALSE );
  139. HEAP_FREE_NOT_NULL(pigc);
  140. if ( ptszLogLevel ) { FreeString( ptszLogLevel ); }
  141. if (hFile is NULL)
  142. {
  143. switch(dwRes)
  144. {
  145. case NO_ERROR:
  146. break;
  147. case ERROR_NOT_FOUND:
  148. DisplayMessage(g_hModule, EMSG_PROTO_NO_GLOBAL_INFO);
  149. break;
  150. case ERROR_NOT_ENOUGH_MEMORY:
  151. DisplayMessage(g_hModule, EMSG_NOT_ENOUGH_MEMORY);
  152. break;
  153. default:
  154. DisplayError(g_hModule, dwRes);
  155. break;
  156. }
  157. }
  158. return NO_ERROR;
  159. }
  160. DWORD
  161. UpdateQosGlobalConfig(
  162. PIPQOS_GLOBAL_CONFIG pigcGlobalCfg,
  163. DWORD dwBitVector
  164. )
  165. /*++
  166. Routine Descqostion:
  167. Updates QOS global config info
  168. Arguments:
  169. pigcGlobalCfg - The new values to be set
  170. dwBitVector - Which fields need to be modified
  171. Return Value:
  172. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  173. --*/
  174. {
  175. DWORD dwRes = (DWORD) -1, dwIndex = (DWORD) -1;
  176. DWORD dwSize = 0, dwCount, i, j;
  177. DWORD dwBlkSize, dwNewBlkSize, dwQosCount;
  178. PDWORD pdwAddrTable= NULL, pdwNewAddrTable = NULL;
  179. PDWORD pdwSrcAddrTable = NULL;
  180. PIPQOS_GLOBAL_CONFIG pigcSrc = NULL, pigcDst = NULL;
  181. PBOOL pbToDelete;
  182. DEBUG("In UpdateQosGlobalConfig");
  183. if (dwBitVector is 0)
  184. {
  185. return ERROR_OKAY;
  186. }
  187. //
  188. // Get Global Config info from Registry first
  189. //
  190. do
  191. {
  192. dwRes = IpmontrGetInfoBlockFromGlobalInfo(MS_IP_QOSMGR,
  193. (PBYTE *) &pigcSrc,
  194. &dwBlkSize,
  195. &dwQosCount);
  196. if (dwRes != NO_ERROR)
  197. {
  198. break;
  199. }
  200. if ( pigcSrc == NULL )
  201. {
  202. dwRes = ERROR_NOT_FOUND;
  203. break;
  204. }
  205. //
  206. // We have a fixed len global info - so
  207. // no reallocation and recopy necessary
  208. //
  209. dwNewBlkSize = dwBlkSize;
  210. pigcDst = pigcSrc;
  211. if (dwBitVector & QOS_LOG_MASK)
  212. {
  213. pigcDst->LoggingLevel = pigcGlobalCfg->LoggingLevel;
  214. }
  215. //
  216. // Set the info
  217. //
  218. dwRes = IpmontrSetInfoBlockInGlobalInfo(MS_IP_QOSMGR,
  219. (PBYTE) pigcDst,
  220. dwNewBlkSize,
  221. dwQosCount);
  222. if (dwRes != NO_ERROR)
  223. {
  224. break;
  225. }
  226. } while (FALSE);
  227. HEAP_FREE_NOT_NULL(pigcSrc);
  228. //
  229. // error processing
  230. //
  231. switch(dwRes)
  232. {
  233. case NO_ERROR:
  234. dwRes = ERROR_OKAY;
  235. break;
  236. case ERROR_NOT_FOUND:
  237. DisplayMessage(g_hModule, EMSG_PROTO_NO_GLOBAL_INFO );
  238. dwRes = ERROR_SUPPRESS_OUTPUT;
  239. break;
  240. default:
  241. break;
  242. }
  243. return dwRes;
  244. }
  245. DWORD
  246. MakeQosInterfaceInfo(
  247. IN ROUTER_INTERFACE_TYPE rifType,
  248. OUT PBYTE *ppbStart,
  249. OUT PDWORD pdwSize
  250. )
  251. /*++
  252. Routine Descqostion:
  253. Creates a QOS interface info block.
  254. Arguments:
  255. rifType - Interface type
  256. ppbStart - Pointer to the info block
  257. pdwSize - Pointer to size of the info block
  258. Return Value:
  259. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  260. --*/
  261. {
  262. *pdwSize = sizeof(IPQOS_IF_CONFIG);
  263. *ppbStart = HeapAlloc(GetProcessHeap(), 0, *pdwSize);
  264. if (*ppbStart is NULL)
  265. {
  266. return ERROR_NOT_ENOUGH_MEMORY;
  267. }
  268. CopyMemory( *ppbStart, g_pIpqosInterfaceDefault, *pdwSize);
  269. return NO_ERROR;
  270. }
  271. DWORD
  272. ShowQosAllInterfaceInfo(
  273. IN HANDLE hFile
  274. )
  275. /*++
  276. Routine Descqostion:
  277. Displays config info for all
  278. qos enabled interfaces
  279. Arguments:
  280. hFile - NULL, or file handle
  281. --*/
  282. {
  283. DWORD dwErr, dwCount, dwTotal;
  284. DWORD dwNumParsed, i, dwNumBlocks=1, dwSize, dwIfType;
  285. PBYTE pBuffer;
  286. PMPR_INTERFACE_0 pmi0;
  287. WCHAR wszIfDesc[MAX_INTERFACE_NAME_LEN + 1];
  288. //
  289. // dump qos config for all interfaces
  290. //
  291. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0,
  292. &dwCount,
  293. &dwTotal);
  294. if(dwErr != NO_ERROR)
  295. {
  296. return dwErr;
  297. }
  298. for(i = 0; i < dwCount; i++)
  299. {
  300. // make sure that Qos is configured on that interface
  301. dwErr = IpmontrGetInfoBlockFromInterfaceInfo(pmi0[i].wszInterfaceName,
  302. MS_IP_QOSMGR,
  303. &pBuffer,
  304. &dwSize,
  305. &dwNumBlocks,
  306. &dwIfType);
  307. if (dwErr isnot NO_ERROR) {
  308. continue;
  309. }
  310. else {
  311. HEAP_FREE(pBuffer) ;
  312. }
  313. ShowQosInterfaceInfo(hFile, pmi0[i].wszInterfaceName) ;
  314. //
  315. // At this point we do not have any flags on interface
  316. //
  317. // if (hFile)
  318. // {
  319. // //
  320. // // only for dump include the flag setting as part of
  321. // // interface settings. Otherwise Interface flag settings
  322. // // are handled by the show flags command
  323. // //
  324. //
  325. // ShowQosInterfaceFlags(hFile, pmi0[i].wszInterfaceName);
  326. // }
  327. }
  328. return NO_ERROR ;
  329. }
  330. DWORD
  331. ShowQosInterfaceInfo(
  332. IN HANDLE hFile,
  333. IN PWCHAR pwszIfGuid
  334. )
  335. /*++
  336. Routine Descqostion:
  337. Displays QOS interface config info
  338. Arguments:
  339. pwszIfGuid - Interface name
  340. Return Value:
  341. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  342. --*/
  343. {
  344. WCHAR wszInterfaceName[ MAX_INTERFACE_NAME_LEN + 1 ] = L"\0";
  345. PWCHAR pwszFriendlyIfName = NULL;
  346. DWORD dwBufferSize = sizeof(wszInterfaceName);
  347. DWORD dwRes = (DWORD) -1,
  348. dwCnt = 0;
  349. PDWORD pdwAddr = NULL;
  350. PIPQOS_IF_CONFIG piic = NULL;
  351. PTCHAR ptszState = NULL;
  352. VALUE_TOKEN vtStateTable1[]
  353. = {IPQOS_STATE_ENABLED,TOKEN_OPT_VALUE_ENABLE,
  354. IPQOS_STATE_DISABLED,TOKEN_OPT_VALUE_DISABLE};
  355. VALUE_STRING vtStateTable2[]
  356. = {IPQOS_STATE_ENABLED,STRING_ENABLED,
  357. IPQOS_STATE_DISABLED,STRING_DISABLED};
  358. DWORD dwBlkSize, dwIfType, dwCount;
  359. do
  360. {
  361. dwRes = IpmontrGetInfoBlockFromInterfaceInfo(pwszIfGuid,
  362. MS_IP_QOSMGR,
  363. (PBYTE *) &piic,
  364. &dwBlkSize,
  365. &dwCount,
  366. &dwIfType);
  367. if (dwBlkSize is 0)
  368. dwRes = ERROR_NOT_FOUND;
  369. if (dwRes isnot NO_ERROR)
  370. {
  371. break;
  372. }
  373. //
  374. // get friendly name for interface
  375. //
  376. dwRes = IpmontrGetFriendlyNameFromIfName( pwszIfGuid,
  377. wszInterfaceName,
  378. &dwBufferSize );
  379. if ( dwRes isnot NO_ERROR )
  380. {
  381. break;
  382. }
  383. pwszFriendlyIfName = MakeQuotedString( wszInterfaceName );
  384. if ( pwszFriendlyIfName == NULL )
  385. {
  386. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  387. break;
  388. }
  389. //
  390. // get state of the interface
  391. //
  392. GetAltDisplayString(g_hModule, hFile,
  393. piic->QosState,
  394. vtStateTable1,
  395. vtStateTable2,
  396. NUM_VALUES_IN_TABLE(vtStateTable1),
  397. &ptszState);
  398. if ( ptszState == NULL )
  399. {
  400. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  401. break;
  402. }
  403. if (hFile)
  404. {
  405. DisplayMessageT(DMP_QOS_INTERFACE_HEADER,
  406. pwszFriendlyIfName);
  407. DisplayMessageT(DMP_QOS_DELETE_INTERFACE,
  408. pwszFriendlyIfName);
  409. DisplayMessageT(DMP_QOS_ADD_INTERFACE,
  410. pwszFriendlyIfName,
  411. ptszState);
  412. DisplayMessageT(DMP_QOS_SET_INTERFACE,
  413. pwszFriendlyIfName,
  414. ptszState);
  415. ShowQosFlowsOnIf(hFile, pwszIfGuid, NULL);
  416. DisplayMessageT(DMP_QOS_INTERFACE_FOOTER,
  417. pwszFriendlyIfName);
  418. }
  419. else
  420. {
  421. DisplayMessage(g_hModule, MSG_QOS_IF_INFO,
  422. pwszFriendlyIfName,
  423. ptszState);
  424. ShowQosFlowsOnIf(hFile, pwszIfGuid, NULL);
  425. }
  426. dwRes = NO_ERROR;
  427. } while ( FALSE );
  428. HEAP_FREE_NOT_NULL(piic);
  429. FREE_STRING_NOT_NULL( ptszState ) ;
  430. if ( pwszFriendlyIfName )
  431. {
  432. FreeQuotedString( pwszFriendlyIfName );
  433. }
  434. switch(dwRes)
  435. {
  436. case NO_ERROR:
  437. break;
  438. case ERROR_NOT_FOUND:
  439. DisplayMessage(g_hModule, EMSG_PROTO_NO_IF_INFO,
  440. L"RouterInterfaceConfig");
  441. break;
  442. default:
  443. DisplayError(g_hModule, dwRes);
  444. break;
  445. }
  446. return NO_ERROR;
  447. }
  448. DWORD
  449. UpdateQosInterfaceConfig(
  450. IN PWCHAR pwszIfGuid,
  451. IN PIPQOS_IF_CONFIG pChangeCfg,
  452. IN DWORD dwBitVector,
  453. IN BOOL bAddSet
  454. )
  455. /*++
  456. Routine Descqostion:
  457. Updates QOS interface config info
  458. Arguments:
  459. pwszIfGuid - Interface name
  460. pFinalCfg - The old config(if bSet), or default config(if bAdd)
  461. pChangeCfg - The changes to be applied to pFinalCfg (specified
  462. on cmd line)
  463. dwBitVector - Which fields need to be modified
  464. bAddSet - Is the interface being added or set.
  465. Return Value:
  466. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  467. --*/
  468. {
  469. DWORD dwErr = NO_ERROR, dwSize = 0, dwQosCount=1;
  470. DWORD i, dwIfType;
  471. PIPQOS_IF_CONFIG pFinalCfg, piicDst = NULL;
  472. DEBUG("In UpdateQosInterfaceConfig");
  473. do
  474. {
  475. if (bAddSet) {
  476. //
  477. // Create default protocol info block
  478. //
  479. dwErr = IpmontrGetInterfaceType(pwszIfGuid, &dwIfType);
  480. if (dwErr isnot NO_ERROR)
  481. {
  482. break;
  483. }
  484. dwErr = MakeQosInterfaceInfo(dwIfType,(PBYTE *)&pFinalCfg,&dwSize);
  485. if (dwErr isnot NO_ERROR)
  486. {
  487. break;
  488. }
  489. }
  490. else {
  491. //
  492. // get current interface config
  493. //
  494. dwErr = GetInfoBlockFromInterfaceInfoEx(pwszIfGuid,
  495. MS_IP_QOSMGR,
  496. (PBYTE *)&pFinalCfg,
  497. &dwSize,
  498. &dwQosCount,
  499. &dwIfType);
  500. if (dwErr isnot NO_ERROR)
  501. {
  502. return dwErr;
  503. }
  504. }
  505. piicDst = HeapAlloc(GetProcessHeap(), 0, dwSize);
  506. if ( piicDst == NULL )
  507. {
  508. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  509. break;
  510. }
  511. //
  512. // Update the state on interface (and other vars)
  513. //
  514. *piicDst = *pFinalCfg;
  515. if (dwBitVector & QOS_IF_STATE_MASK)
  516. {
  517. piicDst->QosState = pChangeCfg->QosState;
  518. }
  519. //
  520. // Set the info
  521. //
  522. dwErr = IpmontrSetInfoBlockInInterfaceInfo(pwszIfGuid,
  523. MS_IP_QOSMGR,
  524. (PBYTE) piicDst,
  525. dwSize,
  526. dwQosCount);
  527. if (dwErr isnot NO_ERROR)
  528. {
  529. break;
  530. }
  531. } while ( FALSE );
  532. HEAP_FREE_NOT_NULL(pFinalCfg);
  533. HEAP_FREE_NOT_NULL(piicDst);
  534. return dwErr;
  535. }
  536. DWORD
  537. UpdateAllInterfaceConfigs(
  538. VOID
  539. )
  540. {
  541. PMPR_INTERFACE_0 pmi0;
  542. PIPQOS_IF_CONFIG piicBlk;
  543. DWORD dwErr, dwCount, dwTotal, i;
  544. DWORD dwBlkSize, dwBlkCount, dwIfType;
  545. //
  546. // Enumerate all interfaces applicable to QOS
  547. //
  548. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0,
  549. &dwCount,
  550. &dwTotal);
  551. if(dwErr != NO_ERROR)
  552. {
  553. DisplayError(g_hModule, dwErr);
  554. return dwErr;
  555. }
  556. for (i = 0; i < dwCount; i++)
  557. {
  558. dwErr = IpmontrGetInfoBlockFromInterfaceInfo(pmi0[i].wszInterfaceName,
  559. MS_IP_QOSMGR,
  560. (PBYTE *) &piicBlk,
  561. &dwBlkSize,
  562. &dwBlkCount,
  563. &dwIfType);
  564. if (dwErr == NO_ERROR)
  565. {
  566. //
  567. // Get and set back the interface info
  568. //
  569. dwErr =IpmontrSetInfoBlockInInterfaceInfo(pmi0[i].wszInterfaceName,
  570. MS_IP_QOSMGR,
  571. (PBYTE) piicBlk,
  572. dwBlkSize,
  573. dwBlkCount);
  574. HEAP_FREE(piicBlk);
  575. }
  576. }
  577. return NO_ERROR;
  578. }