srv_config.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. // Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef DHCPSRV_CONFIG_H
  7. #define DHCPSRV_CONFIG_H
  8. #include <dhcpsrv/cfg_db_access.h>
  9. #include <dhcpsrv/cfg_duid.h>
  10. #include <dhcpsrv/cfg_expiration.h>
  11. #include <dhcpsrv/cfg_host_operations.h>
  12. #include <dhcpsrv/cfg_hosts.h>
  13. #include <dhcpsrv/cfg_iface.h>
  14. #include <dhcpsrv/cfg_option.h>
  15. #include <dhcpsrv/cfg_option_def.h>
  16. #include <dhcpsrv/cfg_rsoo.h>
  17. #include <dhcpsrv/cfg_subnets4.h>
  18. #include <dhcpsrv/cfg_subnets6.h>
  19. #include <dhcpsrv/cfg_mac_source.h>
  20. #include <dhcpsrv/client_class_def.h>
  21. #include <dhcpsrv/logging_info.h>
  22. #include <cc/data.h>
  23. #include <boost/shared_ptr.hpp>
  24. #include <vector>
  25. #include <stdint.h>
  26. namespace isc {
  27. namespace dhcp {
  28. class CfgMgr;
  29. /// @brief Specifies current DHCP configuration
  30. ///
  31. /// @todo Migrate all other configuration parameters from cfgmgr.h here
  32. class SrvConfig {
  33. public:
  34. /// @name Constants for selection of parameters returned by @c getConfigSummary
  35. ///
  36. //@{
  37. /// Nothing selected
  38. static const uint32_t CFGSEL_NONE = 0x00000000;
  39. /// Number of IPv4 subnets
  40. static const uint32_t CFGSEL_SUBNET4 = 0x00000001;
  41. /// Number of IPv6 subnets
  42. static const uint32_t CFGSEL_SUBNET6 = 0x00000002;
  43. /// Number of enabled ifaces
  44. static const uint32_t CFGSEL_IFACE4 = 0x00000004;
  45. /// Number of v6 ifaces
  46. static const uint32_t CFGSEL_IFACE6 = 0x00000008;
  47. /// DDNS enabled/disabled
  48. static const uint32_t CFGSEL_DDNS = 0x00000010;
  49. /// Number of all subnets
  50. static const uint32_t CFGSEL_SUBNET = 0x00000003;
  51. /// IPv4 related config
  52. static const uint32_t CFGSEL_ALL4 = 0x00000015;
  53. /// IPv6 related config
  54. static const uint32_t CFGSEL_ALL6 = 0x0000001A;
  55. /// Whole config
  56. static const uint32_t CFGSEL_ALL = 0xFFFFFFFF;
  57. //@}
  58. /// @brief Default constructor.
  59. ///
  60. /// This constructor sets configuration sequence number to 0.
  61. SrvConfig();
  62. /// @brief Constructor.
  63. ///
  64. /// Sets arbitrary configuration sequence number.
  65. SrvConfig(const uint32_t sequence);
  66. /// @brief Returns summary of the configuration in the textual format.
  67. ///
  68. /// This method returns the brief text describing the current configuration.
  69. /// It may be used for logging purposes, e.g. when the new configuration is
  70. /// committed to notify a user about the changes in configuration.
  71. ///
  72. /// @todo Currently this method uses @c CfgMgr accessors to get the
  73. /// configuration parameters. Once these parameters are migrated from the
  74. /// @c CfgMgr this method will have to be modified accordingly.
  75. ///
  76. /// @todo Implement reporting a summary of interfaces being used for
  77. /// receiving and sending DHCP messages. This will be implemented with
  78. /// ticket #3512.
  79. ///
  80. /// @param selection Is a bitfield which describes the parts of the
  81. /// configuration to be returned.
  82. ///
  83. /// @return Summary of the configuration in the textual format.
  84. std::string getConfigSummary(const uint32_t selection) const;
  85. /// @brief Returns configuration sequence number.
  86. uint32_t getSequence() const {
  87. return (sequence_);
  88. }
  89. /// @brief Compares configuration sequence with other sequence.
  90. ///
  91. /// This method compares sequence numbers of two configurations for
  92. /// equality. The sequence numbers are meant to be unique, so if
  93. /// they are equal it means that they point to the same configuration.
  94. ///
  95. /// @param other Configuration which sequence number should be
  96. /// compared with the sequence number of this configuration.
  97. ///
  98. /// @return true if sequence numbers are equal.
  99. bool sequenceEquals(const SrvConfig& other);
  100. /// @name Modifiers and accesors for the configuration objects.
  101. ///
  102. /// @warning References to the objects returned by accessors are only
  103. /// valid during the lifetime of the @c SrvConfig object which
  104. /// returned them.
  105. ///
  106. //@{
  107. /// @brief Returns logging specific configuration.
  108. const LoggingInfoStorage& getLoggingInfo() const {
  109. return (logging_info_);
  110. }
  111. /// @brief Sets logging specific configuration.
  112. ///
  113. /// @param logging_info New logging configuration.
  114. void addLoggingInfo(const LoggingInfo& logging_info) {
  115. logging_info_.push_back(logging_info);
  116. }
  117. /// @brief Returns non-const pointer to interface configuration.
  118. ///
  119. /// This function returns a non-const pointer to the interface
  120. /// configuration.
  121. ///
  122. /// @return Object representing configuration of interfaces.
  123. CfgIfacePtr getCfgIface() {
  124. return (cfg_iface_);
  125. }
  126. /// @brief Returns const pointer to interface configuration.
  127. ///
  128. /// This function returns a const pointer to the interface
  129. /// configuration.
  130. ///
  131. /// @return Object representing configuration of interfaces.
  132. ConstCfgIfacePtr getCfgIface() const {
  133. return (cfg_iface_);
  134. }
  135. /// @brief Return pointer to non-const object representing user-defined
  136. /// option definitions.
  137. ///
  138. /// This function returns a pointer to the object which represents the
  139. /// user defined option definitions grouped by option space name.
  140. ///
  141. /// @return Pointer to an object holding option definitions.
  142. CfgOptionDefPtr getCfgOptionDef() {
  143. return (cfg_option_def_);
  144. }
  145. /// @brief Returns pointer to the const object representing user-defined
  146. /// option definitions.
  147. ///
  148. /// This function returns a pointer to the object which represents the
  149. /// user defined option definitions grouped by option space name.
  150. ///
  151. /// @return Pointer to an object holding option definitions.
  152. ConstCfgOptionDefPtr getCfgOptionDef() const {
  153. return (cfg_option_def_);
  154. }
  155. /// @brief Returns pointer to the non-const object holding options.
  156. ///
  157. /// This method returns a pointer to the object which holds instances
  158. /// of the options to be returned to the clients belonging to any subnet.
  159. ///
  160. /// @return Pointer to the object holding options.
  161. CfgOptionPtr getCfgOption() {
  162. return (cfg_option_);
  163. }
  164. /// @brief Returns pointer to the const object holding options.
  165. ///
  166. /// This method returns a pointer to the object which holds instances
  167. /// of the options to be returned to the clients belonging to any subnet.
  168. ///
  169. /// @return Pointer to the object holding options.
  170. const ConstCfgOptionPtr getCfgOption() const {
  171. return (cfg_option_);
  172. }
  173. /// @brief Returns pointer to non-const object holding subnets configuration
  174. /// for DHCPv4.
  175. ///
  176. /// @return Pointer to the object holding subnets configuration for DHCPv4.
  177. CfgSubnets4Ptr getCfgSubnets4() {
  178. return (cfg_subnets4_);
  179. }
  180. /// @brief Returns pointer to const object holding subnets configuration for
  181. /// DHCPv4.
  182. ///
  183. /// @return Pointer to the object holding subnets configuration for DHCPv4.
  184. ConstCfgSubnets4Ptr getCfgSubnets4() const {
  185. return (cfg_subnets4_);
  186. }
  187. /// @brief Returns pointer to non-const object holding subnets configuration
  188. /// for DHCPv6.
  189. ///
  190. /// @return Pointer to the object holding subnets configuration for DHCPv6.
  191. CfgSubnets6Ptr getCfgSubnets6() {
  192. return (cfg_subnets6_);
  193. }
  194. /// @brief Returns pointer to const object holding subnets configuration for
  195. /// DHCPv6.
  196. ///
  197. /// @return Pointer to the object holding subnets configuration for DHCPv6.
  198. ConstCfgSubnets6Ptr getCfgSubnets6() const {
  199. return (cfg_subnets6_);
  200. }
  201. /// @brief Returns pointer to the non-const objects representing host
  202. /// reservations for different IPv4 and IPv6 subnets.
  203. ///
  204. /// @return Pointer to the non-const object holding host reservations.
  205. CfgHostsPtr getCfgHosts() {
  206. return (cfg_hosts_);
  207. }
  208. /// @brief Returns pointer to the const objects representing host
  209. /// reservations for different IPv4 and IPv6 subnets.
  210. ///
  211. /// @return Pointer to the const object holding host reservations.
  212. ConstCfgHostsPtr getCfgHosts() const {
  213. return (cfg_hosts_);
  214. }
  215. /// @brief Returns pointer to the non-const object representing
  216. /// set of RSOO-enabled options.
  217. ///
  218. /// @return Pointer to the non-const object holding RSOO-enabled
  219. /// options.
  220. CfgRSOOPtr getCfgRSOO() {
  221. return (cfg_rsoo_);
  222. }
  223. /// @brief Returns pointer to the const object representing set
  224. /// of RSOO-enabled options.
  225. ///
  226. /// @return Pointer to the const object holding RSOO-enabled
  227. /// options.
  228. ConstCfgRSOOPtr getCfgRSOO() const {
  229. return (cfg_rsoo_);
  230. }
  231. /// @brief Returns pointer to the object holding configuration pertaining
  232. /// to processing expired leases.
  233. CfgExpirationPtr getCfgExpiration() {
  234. return (cfg_expiration_);
  235. }
  236. /// @brief Returns pointer to the const object holding configuration
  237. /// pertaining to processing expired leases.
  238. ConstCfgExpirationPtr getCfgExpiration() const {
  239. return (cfg_expiration_);
  240. }
  241. /// @brief Returns pointer to the object holding configuration of the
  242. /// server identifier.
  243. CfgDUIDPtr getCfgDUID() {
  244. return (cfg_duid_);
  245. }
  246. /// @brief Returns const pointer to the object holding configuration
  247. /// of the server identifier.
  248. ConstCfgDUIDPtr getCfgDUID() const {
  249. return (cfg_duid_);
  250. }
  251. /// @brief Returns pointer to the object holding configuration of the
  252. /// lease and host database connection parameters.
  253. CfgDbAccessPtr getCfgDbAccess() {
  254. return (cfg_db_access_);
  255. }
  256. /// @brief Returns const pointer to the object holding configuration of
  257. /// the lease and host database connection parameters.
  258. ConstCfgDbAccessPtr getCfgDbAccess() const {
  259. return (cfg_db_access_);
  260. }
  261. /// @brief Returns pointer to the object holding general configuration
  262. /// for host reservations in DHCPv4.
  263. CfgHostOperationsPtr getCfgHostOperations4() {
  264. return (cfg_host_operations4_);
  265. }
  266. /// @brief Returns const pointer to the object holding general
  267. /// configuration for host reservations in DHCPv4
  268. ConstCfgHostOperationsPtr getCfgHostOperations4() const {
  269. return (cfg_host_operations4_);
  270. }
  271. /// @brief Returns pointer to the object holding general configuration
  272. /// for host reservations in DHCPv6.
  273. CfgHostOperationsPtr getCfgHostOperations6() {
  274. return (cfg_host_operations6_);
  275. }
  276. /// @brief Returns const pointer to the object holding general
  277. /// configuration for host reservations in DHCPv6
  278. ConstCfgHostOperationsPtr getCfgHostOperations6() const {
  279. return (cfg_host_operations6_);
  280. }
  281. //@}
  282. /// @brief Returns non-const reference to an array that stores
  283. /// MAC/hardware address sources.
  284. ///
  285. /// @return non-const reference to MAC/hardware address sources
  286. CfgMACSource& getMACSources() {
  287. return (cfg_mac_source_);
  288. }
  289. /// @brief Returns const reference to an array that stores
  290. /// MAC/hardware address sources.
  291. ///
  292. /// @return const reference to MAC/hardware address sources
  293. const CfgMACSource& getMACSources() const {
  294. return (cfg_mac_source_);
  295. }
  296. /// @brief Returns information about control socket
  297. /// @return pointer to the Element that holds control-socket map
  298. const isc::data::ConstElementPtr getControlSocketInfo() const {
  299. return (control_socket_);
  300. }
  301. /// @brief Sets information about the control socket
  302. /// @param control_socket Element that holds control-socket map
  303. void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket) {
  304. control_socket_ = control_socket;
  305. }
  306. /// @brief Returns pointer to the dictionary of global client
  307. /// class definitions
  308. ClientClassDictionaryPtr getClientClassDictionary() {
  309. return (class_dictionary_);
  310. }
  311. /// @brief Returns pointer to const dictionary of global client
  312. /// class definitions
  313. const ClientClassDictionaryPtr getClientClassDictionary() const {
  314. return (class_dictionary_);
  315. }
  316. /// @brief Sets the client class dictionary
  317. /// @param dictionary pointer to the new class dictionary
  318. void setClientClassDictionary(const ClientClassDictionaryPtr& dictionary) {
  319. class_dictionary_ = dictionary;
  320. }
  321. /// @brief Copies the currnet configuration to a new configuration.
  322. ///
  323. /// This method copies the parameters stored in the configuration to
  324. /// an object passed as parameter. The configuration sequence is not
  325. /// copied.
  326. ///
  327. /// @warning Some of the configuration objects are not copied at
  328. /// this point, e.g. subnets. This is because they contain quite complex
  329. /// data structures and they make use of pointers, so in many cases
  330. /// the default copy constructors can't be used. Implementing this
  331. /// requires quite a lot of time so this is left as is for now.
  332. /// The lack of ability to copy the entire configuration makes
  333. /// revert function of the @c CfgMgr unsuable.
  334. ///
  335. /// @param [out] new_config An object to which the configuration will
  336. /// be copied.
  337. void copy(SrvConfig& new_config) const;
  338. /// @brief Apply logging configuration to log4cplus.
  339. void applyLoggingCfg() const;
  340. /// @name Methods and operators used to compare configurations.
  341. ///
  342. //@{
  343. ///
  344. /// @brief Compares two objects for equality.
  345. ///
  346. /// It ignores the configuration sequence number when checking for
  347. /// equality of objects.
  348. ///
  349. /// @param other An object to be compared with this object.
  350. ///
  351. /// @return true if two objects are equal, false otherwise.
  352. bool equals(const SrvConfig& other) const;
  353. /// @brief Compares two objects for inequality.
  354. ///
  355. /// It ignores the configuration sequence number when checking for
  356. /// inequality of objects.
  357. ///
  358. /// @param other An object to be compared with this object.
  359. ///
  360. /// @return true if two objects are not equal, false otherwise.
  361. bool nequals(const SrvConfig& other) const {
  362. return (!equals(other));
  363. }
  364. /// @brief Equality operator.
  365. ///
  366. /// It ignores the configuration sequence number when checking for
  367. /// equality of objects.
  368. ///
  369. /// @param other An object to be compared with this object.
  370. ///
  371. /// @return true if two objects are equal, false otherwise.
  372. bool operator==(const SrvConfig& other) const {
  373. return (equals(other));
  374. }
  375. /// @param other An object to be compared with this object.
  376. ///
  377. /// It ignores the configuration sequence number when checking for
  378. /// inequality of objects.
  379. ///
  380. /// @param other An object to be compared with this object.
  381. ///
  382. /// @return true if two objects are not equal, false otherwise.
  383. bool operator!=(const SrvConfig& other) const {
  384. return (nequals(other));
  385. }
  386. //@}
  387. /// @brief Updates statistics.
  388. ///
  389. /// This method calls appropriate methods in child objects that update
  390. /// related statistics. See @ref CfgSubnets4::updateStatistics and
  391. /// @ref CfgSubnets6::updateStatistics for details.
  392. void updateStatistics();
  393. /// @brief Removes statistics.
  394. ///
  395. /// This method calls appropriate methods in child objects that remove
  396. /// related statistics. See @ref CfgSubnets4::removeStatistics and
  397. /// @ref CfgSubnets6::removeStatistics for details.
  398. void removeStatistics();
  399. /// @brief Sets decline probation-period
  400. ///
  401. /// Probation-period is the timer, expressed, in seconds, that specifies how
  402. /// long a lease is unavailable after reported as declined.
  403. ///
  404. /// @param decline_timer number of seconds after declined lease is restored
  405. void setDeclinePeriod(const uint32_t decline_timer) {
  406. decline_timer_ = decline_timer;
  407. }
  408. /// @brief Returns probation-period
  409. ///
  410. /// See @ref setDeclinePeriod for brief discussion.
  411. /// @return value of probation-period, expressed in seconds
  412. uint32_t getDeclinePeriod() const {
  413. return (decline_timer_);
  414. }
  415. private:
  416. /// @brief Sequence number identifying the configuration.
  417. uint32_t sequence_;
  418. /// @brief Logging specific information.
  419. LoggingInfoStorage logging_info_;
  420. /// @brief Interface configuration.
  421. ///
  422. /// Used to select interfaces on which the DHCP server will listen to
  423. /// queries.
  424. CfgIfacePtr cfg_iface_;
  425. /// @brief Pointer to option definitions configuration.
  426. ///
  427. /// This object holds the user-defined option definitions grouped
  428. /// by option space name.
  429. CfgOptionDefPtr cfg_option_def_;
  430. /// @brief Pointer to options (data) configuration.
  431. ///
  432. /// This object holds the instances of the options to be sent to clients
  433. /// connected to any subnet.
  434. CfgOptionPtr cfg_option_;
  435. /// @brief Pointer to subnets configuration for IPv4.
  436. CfgSubnets4Ptr cfg_subnets4_;
  437. /// @brief Pointer to subnets configuration for IPv6.
  438. CfgSubnets6Ptr cfg_subnets6_;
  439. /// @brief Pointer to the configuration for hosts reservation.
  440. ///
  441. /// This object holds a list of @c Host objects representing host
  442. /// reservations for different IPv4 and IPv6 subnets.
  443. CfgHostsPtr cfg_hosts_;
  444. /// @brief A list of configured MAC sources.
  445. CfgMACSource cfg_mac_source_;
  446. /// @brief Pointer to the configuration for RSOO-enabled options.
  447. ///
  448. /// This object holds a set of RSOO-enabled options. See
  449. /// RFC 6422 for the definition of the RSOO-enabled option.
  450. CfgRSOOPtr cfg_rsoo_;
  451. /// @brief Pointer to the configuration pertaining to processing of
  452. /// expired leases.
  453. CfgExpirationPtr cfg_expiration_;
  454. /// @brief Pointer to the configuration of the server identifier.
  455. CfgDUIDPtr cfg_duid_;
  456. /// @brief Pointer to the configuration of the lease and host database
  457. /// connection parameters.
  458. CfgDbAccessPtr cfg_db_access_;
  459. /// @brief Pointer to the general configuration for host reservations in
  460. /// DHCPv4.
  461. CfgHostOperationsPtr cfg_host_operations4_;
  462. /// @brief Pointer to the general configuration for host reservations in
  463. /// DHCPv6.
  464. CfgHostOperationsPtr cfg_host_operations6_;
  465. /// @brief Pointer to the control-socket information
  466. isc::data::ConstElementPtr control_socket_;
  467. /// @brief Pointer to the dictionary of global client class definitions
  468. ClientClassDictionaryPtr class_dictionary_;
  469. /// @brief Decline Period time
  470. ///
  471. /// This timer specifies decline probation period, the time after a declined
  472. /// lease is recovered back to available state. Expressed in seconds.
  473. uint32_t decline_timer_;
  474. };
  475. /// @name Pointers to the @c SrvConfig object.
  476. ///
  477. //@{
  478. /// @brief Non-const pointer to the @c SrvConfig.
  479. typedef boost::shared_ptr<SrvConfig> SrvConfigPtr;
  480. /// @brief Const pointer to the @c SrvConfig.
  481. typedef boost::shared_ptr<const SrvConfig> ConstSrvConfigPtr;
  482. //@}
  483. } // namespace isc::dhcp
  484. } // namespace isc
  485. #endif // DHCPSRV_CONFIG_H