Kea  1.5.0
d2_config.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef D2_CONFIG_H
8 #define D2_CONFIG_H
9 
10 #include <asiolink/io_service.h>
11 #include <cc/data.h>
12 #include <cc/simple_parser.h>
13 #include <cc/cfg_to_element.h>
14 #include <cc/user_context.h>
16 #include <dns/tsig.h>
17 #include <exceptions/exceptions.h>
18 #include <process/d_cfg_mgr.h>
19 
20 #include <boost/foreach.hpp>
21 
22 #include <stdint.h>
23 #include <string>
24 
25 namespace isc {
26 namespace d2 {
27 
127 
130 class D2CfgError : public isc::Exception {
131 public:
132  D2CfgError(const char* file, size_t line, const char* what) :
133  isc::Exception(file, line, what) { };
134 };
135 
137 class D2Params {
138 public:
154  D2Params(const isc::asiolink::IOAddress& ip_address,
155  const size_t port,
156  const size_t dns_server_timeout,
157  const dhcp_ddns::NameChangeProtocol& ncr_protocol,
158  const dhcp_ddns::NameChangeFormat& ncr_format);
159 
162  D2Params();
163 
165  virtual ~D2Params();
166 
169  return(ip_address_);
170  }
171 
173  size_t getPort() const {
174  return(port_);
175  }
176 
178  size_t getDnsServerTimeout() const {
179  return(dns_server_timeout_);
180  }
181 
184  return(ncr_protocol_);
185  }
186 
189  return(ncr_format_);
190  }
191 
199  std::string getConfigSummary() const;
200 
202  bool operator == (const D2Params& other) const;
203 
205  bool operator != (const D2Params& other) const;
206 
208  std::string toText() const;
209 
210 protected:
222  virtual void validateContents();
223 
224 private:
226  isc::asiolink::IOAddress ip_address_;
227 
229  size_t port_;
230 
232  size_t dns_server_timeout_;
233 
236  dhcp_ddns::NameChangeProtocol ncr_protocol_;
237 
240  dhcp_ddns::NameChangeFormat ncr_format_;
241 };
242 
247 std::ostream&
248 operator<<(std::ostream& os, const D2Params& config);
249 
251 typedef boost::shared_ptr<D2Params> D2ParamsPtr;
252 
261 public:
263 
264  static const char* HMAC_MD5_STR;
265  static const char* HMAC_SHA1_STR;
266  static const char* HMAC_SHA256_STR;
267  static const char* HMAC_SHA224_STR;
268  static const char* HMAC_SHA384_STR;
269  static const char* HMAC_SHA512_STR;
270  //}@
271 
303  TSIGKeyInfo(const std::string& name, const std::string& algorithm,
304  const std::string& secret, uint32_t digestbits = 0);
305 
307  virtual ~TSIGKeyInfo();
308 
312  const std::string getName() const {
313  return (name_);
314  }
315 
319  const std::string getAlgorithm() const {
320  return (algorithm_);
321  }
322 
326  uint32_t getDigestbits() const {
327  return (digestbits_);
328  }
329 
333  const std::string getSecret() const {
334  return (secret_);
335  }
336 
341  const dns::TSIGKeyPtr& getTSIGKey() const {
342  return (tsig_key_);
343  }
344 
358  static const dns::Name& stringToAlgorithmName(const std::string&
359  algorithm_id);
360 
364  virtual isc::data::ElementPtr toElement() const;
365 
366 private:
375  void remakeKey();
376 
381  std::string name_;
382 
384  std::string algorithm_;
385 
387  std::string secret_;
388 
391  uint32_t digestbits_;
392 
394  dns::TSIGKeyPtr tsig_key_;
395 };
396 
398 typedef boost::shared_ptr<TSIGKeyInfo> TSIGKeyInfoPtr;
399 
401 typedef std::map<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMap;
402 
404 typedef std::pair<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMapPair;
405 
407 typedef boost::shared_ptr<TSIGKeyInfoMap> TSIGKeyInfoMapPtr;
408 
409 
416 public:
418  static const uint32_t STANDARD_DNS_PORT = 53;
419 
432  DnsServerInfo(const std::string& hostname,
433  isc::asiolink::IOAddress ip_address,
434  uint32_t port = STANDARD_DNS_PORT,
435  bool enabled=true);
436 
438  virtual ~DnsServerInfo();
439 
443  const std::string getHostname() const {
444  return (hostname_);
445  }
446 
450  uint32_t getPort() const {
451  return (port_);
452  }
453 
458  return (ip_address_);
459  }
460 
465  bool isEnabled() const {
466  return (enabled_);
467  }
468 
470  void enable() {
471  enabled_ = true;
472  }
473 
475  void disable() {
476  enabled_ = false;
477  }
478 
480  std::string toText() const;
481 
485  virtual isc::data::ElementPtr toElement() const;
486 
487 
488 private:
491  std::string hostname_;
492 
495  isc::asiolink::IOAddress ip_address_;
496 
498  uint32_t port_;
499 
502  bool enabled_;
503 };
504 
505 std::ostream&
506 operator<<(std::ostream& os, const DnsServerInfo& server);
507 
509 typedef boost::shared_ptr<DnsServerInfo> DnsServerInfoPtr;
510 
512 typedef std::vector<DnsServerInfoPtr> DnsServerInfoStorage;
513 
515 typedef boost::shared_ptr<DnsServerInfoStorage> DnsServerInfoStoragePtr;
516 
517 
526 public:
533  DdnsDomain(const std::string& name,
534  DnsServerInfoStoragePtr servers,
535  const TSIGKeyInfoPtr& tsig_key_info = TSIGKeyInfoPtr());
536 
538  virtual ~DdnsDomain();
539 
543  const std::string getName() const {
544  return (name_);
545  }
546 
551  const std::string getKeyName() const;
552 
557  return (servers_);
558  }
559 
565  return (tsig_key_info_);
566  }
567 
571  virtual isc::data::ElementPtr toElement() const;
572 
573 private:
575  std::string name_;
576 
578  DnsServerInfoStoragePtr servers_;
579 
582  TSIGKeyInfoPtr tsig_key_info_;
583 };
584 
586 typedef boost::shared_ptr<DdnsDomain> DdnsDomainPtr;
587 
589 typedef std::map<std::string, DdnsDomainPtr> DdnsDomainMap;
590 
592 typedef std::pair<std::string, DdnsDomainPtr> DdnsDomainMapPair;
593 
595 typedef boost::shared_ptr<DdnsDomainMap> DdnsDomainMapPtr;
596 
609 public:
611  static const char* wildcard_domain_name_;
612 
616  DdnsDomainListMgr(const std::string& name);
617 
619  virtual ~DdnsDomainListMgr ();
620 
639  virtual bool matchDomain(const std::string& fqdn, DdnsDomainPtr& domain);
640 
644  const std::string getName() const {
645  return (name_);
646  }
647 
651  uint32_t size() const {
652  return (domains_->size());
653  }
654 
660  return (wildcard_domain_);
661  }
662 
667  return (domains_);
668  }
669 
673  void setDomains(DdnsDomainMapPtr domains);
674 
678  virtual isc::data::ElementPtr toElement() const;
679 
680 private:
682  std::string name_;
683 
685  DdnsDomainMapPtr domains_;
686 
688  DdnsDomainPtr wildcard_domain_;
689 };
690 
692 typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;
693 
705 public:
706 
709  };
710 
712  virtual ~DScalarContext() {
713  }
714 
719  return (process::ConfigPtr(new DScalarContext(*this)));
720  }
721 
726  isc_throw(isc::NotImplemented, "DScalarContext::ElementPtr");
727  }
728 
729 protected:
731  DScalarContext(const DScalarContext& rhs) : ConfigBase(rhs) {
732  }
733 
734 private:
736  DScalarContext& operator=(const DScalarContext& rhs);
737 };
738 
740 typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
741 
747 public:
757 
758 };
759 
765 public:
779 };
780 
786 public:
802 };
803 
810 public:
823 };
824 
830 public:
841  const TSIGKeyInfoMapPtr keys);
842 };
843 
849 public:
862  DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config,
863  const TSIGKeyInfoMapPtr keys);
864 };
865 
872 public:
885  const std::string& mgr_name,
886  const TSIGKeyInfoMapPtr keys);
887 };
888 
889 
890 }; // end of isc::d2 namespace
891 }; // end of isc namespace
892 
893 #endif // D2_CONFIG_H
static const char * HMAC_SHA256_STR
Definition: d2_config.h:266
The Name class encapsulates DNS names.
Definition: name.h:223
static const char * wildcard_domain_name_
defines the domain name for denoting the wildcard domain.
Definition: d2_config.h:611
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
Definition: d2_config.h:398
std::ostream & operator<<(std::ostream &os, const D2Params &config)
Dumps the contents of a D2Params as text to an output stream.
Definition: d2_config.cc:120
virtual process::ConfigPtr clone()
Creates a clone of a DStubContext.
Definition: d2_config.h:718
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
Definition: d2_config.h:251
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
Definition: d2_config.h:407
const TSIGKeyInfoPtr & getTSIGKeyInfo()
Getter which returns the domain's TSIGKey info.
Definition: d2_config.h:564
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
Definition: d2_config.h:457
A generic exception that is thrown when a function is not implemented.
bool operator !=(const D2Params &other) const
Compares two D2Params's for inequality.
Definition: d2_config.cc:100
DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config, const std::string &mgr_name, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given manager element.
Definition: d2_config.cc:624
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:185
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_cfg_mgr.h:120
Parser for a list of DdnsDomains.
Definition: d2_config.h:848
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:586
virtual ~DScalarContext()
Destructor.
Definition: d2_config.h:712
Storage container for scalar configuration parameters.
Definition: d2_config.h:704
const std::string getSecret() const
Getter which returns the key's secret.
Definition: d2_config.h:333
const std::string getAlgorithm() const
Getter which returns the key's algorithm string ID.
Definition: d2_config.h:319
Base class for user context.
Definition: user_context.h:22
Parser for DdnsDomainListMgr.
Definition: d2_config.h:871
std::string toText() const
Returns a text representation for the server.
Definition: d2_config.cc:214
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
Definition: d2_config.cc:91
DnsServerInfoPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given "dns-server" element.
Definition: d2_config.cc:479
Base class for all configurations.
Definition: config_base.h:31
static const char * HMAC_SHA224_STR
Definition: d2_config.h:267
const std::string getName() const
Getter which returns the domain's name.
Definition: d2_config.h:543
Exception thrown when the error during configuration handling occurs.
Definition: d2_config.h:130
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
boost::shared_ptr< DScalarContext > DScalarContextPtr
Defines a pointer for DScalarContext instances.
Definition: d2_config.h:740
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
Definition: d2_config.cc:302
const std::string getName() const
Getter which returns the key's name.
Definition: d2_config.h:312
uint32_t getPort() const
Getter which returns the server's port number.
Definition: d2_config.h:450
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
Definition: d2_config.h:168
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
Definition: d2_config.h:401
NameChangeFormat
Defines the list of data wire formats supported.
Definition: ncr_msg.h:60
TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config)
Performs the parsing of the given list "tsig-key" elements.
Definition: d2_config.cc:456
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition: d2_config.h:512
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
Definition: d2_config.cc:547
static const char * HMAC_SHA384_STR
Definition: d2_config.h:268
virtual ~TSIGKeyInfo()
Destructor.
Definition: d2_config.cc:142
size_t getDnsServerTimeout() const
Return the DNS server timeout value.
Definition: d2_config.h:178
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
Definition: d2_config.h:592
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void disable()
Sets the server's enabled flag to false.
Definition: d2_config.h:475
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:264
uint32_t size() const
Returns the number of domains in the domain list.
Definition: d2_config.h:651
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.h:725
std::string getConfigSummary() const
Return summary of the configuration used by D2.
Definition: d2_config.cc:83
Parser for TSIGKeyInfo.
Definition: d2_config.h:746
Represents a DNS domain that is may be updated dynamically.
Definition: d2_config.h:525
Represents a TSIG Key.
Definition: d2_config.h:260
static const uint32_t STANDARD_DNS_PORT
defines DNS standard port value
Definition: d2_config.h:418
const DnsServerInfoStoragePtr & getServers()
Getter which returns the domain's list of servers.
Definition: d2_config.h:556
D2Params()
Default constructor The default constructor creates an instance that has updates disabled.
Definition: d2_config.cc:43
Abstract class for configuration Cfg_* classes.
Parser for a list of DnsServerInfos.
Definition: d2_config.h:809
static const dns::Name & stringToAlgorithmName(const std::string &algorithm_id)
Converts algorithm id to dns::TSIGKey algorithm dns::Name.
Definition: d2_config.cc:146
virtual bool matchDomain(const std::string &fqdn, DdnsDomainPtr &domain)
Matches a given name to a domain based on a longest match scheme.
Definition: d2_config.cc:320
std::string toText() const
Generates a string representation of the class contents.
Definition: d2_config.cc:105
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
const dhcp_ddns::NameChangeProtocol & getNcrProtocol() const
Return the socket protocol in use.
Definition: d2_config.h:183
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
Definition: d2_config.h:589
Provides storage for and management of a list of DNS domains.
Definition: d2_config.h:608
Parser for DdnsDomain.
Definition: d2_config.h:829
boost::shared_ptr< TSIGKey > TSIGKeyPtr
Definition: tsig.h:437
const std::string getName() const
Fetches the manager's name.
Definition: d2_config.h:644
virtual void validateContents()
Validates member values.
Definition: d2_config.cc:54
DdnsDomain(const std::string &name, DnsServerInfoStoragePtr servers, const TSIGKeyInfoPtr &tsig_key_info=TSIGKeyInfoPtr())
Constructor.
Definition: d2_config.cc:244
DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given list "ddns-domain" elements.
Definition: d2_config.cc:600
const DdnsDomainPtr & getWildcardDomain()
Fetches the wild card domain.
Definition: d2_config.h:659
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
DdnsDomainListMgr(const std::string &name)
Constructor.
Definition: d2_config.cc:293
TSIGKeyInfo(const std::string &name, const std::string &algorithm, const std::string &secret, uint32_t digestbits=0)
Constructor.
Definition: d2_config.cc:135
Represents a specific DNS Server.
Definition: d2_config.h:415
static const char * HMAC_SHA1_STR
Definition: d2_config.h:265
virtual ~DdnsDomain()
Destructor.
Definition: d2_config.cc:251
DnsServerInfo(const std::string &hostname, isc::asiolink::IOAddress ip_address, uint32_t port=STANDARD_DNS_PORT, bool enabled=true)
Constructor.
Definition: d2_config.cc:203
virtual ~DnsServerInfo()
Destructor.
Definition: d2_config.cc:210
const std::string getKeyName() const
Convenience method which returns the domain's TSIG key name.
Definition: d2_config.cc:255
const std::string getHostname() const
Getter which returns the server's hostname.
Definition: d2_config.h:443
const DdnsDomainMapPtr & getDomains()
Fetches the domain list.
Definition: d2_config.h:666
std::pair< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMapPair
Defines a iterator pairing of name and TSIGKeyInfo.
Definition: d2_config.h:404
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
Definition: d2_config.h:264
virtual ~D2Params()
Destructor.
Definition: d2_config.cc:51
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:66
D2CfgError(const char *file, size_t line, const char *what)
Definition: d2_config.h:132
const dns::TSIGKeyPtr & getTSIGKey() const
Getter which returns the TSIG key used to sign and verify messages.
Definition: d2_config.h:341
uint32_t getDigestbits() const
Getter which returns the key's minimum truncated length.
Definition: d2_config.h:326
DScalarContext(const DScalarContext &rhs)
Copy constructor.
Definition: d2_config.h:731
Parser for a list of TSIGKeyInfos.
Definition: d2_config.h:764
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:515
bool isEnabled() const
Convenience method which returns whether or not the server is enabled.
Definition: d2_config.h:465
size_t getPort() const
Return the TCP/UPD port D2 listens on.
Definition: d2_config.h:173
DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config)
Performs the actual parsing of the given list "dns-server" elements.
Definition: d2_config.cc:533
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:385
const dhcp_ddns::NameChangeFormat & getNcrFormat() const
Return the expected format of inbound requests (NCRs).
Definition: d2_config.h:188
void enable()
Sets the server's enabled flag to true.
Definition: d2_config.h:470
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
Definition: d2_config.h:595
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:221
Parser for DnsServerInfo.
Definition: d2_config.h:785
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:509
Acts as a storage vault for D2 global scalar parameters.
Definition: d2_config.h:137
static const char * HMAC_SHA512_STR
Definition: d2_config.h:269
virtual ~DdnsDomainListMgr()
Destructor.
Definition: d2_config.cc:298
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the SrvConfig.
Definition: config_base.h:119
DScalarContext()
Constructor.
Definition: d2_config.h:708
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.
Definition: d2_config.cc:402