13 #include <boost/algorithm/string/predicate.hpp> 25 const char* D2ClientConfig::DFT_SERVER_IP =
"127.0.0.1";
26 const size_t D2ClientConfig::DFT_SERVER_PORT = 53001;
27 const char* D2ClientConfig::DFT_V4_SENDER_IP =
"0.0.0.0";
28 const char* D2ClientConfig::DFT_V6_SENDER_IP =
"::";
29 const size_t D2ClientConfig::DFT_SENDER_PORT = 0;
30 const size_t D2ClientConfig::DFT_MAX_QUEUE_SIZE = 1024;
31 const char* D2ClientConfig::DFT_NCR_PROTOCOL =
"UDP";
32 const char* D2ClientConfig::DFT_NCR_FORMAT =
"JSON";
33 const bool D2ClientConfig::DFT_OVERRIDE_NO_UPDATE =
false;
34 const bool D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE =
false;
35 const char* D2ClientConfig::DFT_REPLACE_CLIENT_NAME_MODE =
"NEVER";
36 const char* D2ClientConfig::DFT_GENERATED_PREFIX =
"myhost";
37 const char* D2ClientConfig::DFT_HOSTNAME_CHAR_SET =
"";
38 const char* D2ClientConfig::DFT_HOSTNAME_CHAR_REPLACEMENT =
"";
40 D2ClientConfig::ReplaceClientNameMode
41 D2ClientConfig::stringToReplaceClientNameMode(
const std::string& mode_str) {
42 if (boost::iequals(mode_str,
"never")) {
43 return (D2ClientConfig::RCM_NEVER);
46 if (boost::iequals(mode_str,
"always")) {
47 return (D2ClientConfig::RCM_ALWAYS);
50 if (boost::iequals(mode_str,
"when-present")) {
51 return (D2ClientConfig::RCM_WHEN_PRESENT);
54 if (boost::iequals(mode_str,
"when-not-present")) {
55 return (D2ClientConfig::RCM_WHEN_NOT_PRESENT);
59 "Invalid ReplaceClientNameMode: " << mode_str);
65 case D2ClientConfig::RCM_NEVER:
67 case D2ClientConfig::RCM_ALWAYS:
69 case D2ClientConfig::RCM_WHEN_PRESENT:
70 return (
"when-present");
71 case D2ClientConfig::RCM_WHEN_NOT_PRESENT:
72 return (
"when-not-present");
77 std::ostringstream stream;
78 stream <<
"unknown(" << mode <<
")";
79 return (stream.str());
82 D2ClientConfig::D2ClientConfig(
const bool enable_updates,
84 const size_t server_port,
86 const size_t sender_port,
87 const size_t max_queue_size,
92 const bool override_no_update,
93 const bool override_client_update,
95 const std::string& generated_prefix,
96 const std::string& qualifying_suffix,
97 const std::string& hostname_char_set,
98 const std::string& hostname_char_replacement)
99 : enable_updates_(enable_updates),
100 server_ip_(server_ip),
101 server_port_(server_port),
102 sender_ip_(sender_ip),
103 sender_port_(sender_port),
104 max_queue_size_(max_queue_size),
105 ncr_protocol_(ncr_protocol),
106 ncr_format_(ncr_format),
107 override_no_update_(override_no_update),
108 override_client_update_(override_client_update),
109 replace_client_name_mode_(replace_client_name_mode),
110 generated_prefix_(generated_prefix),
111 qualifying_suffix_(qualifying_suffix),
112 hostname_char_set_(hostname_char_set),
113 hostname_char_replacement_(hostname_char_replacement),
114 hostname_sanitizer_(0) {
119 : enable_updates_(false),
121 server_port_(DFT_SERVER_PORT),
123 sender_port_(DFT_SENDER_PORT),
124 max_queue_size_(DFT_MAX_QUEUE_SIZE),
127 override_no_update_(DFT_OVERRIDE_NO_UPDATE),
128 override_client_update_(DFT_OVERRIDE_CLIENT_UPDATE),
129 replace_client_name_mode_(stringToReplaceClientNameMode(DFT_REPLACE_CLIENT_NAME_MODE)),
130 generated_prefix_(DFT_GENERATED_PREFIX),
131 qualifying_suffix_(
""),
132 hostname_char_set_(DFT_HOSTNAME_CHAR_SET),
133 hostname_char_replacement_(DFT_HOSTNAME_CHAR_SET),
134 hostname_sanitizer_(0) {
142 enable_updates_ = enable;
150 <<
" is not yet supported");
156 <<
" is not yet supported");
161 <<
"server-ip: " << server_ip_.
toText()
162 <<
" is: " << (server_ip_.
isV4() ?
"IPv4" :
"IPv6")
163 <<
" while sender-ip: " << sender_ip_.
toText()
164 <<
" is: " << (sender_ip_.
isV4() ?
"IPv4" :
"IPv6"));
167 if (server_ip_ == sender_ip_ && server_port_ == sender_port_) {
169 " share the exact same IP address/port: " 170 << server_ip_.
toText() <<
"/" << server_port_);
173 if (!hostname_char_set_.empty()) {
176 hostname_char_replacement_));
177 }
catch (
const std::exception& ex) {
179 " is not a valid regular expression");
189 return ((enable_updates_ == other.enable_updates_) &&
190 (server_ip_ == other.server_ip_) &&
191 (server_port_ == other.server_port_) &&
192 (sender_ip_ == other.sender_ip_) &&
193 (sender_port_ == other.sender_port_) &&
194 (max_queue_size_ == other.max_queue_size_) &&
195 (ncr_protocol_ == other.ncr_protocol_) &&
196 (ncr_format_ == other.ncr_format_) &&
197 (override_no_update_ == other.override_no_update_) &&
198 (override_client_update_ == other.override_client_update_) &&
199 (replace_client_name_mode_ == other.replace_client_name_mode_) &&
200 (generated_prefix_ == other.generated_prefix_) &&
201 (qualifying_suffix_ == other.qualifying_suffix_) &&
202 (hostname_char_set_ == other.hostname_char_set_) &&
203 (hostname_char_replacement_ == other.hostname_char_replacement_));
208 return (!(*
this == other));
213 std::ostringstream stream;
215 stream <<
"enable_updates: " << (enable_updates_ ?
"yes" :
"no");
216 if (enable_updates_) {
217 stream <<
", server-ip: " << server_ip_.
toText()
218 <<
", server-port: " << server_port_
219 <<
", sender-ip: " << sender_ip_.
toText()
220 <<
", sender-port: " << sender_port_
221 <<
", max-queue-size: " << max_queue_size_
224 <<
", override-no-update: " << (override_no_update_ ?
226 <<
", override-client-update: " << (override_client_update_ ?
228 <<
", replace-client-name: " 230 <<
", generated-prefix: [" << generated_prefix_ <<
"]" 231 <<
", qualifying-suffix: [" << qualifying_suffix_ <<
"]" 232 <<
", hostname-char-set: [" << hostname_char_set_ <<
"]" 233 <<
", hostname-char-replacement: [" << hostname_char_replacement_ <<
"]";
236 return (stream.str());
245 result->set(
"enable-updates", Element::create(enable_updates_));
247 result->set(
"qualifying-suffix", Element::create(qualifying_suffix_));
249 result->set(
"server-ip", Element::create(server_ip_.
toText()));
251 result->set(
"server-port", Element::create(static_cast<long long>(server_port_)));
253 result->set(
"sender-ip", Element::create(sender_ip_.
toText()));
255 result->set(
"sender-port", Element::create(static_cast<long long>(sender_port_)));
257 result->set(
"max-queue-size", Element::create(static_cast<long long>(max_queue_size_)));
263 result->set(
"override-no-update", Element::create(override_no_update_));
265 result->set(
"override-client-update", Element::create(override_client_update_));
267 result->set(
"replace-client-name",
270 result->set(
"generated-prefix", Element::create(generated_prefix_));
272 result->set(
"hostname-char-set", Element::create(hostname_char_set_));
274 result->set(
"hostname-char-replacement", Element::create(hostname_char_replacement_));
Defines the D2ClientConfig class.
bool operator==(const D2ClientConfig &other) const
Compares two D2ClientConfigs for equality.
NameChangeProtocol stringToNcrProtocol(const std::string &protocol_str)
Function which converts labels to NameChangeProtocol enum values.
std::string toText() const
Generates a string representation of the class contents.
boost::shared_ptr< Element > ElementPtr
NameChangeFormat
Defines the list of data wire formats supported.
This file provides UDP socket based implementation for sending and receiving NameChangeRequests.
D2ClientConfig()
Default constructor The default constructor creates an instance that has updates disabled.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
std::string ncrProtocolToString(NameChangeProtocol protocol)
Function which converts NameChangeProtocol enums to text labels.
An exception that is thrown if an error occurs while configuring the D2 DHCP DDNS client.
Acts as a storage vault for D2 client configuration.
virtual ~D2ClientConfig()
Destructor.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
bool isV4() const
Convenience function to check for an IPv4 address.
virtual void validateContents()
Validates member values.
Implements a regular expression based string scrubber.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string toText() const
Convert the address to a string.
ReplaceClientNameMode
Defines the client name replacement modes.
A wrapper interface for the ASIO library.
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
NameChangeProtocol
Defines the list of socket protocols supported.
NameChangeFormat stringToNcrFormat(const std::string &fmt_str)
Function which converts labels to NameChangeFormat enum values.
The IOAddress class represents an IP addresses (version agnostic)
static std::string replaceClientNameModeToString(const ReplaceClientNameMode &mode)
Converts NameChangeFormat enums to text labels.
bool operator !=(const D2ClientConfig &other) const
Compares two D2ClientConfigs for inequality.
short getFamily() const
Returns the address family.
void enableUpdates(bool enable)
Sets enable-updates flag to the given value.