Kea  2.1.7-git
d2_config.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2021 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>
15 #include <d2srv/d2_tsig_key.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 
133 
136 class D2CfgError : public isc::Exception {
137 public:
138  D2CfgError(const char* file, size_t line, const char* what) :
139  isc::Exception(file, line, what) { };
140 };
141 
143 class D2Params {
144 public:
160  D2Params(const isc::asiolink::IOAddress& ip_address,
161  const size_t port,
162  const size_t dns_server_timeout,
163  const dhcp_ddns::NameChangeProtocol& ncr_protocol,
164  const dhcp_ddns::NameChangeFormat& ncr_format);
165 
168  D2Params();
169 
171  virtual ~D2Params();
172 
175  return(ip_address_);
176  }
177 
179  size_t getPort() const {
180  return(port_);
181  }
182 
184  size_t getDnsServerTimeout() const {
185  return(dns_server_timeout_);
186  }
187 
190  return(ncr_protocol_);
191  }
192 
195  return(ncr_format_);
196  }
197 
205  std::string getConfigSummary() const;
206 
208  bool operator == (const D2Params& other) const;
209 
211  bool operator != (const D2Params& other) const;
212 
214  std::string toText() const;
215 
216 protected:
228  virtual void validateContents();
229 
230 private:
232  isc::asiolink::IOAddress ip_address_;
233 
235  size_t port_;
236 
238  size_t dns_server_timeout_;
239 
242  dhcp_ddns::NameChangeProtocol ncr_protocol_;
243 
246  dhcp_ddns::NameChangeFormat ncr_format_;
247 };
248 
253 std::ostream&
254 operator<<(std::ostream& os, const D2Params& config);
255 
257 typedef boost::shared_ptr<D2Params> D2ParamsPtr;
258 
267 public:
269 
270  static const char* HMAC_MD5_STR;
271  static const char* HMAC_SHA1_STR;
272  static const char* HMAC_SHA256_STR;
273  static const char* HMAC_SHA224_STR;
274  static const char* HMAC_SHA384_STR;
275  static const char* HMAC_SHA512_STR;
276  //}@
277 
309  TSIGKeyInfo(const std::string& name, const std::string& algorithm,
310  const std::string& secret, uint32_t digestbits = 0);
311 
313  virtual ~TSIGKeyInfo();
314 
318  const std::string getName() const {
319  return (name_);
320  }
321 
325  const std::string getAlgorithm() const {
326  return (algorithm_);
327  }
328 
332  uint32_t getDigestbits() const {
333  return (digestbits_);
334  }
335 
339  const std::string getSecret() const {
340  return (secret_);
341  }
342 
347  const D2TsigKeyPtr& getTSIGKey() const {
348  return (tsig_key_);
349  }
350 
364  static const dns::Name& stringToAlgorithmName(const std::string&
365  algorithm_id);
366 
370  virtual isc::data::ElementPtr toElement() const;
371 
372 private:
381  void remakeKey();
382 
387  std::string name_;
388 
390  std::string algorithm_;
391 
393  std::string secret_;
394 
397  uint32_t digestbits_;
398 
400  D2TsigKeyPtr tsig_key_;
401 };
402 
404 typedef boost::shared_ptr<TSIGKeyInfo> TSIGKeyInfoPtr;
405 
407 typedef std::map<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMap;
408 
410 typedef std::pair<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMapPair;
411 
413 typedef boost::shared_ptr<TSIGKeyInfoMap> TSIGKeyInfoMapPtr;
414 
415 
422 public:
424  static const uint32_t STANDARD_DNS_PORT = 53;
425 
442  DnsServerInfo(const std::string& hostname,
443  isc::asiolink::IOAddress ip_address,
444  uint32_t port = STANDARD_DNS_PORT,
445  bool enabled = true,
446  const TSIGKeyInfoPtr& tsig_key_info = TSIGKeyInfoPtr(),
447  bool inherited_key = true);
448 
450  virtual ~DnsServerInfo();
451 
455  const std::string getHostname() const {
456  return (hostname_);
457  }
458 
462  uint32_t getPort() const {
463  return (port_);
464  }
465 
470  return (ip_address_);
471  }
472 
477  bool isEnabled() const {
478  return (enabled_);
479  }
480 
482  void enable() {
483  enabled_ = true;
484  }
485 
487  void disable() {
488  enabled_ = false;
489  }
490 
495  const std::string getKeyName() const;
496 
501  const TSIGKeyInfoPtr& getTSIGKeyInfo() {
502  return (tsig_key_info_);
503  }
504 
506  std::string toText() const;
507 
511  virtual isc::data::ElementPtr toElement() const;
512 
513 private:
516  std::string hostname_;
517 
520  isc::asiolink::IOAddress ip_address_;
521 
523  uint32_t port_;
524 
527  bool enabled_;
528 
531  TSIGKeyInfoPtr tsig_key_info_;
532 
535  bool inherited_key_;
536 };
537 
538 std::ostream&
539 operator<<(std::ostream& os, const DnsServerInfo& server);
540 
542 typedef boost::shared_ptr<DnsServerInfo> DnsServerInfoPtr;
543 
545 typedef std::vector<DnsServerInfoPtr> DnsServerInfoStorage;
546 
548 typedef boost::shared_ptr<DnsServerInfoStorage> DnsServerInfoStoragePtr;
549 
550 
559 public:
565  DdnsDomain(const std::string& name, DnsServerInfoStoragePtr servers,
566  const std::string& key_name = "");
567 
569  virtual ~DdnsDomain();
570 
574  const std::string getName() const {
575  return (name_);
576  }
577 
584  const std::string getKeyName() const {
585  return (key_name_);
586  }
587 
591  const DnsServerInfoStoragePtr& getServers() {
592  return (servers_);
593  }
594 
598  virtual isc::data::ElementPtr toElement() const;
599 
600 private:
602  std::string name_;
603 
605  DnsServerInfoStoragePtr servers_;
606 
608  std::string key_name_;
609 };
610 
612 typedef boost::shared_ptr<DdnsDomain> DdnsDomainPtr;
613 
615 typedef std::map<std::string, DdnsDomainPtr> DdnsDomainMap;
616 
618 typedef std::pair<std::string, DdnsDomainPtr> DdnsDomainMapPair;
619 
621 typedef boost::shared_ptr<DdnsDomainMap> DdnsDomainMapPtr;
622 
635 public:
637  static const char* wildcard_domain_name_;
638 
642  DdnsDomainListMgr(const std::string& name);
643 
645  virtual ~DdnsDomainListMgr ();
646 
665  virtual bool matchDomain(const std::string& fqdn, DdnsDomainPtr& domain);
666 
670  const std::string getName() const {
671  return (name_);
672  }
673 
677  uint32_t size() const {
678  return (domains_->size());
679  }
680 
685  const DdnsDomainPtr& getWildcardDomain() {
686  return (wildcard_domain_);
687  }
688 
692  const DdnsDomainMapPtr &getDomains() {
693  return (domains_);
694  }
695 
699  void setDomains(DdnsDomainMapPtr domains);
700 
704  virtual isc::data::ElementPtr toElement() const;
705 
706 private:
708  std::string name_;
709 
711  DdnsDomainMapPtr domains_;
712 
714  DdnsDomainPtr wildcard_domain_;
715 };
716 
718 typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;
719 
731 public:
732 
735  };
736 
738  virtual ~DScalarContext() {
739  }
740 
745  return (process::ConfigPtr(new DScalarContext(*this)));
746  }
747 
752  isc_throw(isc::NotImplemented, "DScalarContext::ElementPtr");
753  }
754 
755 protected:
757  DScalarContext(const DScalarContext& rhs) : ConfigBase(rhs) {
758  }
759 
760 private:
762  DScalarContext& operator=(const DScalarContext& rhs);
763 };
764 
766 typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
767 
773 public:
782  TSIGKeyInfoPtr parse(data::ConstElementPtr key_config);
783 
784 };
785 
791 public:
804  TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config);
805 };
806 
812 public:
829  DnsServerInfoPtr parse(data::ConstElementPtr server_config,
830  data::ConstElementPtr domain_config,
831  const TSIGKeyInfoMapPtr keys);
832 };
833 
840 public:
854  DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config,
855  data::ConstElementPtr domain_config,
856  const TSIGKeyInfoMapPtr keys);
857 };
858 
864 public:
874  DdnsDomainPtr parse(data::ConstElementPtr domain_config,
875  const TSIGKeyInfoMapPtr keys);
876 };
877 
883 public:
896  DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config,
897  const TSIGKeyInfoMapPtr keys);
898 };
899 
906 public:
918  DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config,
919  const std::string& mgr_name,
920  const TSIGKeyInfoMapPtr keys);
921 };
922 
923 } // end of isc::d2 namespace
924 } // end of isc namespace
925 
926 #endif // D2_CONFIG_H
static const char * HMAC_SHA256_STR
Definition: d2_config.h:272
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:637
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
Definition: d2_config.h:404
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:744
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
Definition: d2_config.h:257
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
Definition: d2_config.h:413
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server&#39;s ip_address.
Definition: d2_config.h:469
A generic exception that is thrown when a function is not implemented.
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_cfg_mgr.h:153
Parser for a list of DdnsDomains.
Definition: d2_config.h:882
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:612
virtual ~DScalarContext()
Destructor.
Definition: d2_config.h:738
Storage container for scalar configuration parameters.
Definition: d2_config.h:730
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition: d2_tsig_key.h:71
const std::string getSecret() const
Getter which returns the key&#39;s secret.
Definition: d2_config.h:339
const std::string getAlgorithm() const
Getter which returns the key&#39;s algorithm string ID.
Definition: d2_config.h:325
Base class for user context.
Definition: user_context.h:22
Parser for DdnsDomainListMgr.
Definition: d2_config.h:905
bool operator!=(const Element &a, const Element &b)
Definition: data.cc:214
Base class for all configurations.
Definition: config_base.h:33
static const char * HMAC_SHA224_STR
Definition: d2_config.h:273
const std::string getName() const
Getter which returns the domain&#39;s name.
Definition: d2_config.h:574
Exception thrown when the error during configuration handling occurs.
Definition: d2_config.h:136
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
boost::shared_ptr< DScalarContext > DScalarContextPtr
Defines a pointer for DScalarContext instances.
Definition: d2_config.h:766
const std::string getName() const
Getter which returns the key&#39;s name.
Definition: d2_config.h:318
uint32_t getPort() const
Getter which returns the server&#39;s port number.
Definition: d2_config.h:462
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
Definition: d2_config.h:174
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
Definition: d2_config.h:407
NameChangeFormat
Defines the list of data wire formats supported.
Definition: ncr_msg.h:60
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition: d2_config.h:545
static const char * HMAC_SHA384_STR
Definition: d2_config.h:274
size_t getDnsServerTimeout() const
Return the DNS server timeout value.
Definition: d2_config.h:184
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
Definition: d2_config.h:618
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void disable()
Sets the server&#39;s enabled flag to false.
Definition: d2_config.h:487
uint32_t size() const
Returns the number of domains in the domain list.
Definition: d2_config.h:677
bool operator==(const Element &a, const Element &b)
Definition: data.cc:210
#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:751
Parser for TSIGKeyInfo.
Definition: d2_config.h:772
Represents a DNS domain that is may be updated dynamically.
Definition: d2_config.h:558
Represents a TSIG Key.
Definition: d2_config.h:266
const DnsServerInfoStoragePtr & getServers()
Getter which returns the domain&#39;s list of servers.
Definition: d2_config.h:591
Abstract class for configuration Cfg_* classes.
Parser for a list of DnsServerInfos.
Definition: d2_config.h:839
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
const dhcp_ddns::NameChangeProtocol & getNcrProtocol() const
Return the socket protocol in use.
Definition: d2_config.h:189
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
Definition: d2_config.h:615
Provides storage for and management of a list of DNS domains.
Definition: d2_config.h:634
Parser for DdnsDomain.
Definition: d2_config.h:863
const TSIGKeyInfoPtr & getTSIGKeyInfo()
Getter which returns the server&#39;s TSIGKey info.
Definition: d2_config.h:501
const D2TsigKeyPtr & getTSIGKey() const
Getter which returns the TSIG key used to sign and verify messages.
Definition: d2_config.h:347
const std::string getName() const
Fetches the manager&#39;s name.
Definition: d2_config.h:670
const DdnsDomainPtr & getWildcardDomain()
Fetches the wild card domain.
Definition: d2_config.h:685
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
Represents a specific DNS Server.
Definition: d2_config.h:421
static const char * HMAC_SHA1_STR
Definition: d2_config.h:271
const std::string getKeyName() const
Getter which returns the domain&#39;s TSIG key name.
Definition: d2_config.h:584
const Name & name_
Definition: dns/message.cc:693
const std::string getHostname() const
Getter which returns the server&#39;s hostname.
Definition: d2_config.h:455
const DdnsDomainMapPtr & getDomains()
Fetches the domain list.
Definition: d2_config.h:692
std::pair< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMapPair
Defines a iterator pairing of name and TSIGKeyInfo.
Definition: d2_config.h:410
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
Definition: d2_config.h:270
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:138
uint32_t getDigestbits() const
Getter which returns the key&#39;s minimum truncated length.
Definition: d2_config.h:332
DScalarContext(const DScalarContext &rhs)
Copy constructor.
Definition: d2_config.h:757
Parser for a list of TSIGKeyInfos.
Definition: d2_config.h:790
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:548
bool isEnabled() const
Convenience method which returns whether or not the server is enabled.
Definition: d2_config.h:477
size_t getPort() const
Return the TCP/UPD port D2 listens on.
Definition: d2_config.h:179
const dhcp_ddns::NameChangeFormat & getNcrFormat() const
Return the expected format of inbound requests (NCRs).
Definition: d2_config.h:194
void enable()
Sets the server&#39;s enabled flag to true.
Definition: d2_config.h:482
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
Definition: d2_config.h:621
Parser for DnsServerInfo.
Definition: d2_config.h:811
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:542
Acts as a storage vault for D2 global scalar parameters.
Definition: d2_config.h:143
static const char * HMAC_SHA512_STR
Definition: d2_config.h:275
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Definition: config_base.h:176
DScalarContext()
Constructor.
Definition: d2_config.h:734