d2_client_cfg.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Copyright (C) 2013-2014 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 D2_CLIENT_CFG_H
  15. #define D2_CLIENT_CFG_H
  16. /// @file d2_client_cfg.h Defines the D2ClientConfig class.
  17. /// This file defines the classes Kea uses to manage configuration needed to
  18. /// act as a client of the kea-dhcp-ddns module (aka D2).
  19. ///
  20. #include <asiolink/io_address.h>
  21. #include <dhcp_ddns/ncr_io.h>
  22. #include <exceptions/exceptions.h>
  23. #include <boost/shared_ptr.hpp>
  24. #include <stdint.h>
  25. #include <string>
  26. #include <vector>
  27. namespace isc {
  28. namespace dhcp {
  29. /// An exception that is thrown if an error occurs while configuring
  30. /// the D2 DHCP DDNS client.
  31. class D2ClientError : public isc::Exception {
  32. public:
  33. /// @brief constructor
  34. ///
  35. /// @param file name of the file, where exception occurred
  36. /// @param line line of the file, where exception occurred
  37. /// @param what text description of the issue that caused exception
  38. D2ClientError(const char* file, size_t line, const char* what)
  39. : isc::Exception(file, line, what) {}
  40. };
  41. /// @brief Acts as a storage vault for D2 client configuration
  42. ///
  43. /// A simple container class for storing and retrieving the configuration
  44. /// parameters associated with DHCP-DDNS and acting as a client of D2.
  45. /// Instances of this class may be constructed through configuration parsing.
  46. ///
  47. class D2ClientConfig {
  48. public:
  49. /// @brief Default configuration constants.
  50. /// @todo For now these are hard-coded as configuraiton layer cannot
  51. /// readily provide them (see Trac #3358).
  52. static const char *DFT_SERVER_IP;
  53. static const size_t DFT_SERVER_PORT;
  54. static const char *DFT_V4_SENDER_IP;
  55. static const char *DFT_V6_SENDER_IP;
  56. static const size_t DFT_SENDER_PORT;
  57. static const size_t DFT_MAX_QUEUE_SIZE;
  58. static const char *DFT_NCR_PROTOCOL;
  59. static const char *DFT_NCR_FORMAT;
  60. static const bool DFT_ALWAYS_INCLUDE_FQDN;
  61. static const bool DFT_OVERRIDE_NO_UPDATE;
  62. static const bool DFT_OVERRIDE_CLIENT_UPDATE;
  63. static const bool DFT_REPLACE_CLIENT_NAME;
  64. static const char *DFT_GENERATED_PREFIX;
  65. static const char *DFT_QUALIFYING_SUFFIX;
  66. /// @brief Constructor
  67. ///
  68. /// @param enable_updates Enables DHCP-DDNS updates
  69. /// @param server_ip IP address of the kea-dhcp-ddns server (IPv4 or IPv6)
  70. /// @param server_port IP port of the kea-dhcp-ddns server
  71. /// @param sender_ip IP address of the kea-dhcp-ddns server (IPv4 or IPv6)
  72. /// @param sender_port IP port of the kea-dhcp-ddns server
  73. /// @param max_queue_size maximum NCRs allowed in sender's queue
  74. /// @param ncr_protocol Socket protocol to use with kea-dhcp-ddns
  75. /// Currently only UDP is supported.
  76. /// @param ncr_format Format of the kea-dhcp-ddns requests.
  77. /// Currently only JSON format is supported.
  78. /// @param always_include_fqdn Enables always including the FQDN option in
  79. /// DHCP responses.
  80. /// @param override_no_update Enables updates, even if clients request no
  81. /// updates.
  82. /// @param override_client_update Perform updates, even if client requested
  83. /// delegation.
  84. /// @param replace_client_name enables replacement of the domain-name
  85. /// supplied by the client with a generated name.
  86. /// @param generated_prefix Prefix to use when generating domain-names.
  87. /// @param qualifying_suffix Suffix to use to qualify partial domain-names.
  88. ///
  89. /// @throw D2ClientError if given an invalid protocol or format.
  90. D2ClientConfig(const bool enable_updates,
  91. const isc::asiolink::IOAddress& server_ip,
  92. const size_t server_port,
  93. const isc::asiolink::IOAddress& sender_ip,
  94. const size_t sender_port,
  95. const size_t max_queue_size,
  96. const dhcp_ddns::NameChangeProtocol& ncr_protocol,
  97. const dhcp_ddns::NameChangeFormat& ncr_format,
  98. const bool always_include_fqdn,
  99. const bool override_no_update,
  100. const bool override_client_update,
  101. const bool replace_client_name,
  102. const std::string& generated_prefix,
  103. const std::string& qualifying_suffix);
  104. /// @brief Default constructor
  105. /// The default constructor creates an instance that has updates disabled.
  106. D2ClientConfig();
  107. /// @brief Destructor
  108. virtual ~D2ClientConfig();
  109. /// @brief Return whether or not DHCP-DDNS updating is enabled.
  110. bool getEnableUpdates() const {
  111. return(enable_updates_);
  112. }
  113. /// @brief Return the IP address of kea-dhcp-ddns (IPv4 or IPv6).
  114. const isc::asiolink::IOAddress& getServerIp() const {
  115. return(server_ip_);
  116. }
  117. /// @brief Return the IP port of kea-dhcp-ddns.
  118. size_t getServerPort() const {
  119. return(server_port_);
  120. }
  121. /// @brief Return the IP address client should use to send
  122. const isc::asiolink::IOAddress& getSenderIp() const {
  123. return(sender_ip_);
  124. }
  125. /// @brief Return the IP port client should use to send
  126. size_t getSenderPort() const {
  127. return(sender_port_);
  128. }
  129. /// @brief Return Maximun sender queue size
  130. size_t getMaxQueueSize() const {
  131. return(max_queue_size_);
  132. }
  133. /// @brief Return the socket protocol to use with kea-dhcp-ddns.
  134. const dhcp_ddns::NameChangeProtocol& getNcrProtocol() const {
  135. return(ncr_protocol_);
  136. }
  137. /// @brief Return the kea-dhcp-ddns request format.
  138. const dhcp_ddns::NameChangeFormat& getNcrFormat() const {
  139. return(ncr_format_);
  140. }
  141. /// @brief Return whether or not FQDN is always included in DHCP responses.
  142. bool getAlwaysIncludeFqdn() const {
  143. return(always_include_fqdn_);
  144. }
  145. /// @brief Return if updates are done even if clients request no updates.
  146. bool getOverrideNoUpdate() const {
  147. return(override_no_update_);
  148. }
  149. /// @brief Return if updates are done even when clients request delegation.
  150. bool getOverrideClientUpdate() const {
  151. return(override_client_update_);
  152. }
  153. /// @brief Return whether or not client's domain-name is always replaced.
  154. bool getReplaceClientName() const {
  155. return(replace_client_name_);
  156. }
  157. /// @brief Return the prefix to use when generating domain-names.
  158. const std::string& getGeneratedPrefix() const {
  159. return(generated_prefix_);
  160. }
  161. /// @brief Return the suffix to use to qualify partial domain-names.
  162. const std::string& getQualifyingSuffix() const {
  163. return(qualifying_suffix_);
  164. }
  165. /// @brief Compares two D2ClientConfigs for equality
  166. bool operator == (const D2ClientConfig& other) const;
  167. /// @brief Compares two D2ClientConfigs for inequality
  168. bool operator != (const D2ClientConfig& other) const;
  169. /// @brief Generates a string representation of the class contents.
  170. std::string toText() const;
  171. /// @brief Sets enable-updates flag to the given value.
  172. ///
  173. /// This is the only value that may be altered outside the constructor
  174. /// as it may be desirable to toggle it off and on when dealing with
  175. /// D2 IO errors.
  176. ///
  177. /// @param enable boolean value to assign to the enable-updates flag
  178. void enableUpdates(bool enable);
  179. protected:
  180. /// @brief Validates member values.
  181. ///
  182. /// Method is used by the constructor to validate member contents.
  183. ///
  184. /// @throw D2ClientError if given an invalid protocol or format.
  185. virtual void validateContents();
  186. private:
  187. /// @brief Indicates whether or not DHCP DDNS updating is enabled.
  188. bool enable_updates_;
  189. /// @brief IP address of the kea-dhcp-ddns server (IPv4 or IPv6).
  190. isc::asiolink::IOAddress server_ip_;
  191. /// @brief IP port of the kea-dhcp-ddns server.
  192. size_t server_port_;
  193. /// @brief IP address on which the client should send
  194. isc::asiolink::IOAddress sender_ip_;
  195. /// @brief IP port on which the client should send
  196. size_t sender_port_;
  197. /// @brief Maxium number of NCRs allowed to queue waiting to send
  198. size_t max_queue_size_;
  199. /// @brief The socket protocol to use with kea-dhcp-ddns.
  200. /// Currently only UDP is supported.
  201. dhcp_ddns::NameChangeProtocol ncr_protocol_;
  202. /// @brief Format of the kea-dhcp-ddns requests.
  203. /// Currently only JSON format is supported.
  204. dhcp_ddns::NameChangeFormat ncr_format_;
  205. /// @brief Should Kea always include the FQDN option in its response.
  206. bool always_include_fqdn_;
  207. /// @brief Should Kea perform updates, even if client requested no updates.
  208. /// Overrides the client request for no updates via the N flag.
  209. bool override_no_update_;
  210. /// @brief Should Kea perform updates, even if client requested delegation.
  211. bool override_client_update_;
  212. /// @brief Should Kea replace the domain-name supplied by the client.
  213. bool replace_client_name_;
  214. /// @brief Prefix Kea should use when generating domain-names.
  215. std::string generated_prefix_;
  216. /// @brief Suffix Kea should use when to qualify partial domain-names.
  217. std::string qualifying_suffix_;
  218. };
  219. std::ostream&
  220. operator<<(std::ostream& os, const D2ClientConfig& config);
  221. /// @brief Defines a pointer for D2ClientConfig instances.
  222. typedef boost::shared_ptr<D2ClientConfig> D2ClientConfigPtr;
  223. } // namespace isc
  224. } // namespace dhcp
  225. #endif