Kea 2.7.0
d2_config.h
Go to the documentation of this file.
1// Copyright (C) 2013-2024 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>
18#include <process/d_cfg_mgr.h>
19
20#include <stdint.h>
21#include <string>
22
23namespace isc {
24namespace d2 {
25
131
135public:
136 D2CfgError(const char* file, size_t line, const char* what) :
137 isc::Exception(file, line, what) { };
138};
139
141class D2Params {
142public:
158 D2Params(const isc::asiolink::IOAddress& ip_address,
159 const size_t port,
160 const size_t dns_server_timeout,
161 const dhcp_ddns::NameChangeProtocol& ncr_protocol,
162 const dhcp_ddns::NameChangeFormat& ncr_format);
163
166 D2Params();
167
169 virtual ~D2Params();
170
173 return (ip_address_);
174 }
175
177 size_t getPort() const {
178 return (port_);
179 }
180
182 size_t getDnsServerTimeout() const {
183 return (dns_server_timeout_);
184 }
185
188 return (ncr_protocol_);
189 }
190
193 return (ncr_format_);
194 }
195
203 std::string getConfigSummary() const;
204
206 bool operator == (const D2Params& other) const;
207
209 bool operator != (const D2Params& other) const;
210
212 std::string toText() const;
213
214protected:
226 virtual void validateContents();
227
228private:
230 isc::asiolink::IOAddress ip_address_;
231
233 size_t port_;
234
236 size_t dns_server_timeout_;
237
240 dhcp_ddns::NameChangeProtocol ncr_protocol_;
241
244 dhcp_ddns::NameChangeFormat ncr_format_;
245};
246
251std::ostream&
252operator<<(std::ostream& os, const D2Params& config);
253
255typedef boost::shared_ptr<D2Params> D2ParamsPtr;
256
265public:
268 static const char* HMAC_MD5_STR;
269 static const char* HMAC_SHA1_STR;
270 static const char* HMAC_SHA256_STR;
271 static const char* HMAC_SHA224_STR;
272 static const char* HMAC_SHA384_STR;
273 static const char* HMAC_SHA512_STR;
275
308 TSIGKeyInfo(const std::string& name, const std::string& algorithm,
309 const std::string& secret, std::string secret_file = "",
310 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
346 const std::string getSecretFile() const {
347 return (secret_file_);
348 }
349
354 const D2TsigKeyPtr& getTSIGKey() const {
355 return (tsig_key_);
356 }
357
371 static const dns::Name& stringToAlgorithmName(const std::string&
372 algorithm_id);
373
377 virtual isc::data::ElementPtr toElement() const;
378
379private:
388 void remakeKey();
389
394 std::string name_;
395
397 std::string algorithm_;
398
400 std::string secret_;
401
403 std::string secret_file_;
404
407 uint32_t digestbits_;
408
410 D2TsigKeyPtr tsig_key_;
411};
412
414typedef boost::shared_ptr<TSIGKeyInfo> TSIGKeyInfoPtr;
415
417typedef std::map<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMap;
418
420typedef std::pair<std::string, TSIGKeyInfoPtr> TSIGKeyInfoMapPair;
421
423typedef boost::shared_ptr<TSIGKeyInfoMap> TSIGKeyInfoMapPtr;
424
425
432public:
434 static const uint32_t STANDARD_DNS_PORT = 53;
435
452 DnsServerInfo(const std::string& hostname,
453 isc::asiolink::IOAddress ip_address,
454 uint32_t port = STANDARD_DNS_PORT,
455 bool enabled = true,
456 const TSIGKeyInfoPtr& tsig_key_info = TSIGKeyInfoPtr(),
457 bool inherited_key = true);
458
460 virtual ~DnsServerInfo();
461
465 const std::string getHostname() const {
466 return (hostname_);
467 }
468
472 uint32_t getPort() const {
473 return (port_);
474 }
475
480 return (ip_address_);
481 }
482
487 bool isEnabled() const {
488 return (enabled_);
489 }
490
492 void enable() {
493 enabled_ = true;
494 }
495
497 void disable() {
498 enabled_ = false;
499 }
500
505 const std::string getKeyName() const;
506
512 return (tsig_key_info_);
513 }
514
516 std::string toText() const;
517
521 virtual isc::data::ElementPtr toElement() const;
522
523private:
526 std::string hostname_;
527
530 isc::asiolink::IOAddress ip_address_;
531
533 uint32_t port_;
534
537 bool enabled_;
538
541 TSIGKeyInfoPtr tsig_key_info_;
542
545 bool inherited_key_;
546};
547
548std::ostream&
549operator<<(std::ostream& os, const DnsServerInfo& server);
550
552typedef boost::shared_ptr<DnsServerInfo> DnsServerInfoPtr;
553
555typedef std::vector<DnsServerInfoPtr> DnsServerInfoStorage;
556
558typedef boost::shared_ptr<DnsServerInfoStorage> DnsServerInfoStoragePtr;
559
560
569public:
575 DdnsDomain(const std::string& name, DnsServerInfoStoragePtr servers,
576 const std::string& key_name = "");
577
579 virtual ~DdnsDomain();
580
584 const std::string getName() const {
585 return (name_);
586 }
587
594 const std::string getKeyName() const {
595 return (key_name_);
596 }
597
602 return (servers_);
603 }
604
608 virtual isc::data::ElementPtr toElement() const;
609
610private:
612 std::string name_;
613
616
618 std::string key_name_;
619};
620
622typedef boost::shared_ptr<DdnsDomain> DdnsDomainPtr;
623
625typedef std::map<std::string, DdnsDomainPtr> DdnsDomainMap;
626
628typedef std::pair<std::string, DdnsDomainPtr> DdnsDomainMapPair;
629
631typedef boost::shared_ptr<DdnsDomainMap> DdnsDomainMapPtr;
632
645public:
647 static const char* wildcard_domain_name_;
648
652 DdnsDomainListMgr(const std::string& name);
653
655 virtual ~DdnsDomainListMgr ();
656
675 virtual bool matchDomain(const std::string& fqdn, DdnsDomainPtr& domain);
676
680 const std::string getName() const {
681 return (name_);
682 }
683
687 uint32_t size() const {
688 return (domains_->size());
689 }
690
696 return (wildcard_domain_);
697 }
698
703 return (domains_);
704 }
705
709 void setDomains(DdnsDomainMapPtr domains);
710
714 virtual isc::data::ElementPtr toElement() const;
715
716private:
718 std::string name_;
719
721 DdnsDomainMapPtr domains_;
722
724 DdnsDomainPtr wildcard_domain_;
725};
726
728typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;
729
741public:
742
745 };
746
748 virtual ~DScalarContext() {
749 }
750
755 return (process::ConfigPtr(new DScalarContext(*this)));
756 }
757
762 isc_throw(isc::NotImplemented, "DScalarContext::ElementPtr");
763 }
764
765protected:
767 DScalarContext(const DScalarContext& rhs) : ConfigBase(rhs) {
768 }
769
770private:
772 DScalarContext& operator=(const DScalarContext& rhs);
773};
774
776typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
777
783public:
793
794};
795
801public:
815};
816
822public:
840 data::ConstElementPtr domain_config,
841 const TSIGKeyInfoMapPtr keys);
842};
843
850public:
865 data::ConstElementPtr domain_config,
866 const TSIGKeyInfoMapPtr keys);
867};
868
874public:
885 const TSIGKeyInfoMapPtr keys);
886};
887
893public:
907 const TSIGKeyInfoMapPtr keys);
908};
909
916public:
929 const std::string& mgr_name,
930 const TSIGKeyInfoMapPtr keys);
931};
932
933} // end of isc::d2 namespace
934} // end of isc namespace
935
936#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:134
D2CfgError(const char *file, size_t line, const char *what)
Definition d2_config.h:136
Acts as a storage vault for D2 global scalar parameters.
Definition d2_config.h:141
size_t getDnsServerTimeout() const
Return the DNS server timeout value.
Definition d2_config.h:182
D2Params()
Default constructor The default constructor creates an instance that has updates disabled.
Definition d2_config.cc:43
const isc::asiolink::IOAddress & getIpAddress() const
Return the IP address D2 listens on.
Definition d2_config.h:172
bool operator!=(const D2Params &other) const
Compares two D2Params's for inequality.
Definition d2_config.cc:95
const dhcp_ddns::NameChangeFormat & getNcrFormat() const
Return the expected format of inbound requests (NCRs).
Definition d2_config.h:192
size_t getPort() const
Return the TCP/UPD port D2 listens on.
Definition d2_config.h:177
bool operator==(const D2Params &other) const
Compares two D2Params's for equality.
Definition d2_config.cc:86
virtual ~D2Params()
Destructor.
Definition d2_config.cc:51
const dhcp_ddns::NameChangeProtocol & getNcrProtocol() const
Return the socket protocol in use.
Definition d2_config.h:187
std::string getConfigSummary() const
Return summary of the configuration used by D2.
Definition d2_config.cc:78
std::string toText() const
Generates a string representation of the class contents.
Definition d2_config.cc:100
virtual void validateContents()
Validates member values.
Definition d2_config.cc:54
Storage container for scalar configuration parameters.
Definition d2_config.h:740
DScalarContext()
Constructor.
Definition d2_config.h:744
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition d2_config.h:761
virtual process::ConfigPtr clone()
Creates a clone of a DStubContext.
Definition d2_config.h:754
virtual ~DScalarContext()
Destructor.
Definition d2_config.h:748
DScalarContext(const DScalarContext &rhs)
Copy constructor.
Definition d2_config.h:767
Parser for DdnsDomainListMgr.
Definition d2_config.h:915
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:667
Provides storage for and management of a list of DNS domains.
Definition d2_config.h:644
const std::string getName() const
Fetches the manager's name.
Definition d2_config.h:680
DdnsDomainListMgr(const std::string &name)
Constructor.
Definition d2_config.cc:298
const DdnsDomainMapPtr & getDomains()
Fetches the domain list.
Definition d2_config.h:702
const DdnsDomainPtr & getWildcardDomain()
Fetches the wild card domain.
Definition d2_config.h:695
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:325
void setDomains(DdnsDomainMapPtr domains)
Sets the manger's domain list to the given list of domains.
Definition d2_config.cc:307
static const char * wildcard_domain_name_
defines the domain name for denoting the wildcard domain.
Definition d2_config.h:647
virtual ~DdnsDomainListMgr()
Destructor.
Definition d2_config.cc:303
uint32_t size() const
Returns the number of domains in the domain list.
Definition d2_config.h:687
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition d2_config.cc:389
Parser for a list of DdnsDomains.
Definition d2_config.h:892
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:644
Parser for DdnsDomain.
Definition d2_config.h:873
DdnsDomainPtr parse(data::ConstElementPtr domain_config, const TSIGKeyInfoMapPtr keys)
Performs the actual parsing of the given "ddns-domain" element.
Definition d2_config.cc:608
Represents a DNS domain that is may be updated dynamically.
Definition d2_config.h:568
const std::string getKeyName() const
Getter which returns the domain's TSIG key name.
Definition d2_config.h:594
const std::string getName() const
Getter which returns the domain's name.
Definition d2_config.h:584
const DnsServerInfoStoragePtr & getServers()
Getter which returns the domain's list of servers.
Definition d2_config.h:601
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
Parser for a list of DnsServerInfos.
Definition d2_config.h:849
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:592
Parser for DnsServerInfo.
Definition d2_config.h:821
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:500
Represents a specific DNS Server.
Definition d2_config.h:431
bool isEnabled() const
Convenience method which returns whether or not the server is enabled.
Definition d2_config.h:487
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 TSIGKeyInfoPtr & getTSIGKeyInfo()
Getter which returns the server's TSIGKey info.
Definition d2_config.h:511
const std::string getHostname() const
Getter which returns the server's hostname.
Definition d2_config.h:465
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:472
void enable()
Sets the server's enabled flag to true.
Definition d2_config.h:492
static const uint32_t STANDARD_DNS_PORT
defines DNS standard port value
Definition d2_config.h:434
void disable()
Sets the server's enabled flag to false.
Definition d2_config.h:497
const isc::asiolink::IOAddress & getIpAddress() const
Getter which returns the server's ip_address.
Definition d2_config.h:479
virtual ~DnsServerInfo()
Destructor.
Definition d2_config.cc:214
Parser for a list of TSIGKeyInfos.
Definition d2_config.h:800
TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config)
Performs the parsing of the given list "tsig-key" elements.
Definition d2_config.cc:478
Parser for TSIGKeyInfo.
Definition d2_config.h:782
TSIGKeyInfoPtr parse(data::ConstElementPtr key_config)
Performs the actual parsing of the given "tsig-key" element.
Definition d2_config.cc:405
Represents a TSIG Key.
Definition d2_config.h:264
static const char * HMAC_SHA224_STR
Definition d2_config.h:271
TSIGKeyInfo(const std::string &name, const std::string &algorithm, const std::string &secret, std::string secret_file="", uint32_t digestbits=0)
Constructor.
Definition d2_config.cc:130
const std::string getAlgorithm() const
Getter which returns the key's algorithm string ID.
Definition d2_config.h:325
virtual ~TSIGKeyInfo()
Destructor.
Definition d2_config.cc:138
const D2TsigKeyPtr & getTSIGKey() const
Getter which returns the TSIG key used to sign and verify messages.
Definition d2_config.h:354
static const char * HMAC_MD5_STR
Defines string values for the supported TSIG algorithms.
Definition d2_config.h:268
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:181
static const char * HMAC_SHA1_STR
Definition d2_config.h:269
static const char * HMAC_SHA256_STR
Definition d2_config.h:270
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:142
static const char * HMAC_SHA512_STR
Definition d2_config.h:273
const std::string getSecret() const
Getter which returns the key's secret.
Definition d2_config.h:339
const std::string getSecretFile() const
Getter which returns the secret file name.
Definition d2_config.h:346
static const char * HMAC_SHA384_STR
Definition d2_config.h:272
The Name class encapsulates DNS names.
Definition name.h:219
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:622
boost::shared_ptr< DdnsDomainMap > DdnsDomainMapPtr
Defines a pointer to DdnsDomain storage containers.
Definition d2_config.h:631
std::pair< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMapPair
Defines a iterator pairing of name and TSIGKeyInfo.
Definition d2_config.h:420
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
Definition d2_config.h:552
std::map< std::string, DdnsDomainPtr > DdnsDomainMap
Defines a map of DdnsDomains, keyed by the domain name.
Definition d2_config.h:625
std::pair< std::string, DdnsDomainPtr > DdnsDomainMapPair
Defines a iterator pairing domain name and DdnsDomain.
Definition d2_config.h:628
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
Definition d2_config.h:414
std::vector< DnsServerInfoPtr > DnsServerInfoStorage
Defines a storage container for DnsServerInfo pointers.
Definition d2_config.h:555
std::map< std::string, TSIGKeyInfoPtr > TSIGKeyInfoMap
Defines a map of TSIGKeyInfos, keyed by the name.
Definition d2_config.h:417
boost::shared_ptr< DnsServerInfoStorage > DnsServerInfoStoragePtr
Defines a pointer to DnsServerInfo storage containers.
Definition d2_config.h:558
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
Definition d2_config.h:255
boost::shared_ptr< DScalarContext > DScalarContextPtr
Defines a pointer for DScalarContext instances.
Definition d2_config.h:776
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:423
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:59
NameChangeProtocol
Defines the list of socket protocols supported.
Definition ncr_io.h:69
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.