Kea 2.5.5
ha_config.h
Go to the documentation of this file.
1// Copyright (C) 2018-2023 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
11#include <asiolink/crypto_tls.h>
13#include <http/basic_auth.h>
15#include <http/url.h>
16#include <util/optional.h>
17#include <util/state_model.h>
18#include <boost/shared_ptr.hpp>
19#include <cstdint>
20#include <map>
21#include <string>
22
23namespace isc {
24namespace ha {
25
28public:
29 HAConfigValidationError(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) { };
31};
32
33class HAConfig;
34
36typedef boost::shared_ptr<HAConfig> HAConfigPtr;
37
40
42typedef boost::shared_ptr<HAConfigMapper> HAConfigMapperPtr;
43
45class HAConfig {
46public:
47
54 enum HAMode {
58 };
59
65 class PeerConfig {
66 public:
67
82 enum Role {
86 BACKUP
87 };
88
90 PeerConfig();
91
93 std::string getName() const {
94 return (name_);
95 }
96
101 void setName(const std::string& name);
102
105 return (url_);
106 }
107
111 void setUrl(const http::Url& url) {
112 url_ = url;
113 }
114
117 return (trust_anchor_);
118 }
119
124 trust_anchor_ = ca;
125 }
126
129 return (cert_file_);
130 }
131
136 cert_file_ = cert;
137 }
138
141 return (key_file_);
142 }
143
148 key_file_ = key;
149 }
150
153 return (tls_context_);
154 }
155
161 std::string getLogLabel() const;
162
164 Role getRole() const {
165 return (role_);
166 }
167
177 void setRole(const std::string& role);
178
184 static Role stringToRole(const std::string& role);
185
190 static std::string roleToString(const HAConfig::PeerConfig::Role& role);
191
196 bool isAutoFailover() const {
197 return (auto_failover_);
198 }
199
204 void setAutoFailover(const bool auto_failover) {
205 auto_failover_ = auto_failover;
206 }
207
210 return (basic_auth_);
211 }
212
215 return (basic_auth_);
216 }
217
221
227
228 private:
229
230 std::string name_;
231 http::Url url_;
232 util::Optional<std::string> trust_anchor_;
233 util::Optional<std::string> cert_file_;
235 Role role_;
236 bool auto_failover_;
237 http::BasicHttpAuthPtr basic_auth_;
238 };
239
241 typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
242
244 typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
245
248 public:
249
253 explicit StateConfig(const int state);
254
256 int getState() const {
257 return (state_);
258 }
259
262 return (pausing_);
263 }
264
269 void setPausing(const std::string& pausing);
270
275 static util::StatePausing stringToPausing(const std::string& pausing);
276
280 static std::string pausingToString(const util::StatePausing& pausing);
281
282 private:
283
285 int state_;
286
288 util::StatePausing pausing_;
289 };
290
292 typedef boost::shared_ptr<StateConfig> StateConfigPtr;
293
300 public:
301
304 : states_() {
305 }
306
315 StateConfigPtr getStateConfig(const int state);
316
317 private:
318
320 std::map<int, StateConfigPtr> states_;
321 };
322
324 typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
325
327 HAConfig();
328
330 static HAConfigPtr create();
331
342 PeerConfigPtr selectNextPeerConfig(const std::string& name);
343
345 std::string getThisServerName() const {
346 return (this_server_name_);
347 }
348
353 void setThisServerName(const std::string& this_server_name);
354
357 return (ha_mode_);
358 }
359
368 void setHAMode(const std::string& ha_mode);
369
375 static HAMode stringToHAMode(const std::string& ha_mode);
376
381 static std::string HAModeToString(const HAMode& ha_mode);
382
386 return (send_lease_updates_);
387 }
388
398 void setSendLeaseUpdates(const bool send_lease_updates) {
399 send_lease_updates_ = send_lease_updates;
400 }
401
404 bool amSyncingLeases() const {
405 return (sync_leases_);
406 }
407
417 void setSyncLeases(const bool sync_leases) {
418 sync_leases_ = sync_leases;
419 }
420
424 uint32_t getSyncTimeout() const {
425 return (sync_timeout_);
426 }
427
431 void setSyncTimeout(const uint32_t sync_timeout) {
432 sync_timeout_ = sync_timeout;
433 }
434
439 uint32_t getSyncPageLimit() const {
440 return (sync_page_limit_);
441 }
442
447 void setSyncPageLimit(const uint32_t sync_page_limit) {
448 sync_page_limit_ = sync_page_limit;
449 }
450
463 uint32_t getDelayedUpdatesLimit() const {
464 return (delayed_updates_limit_);
465 }
466
479 void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
480 delayed_updates_limit_ = delayed_updates_limit;
481 }
482
491 return (delayed_updates_limit_ > 0);
492 }
493
501 uint32_t getHeartbeatDelay() const {
502 return (heartbeat_delay_);
503 }
504
512 void setHeartbeatDelay(const uint32_t heartbeat_delay) {
513 heartbeat_delay_ = heartbeat_delay;
514 }
515
521 uint32_t getMaxResponseDelay() const {
522 return (max_response_delay_);
523 }
524
532 void setMaxResponseDelay(const uint32_t max_response_delay) {
533 max_response_delay_ = max_response_delay;
534 }
535
540 uint32_t getMaxAckDelay() const {
541 return (max_ack_delay_);
542 }
543
548 void setMaxAckDelay(const uint32_t max_ack_delay) {
549 max_ack_delay_ = max_ack_delay;
550 }
551
556 uint32_t getMaxUnackedClients() const {
557 return (max_unacked_clients_);
558 }
559
564 void setMaxUnackedClients(const uint32_t max_unacked_clients) {
565 max_unacked_clients_ = max_unacked_clients;
566 }
567
583 uint32_t getMaxRejectedLeaseUpdates() const {
585 }
586
597 void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates) {
598 max_rejected_lease_updates_ = max_rejected_lease_updates;
599 }
600
607 void setWaitBackupAck(const bool wait_backup_ack) {
608 wait_backup_ack_ = wait_backup_ack;
609 }
610
616 bool amWaitingBackupAck() const {
617 return (wait_backup_ack_);
618 }
619
625 }
626
631 void setEnableMultiThreading(bool enable_multi_threading) {
632 enable_multi_threading_ = enable_multi_threading;
633 }
634
644 }
645
651 void setHttpDedicatedListener(bool http_dedicated_listener) {
652 http_dedicated_listener_ = http_dedicated_listener;
653 }
654
659 return (http_listener_threads_);
660 }
661
665 void setHttpListenerThreads(uint32_t http_listener_threads) {
666 http_listener_threads_ = http_listener_threads;
667 }
668
673 return (http_client_threads_);
674 }
675
679 void setHttpClientThreads(uint32_t http_client_threads) {
680 http_client_threads_ = http_client_threads;
681 }
682
685 return (trust_anchor_);
686 }
687
692 trust_anchor_ = ca;
693 }
694
697 return (cert_file_);
698 }
699
704 cert_file_ = cert;
705 }
706
709 return (key_file_);
710 }
711
716 key_file_ = key;
717 }
718
721 return (require_client_certs_);
722 }
723
727 void setRequireClientCerts(bool flag) {
729 }
730
732 bool getRestrictCommands() const {
733 return (restrict_commands_);
734 }
735
739 void setRestrictCommands(bool flag) {
740 restrict_commands_ = flag;
741 }
742
749 PeerConfigPtr getPeerConfig(const std::string& name) const;
750
762
767
775
780 return (peers_);
781 }
782
787 return (state_machine_);
788 }
789
804 void validate();
805
806 std::string this_server_name_;
810 uint32_t sync_timeout_;
817 uint32_t max_ack_delay_;
832};
833
834} // end of namespace isc::ha
835} // end of namespace isc
836
837#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:27
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition: ha_config.h:29
HA peer configuration.
Definition: ha_config.h:65
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:164
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition: ha_config.h:116
void setKeyFile(const util::Optional< std::string > &key)
Sets server's key-file.
Definition: ha_config.h:147
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition: ha_config.h:204
void setUrl(const http::Url &url)
Sets server's URL.
Definition: ha_config.h:111
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:196
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition: ha_config.h:140
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition: ha_config.h:226
Role
Server's role in the High Availability setup.
Definition: ha_config.h:82
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:214
std::string getName() const
Returns server name.
Definition: ha_config.h:93
asiolink::TlsContextPtr getTlsContext() const
Returns a pointer to the server's TLS context.
Definition: ha_config.h:152
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:128
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition: ha_config.h:209
http::Url getUrl() const
Returns URL of the server's control channel.
Definition: ha_config.h:104
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets server's trust-anchor.
Definition: ha_config.h:123
void setCertFile(const util::Optional< std::string > &cert)
Sets server's cert-file.
Definition: ha_config.h:135
Configuration specific to a single HA state.
Definition: ha_config.h:247
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition: ha_config.h:261
int getState() const
Returns identifier of the state.
Definition: ha_config.h:256
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:299
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:45
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition: ha_config.h:816
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition: ha_config.h:823
static HAConfigPtr create()
Instantiates a HAConfig.
Definition: ha_config.cc:175
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:811
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:356
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition: ha_config.h:708
std::string getThisServerName() const
Returns name of this server.
Definition: ha_config.h:345
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:607
bool require_client_certs_
Require client certs flag.
Definition: ha_config.h:828
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:463
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition: ha_config.h:822
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition: ha_config.h:665
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition: ha_config.h:715
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:779
HAMode
Mode of operation.
Definition: ha_config.h:54
void validate()
Validates configuration.
Definition: ha_config.cc:280
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition: ha_config.h:651
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition: ha_config.h:813
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition: ha_config.h:501
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition: ha_config.cc:268
bool getRequireClientCerts() const
Returns require-client-certs.
Definition: ha_config.h:720
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:447
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
Definition: ha_config.h:819
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:244
void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates)
Sets the maximum number of clients for whom the lease updates can fail due to other than general erro...
Definition: ha_config.h:597
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:564
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition: ha_config.h:691
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition: ha_config.h:324
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition: ha_config.cc:210
HAMode ha_mode_
Mode of operation.
Definition: ha_config.h:807
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:808
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition: ha_config.h:556
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition: ha_config.h:658
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:385
void setRequireClientCerts(bool flag)
Sets require-client-certs.
Definition: ha_config.h:727
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition: ha_config.h:532
bool getRestrictCommands() const
Returns restrict-commands.
Definition: ha_config.h:732
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition: ha_config.h:679
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition: ha_config.h:417
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition: ha_config.h:818
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:548
PeerConfigMap peers_
Map of peers' configurations.
Definition: ha_config.h:830
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition: ha_config.h:490
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition: ha_config.h:817
util::Optional< std::string > cert_file_
Certificate file.
Definition: ha_config.h:826
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition: ha_config.h:424
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition: ha_config.h:404
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:616
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition: ha_config.h:512
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition: ha_config.h:521
bool restrict_commands_
Restrict commands to HA flag.
Definition: ha_config.h:829
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition: ha_config.cc:198
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition: ha_config.cc:273
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:398
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition: ha_config.h:431
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition: ha_config.cc:255
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:245
util::Optional< std::string > key_file_
Private key file.
Definition: ha_config.h:827
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition: ha_config.h:696
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition: ha_config.cc:180
void setRestrictCommands(bool flag)
Sets restrict-commands.
Definition: ha_config.h:739
uint32_t getMaxRejectedLeaseUpdates() const
Returns a maximum number of clients for whom lease updates failed due to other than general error.
Definition: ha_config.h:583
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:809
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition: ha_config.h:820
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition: ha_config.h:540
StateMachineConfigPtr state_machine_
State machine configuration.
Definition: ha_config.h:831
HAConfig()
Constructor.
Definition: ha_config.cc:162
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition: ha_config.h:825
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition: ha_config.cc:215
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition: ha_config.h:703
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:479
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition: ha_config.h:786
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition: ha_config.h:672
uint32_t http_client_threads_
Number of HTTP client threads.
Definition: ha_config.h:824
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition: ha_config.h:684
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:810
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:292
bool enable_multi_threading_
Enable multi-threading.
Definition: ha_config.h:821
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:815
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition: ha_config.h:439
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition: ha_config.cc:230
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition: ha_config.h:623
std::string this_server_name_
This server name.
Definition: ha_config.h:806
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition: ha_config.h:631
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition: ha_config.h:642
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition: ha_config.h:241
Holds associations between objects and HA relationships.
Represents an URL.
Definition: url.h:20
TLS API.
boost::shared_ptr< HAConfigMapper > HAConfigMapperPtr
Pointer to an object mapping HAConfig to relationships.
Definition: ha_config.h:42
HARelationshipMapper< HAConfig > HAConfigMapper
Type of an object mapping HAConfig to relationships.
Definition: ha_config.h:39
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:36
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.