Kea  2.5.2
d2_config.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2022 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:
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;
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 
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 
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 
686  return (wildcard_domain_);
687  }
688 
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:
783 
784 };
785 
791 public:
805 };
806 
812 public:
830  data::ConstElementPtr domain_config,
831  const TSIGKeyInfoMapPtr keys);
832 };
833 
840 public:
855  data::ConstElementPtr domain_config,
856  const TSIGKeyInfoMapPtr keys);
857 };
858 
864 public:
875  const TSIGKeyInfoMapPtr keys);
876 };
877 
883 public:
896  DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config,
897  const TSIGKeyInfoMapPtr keys);
898 };
899 
906 public:
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
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
Exception thrown when the error during configuration handling occurs.
Definition: d2_config.h:136
D2CfgError(const char *file, size_t line, const char *what)
Definition: d2_config.h:138
Acts as a storage vault for D2 global scalar parameters.
Definition: d2_config.h:143
size_t getDnsServerTimeout() const
Return the DNS server timeout value.
Definition: d2_config.h:184
D2Params()
Default constructor The default constructor creates an instance that has updates disabled.
Definition: d2_config.cc:43
bool operator!=(const D2Params &other) const
Compares two D2Params's for inequality.
Definition: d2_config.cc:100
size_t getPort() const
Return the TCP/UPD port D2 listens on.
Definition: d2_config.h:179
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
Definition: d2_config.cc:91
const dhcp_ddns::NameChangeProtocol & getNcrProtocol() const
Return the socket protocol in use.
Definition: d2_config.h:189
const dhcp_ddns::NameChangeFormat & getNcrFormat() const
Return the expected format of inbound requests (NCRs).
Definition: d2_config.h:194
virtual ~D2Params()
Destructor.
Definition: d2_config.cc:51
std::string getConfigSummary() const
Return summary of the configuration used by D2.
Definition: d2_config.cc:83
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
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
Definition: d2_config.h:174
Storage container for scalar configuration parameters.
Definition: d2_config.h:730
DScalarContext()
Constructor.
Definition: d2_config.h:734
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.h:751
virtual process::ConfigPtr clone()
Creates a clone of a DStubContext.
Definition: d2_config.h:744
virtual ~DScalarContext()
Destructor.
Definition: d2_config.h:738
DScalarContext(const DScalarContext &rhs)
Copy constructor.
Definition: d2_config.h:757
Parser for DdnsDomainListMgr.
Definition: d2_config.h:905
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:655
Provides storage for and management of a list of DNS domains.
Definition: d2_config.h:634
const DdnsDomainMapPtr & getDomains()
Fetches the domain list.
Definition: d2_config.h:692
const std::string getName() const
Fetches the manager's name.
Definition: d2_config.h:670
DdnsDomainListMgr(const std::string &name)
Constructor.
Definition: d2_config.cc:299
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:326
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
Definition: d2_config.cc:308
static const char * wildcard_domain_name_
defines the domain name for denoting the wildcard domain.
Definition: d2_config.h:637
virtual ~DdnsDomainListMgr()
Destructor.
Definition: d2_config.cc:304
uint32_t size() const
Returns the number of domains in the domain list.
Definition: d2_config.h:677
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:391
const DdnsDomainPtr & getWildcardDomain()
Fetches the wild card domain.
Definition: d2_config.h:685
Parser for a list of DdnsDomains.
Definition: d2_config.h:882
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:631
Parser for DdnsDomain.
Definition: d2_config.h:863
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
Definition: d2_config.cc:595
Represents a DNS domain that is may be updated dynamically.
Definition: d2_config.h:558
const std::string getKeyName() const
Getter which returns the domain's TSIG key name.
Definition: d2_config.h:584
const std::string getName() const
Getter which returns the domain's name.
Definition: d2_config.h:574
DdnsDomain(const std::string &name, DnsServerInfoStoragePtr servers, const std::string &key_name="")
Constructor.
Definition: d2_config.cc:260
virtual ~DdnsDomain()
Destructor.
Definition: d2_config.cc:266
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:270
const DnsServerInfoStoragePtr & getServers()
Getter which returns the domain's list of servers.
Definition: d2_config.h:591
Parser for a list of DnsServerInfos.
Definition: d2_config.h:839
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.
Definition: d2_config.cc:578
Parser for DnsServerInfo.
Definition: d2_config.h:811
DnsServerInfoPtr parse(data::ConstElementPtr server_config, data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "dns-server" element.
Definition: d2_config.cc:486
Represents a specific DNS Server.
Definition: d2_config.h:421
bool isEnabled() const
Convenience method which returns whether or not the server is enabled.
Definition: d2_config.h:477
std::string toText() const
Returns a text representation for the server.
Definition: d2_config.cc:227
const std::string getKeyName() const
Convenience method which returns the server's TSIG key name.
Definition: d2_config.cc:218
const std::string getHostname() const
Getter which returns the server's hostname.
Definition: d2_config.h:455
const TSIGKeyInfoPtr & getTSIGKeyInfo()
Getter which returns the server's TSIGKey info.
Definition: d2_config.h:501
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.
Definition: d2_config.cc:203
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:234
uint32_t getPort() const
Getter which returns the server's port number.
Definition: d2_config.h:462
void enable()
Sets the server's enabled flag to true.
Definition: d2_config.h:482
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
Definition: d2_config.h:469
static const uint32_t STANDARD_DNS_PORT
defines DNS standard port value
Definition: d2_config.h:424
void disable()
Sets the server's enabled flag to false.
Definition: d2_config.h:487
virtual ~DnsServerInfo()
Destructor.
Definition: d2_config.cc:214
Parser for a list of TSIGKeyInfos.
Definition: d2_config.h:790
TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config)
Performs the parsing of the given list "tsig-key" elements.
Definition: d2_config.cc:463
Parser for TSIGKeyInfo.
Definition: d2_config.h:772
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.
Definition: d2_config.cc:408
Represents a TSIG Key.
Definition: d2_config.h:266
static const char * HMAC_SHA224_STR
Definition: d2_config.h:273
const std::string getAlgorithm() const
Getter which returns the key's algorithm string ID.
Definition: d2_config.h:325
TSIGKeyInfo(const std::string &name, const std::string &algorithm, const std::string &secret, uint32_t digestbits=0)
Constructor.
Definition: d2_config.cc:135
virtual ~TSIGKeyInfo()
Destructor.
Definition: d2_config.cc:142
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
Definition: d2_config.h:270
const std::string getName() const
Getter which returns the key's name.
Definition: d2_config.h:318
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: d2_config.cc:185
static const char * HMAC_SHA1_STR
Definition: d2_config.h:271
static const char * HMAC_SHA256_STR
Definition: d2_config.h:272
const D2TsigKeyPtr & getTSIGKey() const
Getter which returns the TSIG key used to sign and verify messages.
Definition: d2_config.h:347
uint32_t getDigestbits() const
Getter which returns the key's minimum truncated length.
Definition: d2_config.h:332
static const dns::Name & stringToAlgorithmName(const std::string &algorithm_id)
Converts algorithm id to dns::TSIGKey algorithm dns::Name.
Definition: d2_config.cc:146
static const char * HMAC_SHA512_STR
Definition: d2_config.h:275
const std::string getSecret() const
Getter which returns the key's secret.
Definition: d2_config.h:339
static const char * HMAC_SHA384_STR
Definition: d2_config.h:274
The Name class encapsulates DNS names.
Definition: name.h:223
Base class for all configurations.
Definition: config_base.h:33
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< DdnsDomainListMgr > DdnsDomainListMgrPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_cfg_mgr.h:153
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
Definition: d2_config.h:612
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
Definition: d2_config.h:621
std::pair< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMapPair
Defines a iterator pairing of name and TSIGKeyInfo.
Definition: d2_config.h:410
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition: d2_config.h:542
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
Definition: d2_config.h:615
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
Definition: d2_config.h:618
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
Definition: d2_config.h:404
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition: d2_config.h:545
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
Definition: d2_config.h:407
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
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition: d2_config.h:548
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
Definition: d2_config.h:257
boost::shared_ptr< DScalarContext > DScalarContextPtr
Defines a pointer for DScalarContext instances.
Definition: d2_config.h:766
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition: d2_tsig_key.h:71
boost::shared_ptr< TSIGKeyInfoMap > TSIGKeyInfoMapPtr
Defines a pointer to map of TSIGkeyInfos.
Definition: d2_config.h:413
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< Element > ElementPtr
Definition: data.h:26
NameChangeFormat
Defines the list of data wire formats supported.
Definition: ncr_msg.h:60
NameChangeProtocol
Defines the list of socket protocols supported.
Definition: ncr_io.h:68
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Definition: config_base.h:176
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Definition: user_context.h:22