Kea  1.9.9-git
d2_config.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2019 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 
132 
135 class D2CfgError : public isc::Exception {
136 public:
137  D2CfgError(const char* file, size_t line, const char* what) :
138  isc::Exception(file, line, what) { };
139 };
140 
142 class D2Params {
143 public:
159  D2Params(const isc::asiolink::IOAddress& ip_address,
160  const size_t port,
161  const size_t dns_server_timeout,
162  const dhcp_ddns::NameChangeProtocol& ncr_protocol,
163  const dhcp_ddns::NameChangeFormat& ncr_format);
164 
167  D2Params();
168 
170  virtual ~D2Params();
171 
174  return(ip_address_);
175  }
176 
178  size_t getPort() const {
179  return(port_);
180  }
181 
183  size_t getDnsServerTimeout() const {
184  return(dns_server_timeout_);
185  }
186 
189  return(ncr_protocol_);
190  }
191 
194  return(ncr_format_);
195  }
196 
204  std::string getConfigSummary() const;
205 
207  bool operator == (const D2Params& other) const;
208 
210  bool operator != (const D2Params& other) const;
211 
213  std::string toText() const;
214 
215 protected:
227  virtual void validateContents();
228 
229 private:
231  isc::asiolink::IOAddress ip_address_;
232 
234  size_t port_;
235 
237  size_t dns_server_timeout_;
238 
241  dhcp_ddns::NameChangeProtocol ncr_protocol_;
242 
245  dhcp_ddns::NameChangeFormat ncr_format_;
246 };
247 
252 std::ostream&
253 operator<<(std::ostream& os, const D2Params& config);
254 
256 typedef boost::shared_ptr<D2Params> D2ParamsPtr;
257 
266 public:
268 
269  static const char* HMAC_MD5_STR;
270  static const char* HMAC_SHA1_STR;
271  static const char* HMAC_SHA256_STR;
272  static const char* HMAC_SHA224_STR;
273  static const char* HMAC_SHA384_STR;
274  static const char* HMAC_SHA512_STR;
275  //}@
276 
308  TSIGKeyInfo(const std::string& name, const std::string& algorithm,
309  const std::string& secret, uint32_t digestbits = 0);
310 
312  virtual ~TSIGKeyInfo();
313 
317  const std::string getName() const {
318  return (name_);
319  }
320 
324  const std::string getAlgorithm() const {
325  return (algorithm_);
326  }
327 
331  uint32_t getDigestbits() const {
332  return (digestbits_);
333  }
334 
338  const std::string getSecret() const {
339  return (secret_);
340  }
341 
346  const dns::TSIGKeyPtr& getTSIGKey() const {
347  return (tsig_key_);
348  }
349 
363  static const dns::Name& stringToAlgorithmName(const std::string&
364  algorithm_id);
365 
369  virtual isc::data::ElementPtr toElement() const;
370 
371 private:
380  void remakeKey();
381 
386  std::string name_;
387 
389  std::string algorithm_;
390 
392  std::string secret_;
393 
396  uint32_t digestbits_;
397 
399  dns::TSIGKeyPtr tsig_key_;
400 };
401 
403 typedef boost::shared_ptr<TSIGKeyInfo> TSIGKeyInfoPtr;
404 
406 typedef std::map<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMap;
407 
409 typedef std::pair<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMapPair;
410 
412 typedef boost::shared_ptr<TSIGKeyInfoMap> TSIGKeyInfoMapPtr;
413 
414 
421 public:
423  static const uint32_t STANDARD_DNS_PORT = 53;
424 
437  DnsServerInfo(const std::string& hostname,
438  isc::asiolink::IOAddress ip_address,
439  uint32_t port = STANDARD_DNS_PORT,
440  bool enabled=true);
441 
443  virtual ~DnsServerInfo();
444 
448  const std::string getHostname() const {
449  return (hostname_);
450  }
451 
455  uint32_t getPort() const {
456  return (port_);
457  }
458 
463  return (ip_address_);
464  }
465 
470  bool isEnabled() const {
471  return (enabled_);
472  }
473 
475  void enable() {
476  enabled_ = true;
477  }
478 
480  void disable() {
481  enabled_ = false;
482  }
483 
485  std::string toText() const;
486 
490  virtual isc::data::ElementPtr toElement() const;
491 
492 
493 private:
496  std::string hostname_;
497 
500  isc::asiolink::IOAddress ip_address_;
501 
503  uint32_t port_;
504 
507  bool enabled_;
508 };
509 
510 std::ostream&
511 operator<<(std::ostream& os, const DnsServerInfo& server);
512 
514 typedef boost::shared_ptr<DnsServerInfo> DnsServerInfoPtr;
515 
517 typedef std::vector<DnsServerInfoPtr> DnsServerInfoStorage;
518 
520 typedef boost::shared_ptr<DnsServerInfoStorage> DnsServerInfoStoragePtr;
521 
522 
531 public:
538  DdnsDomain(const std::string& name,
539  DnsServerInfoStoragePtr servers,
540  const TSIGKeyInfoPtr& tsig_key_info = TSIGKeyInfoPtr());
541 
543  virtual ~DdnsDomain();
544 
548  const std::string getName() const {
549  return (name_);
550  }
551 
556  const std::string getKeyName() const;
557 
561  const DnsServerInfoStoragePtr& getServers() {
562  return (servers_);
563  }
564 
569  const TSIGKeyInfoPtr& getTSIGKeyInfo() {
570  return (tsig_key_info_);
571  }
572 
576  virtual isc::data::ElementPtr toElement() const;
577 
578 private:
580  std::string name_;
581 
583  DnsServerInfoStoragePtr servers_;
584 
587  TSIGKeyInfoPtr tsig_key_info_;
588 };
589 
591 typedef boost::shared_ptr<DdnsDomain> DdnsDomainPtr;
592 
594 typedef std::map<std::string, DdnsDomainPtr> DdnsDomainMap;
595 
597 typedef std::pair<std::string, DdnsDomainPtr> DdnsDomainMapPair;
598 
600 typedef boost::shared_ptr<DdnsDomainMap> DdnsDomainMapPtr;
601 
614 public:
616  static const char* wildcard_domain_name_;
617 
621  DdnsDomainListMgr(const std::string& name);
622 
624  virtual ~DdnsDomainListMgr ();
625 
644  virtual bool matchDomain(const std::string& fqdn, DdnsDomainPtr& domain);
645 
649  const std::string getName() const {
650  return (name_);
651  }
652 
656  uint32_t size() const {
657  return (domains_->size());
658  }
659 
664  const DdnsDomainPtr& getWildcardDomain() {
665  return (wildcard_domain_);
666  }
667 
671  const DdnsDomainMapPtr &getDomains() {
672  return (domains_);
673  }
674 
678  void setDomains(DdnsDomainMapPtr domains);
679 
683  virtual isc::data::ElementPtr toElement() const;
684 
685 private:
687  std::string name_;
688 
690  DdnsDomainMapPtr domains_;
691 
693  DdnsDomainPtr wildcard_domain_;
694 };
695 
697 typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;
698 
710 public:
711 
714  };
715 
717  virtual ~DScalarContext() {
718  }
719 
724  return (process::ConfigPtr(new DScalarContext(*this)));
725  }
726 
731  isc_throw(isc::NotImplemented, "DScalarContext::ElementPtr");
732  }
733 
734 protected:
736  DScalarContext(const DScalarContext& rhs) : ConfigBase(rhs) {
737  }
738 
739 private:
741  DScalarContext& operator=(const DScalarContext& rhs);
742 };
743 
745 typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
746 
752 public:
761  TSIGKeyInfoPtr parse(data::ConstElementPtr key_config);
762 
763 };
764 
770 public:
783  TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config);
784 };
785 
791 public:
806  DnsServerInfoPtr parse(data::ConstElementPtr server_config);
807 };
808 
815 public:
827  DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config);
828 };
829 
835 public:
845  DdnsDomainPtr parse(data::ConstElementPtr domain_config,
846  const TSIGKeyInfoMapPtr keys);
847 };
848 
854 public:
867  DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config,
868  const TSIGKeyInfoMapPtr keys);
869 };
870 
877 public:
889  DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config,
890  const std::string& mgr_name,
891  const TSIGKeyInfoMapPtr keys);
892 };
893 
894 
895 }; // end of isc::d2 namespace
896 }; // end of isc namespace
897 
898 #endif // D2_CONFIG_H
static const char * HMAC_SHA256_STR
Definition: d2_config.h:271
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:616
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
Definition: d2_config.h:403
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:723
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
Definition: d2_config.h:256
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
Definition: d2_config.h:412
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
Definition: d2_config.h:173
const dhcp_ddns::NameChangeFormat & getNcrFormat() const
Return the expected format of inbound requests (NCRs).
Definition: d2_config.h:193
uint32_t size() const
Returns the number of domains in the domain list.
Definition: d2_config.h:656
const TSIGKeyInfoPtr & getTSIGKeyInfo()
Getter which returns the domain's TSIGKey info.
Definition: d2_config.h:569
A generic exception that is thrown when a function is not implemented.
uint32_t getPort() const
Getter which returns the server's port number.
Definition: d2_config.h:455
const std::string getName() const
Getter which returns the domain's name.
Definition: d2_config.h:548
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:625
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_cfg_mgr.h:153
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:185
const dhcp_ddns::NameChangeProtocol & getNcrProtocol() const
Return the socket protocol in use.
Definition: d2_config.h:188
Parser for a list of DdnsDomains.
Definition: d2_config.h:853
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:591
const std::string getHostname() const
Getter which returns the server's hostname.
Definition: d2_config.h:448
virtual ~DScalarContext()
Destructor.
Definition: d2_config.h:717
Storage container for scalar configuration parameters.
Definition: d2_config.h:709
Base class for user context.
Definition: user_context.h:22
Parser for DdnsDomainListMgr.
Definition: d2_config.h:876
DnsServerInfoPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given "dns-server" element.
Definition: d2_config.cc:480
Base class for all configurations.
Definition: config_base.h:33
static const char * HMAC_SHA224_STR
Definition: d2_config.h:272
Exception thrown when the error during configuration handling occurs.
Definition: d2_config.h:135
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
Definition: d2_config.cc:91
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:221
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
boost::shared_ptr< DScalarContext > DScalarContextPtr
Defines a pointer for DScalarContext instances.
Definition: d2_config.h:745
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
Definition: d2_config.cc:302
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
Definition: d2_config.h:406
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:457
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition: d2_config.h:517
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
Definition: d2_config.cc:548
static const char * HMAC_SHA384_STR
Definition: d2_config.h:273
virtual ~TSIGKeyInfo()
Destructor.
Definition: d2_config.cc:142
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
Definition: d2_config.h:597
void disable()
Sets the server's enabled flag to false.
Definition: d2_config.h:480
const std::string getSecret() const
Getter which returns the key's secret.
Definition: d2_config.h:338
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
size_t getPort() const
Return the TCP/UPD port D2 listens on.
Definition: d2_config.h:178
Parser for TSIGKeyInfo.
Definition: d2_config.h:751
Represents a DNS domain that is may be updated dynamically.
Definition: d2_config.h:530
Represents a TSIG Key.
Definition: d2_config.h:265
static const uint32_t STANDARD_DNS_PORT
defines DNS standard port value
Definition: d2_config.h:423
const DnsServerInfoStoragePtr & getServers()
Getter which returns the domain's list of servers.
Definition: d2_config.h:561
const std::string getAlgorithm() const
Getter which returns the key's algorithm string ID.
Definition: d2_config.h:324
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:814
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
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:264
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
bool operator!=(const D2Params &other) const
Compares two D2Params's for inequality.
Definition: d2_config.cc:100
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
Definition: d2_config.h:594
Provides storage for and management of a list of DNS domains.
Definition: d2_config.h:613
Parser for DdnsDomain.
Definition: d2_config.h:834
boost::shared_ptr< TSIGKey > TSIGKeyPtr
Definition: tsig.h:436
const std::string getName() const
Getter which returns the key's name.
Definition: d2_config.h:317
bool isEnabled() const
Convenience method which returns whether or not the server is enabled.
Definition: d2_config.h:470
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::string toText() const
Generates a string representation of the class contents.
Definition: d2_config.cc:105
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:601
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
Definition: d2_config.h:462
const DdnsDomainPtr & getWildcardDomain()
Fetches the wild card domain.
Definition: d2_config.h:664
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:420
static const char * HMAC_SHA1_STR
Definition: d2_config.h:270
std::string getConfigSummary() const
Return summary of the configuration used by D2.
Definition: d2_config.cc:83
const std::string getName() const
Fetches the manager's name.
Definition: d2_config.h:649
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
std::string toText() const
Returns a text representation for the server.
Definition: d2_config.cc:214
const DdnsDomainMapPtr & getDomains()
Fetches the domain list.
Definition: d2_config.h:671
size_t getDnsServerTimeout() const
Return the DNS server timeout value.
Definition: d2_config.h:183
const std::string getKeyName() const
Convenience method which returns the domain's TSIG key name.
Definition: d2_config.cc:255
std::pair< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMapPair
Defines a iterator pairing of name and TSIGKeyInfo.
Definition: d2_config.h:409
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
Definition: d2_config.h:269
virtual ~D2Params()
Destructor.
Definition: d2_config.cc:51
uint32_t getDigestbits() const
Getter which returns the key's minimum truncated length.
Definition: d2_config.h:331
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:68
D2CfgError(const char *file, size_t line, const char *what)
Definition: d2_config.h:137
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.h:730
DScalarContext(const DScalarContext &rhs)
Copy constructor.
Definition: d2_config.h:736
const dns::TSIGKeyPtr & getTSIGKey() const
Getter which returns the TSIG key used to sign and verify messages.
Definition: d2_config.h:346
Parser for a list of TSIGKeyInfos.
Definition: d2_config.h:769
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:520
DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config)
Performs the actual parsing of the given list "dns-server" elements.
Definition: d2_config.cc:534
void enable()
Sets the server's enabled flag to true.
Definition: d2_config.h:475
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
Definition: d2_config.h:600
Parser for DnsServerInfo.
Definition: d2_config.h:790
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:385
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:514
Acts as a storage vault for D2 global scalar parameters.
Definition: d2_config.h:142
static const char * HMAC_SHA512_STR
Definition: d2_config.h:274
virtual ~DdnsDomainListMgr()
Destructor.
Definition: d2_config.cc:298
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Definition: config_base.h:176
DScalarContext()
Constructor.
Definition: d2_config.h:713
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.
Definition: d2_config.cc:402