Source code of Windows XP (NT5)
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.

879 lines
21 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,
  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,
  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,
  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. CHAR 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,
  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. _snprintf(AddressFamilySubKey,
  451. MAX_CONFIG_KEY_SIZE,
  452. REG_KEY_ADDR_FAMILY_SUBKEY,
  453. AddressFamily);
  454. Status = RegCreateKeyEx(InstanceConfig,
  455. AddressFamilySubKey,
  456. 0,
  457. NULL,
  458. REG_OPTION_NON_VOLATILE,
  459. KEY_WRITE,
  460. NULL,
  461. &ConfigHandle,
  462. NULL);
  463. // Close the instance key as you no longer need it
  464. RegCloseKey(InstanceConfig);
  465. if (Status != NO_ERROR)
  466. {
  467. Trace1(ERR,
  468. "Address Family Config: Error %d creating address family key",
  469. Status);
  470. TraceLeave("RtmWriteAddressFamilyConfig");
  471. return Status;
  472. }
  473. //
  474. // Write values in address family config into the registry
  475. //
  476. do
  477. {
  478. //
  479. // Write the 'address size' value into the registry
  480. //
  481. KeyValue = AddrFamilyConfig->AddressSize;
  482. if ((KeyValue < MINIMUM_ADDRESS_SIZE) ||
  483. (KeyValue > MAXIMUM_ADDRESS_SIZE))
  484. {
  485. Trace1(ERR,
  486. "Address Family Config: Address Size %d out of bounds",
  487. KeyValue);
  488. break;
  489. }
  490. Status = RegSetValueEx(ConfigHandle,
  491. REG_KEY_ADDRESS_SIZE,
  492. 0,
  493. REG_DWORD,
  494. (PBYTE)&KeyValue,
  495. sizeof(ULONG));
  496. if (Status != NO_ERROR)
  497. {
  498. break;
  499. }
  500. //
  501. // Write the 'views supported' value into the registry
  502. //
  503. KeyValue = AddrFamilyConfig->ViewsSupported;
  504. if (KeyValue == 0)
  505. {
  506. Trace0(ERR, "Address Family Config: No supported views");
  507. break;
  508. }
  509. Status = RegSetValueEx(ConfigHandle,
  510. REG_KEY_VIEWS_SUPPORTED,
  511. 0,
  512. REG_DWORD,
  513. (PBYTE)&KeyValue,
  514. sizeof(ULONG));
  515. if (Status != NO_ERROR)
  516. {
  517. break;
  518. }
  519. //
  520. // Write 'max change notifications' value into registry
  521. //
  522. KeyValue = AddrFamilyConfig->MaxChangeNotifyRegns;
  523. if ((KeyValue < MIN_MAX_NOTIFY_REGS) ||
  524. (KeyValue > MAX_MAX_NOTIFY_REGS))
  525. {
  526. Trace1(ERR,
  527. "Address Family Config: # Change notify regs out of range",
  528. KeyValue);
  529. break;
  530. }
  531. Status = RegSetValueEx(ConfigHandle,
  532. REG_KEY_MAX_NOTIFY_REGS,
  533. 0,
  534. REG_DWORD,
  535. (PBYTE)&KeyValue,
  536. sizeof(ULONG));
  537. if (Status != NO_ERROR)
  538. {
  539. break;
  540. }
  541. //
  542. // Write 'max opaque info ptrs' value into registry
  543. //
  544. KeyValue = AddrFamilyConfig->MaxOpaqueInfoPtrs;
  545. if (((int)KeyValue < MIN_OPAQUE_INFO_PTRS) ||
  546. (KeyValue > MAX_OPAQUE_INFO_PTRS))
  547. {
  548. Trace1(ERR,
  549. "Address Family Config: # opaque ptrs out of range",
  550. KeyValue);
  551. break;
  552. }
  553. Status = RegSetValueEx(ConfigHandle,
  554. REG_KEY_OPAQUE_INFO_PTRS,
  555. 0,
  556. REG_DWORD,
  557. (PBYTE)&KeyValue,
  558. sizeof(ULONG));
  559. if (Status != NO_ERROR)
  560. {
  561. break;
  562. }
  563. //
  564. // Write 'max next hops per route' value into registry
  565. //
  566. KeyValue = AddrFamilyConfig->MaxNextHopsInRoute;
  567. if ((KeyValue < MIN_NEXTHOPS_IN_ROUTE) ||
  568. (KeyValue > MAX_NEXTHOPS_IN_ROUTE))
  569. {
  570. Trace1(ERR,
  571. "Address Family Config: # nexthops out of range",
  572. KeyValue);
  573. break;
  574. }
  575. Status = RegSetValueEx(ConfigHandle,
  576. REG_KEY_NEXTHOPS_IN_ROUTE,
  577. 0,
  578. REG_DWORD,
  579. (PBYTE)&KeyValue,
  580. sizeof(ULONG));
  581. if (Status != NO_ERROR)
  582. {
  583. break;
  584. }
  585. //
  586. // Write 'max handles returned in enum' value into registry
  587. //
  588. KeyValue = AddrFamilyConfig->MaxHandlesInEnum;
  589. if ((KeyValue < MIN_MAX_HANDLES_IN_ENUM) ||
  590. (KeyValue > MAX_MAX_HANDLES_IN_ENUM))
  591. {
  592. Trace1(ERR,
  593. "Address Family Config: # handles returned in enum",
  594. KeyValue);
  595. break;
  596. }
  597. Status = RegSetValueEx(ConfigHandle,
  598. REG_KEY_MAX_HANDLES_IN_ENUM,
  599. 0,
  600. REG_DWORD,
  601. (PBYTE)&KeyValue,
  602. sizeof(ULONG));
  603. if (Status != NO_ERROR)
  604. {
  605. break;
  606. }
  607. //
  608. // Close the address family key once you are done writing
  609. //
  610. RegCloseKey(ConfigHandle);
  611. TraceLeave("RtmWriteAddressFamilyConfig");
  612. return NO_ERROR;
  613. }
  614. while (FALSE);
  615. //
  616. // Were config values out of bounds ? Adjust err code
  617. //
  618. if (Status == NO_ERROR)
  619. {
  620. Status = ERROR_INVALID_PARAMETER;
  621. }
  622. //
  623. // Error occured, close the handle and delete the key
  624. //
  625. Trace1(ERR,
  626. "Address Family Config: Error %d writing address family params",
  627. Status);
  628. RegCloseKey(ConfigHandle);
  629. _snprintf(RtmGlobals.RegistryPath + RTM_CONFIG_ROOT_SIZE - 1,
  630. MAX_CONFIG_KEY_SIZE,
  631. REG_KEY_ADDR_FAMILY_TEMPLATE,
  632. RtmInstanceId,
  633. AddressFamily);
  634. RegDeleteKey(HKEY_LOCAL_MACHINE, RtmGlobals.RegistryPath);
  635. TraceLeave("RtmWriteAddressFamilyConfig");
  636. return Status;
  637. }