Kea 2.2.0
ha_config.h
Go to the documentation of this file.
1// Copyright (C) 2018-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 HA_CONFIG_H
8#define HA_CONFIG_H
9
10#include <asiolink/crypto_tls.h>
12#include <http/basic_auth.h>
14#include <http/url.h>
15#include <util/optional.h>
16#include <util/state_model.h>
17#include <boost/shared_ptr.hpp>
18#include <cstdint>
19#include <map>
20#include <string>
21
22namespace isc {
23namespace ha {
24
27public:
28 HAConfigValidationError(const char* file, size_t line, const char* what) :
29 isc::Exception(file, line, what) { };
30};
31
33class HAConfig {
34public:
35
42 enum HAMode {
46 };
47
53 class PeerConfig {
54 public:
55
70 enum Role {
74 BACKUP
75 };
76
78 PeerConfig();
79
81 std::string getName() const {
82 return (name_);
83 }
84
89 void setName(const std::string& name);
90
92 http::Url getUrl() const {
93 return (url_);
94 }
95
99 void setUrl(const http::Url& url) {
100 url_ = url;
101 }
102
105 return (trust_anchor_);
106 }
107
112 trust_anchor_ = ca;
113 }
114
117 return (cert_file_);
118 }
119
124 cert_file_ = cert;
125 }
126
129 return (key_file_);
130 }
131
136 key_file_ = key;
137 }
138
141 return (tls_context_);
142 }
143
149 std::string getLogLabel() const;
150
152 Role getRole() const {
153 return (role_);
154 }
155
165 void setRole(const std::string& role);
166
172 static Role stringToRole(const std::string& role);
173
178 static std::string roleToString(const HAConfig::PeerConfig::Role& role);
179
184 bool isAutoFailover() const {
185 return (auto_failover_);
186 }
187
192 void setAutoFailover(const bool auto_failover) {
193 auto_failover_ = auto_failover;
194 }
195
198 return (basic_auth_);
199 }
200
203 return (basic_auth_);
204 }
205
209
215
216 private:
217
218 std::string name_;
219 http::Url url_;
220 util::Optional<std::string> trust_anchor_;
221 util::Optional<std::string> cert_file_;
223 Role role_;
224 bool auto_failover_;
225 http::BasicHttpAuthPtr basic_auth_;
226 };
227
229 typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
230
232 typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
233
236 public:
237
241 explicit StateConfig(const int state);
242
244 int getState() const {
245 return (state_);
246 }
247
250 return (pausing_);
251 }
252
257 void setPausing(const std::string& pausing);
258
263 static util::StatePausing stringToPausing(const std::string& pausing);
264
268 static std::string pausingToString(const util::StatePausing& pausing);
269
270 private:
271
273 int state_;
274
276 util::StatePausing pausing_;
277 };
278
280 typedef boost::shared_ptr<StateConfig> StateConfigPtr;
281
288 public:
289
292 : states_() {
293 }
294
303 StateConfigPtr getStateConfig(const int state);
304
305 private:
306
308 std::map<int, StateConfigPtr> states_;
309 };
310
312 typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
313
315 HAConfig();
316
327 PeerConfigPtr selectNextPeerConfig(const std::string& name);
328
330 std::string getThisServerName() const {
331 return (this_server_name_);
332 }
333
338 void setThisServerName(const std::string& this_server_name);
339
342 return (ha_mode_);
343 }
344
353 void setHAMode(const std::string& ha_mode);
354
360 static HAMode stringToHAMode(const std::string& ha_mode);
361
366 static std::string HAModeToString(const HAMode& ha_mode);
367
371 return (send_lease_updates_);
372 }
373
383 void setSendLeaseUpdates(const bool send_lease_updates) {
384 send_lease_updates_ = send_lease_updates;
385 }
386
389 bool amSyncingLeases() const {
390 return (sync_leases_);
391 }
392
402 void setSyncLeases(const bool sync_leases) {
403 sync_leases_ = sync_leases;
404 }
405
409 uint32_t getSyncTimeout() const {
410 return (sync_timeout_);
411 }
412
416 void setSyncTimeout(const uint32_t sync_timeout) {
417 sync_timeout_ = sync_timeout;
418 }
419
424 uint32_t getSyncPageLimit() const {
425 return (sync_page_limit_);
426 }
427
432 void setSyncPageLimit(const uint32_t sync_page_limit) {
433 sync_page_limit_ = sync_page_limit;
434 }
435
448 uint32_t getDelayedUpdatesLimit() const {
449 return (delayed_updates_limit_);
450 }
451
464 void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
465 delayed_updates_limit_ = delayed_updates_limit;
466 }
467
476 return (delayed_updates_limit_ > 0);
477 }
478
486 uint32_t getHeartbeatDelay() const {
487 return (heartbeat_delay_);
488 }
489
497 void setHeartbeatDelay(const uint32_t heartbeat_delay) {
498 heartbeat_delay_ = heartbeat_delay;
499 }
500
506 uint32_t getMaxResponseDelay() const {
507 return (max_response_delay_);
508 }
509
517 void setMaxResponseDelay(const uint32_t max_response_delay) {
518 max_response_delay_ = max_response_delay;
519 }
520
525 uint32_t getMaxAckDelay() const {
526 return (max_ack_delay_);
527 }
528
533 void setMaxAckDelay(const uint32_t max_ack_delay) {
534 max_ack_delay_ = max_ack_delay;
535 }
536
541 uint32_t getMaxUnackedClients() const {
542 return (max_unacked_clients_);
543 }
544
549 void setMaxUnackedClients(const uint32_t max_unacked_clients) {
550 max_unacked_clients_ = max_unacked_clients;
551 }
552
559 void setWaitBackupAck(const bool wait_backup_ack) {
560 wait_backup_ack_ = wait_backup_ack;
561 }
562
568 bool amWaitingBackupAck() const {
569 return (wait_backup_ack_);
570 }
571
577 }
578
583 void setEnableMultiThreading(bool enable_multi_threading) {
584 enable_multi_threading_ = enable_multi_threading;
585 }
586
596 }
597
603 void setHttpDedicatedListener(bool http_dedicated_listener) {
604 http_dedicated_listener_ = http_dedicated_listener;
605 }
606
611 return (http_listener_threads_);
612 }
613
617 void setHttpListenerThreads(uint32_t http_listener_threads) {
618 http_listener_threads_ = http_listener_threads;
619 }
620
625 return (http_client_threads_);
626 }
627
631 void setHttpClientThreads(uint32_t http_client_threads) {
632 http_client_threads_ = http_client_threads;
633 }
634
637 return (trust_anchor_);
638 }
639
644 trust_anchor_ = ca;
645 }
646
649 return (cert_file_);
650 }
651
656 cert_file_ = cert;
657 }
658
661 return (key_file_);
662 }
663
668 key_file_ = key;
669 }
670
673 return (require_client_certs_);
674 }
675
679 void setRequireClientCerts(bool flag) {
681 }
682
684 bool getRestrictCommands() const {
685 return (restrict_commands_);
686 }
687
691 void setRestrictCommands(bool flag) {
692 restrict_commands_ = flag;
693 }
694
701 PeerConfigPtr getPeerConfig(const std::string& name) const;
702
714
719
727
732 return (peers_);
733 }
734
739 return (state_machine_);
740 }
741
756 void validate();
757
758 std::string this_server_name_;
762 uint32_t sync_timeout_;
769 uint32_t max_ack_delay_;
783};
784
786typedef boost::shared_ptr<HAConfig> HAConfigPtr;
787
788} // end of namespace isc::ha
789} // end of namespace isc
790
791#endif
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.
Exception thrown when configuration validation fails.
Definition: ha_config.h:26
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition: ha_config.h:28
HA peer configuration.
Definition: ha_config.h:53
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition: ha_config.cc:52
Role getRole() const
Returns server's role.
Definition: ha_config.h:152
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition: ha_config.h:104
void setKeyFile(const util::Optional< std::string > &key)
Sets server's key-file.
Definition: ha_config.h:135
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition: ha_config.h:192
void setUrl(const http::Url &url)
Sets server's URL.
Definition: ha_config.h:99
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
Definition: ha_config.cc:96
bool isAutoFailover() const
Checks if the auto-failover function is enabled for the server.
Definition: ha_config.h:184
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition: ha_config.h:128
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition: ha_config.h:214
Role
Server's role in the High Availability setup.
Definition: ha_config.h:70
void setRole(const std::string &role)
Sets servers role.
Definition: ha_config.cc:47
const http::BasicHttpAuthPtr & getBasicAuth() const
Returns const basic HTTP authentication.
Definition: ha_config.h:202
std::string getName() const
Returns server name.
Definition: ha_config.h:81
asiolink::TlsContextPtr getTlsContext() const
Returns a pointer to the server's TLS context.
Definition: ha_config.h:140
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Definition: ha_config.cc:79
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition: ha_config.cc:59
void setName(const std::string &name)
Sets server name.
Definition: ha_config.cc:36
util::Optional< std::string > getCertFile() const
Returns server's cert-file.
Definition: ha_config.h:116
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition: ha_config.h:197
http::Url getUrl() const
Returns URL of the server's control channel.
Definition: ha_config.h:92
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets server's trust-anchor.
Definition: ha_config.h:111
void setCertFile(const util::Optional< std::string > &cert)
Sets server's cert-file.
Definition: ha_config.h:123
Configuration specific to a single HA state.
Definition: ha_config.h:235
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition: ha_config.h:249
int getState() const
Returns identifier of the state.
Definition: ha_config.h:244
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
Definition: ha_config.cc:114
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
Definition: ha_config.cc:109
StateConfig(const int state)
Constructor.
Definition: ha_config.cc:104
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition: ha_config.cc:129
State machine configuration information.
Definition: ha_config.h:287
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition: ha_config.cc:148
Storage for High Availability configuration.
Definition: ha_config.h:33
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition: ha_config.h:768
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition: ha_config.h:774
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:763
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:341
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition: ha_config.h:660
std::string getThisServerName() const
Returns name of this server.
Definition: ha_config.h:330
void setWaitBackupAck(const bool wait_backup_ack)
Configures the server to wait/not wait for the lease update acknowledgments from the backup servers.
Definition: ha_config.h:559
bool require_client_certs_
Require client certs flag.
Definition: ha_config.h:779
uint32_t getDelayedUpdatesLimit() const
Returns the maximum number of lease updates which can be held unsent in the communication-recovery st...
Definition: ha_config.h:448
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition: ha_config.h:773
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition: ha_config.h:617
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition: ha_config.h:667
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:731
HAMode
Mode of operation.
Definition: ha_config.h:42
void validate()
Validates configuration.
Definition: ha_config.cc:275
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition: ha_config.h:603
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition: ha_config.h:765
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition: ha_config.h:486
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition: ha_config.cc:263
bool getRequireClientCerts() const
Returns require-client-certs.
Definition: ha_config.h:672
void setSyncPageLimit(const uint32_t sync_page_limit)
Sets new page limit size for leases fetched from the partner during database synchronization.
Definition: ha_config.h:432
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:232
void setMaxUnackedClients(const uint32_t max_unacked_clients)
Set maximum number of clients which may fail to communicate with the DHCP server before entering part...
Definition: ha_config.h:549
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition: ha_config.h:643
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition: ha_config.h:312
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition: ha_config.cc:205
HAMode ha_mode_
Mode of operation.
Definition: ha_config.h:759
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:760
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition: ha_config.h:541
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition: ha_config.h:610
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:370
void setRequireClientCerts(bool flag)
Sets require-client-certs.
Definition: ha_config.h:679
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition: ha_config.h:517
bool getRestrictCommands() const
Returns restrict-commands.
Definition: ha_config.h:684
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition: ha_config.h:631
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition: ha_config.h:402
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition: ha_config.h:770
void setMaxAckDelay(const uint32_t max_ack_delay)
Sets maximum time for a client trying to communicate with DHCP server to completed the transaction.
Definition: ha_config.h:533
PeerConfigMap peers_
Map of peers' configurations.
Definition: ha_config.h:781
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition: ha_config.h:475
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition: ha_config.h:769
util::Optional< std::string > cert_file_
Certificate file.
Definition: ha_config.h:777
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition: ha_config.h:409
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition: ha_config.h:389
bool amWaitingBackupAck() const
Checks if the server is configured to wait for the acknowledgments to the lease updates from the back...
Definition: ha_config.h:568
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition: ha_config.h:497
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition: ha_config.h:506
bool restrict_commands_
Restrict commands to HA flag.
Definition: ha_config.h:780
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition: ha_config.cc:193
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition: ha_config.cc:268
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:383
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition: ha_config.h:416
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition: ha_config.cc:250
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:240
util::Optional< std::string > key_file_
Private key file.
Definition: ha_config.h:778
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition: ha_config.h:648
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition: ha_config.cc:175
void setRestrictCommands(bool flag)
Sets restrict-commands.
Definition: ha_config.h:691
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:761
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition: ha_config.h:771
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition: ha_config.h:525
StateMachineConfigPtr state_machine_
State machine configuration.
Definition: ha_config.h:782
HAConfig()
Constructor.
Definition: ha_config.cc:162
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition: ha_config.h:776
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition: ha_config.cc:210
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition: ha_config.h:655
void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit)
Sets new limit for the number of lease updates to be held unsent in the communication-recovery state.
Definition: ha_config.h:464
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition: ha_config.h:738
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition: ha_config.h:624
uint32_t http_client_threads_
Number of HTTP client threads.
Definition: ha_config.h:775
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition: ha_config.h:636
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:762
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:280
bool enable_multi_threading_
Enable multi-threading.
Definition: ha_config.h:772
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:767
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition: ha_config.h:424
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition: ha_config.cc:225
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition: ha_config.h:575
std::string this_server_name_
This server name.
Definition: ha_config.h:758
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition: ha_config.h:583
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition: ha_config.h:594
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition: ha_config.h:229
Represents an URL.
Definition: url.h:20
TLS API.
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:786
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
Definition: basic_auth.h:70
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
StatePausing
State machine pausing modes.
Definition: state_model.h:45
Defines the logger used by the top-level component of kea-lfc.
This file defines the class StateModel.