15 #include <boost/foreach.hpp> 16 #include <boost/scoped_ptr.hpp> 17 #include <boost/algorithm/string/predicate.hpp> 32 const size_t dns_server_timeout,
35 : ip_address_(ip_address),
37 dns_server_timeout_(dns_server_timeout),
38 ncr_protocol_(ncr_protocol),
39 ncr_format_(ncr_format) {
45 port_(53001), dns_server_timeout_(500),
46 ncr_protocol_(dhcp_ddns::
NCR_UDP),
55 if ((ip_address_.
toText() ==
"0.0.0.0") || (ip_address_.
toText() ==
"::")) {
57 "D2Params: IP address cannot be \"" << ip_address_ <<
"\"");
64 if (dns_server_timeout_ < 1) {
66 "D2Params: DNS server timeout must be larger than 0");
72 <<
" is not yet supported");
78 <<
" is not yet supported");
92 return ((ip_address_ == other.ip_address_) &&
93 (port_ == other.port_) &&
94 (dns_server_timeout_ == other.dns_server_timeout_) &&
95 (ncr_protocol_ == other.ncr_protocol_) &&
96 (ncr_format_ == other.ncr_format_));
101 return (!(*
this == other));
106 std::ostringstream stream;
108 stream <<
", ip-address: " << ip_address_.
toText()
109 <<
", port: " << port_
110 <<
", dns-server-timeout_: " << dns_server_timeout_
111 <<
", ncr-protocol: " 113 <<
", ncr-format: " << ncr_format_
116 return (stream.str());
136 const std::string& secret, uint32_t digestbits)
137 :
name_(name), algorithm_(algorithm), secret_(secret),
138 digestbits_(digestbits), tsig_key_() {
165 TSIGKeyInfo::remakeKey() {
170 std::ostringstream stream;
174 if (digestbits_ > 0) {
175 stream <<
":" << digestbits_;
178 tsig_key_.reset(
new D2TsigKey(stream.str()));
179 }
catch (
const std::exception& ex) {
190 result->set(
"name", Element::create(name_));
192 result->set(
"algorithm", Element::create(algorithm_));
194 result->set(
"secret", Element::create(secret_));
196 result->set(
"digest-bits",
197 Element::create(static_cast<int64_t>(digestbits_)));
209 : hostname_(hostname), ip_address_(ip_address), port_(port),
210 enabled_(enabled), tsig_key_info_(tsig_key_info),
211 inherited_key_(inherited_key) {
219 if (tsig_key_info_) {
220 return (tsig_key_info_->getName());
228 std::ostringstream stream;
230 return (stream.str());
239 result->set(
"hostname", Element::create(hostname_));
241 result->set(
"ip-address", Element::create(ip_address_.
toText()));
243 result->set(
"port", Element::create(static_cast<int64_t>(port_)));
245 if (tsig_key_info_ && !inherited_key_) {
246 result->set(
"key-name", Element::create(tsig_key_info_->getName()));
262 const std::string& key_name)
263 :
name_(name), servers_(servers), key_name_(key_name) {
275 result->set(
"name", Element::create(name_));
278 for (DnsServerInfoStorage::const_iterator server = servers_->begin();
279 server != servers_->end(); ++server) {
280 ElementPtr dns_server = (*server)->toElement();
281 servers->add(dns_server);
284 if (!servers->empty()) {
285 result->set(
"dns-servers", servers);
288 if (!key_name_.empty()) {
289 result->set(
"key-name", Element::create(key_name_));
311 "DdnsDomainListMgr::setDomains: Domain list may not be null");
320 if (gotit != domains_->end()) {
321 wildcard_domain_ = gotit->second;
328 if ((
size() == 1) && (wildcard_domain_)) {
329 domain = wildcard_domain_;
336 size_t req_len = fqdn.size();
337 size_t match_len = 0;
340 BOOST_FOREACH (map_pair, *domains_) {
341 std::string domain_name = map_pair.first;
342 size_t dom_len = domain_name.size();
345 if (req_len < dom_len) {
350 if (req_len == dom_len) {
351 if (boost::iequals(fqdn, domain_name)) {
353 domain = map_pair.second;
361 size_t offset = req_len - dom_len;
362 if ((fqdn[offset - 1] ==
'.') &&
363 (boost::iequals(fqdn.substr(offset), domain_name))) {
366 if (dom_len > match_len) {
368 best_match = map_pair.second;
377 if (wildcard_domain_) {
378 domain = wildcard_domain_;
394 for (DdnsDomainMap::const_iterator domain = domains_->begin();
395 domain != domains_->end(); ++domain) {
396 ElementPtr ddns_domain = domain->second->toElement();
397 result->add(ddns_domain);
409 std::string name = getString(key_config,
"name");
410 std::string algorithm = getString(key_config,
"algorithm");
411 uint32_t digestbits = getInteger(key_config,
"digest-bits");
412 std::string secret = getString(key_config,
"secret");
418 }
catch (
const std::exception& ex) {
420 <<
" (" << getPosition(
"algorithm", key_config) <<
")");
426 if ((digestbits > 0) &&
427 ((digestbits < 80) ||
428 (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA224_STR)
429 && (digestbits < 112)) ||
430 (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA256_STR)
431 && (digestbits < 128)) ||
432 (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA384_STR)
433 && (digestbits < 192)) ||
434 (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA512_STR)
435 && (digestbits < 256)))) {
437 << getPosition(
"digest-bits", key_config)
446 key_info.reset(
new TSIGKeyInfo(name, algorithm, secret, digestbits));
447 }
catch (
const std::exception& ex) {
449 << key_config->getPosition() <<
")");
454 key_info->setContext(user_context);
467 BOOST_FOREACH(key_config, key_list->listValue()) {
471 if (keys->find(key->getName()) != keys->end()) {
474 <<
" (" << getPosition(
"name", key_config) <<
")");
477 (*keys)[key->getName()] = key;
489 std::string hostname = getString(server_config,
"hostname");
490 std::string ip_address = getString(server_config,
"ip-address");
491 uint32_t port = getInteger(server_config,
"port");
492 std::string key_name = getString(server_config,
"key-name");
498 bool inherited_key =
true;
499 if (key_name.empty()) {
500 std::string domain_key_name = getString(domain_config,
"key-name");
501 if (!domain_key_name.empty()) {
502 key_name = domain_key_name;
505 inherited_key =
false;
507 if (!key_name.empty()) {
509 TSIGKeyInfoMap::iterator kit = keys->find(key_name);
510 if (kit != keys->end()) {
511 tsig_key_info = kit->second;
515 if (!tsig_key_info) {
518 <<
"undefined key: " << key_name <<
" (" 519 << getPosition(
"key-name", domain_config) <<
")");
522 <<
"undefined key: " << key_name <<
" (" 523 << getPosition(
"key-name", server_config) <<
")");
529 if (hostname.empty() == ip_address.empty()) {
531 " of hostname or IP address" 532 <<
" (" << server_config->getPosition() <<
")");
536 if (!hostname.empty()) {
551 <<
" (" << getPosition(
"hostname", server_config) <<
")");
563 <<
" (" << getPosition(
"ip-address", server_config) <<
")");
569 server_info->setContext(user_context);
572 return (server_info);
584 BOOST_FOREACH(server_config, server_list->listValue()) {
586 parser.
parse(server_config, domain_config, keys);
587 servers->push_back(server);
597 std::string name = getString(domain_config,
"name");
598 std::string key_name = getString(domain_config,
"key-name");
604 servers_config = domain_config->get(
"dns-servers");
605 }
catch (
const std::exception& ex) {
607 <<
" (" << servers_config->getPosition() <<
")");
612 server_parser.
parse(servers_config, domain_config, keys);
613 if (servers->size() == 0) {
615 << servers_config->getPosition());
623 domain->setContext(user_context);
636 BOOST_FOREACH(domain_config, domain_list->listValue()) {
640 if (domains->find(domain->getName()) != domains->end()) {
643 <<
" (" << getPosition(
"name", domain_config) <<
")");
646 (*domains)[domain->getName()] = domain;
656 const std::string& mgr_name,
662 if (domains_config) {
667 mgr->setDomains(domains);
static const char * HMAC_SHA256_STR
The Name class encapsulates DNS names.
static const char * wildcard_domain_name_
defines the domain name for denoting the wildcard domain.
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
std::ostream & operator<<(std::ostream &os, const D2Params &config)
Dumps the contents of a D2Params as text to an output stream.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
DdnsDomain(const std::string &name, DnsServerInfoStoragePtr servers, const std::string &key_name="")
Constructor.
DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config, data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given list "dns-server" elements.
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
const std::string getKeyName() const
Convenience method which returns the server's TSIG key name.
DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config, const std::string &mgr_name, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given manager element.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
Parser for a list of DdnsDomains.
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
std::string toText() const
Returns a text representation for the server.
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
static const char * HMAC_SHA224_STR
Exception thrown when the error during configuration handling occurs.
static const Name & HMACSHA224_NAME()
HMAC-SHA256 (RFC4635)
Statistics keeping extension of the DNS TSIGKey class.
boost::shared_ptr< Element > ElementPtr
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
uint32_t getPort() const
Getter which returns the server's port number.
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
static const Name & HMACSHA1_NAME()
HMAC-SHA1 (RFC4635)
NameChangeFormat
Defines the list of data wire formats supported.
TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config)
Performs the parsing of the given list "tsig-key" elements.
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
static const char * HMAC_SHA384_STR
virtual ~TSIGKeyInfo()
Destructor.
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
uint32_t size() const
Returns the number of domains in the domain list.
static const Name & HMACSHA256_NAME()
HMAC-SHA256 (RFC4635)
#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.
std::string getConfigSummary() const
Return summary of the configuration used by D2.
Represents a DNS domain that is may be updated dynamically.
static const Name & HMACSHA512_NAME()
HMAC-SHA256 (RFC4635)
D2Params()
Default constructor The default constructor creates an instance that has updates disabled.
Parser for a list of DnsServerInfos.
static const dns::Name & stringToAlgorithmName(const std::string &algorithm_id)
Converts algorithm id to dns::TSIGKey algorithm dns::Name.
isc::log::Logger dhcp_to_d2_logger("dhcp-to-d2")
virtual bool matchDomain(const std::string &fqdn, DdnsDomainPtr &domain)
Matches a given name to a domain based on a longest match scheme.
std::string toText() const
Generates a string representation of the class contents.
DnsServerInfoPtr parse(data::ConstElementPtr server_config, data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "dns-server" element.
boost::shared_ptr< const Element > ConstElementPtr
static const Name & HMACMD5_NAME()
HMAC-MD5 (RFC2845)
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
virtual void validateContents()
Validates member values.
const isc::log::MessageID DHCP_DDNS_NO_MATCH
DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given list "ddns-domain" elements.
Defines the logger used by the top-level component of kea-lfc.
DdnsDomainListMgr(const std::string &name)
Constructor.
TSIGKeyInfo(const std::string &name, const std::string &algorithm, const std::string &secret, uint32_t digestbits=0)
Constructor.
Represents a specific DNS Server.
static const char * HMAC_SHA1_STR
std::string toText() const
Convert the address to a string.
virtual ~DdnsDomain()
Destructor.
virtual ~DnsServerInfo()
Destructor.
A wrapper interface for the ASIO library.
std::string ncrFormatToString(NameChangeFormat format)
Function which converts NameChangeFormat enums to text labels.
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
virtual ~D2Params()
Destructor.
NameChangeProtocol
Defines the list of socket protocols supported.
An exception that is thrown if an error occurs within the IO module.
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
The IOAddress class represents an IP addresses (version agnostic)
size_t getPort() const
Return the TCP/UPD port D2 listens on.
bool operator!=(const D2Params &other) const
Compares two D2Params's for inequality.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Parser for DnsServerInfo.
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
static const Name & HMACSHA384_NAME()
HMAC-SHA256 (RFC4635)
Acts as a storage vault for D2 global scalar parameters.
static const char * HMAC_SHA512_STR
virtual ~DdnsDomainListMgr()
Destructor.
DnsServerInfo(const std::string &hostname, isc::asiolink::IOAddress ip_address, uint32_t port=STANDARD_DNS_PORT, bool enabled=true, const TSIGKeyInfoPtr &tsig_key_info=TSIGKeyInfoPtr(), bool inherited_key=true)
Constructor.
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.