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.

881 lines
22 KiB

  1. /*++
  2. Copyright (c) 1997-1998 Microsoft Corporation
  3. Module Name:
  4. rtmcnfg.c
  5. Abstract:
  6. Routines that operate on configuration
  7. information for RTM in the registry.
  8. Author:
  9. Chaitanya Kodeboyina (chaitk) 21-Aug-1998
  10. Revision History:
  11. --*/
  12. #include "pchrtm.h"
  13. #pragma hdrstop
  14. DWORD
  15. RtmWriteDefaultConfig (
  16. IN USHORT RtmInstanceId
  17. )
  18. /*++
  19. Routine Description:
  20. Write default configuration information into the
  21. registry.
  22. Arguments:
  23. RtmInstanceId - Unique Id for this RTM instance
  24. Return Value:
  25. Status of the operation.
  26. --*/
  27. {
  28. RTM_INSTANCE_CONFIG InstanceConfig;
  29. RTM_ADDRESS_FAMILY_CONFIG AddrFamConfig;
  30. DWORD Status;
  31. CHECK_FOR_RTM_API_INITIALIZED();
  32. TraceEnter("RtmWriteDefaultConfig");
  33. //
  34. // We have no RTM instance parameters at present
  35. //
  36. Status = RtmWriteInstanceConfig(RtmInstanceId, &InstanceConfig);
  37. if (Status != NO_ERROR)
  38. {
  39. Trace1(ERR, "Default Config: Error %d writing instance key", Status);
  40. TraceLeave("RtmWriteDefaultConfig");
  41. return Status;
  42. }
  43. //
  44. // Set up default address family parameters
  45. //
  46. AddrFamConfig.AddressSize = DEFAULT_ADDRESS_SIZE;
  47. AddrFamConfig.MaxOpaqueInfoPtrs = DEFAULT_OPAQUE_INFO_PTRS;
  48. AddrFamConfig.MaxNextHopsInRoute = DEFAULT_NEXTHOPS_IN_ROUTE;
  49. AddrFamConfig.ViewsSupported = DEFAULT_VIEWS_SUPPORTED;
  50. AddrFamConfig.MaxHandlesInEnum = DEFAULT_MAX_HANDLES_IN_ENUM;
  51. AddrFamConfig.MaxChangeNotifyRegns = DEFAULT_MAX_NOTIFY_REGS;
  52. //
  53. // Write the default address family config
  54. //
  55. Status = RtmWriteAddressFamilyConfig(RtmInstanceId,
  56. AF_INET,
  57. &AddrFamConfig);
  58. if (Status != NO_ERROR)
  59. {
  60. Trace1(ERR,
  61. "Default Config: Error %d writing address family subkey",
  62. Status);
  63. }
  64. TraceLeave("RtmWriteDefaultConfig");
  65. return Status;
  66. }
  67. DWORD
  68. WINAPI
  69. RtmReadInstanceConfig (
  70. IN USHORT RtmInstanceId,
  71. OUT PRTM_INSTANCE_CONFIG InstanceConfig
  72. )
  73. /*++
  74. Routine Description:
  75. Reads the configuration information for a particular
  76. instance at creation time.
  77. Arguments:
  78. RtmInstanceId - Unique Id for this instance,
  79. InstanceConfig - Buffer in which config info is retd.
  80. Return Value:
  81. Status of the operation.
  82. --*/
  83. {
  84. HKEY ConfigHandle;
  85. ULONG KeySize;
  86. DWORD Status;
  87. UNREFERENCED_PARAMETER(InstanceConfig);
  88. CHECK_FOR_RTM_API_INITIALIZED();
  89. TraceEnter("RtmReadInstanceConfig");
  90. //
  91. // Open the key that holds this instance's config
  92. //
  93. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  94. (MAX_CONFIG_KEY_SIZE - RTM_CONFIG_ROOT_SIZE)/sizeof(TCHAR),
  95. REG_KEY_INSTANCE_TEMPLATE,
  96. RtmInstanceId);
  97. Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  98. RtmGlobals.RegistryPath,
  99. 0,
  100. KEY_READ,
  101. &ConfigHandle);
  102. if (Status != NO_ERROR)
  103. {
  104. Trace1(ERR, "Instance Config: Error %d opening instance key", Status);
  105. TraceLeave("RtmReadInstanceConfig");
  106. return Status;
  107. }
  108. do
  109. {
  110. //
  111. // Query values for parameters in instance config
  112. //
  113. KeySize = sizeof(DWORD);
  114. // Nothing in the instance config at present
  115. //
  116. // Close the instance key once you are done querying
  117. //
  118. RegCloseKey(ConfigHandle);
  119. TraceLeave("RtmReadInstanceConfig");
  120. return NO_ERROR;
  121. }
  122. while (FALSE);
  123. //
  124. // Some error in the config - close handle and ret error
  125. //
  126. RegCloseKey(ConfigHandle);
  127. TraceLeave("RtmReadInstanceConfig");
  128. return (Status != NO_ERROR) ? Status: ERROR_BAD_CONFIGURATION;
  129. }
  130. DWORD
  131. WINAPI
  132. RtmWriteInstanceConfig (
  133. IN USHORT RtmInstanceId,
  134. IN PRTM_INSTANCE_CONFIG InstanceConfig
  135. )
  136. /*++
  137. Routine Description:
  138. Write the input instance config information into the
  139. registry.
  140. Arguments:
  141. RtmInstanceId - Unique Id for this instance,
  142. InstanceConfig - Config info for this instance.
  143. Return Value:
  144. Status of the operation.
  145. --*/
  146. {
  147. HKEY ConfigHandle;
  148. DWORD Status;
  149. UNREFERENCED_PARAMETER(InstanceConfig);
  150. CHECK_FOR_RTM_API_INITIALIZED();
  151. TraceEnter("RtmWriteInstanceConfig");
  152. //
  153. // Create a key (or open existing) to hold instance's config
  154. //
  155. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  156. (MAX_CONFIG_KEY_SIZE - RTM_CONFIG_ROOT_SIZE)/sizeof(TCHAR),
  157. REG_KEY_INSTANCE_TEMPLATE,
  158. RtmInstanceId);
  159. Status = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  160. RtmGlobals.RegistryPath,
  161. 0,
  162. NULL,
  163. REG_OPTION_NON_VOLATILE,
  164. KEY_WRITE,
  165. NULL,
  166. &ConfigHandle,
  167. NULL);
  168. if (Status != NO_ERROR)
  169. {
  170. Trace1(ERR, "Instance Config: Error %d creating instance key", Status);
  171. TraceLeave("RtmWriteInstanceConfig");
  172. return Status;
  173. }
  174. do
  175. {
  176. //
  177. // Write values in instance config into the registry
  178. //
  179. // Nothing in the instance config at present time
  180. //
  181. // Close the instance key once you are done writing
  182. //
  183. RegCloseKey(ConfigHandle);
  184. TraceLeave("RtmWriteInstanceConfig");
  185. return NO_ERROR;
  186. }
  187. while (FALSE);
  188. //
  189. // Error writing values; close the handle and delete the key
  190. //
  191. Trace1(ERR,
  192. "Instance Config: Error %d writing instance config parameters",
  193. Status);
  194. RegCloseKey(ConfigHandle);
  195. RegDeleteKey(HKEY_LOCAL_MACHINE, RtmGlobals.RegistryPath);
  196. TraceLeave("RtmWriteInstanceConfig");
  197. return Status;
  198. }
  199. DWORD
  200. WINAPI
  201. RtmReadAddressFamilyConfig (
  202. IN USHORT RtmInstanceId,
  203. IN USHORT AddressFamily,
  204. OUT PRTM_ADDRESS_FAMILY_CONFIG AddrFamilyConfig
  205. )
  206. /*++
  207. Routine Description:
  208. Reads the configuration information for a particular
  209. address family at creation time.
  210. Arguments:
  211. RtmInstanceId - ID (IPv4..) for this addr family info,
  212. AddrFamilyConfig - Buffer in which addr family info is retd.
  213. Return Value:
  214. Status of the operation.
  215. --*/
  216. {
  217. HKEY ConfigHandle;
  218. ULONG KeySize;
  219. ULONG KeyValue;
  220. ULONG KeyType;
  221. DWORD Status;
  222. CHECK_FOR_RTM_API_INITIALIZED();
  223. TraceEnter("RtmReadAddressFamilyConfig");
  224. //
  225. // Open the key that holds this address family's config
  226. //
  227. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  228. (MAX_CONFIG_KEY_SIZE - RTM_CONFIG_ROOT_SIZE)/sizeof(TCHAR),
  229. REG_KEY_ADDR_FAMILY_TEMPLATE,
  230. RtmInstanceId,
  231. AddressFamily);
  232. Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  233. RtmGlobals.RegistryPath,
  234. 0,
  235. KEY_READ,
  236. &ConfigHandle);
  237. if (Status != NO_ERROR)
  238. {
  239. Trace1(ERR,
  240. "Address Family Config: Error %d opening address family key",
  241. Status);
  242. TraceLeave("RtmReadAddressFamilyConfig");
  243. return Status;
  244. }
  245. do
  246. {
  247. //
  248. // Query values for parameters in address family config
  249. //
  250. KeySize = sizeof(DWORD);
  251. //
  252. // Query the 'address size' parameter
  253. //
  254. Status = RegQueryValueEx(ConfigHandle,
  255. REG_KEY_ADDRESS_SIZE,
  256. NULL,
  257. &KeyType,
  258. (PBYTE)&KeyValue,
  259. &KeySize);
  260. if ((Status != NO_ERROR) || (KeyType != REG_DWORD))
  261. {
  262. Trace1(ERR,
  263. "Address Family Config: Error %d reading address size key",
  264. Status);
  265. break;
  266. }
  267. if ((KeyValue < MINIMUM_ADDRESS_SIZE) ||
  268. (KeyValue > MAXIMUM_ADDRESS_SIZE))
  269. {
  270. Trace1(ERR,
  271. "Address Family Config: Address Size %d out of bounds",
  272. KeyValue);
  273. break;
  274. }
  275. AddrFamilyConfig->AddressSize = KeyValue;
  276. //
  277. // Query the 'views supported' parameter
  278. //
  279. Status = RegQueryValueEx(ConfigHandle,
  280. REG_KEY_VIEWS_SUPPORTED,
  281. NULL,
  282. &KeyType,
  283. (PBYTE)&KeyValue,
  284. &KeySize);
  285. AddrFamilyConfig->ViewsSupported = DEFAULT_VIEWS_SUPPORTED;
  286. if (Status == NO_ERROR)
  287. {
  288. if (KeyValue == 0)
  289. {
  290. Trace0(ERR, "Address Family Config: No supported views");
  291. break;
  292. }
  293. AddrFamilyConfig->ViewsSupported = KeyValue;
  294. }
  295. //
  296. // Query the 'max change notifications' parameter
  297. //
  298. Status = RegQueryValueEx(ConfigHandle,
  299. REG_KEY_MAX_NOTIFY_REGS,
  300. NULL,
  301. &KeyType,
  302. (PBYTE)&KeyValue,
  303. &KeySize);
  304. AddrFamilyConfig->MaxChangeNotifyRegns = DEFAULT_MAX_NOTIFY_REGS;
  305. if (Status == NO_ERROR)
  306. {
  307. if ((KeyValue < MIN_MAX_NOTIFY_REGS) ||
  308. (KeyValue > MAX_MAX_NOTIFY_REGS))
  309. {
  310. Trace1(ERR,
  311. "Address Family Config: # notifications out of range",
  312. KeyValue);
  313. break;
  314. }
  315. AddrFamilyConfig->MaxChangeNotifyRegns = KeyValue;
  316. }
  317. //
  318. // Query the 'max opaque info ptrs' parameter
  319. //
  320. Status = RegQueryValueEx(ConfigHandle,
  321. REG_KEY_OPAQUE_INFO_PTRS,
  322. NULL,
  323. &KeyType,
  324. (PBYTE)&KeyValue,
  325. &KeySize);
  326. AddrFamilyConfig->MaxOpaqueInfoPtrs = DEFAULT_OPAQUE_INFO_PTRS;
  327. if (Status == NO_ERROR)
  328. {
  329. if (((int)KeyValue < MIN_OPAQUE_INFO_PTRS) ||
  330. (KeyValue > MAX_OPAQUE_INFO_PTRS))
  331. {
  332. Trace1(ERR,
  333. "Address Family Config: # opaque ptrs out of range",
  334. KeyValue);
  335. break;
  336. }
  337. AddrFamilyConfig->MaxOpaqueInfoPtrs = KeyValue;
  338. }
  339. //
  340. // Query the 'max next hops per route' parameter
  341. //
  342. Status = RegQueryValueEx(ConfigHandle,
  343. REG_KEY_NEXTHOPS_IN_ROUTE,
  344. NULL,
  345. &KeyType,
  346. (PBYTE)&KeyValue,
  347. &KeySize);
  348. AddrFamilyConfig->MaxNextHopsInRoute = DEFAULT_NEXTHOPS_IN_ROUTE;
  349. if (Status == NO_ERROR)
  350. {
  351. if ((KeyValue < MIN_NEXTHOPS_IN_ROUTE) ||
  352. (KeyValue > MAX_NEXTHOPS_IN_ROUTE))
  353. {
  354. Trace1(ERR,
  355. "Address Family Config: # nexthops out of range",
  356. KeyValue);
  357. break;
  358. }
  359. AddrFamilyConfig->MaxNextHopsInRoute = KeyValue;
  360. }
  361. //
  362. // Query the 'max handles returned in enum' parameter
  363. //
  364. Status = RegQueryValueEx(ConfigHandle,
  365. REG_KEY_MAX_HANDLES_IN_ENUM,
  366. NULL,
  367. &KeyType,
  368. (PBYTE)&KeyValue,
  369. &KeySize);
  370. AddrFamilyConfig->MaxHandlesInEnum = DEFAULT_MAX_HANDLES_IN_ENUM;
  371. if (Status == NO_ERROR)
  372. {
  373. if ((KeyValue < MIN_MAX_HANDLES_IN_ENUM) ||
  374. (KeyValue > MAX_MAX_HANDLES_IN_ENUM))
  375. {
  376. Trace1(ERR,
  377. "Address Family Config: # handles returned in enum",
  378. KeyValue);
  379. break;
  380. }
  381. AddrFamilyConfig->MaxHandlesInEnum = KeyValue;
  382. }
  383. //
  384. // Close the instance key once you are done querying
  385. //
  386. RegCloseKey(ConfigHandle);
  387. TraceLeave("RtmReadAddressFamilyConfig");
  388. return NO_ERROR;
  389. }
  390. while (FALSE);
  391. //
  392. // Some error in the config - close handle and ret error
  393. //
  394. RegCloseKey(ConfigHandle);
  395. TraceLeave("RtmReadAddressFamilyConfig");
  396. return (Status != NO_ERROR) ? Status: ERROR_BAD_CONFIGURATION;
  397. }
  398. DWORD
  399. WINAPI
  400. RtmWriteAddressFamilyConfig (
  401. IN USHORT RtmInstanceId,
  402. IN USHORT AddressFamily,
  403. IN PRTM_ADDRESS_FAMILY_CONFIG AddrFamilyConfig
  404. )
  405. /*++
  406. Routine Description:
  407. Write the input address family config information
  408. into the registry.
  409. Arguments:
  410. RtmInstanceId - Instance to which addr family belongs to,
  411. AddressFamily - ID for this address family,
  412. AddrFamilyConfig - Configuration info for this address family.
  413. Return Value:
  414. Status of the operation.
  415. --*/
  416. {
  417. TCHAR AddressFamilySubKey[MAX_CONFIG_KEY_SIZE];
  418. HKEY InstanceConfig;
  419. HKEY ConfigHandle;
  420. ULONG KeyValue;
  421. DWORD Status;
  422. CHECK_FOR_RTM_API_INITIALIZED();
  423. TraceEnter("RtmWriteAddressFamilyConfig");
  424. //
  425. // Open the existing key that holds this RTM instance's config
  426. //
  427. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  428. (MAX_CONFIG_KEY_SIZE - RTM_CONFIG_ROOT_SIZE)/sizeof(TCHAR),
  429. REG_KEY_INSTANCE_TEMPLATE,
  430. RtmInstanceId);
  431. Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  432. RtmGlobals.RegistryPath,
  433. 0,
  434. KEY_READ,
  435. &InstanceConfig);
  436. if (Status != NO_ERROR)
  437. {
  438. //
  439. // Need to create an instance before creating addr family
  440. //
  441. Trace1(ERR,
  442. "Address Family Config: Error %d opening instance key",
  443. Status);
  444. TraceLeave("RtmWriteAddressFamilyConfig");
  445. return Status;
  446. }
  447. //
  448. // Create (or open existing) key to hold addr family's config
  449. //
  450. AddressFamilySubKey[MAX_CONFIG_KEY_SIZE - 1] = '\0';
  451. _snprintf(AddressFamilySubKey,
  452. (MAX_CONFIG_KEY_SIZE - 1)/sizeof(TCHAR),
  453. REG_KEY_ADDR_FAMILY_SUBKEY,
  454. AddressFamily);
  455. Status = RegCreateKeyEx(InstanceConfig,
  456. AddressFamilySubKey,
  457. 0,
  458. NULL,
  459. REG_OPTION_NON_VOLATILE,
  460. KEY_WRITE,
  461. NULL,
  462. &ConfigHandle,
  463. NULL);
  464. // Close the instance key as you no longer need it
  465. RegCloseKey(InstanceConfig);
  466. if (Status != NO_ERROR)
  467. {
  468. Trace1(ERR,
  469. "Address Family Config: Error %d creating address family key",
  470. Status);
  471. TraceLeave("RtmWriteAddressFamilyConfig");
  472. return Status;
  473. }
  474. //
  475. // Write values in address family config into the registry
  476. //
  477. do
  478. {
  479. //
  480. // Write the 'address size' value into the registry
  481. //
  482. KeyValue = AddrFamilyConfig->AddressSize;
  483. if ((KeyValue < MINIMUM_ADDRESS_SIZE) ||
  484. (KeyValue > MAXIMUM_ADDRESS_SIZE))
  485. {
  486. Trace1(ERR,
  487. "Address Family Config: Address Size %d out of bounds",
  488. KeyValue);
  489. break;
  490. }
  491. Status = RegSetValueEx(ConfigHandle,
  492. REG_KEY_ADDRESS_SIZE,
  493. 0,
  494. REG_DWORD,
  495. (PBYTE)&KeyValue,
  496. sizeof(ULONG));
  497. if (Status != NO_ERROR)
  498. {
  499. break;
  500. }
  501. //
  502. // Write the 'views supported' value into the registry
  503. //
  504. KeyValue = AddrFamilyConfig->ViewsSupported;
  505. if (KeyValue == 0)
  506. {
  507. Trace0(ERR, "Address Family Config: No supported views");
  508. break;
  509. }
  510. Status = RegSetValueEx(ConfigHandle,
  511. REG_KEY_VIEWS_SUPPORTED,
  512. 0,
  513. REG_DWORD,
  514. (PBYTE)&KeyValue,
  515. sizeof(ULONG));
  516. if (Status != NO_ERROR)
  517. {
  518. break;
  519. }
  520. //
  521. // Write 'max change notifications' value into registry
  522. //
  523. KeyValue = AddrFamilyConfig->MaxChangeNotifyRegns;
  524. if ((KeyValue < MIN_MAX_NOTIFY_REGS) ||
  525. (KeyValue > MAX_MAX_NOTIFY_REGS))
  526. {
  527. Trace1(ERR,
  528. "Address Family Config: # Change notify regs out of range",
  529. KeyValue);
  530. break;
  531. }
  532. Status = RegSetValueEx(ConfigHandle,
  533. REG_KEY_MAX_NOTIFY_REGS,
  534. 0,
  535. REG_DWORD,
  536. (PBYTE)&KeyValue,
  537. sizeof(ULONG));
  538. if (Status != NO_ERROR)
  539. {
  540. break;
  541. }
  542. //
  543. // Write 'max opaque info ptrs' value into registry
  544. //
  545. KeyValue = AddrFamilyConfig->MaxOpaqueInfoPtrs;
  546. if (((int)KeyValue < MIN_OPAQUE_INFO_PTRS) ||
  547. (KeyValue > MAX_OPAQUE_INFO_PTRS))
  548. {
  549. Trace1(ERR,
  550. "Address Family Config: # opaque ptrs out of range",
  551. KeyValue);
  552. break;
  553. }
  554. Status = RegSetValueEx(ConfigHandle,
  555. REG_KEY_OPAQUE_INFO_PTRS,
  556. 0,
  557. REG_DWORD,
  558. (PBYTE)&KeyValue,
  559. sizeof(ULONG));
  560. if (Status != NO_ERROR)
  561. {
  562. break;
  563. }
  564. //
  565. // Write 'max next hops per route' value into registry
  566. //
  567. KeyValue = AddrFamilyConfig->MaxNextHopsInRoute;
  568. if ((KeyValue < MIN_NEXTHOPS_IN_ROUTE) ||
  569. (KeyValue > MAX_NEXTHOPS_IN_ROUTE))
  570. {
  571. Trace1(ERR,
  572. "Address Family Config: # nexthops out of range",
  573. KeyValue);
  574. break;
  575. }
  576. Status = RegSetValueEx(ConfigHandle,
  577. REG_KEY_NEXTHOPS_IN_ROUTE,
  578. 0,
  579. REG_DWORD,
  580. (PBYTE)&KeyValue,
  581. sizeof(ULONG));
  582. if (Status != NO_ERROR)
  583. {
  584. break;
  585. }
  586. //
  587. // Write 'max handles returned in enum' value into registry
  588. //
  589. KeyValue = AddrFamilyConfig->MaxHandlesInEnum;
  590. if ((KeyValue < MIN_MAX_HANDLES_IN_ENUM) ||
  591. (KeyValue > MAX_MAX_HANDLES_IN_ENUM))
  592. {
  593. Trace1(ERR,
  594. "Address Family Config: # handles returned in enum",
  595. KeyValue);
  596. break;
  597. }
  598. Status = RegSetValueEx(ConfigHandle,
  599. REG_KEY_MAX_HANDLES_IN_ENUM,
  600. 0,
  601. REG_DWORD,
  602. (PBYTE)&KeyValue,
  603. sizeof(ULONG));
  604. if (Status != NO_ERROR)
  605. {
  606. break;
  607. }
  608. //
  609. // Close the address family key once you are done writing
  610. //
  611. RegCloseKey(ConfigHandle);
  612. TraceLeave("RtmWriteAddressFamilyConfig");
  613. return NO_ERROR;
  614. }
  615. while (FALSE);
  616. //
  617. // Were config values out of bounds ? Adjust err code
  618. //
  619. if (Status == NO_ERROR)
  620. {
  621. Status = ERROR_INVALID_PARAMETER;
  622. }
  623. //
  624. // Error occured, close the handle and delete the key
  625. //
  626. Trace1(ERR,
  627. "Address Family Config: Error %d writing address family params",
  628. Status);
  629. RegCloseKey(ConfigHandle);
  630. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  631. (MAX_CONFIG_KEY_SIZE - RTM_CONFIG_ROOT_SIZE)/sizeof(TCHAR),
  632. REG_KEY_ADDR_FAMILY_TEMPLATE,
  633. RtmInstanceId,
  634. AddressFamily);
  635. RegDeleteKey(HKEY_LOCAL_MACHINE, RtmGlobals.RegistryPath);
  636. TraceLeave("RtmWriteAddressFamilyConfig");
  637. return Status;
  638. }