srv_config.h 20 KB

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