srv_config.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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_hosts.h>
  17. #include <dhcpsrv/cfg_iface.h>
  18. #include <dhcpsrv/cfg_option.h>
  19. #include <dhcpsrv/cfg_option_def.h>
  20. #include <dhcpsrv/cfg_rsoo.h>
  21. #include <dhcpsrv/cfg_subnets4.h>
  22. #include <dhcpsrv/cfg_subnets6.h>
  23. #include <dhcpsrv/cfg_mac_source.h>
  24. #include <dhcpsrv/logging_info.h>
  25. #include <cc/data.h>
  26. #include <boost/shared_ptr.hpp>
  27. #include <vector>
  28. #include <stdint.h>
  29. namespace isc {
  30. namespace dhcp {
  31. class CfgMgr;
  32. /// @brief Specifies current DHCP configuration
  33. ///
  34. /// @todo Migrate all other configuration parameters from cfgmgr.h here
  35. class SrvConfig {
  36. public:
  37. /// @name Constants for selection of parameters returned by @c getConfigSummary
  38. ///
  39. //@{
  40. /// Nothing selected
  41. static const uint32_t CFGSEL_NONE = 0x00000000;
  42. /// Number of IPv4 subnets
  43. static const uint32_t CFGSEL_SUBNET4 = 0x00000001;
  44. /// Number of IPv6 subnets
  45. static const uint32_t CFGSEL_SUBNET6 = 0x00000002;
  46. /// Number of enabled ifaces
  47. static const uint32_t CFGSEL_IFACE4 = 0x00000004;
  48. /// Number of v6 ifaces
  49. static const uint32_t CFGSEL_IFACE6 = 0x00000008;
  50. /// DDNS enabled/disabled
  51. static const uint32_t CFGSEL_DDNS = 0x00000010;
  52. /// Number of all subnets
  53. static const uint32_t CFGSEL_SUBNET = 0x00000003;
  54. /// IPv4 related config
  55. static const uint32_t CFGSEL_ALL4 = 0x00000015;
  56. /// IPv6 related config
  57. static const uint32_t CFGSEL_ALL6 = 0x0000001A;
  58. /// Whole config
  59. static const uint32_t CFGSEL_ALL = 0xFFFFFFFF;
  60. //@}
  61. /// @brief Default constructor.
  62. ///
  63. /// This constructor sets configuration sequence number to 0.
  64. SrvConfig();
  65. /// @brief Constructor.
  66. ///
  67. /// Sets arbitrary configuration sequence number.
  68. SrvConfig(const uint32_t sequence);
  69. /// @brief Returns summary of the configuration in the textual format.
  70. ///
  71. /// This method returns the brief text describing the current configuration.
  72. /// It may be used for logging purposes, e.g. when the new configuration is
  73. /// committed to notify a user about the changes in configuration.
  74. ///
  75. /// @todo Currently this method uses @c CfgMgr accessors to get the
  76. /// configuration parameters. Once these parameters are migrated from the
  77. /// @c CfgMgr this method will have to be modified accordingly.
  78. ///
  79. /// @todo Implement reporting a summary of interfaces being used for
  80. /// receiving and sending DHCP messages. This will be implemented with
  81. /// ticket #3512.
  82. ///
  83. /// @param selection Is a bitfield which describes the parts of the
  84. /// configuration to be returned.
  85. ///
  86. /// @return Summary of the configuration in the textual format.
  87. std::string getConfigSummary(const uint32_t selection) const;
  88. /// @brief Returns configuration sequence number.
  89. uint32_t getSequence() const {
  90. return (sequence_);
  91. }
  92. /// @brief Compares configuration sequence with other sequence.
  93. ///
  94. /// This method compares sequence numbers of two configurations for
  95. /// equality. The sequence numbers are meant to be unique, so if
  96. /// they are equal it means that they point to the same configuration.
  97. ///
  98. /// @param other Configuration which sequence number should be
  99. /// compared with the sequence number of this configuration.
  100. ///
  101. /// @return true if sequence numbers are equal.
  102. bool sequenceEquals(const SrvConfig& other);
  103. /// @name Modifiers and accesors for the configuration objects.
  104. ///
  105. /// @warning References to the objects returned by accessors are only
  106. /// valid during the lifetime of the @c SrvConfig object which
  107. /// returned them.
  108. ///
  109. //@{
  110. /// @brief Returns logging specific configuration.
  111. const LoggingInfoStorage& getLoggingInfo() const {
  112. return (logging_info_);
  113. }
  114. /// @brief Sets logging specific configuration.
  115. ///
  116. /// @param logging_info New logging configuration.
  117. void addLoggingInfo(const LoggingInfo& logging_info) {
  118. logging_info_.push_back(logging_info);
  119. }
  120. /// @brief Returns non-const pointer to interface configuration.
  121. ///
  122. /// This function returns a non-const pointer to the interface
  123. /// configuration.
  124. ///
  125. /// @return Object representing configuration of interfaces.
  126. CfgIfacePtr getCfgIface() {
  127. return (cfg_iface_);
  128. }
  129. /// @brief Returns const pointer to interface configuration.
  130. ///
  131. /// This function returns a const pointer to the interface
  132. /// configuration.
  133. ///
  134. /// @return Object representing configuration of interfaces.
  135. ConstCfgIfacePtr getCfgIface() const {
  136. return (cfg_iface_);
  137. }
  138. /// @brief Return pointer to non-const object representing user-defined
  139. /// option definitions.
  140. ///
  141. /// This function returns a pointer to the object which represents the
  142. /// user defined option definitions grouped by option space name.
  143. ///
  144. /// @return Pointer to an object holding option definitions.
  145. CfgOptionDefPtr getCfgOptionDef() {
  146. return (cfg_option_def_);
  147. }
  148. /// @brief Returns pointer to the const object representing user-defined
  149. /// option definitions.
  150. ///
  151. /// This function returns a pointer to the object which represents the
  152. /// user defined option definitions grouped by option space name.
  153. ///
  154. /// @return Pointer to an object holding option definitions.
  155. ConstCfgOptionDefPtr getCfgOptionDef() const {
  156. return (cfg_option_def_);
  157. }
  158. /// @brief Returns pointer to the non-const object holding options.
  159. ///
  160. /// This method returns a pointer to the object which holds instances
  161. /// of the options to be returned to the clients belonging to any subnet.
  162. ///
  163. /// @return Pointer to the object holding options.
  164. CfgOptionPtr getCfgOption() {
  165. return (cfg_option_);
  166. }
  167. /// @brief Returns pointer to the const object holding options.
  168. ///
  169. /// This method returns a pointer to the object which holds instances
  170. /// of the options to be returned to the clients belonging to any subnet.
  171. ///
  172. /// @return Pointer to the object holding options.
  173. const ConstCfgOptionPtr getCfgOption() const {
  174. return (cfg_option_);
  175. }
  176. /// @brief Returns pointer to non-const object holding subnets configuration
  177. /// for DHCPv4.
  178. ///
  179. /// @return Pointer to the object holding subnets configuration for DHCPv4.
  180. CfgSubnets4Ptr getCfgSubnets4() {
  181. return (cfg_subnets4_);
  182. }
  183. /// @brief Returns pointer to const object holding subnets configuration for
  184. /// DHCPv4.
  185. ///
  186. /// @return Pointer to the object holding subnets configuration for DHCPv4.
  187. ConstCfgSubnets4Ptr getCfgSubnets4() const {
  188. return (cfg_subnets4_);
  189. }
  190. /// @brief Returns pointer to non-const object holding subnets configuration
  191. /// for DHCPv6.
  192. ///
  193. /// @return Pointer to the object holding subnets configuration for DHCPv6.
  194. CfgSubnets6Ptr getCfgSubnets6() {
  195. return (cfg_subnets6_);
  196. }
  197. /// @brief Returns pointer to const object holding subnets configuration for
  198. /// DHCPv6.
  199. ///
  200. /// @return Pointer to the object holding subnets configuration for DHCPv6.
  201. ConstCfgSubnets6Ptr getCfgSubnets6() const {
  202. return (cfg_subnets6_);
  203. }
  204. /// @brief Returns pointer to the non-const objects representing host
  205. /// reservations for different IPv4 and IPv6 subnets.
  206. ///
  207. /// @return Pointer to the non-const object holding host reservations.
  208. CfgHostsPtr getCfgHosts() {
  209. return (cfg_hosts_);
  210. }
  211. /// @brief Returns pointer to the const objects representing host
  212. /// reservations for different IPv4 and IPv6 subnets.
  213. ///
  214. /// @return Pointer to the const object holding host reservations.
  215. ConstCfgHostsPtr getCfgHosts() const {
  216. return (cfg_hosts_);
  217. }
  218. /// @brief Returns pointer to the non-const object representing
  219. /// set of RSOO-enabled options.
  220. ///
  221. /// @return Pointer to the non-const object holding RSOO-enabled
  222. /// options.
  223. CfgRSOOPtr getCfgRSOO() {
  224. return (cfg_rsoo_);
  225. }
  226. /// @brief Returns pointer to the const object representing set
  227. /// of RSOO-enabled options.
  228. ///
  229. /// @return Pointer to the const object holding RSOO-enabled
  230. /// options.
  231. ConstCfgRSOOPtr getCfgRSOO() const {
  232. return (cfg_rsoo_);
  233. }
  234. //@}
  235. /// @brief Returns non-const reference to an array that stores
  236. /// MAC/hardware address sources.
  237. ///
  238. /// @return non-const reference to MAC/hardware address sources
  239. CfgMACSource& getMACSources() {
  240. return (cfg_mac_source_);
  241. }
  242. /// @brief Returns const reference to an array that stores
  243. /// MAC/hardware address sources.
  244. ///
  245. /// @return const reference to MAC/hardware address sources
  246. const CfgMACSource& getMACSources() const {
  247. return (cfg_mac_source_);
  248. }
  249. /// @brief Returns information about control socket
  250. /// @return pointer to the Element that holds control-socket map
  251. const isc::data::ConstElementPtr getControlSocketInfo() const {
  252. return (control_socket_);
  253. }
  254. /// @brief Sets information about the control socket
  255. /// @param control_socket Element that holds control-socket map
  256. void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket) {
  257. control_socket_ = control_socket;
  258. }
  259. /// @brief Copies the currnet configuration to a new configuration.
  260. ///
  261. /// This method copies the parameters stored in the configuration to
  262. /// an object passed as parameter. The configuration sequence is not
  263. /// copied.
  264. ///
  265. /// @warning Some of the configuration objects are not copied at
  266. /// this point, e.g. subnets. This is because they contain quite complex
  267. /// data structures and they make use of pointers, so in many cases
  268. /// the default copy constructors can't be used. Implementing this
  269. /// requires quite a lot of time so this is left as is for now.
  270. /// The lack of ability to copy the entire configuration makes
  271. /// revert function of the @c CfgMgr unsuable.
  272. ///
  273. /// @param [out] new_config An object to which the configuration will
  274. /// be copied.
  275. void copy(SrvConfig& new_config) const;
  276. /// @brief Apply logging configuration to log4cplus.
  277. void applyLoggingCfg() const;
  278. /// @name Methods and operators used to compare configurations.
  279. ///
  280. //@{
  281. ///
  282. /// @brief Compares two objects for equality.
  283. ///
  284. /// It ignores the configuration sequence number when checking for
  285. /// equality of objects.
  286. ///
  287. /// @param other An object to be compared with this object.
  288. ///
  289. /// @return true if two objects are equal, false otherwise.
  290. bool equals(const SrvConfig& other) const;
  291. /// @brief Compares two objects for inequality.
  292. ///
  293. /// It ignores the configuration sequence number when checking for
  294. /// inequality of objects.
  295. ///
  296. /// @param other An object to be compared with this object.
  297. ///
  298. /// @return true if two objects are not equal, false otherwise.
  299. bool nequals(const SrvConfig& other) const {
  300. return (!equals(other));
  301. }
  302. /// @brief Equality operator.
  303. ///
  304. /// It ignores the configuration sequence number when checking for
  305. /// equality of objects.
  306. ///
  307. /// @param other An object to be compared with this object.
  308. ///
  309. /// @return true if two objects are equal, false otherwise.
  310. bool operator==(const SrvConfig& other) const {
  311. return (equals(other));
  312. }
  313. /// @param other An object to be compared with this object.
  314. ///
  315. /// It ignores the configuration sequence number when checking for
  316. /// inequality of objects.
  317. ///
  318. /// @param other An object to be compared with this object.
  319. ///
  320. /// @return true if two objects are not equal, false otherwise.
  321. bool operator!=(const SrvConfig& other) const {
  322. return (nequals(other));
  323. }
  324. //@}
  325. /// @brief Updates statistics.
  326. ///
  327. /// This method calls appropriate methods in child objects that update
  328. /// related statistics. See @ref CfgSubnets4::updateStatistics and
  329. /// @ref CfgSubnets6::updateStatistics for details.
  330. void updateStatistics();
  331. /// @brief Removes statistics.
  332. ///
  333. /// This method calls appropriate methods in child objects that remove
  334. /// related statistics. See @ref CfgSubnets4::removeStatistics and
  335. /// @ref CfgSubnets6::removeStatistics for details.
  336. void removeStatistics();
  337. private:
  338. /// @brief Sequence number identifying the configuration.
  339. uint32_t sequence_;
  340. /// @brief Logging specific information.
  341. LoggingInfoStorage logging_info_;
  342. /// @brief Interface configuration.
  343. ///
  344. /// Used to select interfaces on which the DHCP server will listen to
  345. /// queries.
  346. CfgIfacePtr cfg_iface_;
  347. /// @brief Pointer to option definitions configuration.
  348. ///
  349. /// This object holds the user-defined option definitions grouped
  350. /// by option space name.
  351. CfgOptionDefPtr cfg_option_def_;
  352. /// @brief Pointer to options (data) configuration.
  353. ///
  354. /// This object holds the instances of the options to be sent to clients
  355. /// connected to any subnet.
  356. CfgOptionPtr cfg_option_;
  357. /// @brief Pointer to subnets configuration for IPv4.
  358. CfgSubnets4Ptr cfg_subnets4_;
  359. /// @brief Pointer to subnets configuration for IPv6.
  360. CfgSubnets6Ptr cfg_subnets6_;
  361. /// @brief Pointer to the configuration for hosts reservation.
  362. ///
  363. /// This object holds a list of @c Host objects representing host
  364. /// reservations for different IPv4 and IPv6 subnets.
  365. CfgHostsPtr cfg_hosts_;
  366. /// @brief A list of configured MAC sources.
  367. CfgMACSource cfg_mac_source_;
  368. /// @brief Pointer to the configuration for RSOO-enabled options.
  369. ///
  370. /// This object holds a set of RSOO-enabled options. See
  371. /// RFC 6422 for the definition of the RSOO-enabled option.
  372. CfgRSOOPtr cfg_rsoo_;
  373. /// @brief Pointer to the control-socket information
  374. isc::data::ConstElementPtr control_socket_;
  375. };
  376. /// @name Pointers to the @c SrvConfig object.
  377. ///
  378. //@{
  379. /// @brief Non-const pointer to the @c SrvConfig.
  380. typedef boost::shared_ptr<SrvConfig> SrvConfigPtr;
  381. /// @brief Const pointer to the @c SrvConfig.
  382. typedef boost::shared_ptr<const SrvConfig> ConstSrvConfigPtr;
  383. //@}
  384. } // namespace isc::dhcp
  385. } // namespace isc
  386. #endif // DHCPSRV_CONFIG_H