srv_config.h 17 KB

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