srv_config.h 14 KB

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