Kea 3.3.3
ha_config.h
Go to the documentation of this file.
1// Copyright (C) 2018-2026 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>
11#include <dhcpsrv/subnet.h>
16#include <http/url.h>
17#include <util/optional.h>
18#include <util/state_model.h>
19
20#include <cstdint>
21#include <map>
22#include <string>
23
24#include <boost/shared_ptr.hpp>
25
26namespace isc {
27namespace ha {
28
31public:
32 HAConfigValidationError(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { }
34};
35
36class HAConfig;
37
39typedef boost::shared_ptr<HAConfig> HAConfigPtr;
40
43
45typedef boost::shared_ptr<HAConfigMapper> HAConfigMapperPtr;
46
48class HAConfig {
49public:
50
62
68 class PeerConfig {
69 public:
70
85 enum Role : uint16_t {
90 };
91
93 PeerConfig();
94
96 std::string getName() const {
97 return (name_);
98 }
99
104 void setName(const std::string& name);
105
108 return (url_);
109 }
110
114 void setUrl(const http::Url& url) {
115 url_ = url;
116 }
117
120 return (trust_anchor_);
121 }
122
127 trust_anchor_ = ca;
128 }
129
132 return (cert_file_);
133 }
134
139 cert_file_ = cert;
140 }
141
144 return (key_file_);
145 }
146
151 key_file_ = key;
152 }
153
158
164 std::string getLogLabel() const;
165
167 Role getRole() const {
168 return (role_);
169 }
170
180 void setRole(const std::string& role);
181
187 static Role stringToRole(const std::string& role);
188
193 static std::string roleToString(const HAConfig::PeerConfig::Role& role);
194
199 bool isAutoFailover() const {
200 return (auto_failover_);
201 }
202
207 void setAutoFailover(const bool auto_failover) {
208 auto_failover_ = auto_failover;
209 }
210
213 return (basic_auth_);
214 }
215
218 return (basic_auth_);
219 }
220
224
227 return (basic_auth_config_);
228 }
229
232 return (basic_auth_config_);
233 }
234
240
241 private:
242
243 std::string name_;
244 http::Url url_;
245 util::Optional<std::string> trust_anchor_;
246 util::Optional<std::string> cert_file_;
248 Role role_;
249 bool auto_failover_;
250 http::BasicHttpAuthPtr basic_auth_;
251 http::BasicHttpAuthConfigPtr basic_auth_config_;
252 };
253
255 typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
256
258 typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
259
262 public:
263
267 explicit StateConfig(const int state);
268
270 int getState() const {
271 return (state_);
272 }
273
276 return (pausing_);
277 }
278
283 void setPausing(const std::string& pausing);
284
289 static util::StatePausing stringToPausing(const std::string& pausing);
290
294 static std::string pausingToString(const util::StatePausing& pausing);
295
296 private:
297
299 int state_;
300
302 util::StatePausing pausing_;
303 };
304
306 typedef boost::shared_ptr<StateConfig> StateConfigPtr;
307
314 public:
315
318 : states_() {
319 }
320
329 StateConfigPtr getStateConfig(const int state);
330
331 private:
332
334 std::map<int, StateConfigPtr> states_;
335 };
336
338 typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
339
341 HAConfig();
342
344 static HAConfigPtr create();
345
356 PeerConfigPtr selectNextPeerConfig(const std::string& name);
357
359 std::string getThisServerName() const {
360 return (this_server_name_);
361 }
362
367 void setThisServerName(const std::string& this_server_name);
368
371 return (ha_mode_);
372 }
373
382 void setHAMode(const std::string& ha_mode);
383
389 static HAMode stringToHAMode(const std::string& ha_mode);
390
395 static std::string HAModeToString(const HAMode& ha_mode);
396
400 return (send_lease_updates_);
401 }
402
412 void setSendLeaseUpdates(const bool send_lease_updates) {
413 send_lease_updates_ = send_lease_updates;
414 }
415
418 bool amSyncingLeases() const {
419 return (sync_leases_);
420 }
421
431 void setSyncLeases(const bool sync_leases) {
432 sync_leases_ = sync_leases;
433 }
434
438 uint32_t getSyncTimeout() const {
439 return (sync_timeout_);
440 }
441
445 void setSyncTimeout(const uint32_t sync_timeout) {
446 sync_timeout_ = sync_timeout;
447 }
448
453 uint32_t getSyncPageLimit() const {
454 return (sync_page_limit_);
455 }
456
461 void setSyncPageLimit(const uint32_t sync_page_limit) {
462 sync_page_limit_ = sync_page_limit;
463 }
464
477 uint32_t getDelayedUpdatesLimit() const {
478 return (delayed_updates_limit_);
479 }
480
493 void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
494 delayed_updates_limit_ = delayed_updates_limit;
495 }
496
505 return (delayed_updates_limit_ > 0);
506 }
507
515 uint32_t getHeartbeatDelay() const {
516 return (heartbeat_delay_);
517 }
518
526 void setHeartbeatDelay(const uint32_t heartbeat_delay) {
527 heartbeat_delay_ = heartbeat_delay;
528 }
529
535 uint32_t getMaxResponseDelay() const {
536 return (max_response_delay_);
537 }
538
546 void setMaxResponseDelay(const uint32_t max_response_delay) {
547 max_response_delay_ = max_response_delay;
548 }
549
554 uint32_t getMaxAckDelay() const {
555 return (max_ack_delay_);
556 }
557
562 void setMaxAckDelay(const uint32_t max_ack_delay) {
563 max_ack_delay_ = max_ack_delay;
564 }
565
570 uint32_t getMaxUnackedClients() const {
571 return (max_unacked_clients_);
572 }
573
578 void setMaxUnackedClients(const uint32_t max_unacked_clients) {
579 max_unacked_clients_ = max_unacked_clients;
580 }
581
597 uint32_t getMaxRejectedLeaseUpdates() const {
599 }
600
611 void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates) {
612 max_rejected_lease_updates_ = max_rejected_lease_updates;
613 }
614
621 void setWaitBackupAck(const bool wait_backup_ack) {
622 wait_backup_ack_ = wait_backup_ack;
623 }
624
630 bool amWaitingBackupAck() const {
631 return (wait_backup_ack_);
632 }
633
640
645 void setEnableMultiThreading(bool enable_multi_threading) {
646 enable_multi_threading_ = enable_multi_threading;
647 }
648
659
665 void setHttpDedicatedListener(bool http_dedicated_listener) {
666 http_dedicated_listener_ = http_dedicated_listener;
667 }
668
673 return (http_listener_threads_);
674 }
675
679 void setHttpListenerThreads(uint32_t http_listener_threads) {
680 http_listener_threads_ = http_listener_threads;
681 }
682
687 return (http_client_threads_);
688 }
689
693 void setHttpClientThreads(uint32_t http_client_threads) {
694 http_client_threads_ = http_client_threads;
695 }
696
701
708
713
718 cert_file_ = cert;
719 }
720
723 return (key_file_);
724 }
725
730 key_file_ = key;
731 }
732
735 return (require_client_certs_);
736 }
737
741 void setRequireClientCerts(bool flag) {
743 }
744
746 bool getRestrictCommands() const {
747 return (restrict_commands_);
748 }
749
753 void setRestrictCommands(bool flag) {
754 restrict_commands_ = flag;
755 }
756
763 PeerConfigPtr getPeerConfig(const std::string& name) const;
764
776
781
789
794 return (peers_);
795 }
796
803
818 void validate();
819
830 static std::string getSubnetServerName(const dhcp::ConstSubnetPtr& subnet);
831
832 std::string this_server_name_;
836 uint32_t sync_timeout_;
843 uint32_t max_ack_delay_;
858};
859
860} // end of namespace isc::ha
861} // end of namespace isc
862
863#endif
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition ha_config.h:32
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition ha_config.cc:58
const http::BasicHttpAuthConfigPtr & getBasicAuthConfig() const
Returns const basic HTTP authentication configuration.
Definition ha_config.h:231
Role getRole() const
Returns server's role.
Definition ha_config.h:167
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition ha_config.h:119
void setKeyFile(const util::Optional< std::string > &key)
Sets server's key-file.
Definition ha_config.h:150
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition ha_config.h:207
void setUrl(const http::Url &url)
Sets server's URL.
Definition ha_config.h:114
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
Definition ha_config.cc:102
bool isAutoFailover() const
Checks if the auto-failover function is enabled for the server.
Definition ha_config.h:199
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition ha_config.h:143
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition ha_config.h:239
void setRole(const std::string &role)
Sets servers role.
Definition ha_config.cc:53
const http::BasicHttpAuthPtr & getBasicAuth() const
Returns const basic HTTP authentication.
Definition ha_config.h:217
std::string getName() const
Returns server name.
Definition ha_config.h:96
http::BasicHttpAuthConfigPtr & getBasicAuthConfig()
Returns non-const basic HTTP authentication configuration.
Definition ha_config.h:226
asiolink::TlsContextPtr getTlsContext() const
Returns a pointer to the server's TLS context.
Definition ha_config.h:155
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Definition ha_config.cc:85
Role
Server's role in the High Availability setup.
Definition ha_config.h:85
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition ha_config.cc:65
void setName(const std::string &name)
Sets server name.
Definition ha_config.cc:42
util::Optional< std::string > getCertFile() const
Returns server's cert-file.
Definition ha_config.h:131
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition ha_config.h:212
http::Url getUrl() const
Returns URL of the server's control channel.
Definition ha_config.h:107
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets server's trust-anchor.
Definition ha_config.h:126
void setCertFile(const util::Optional< std::string > &cert)
Sets server's cert-file.
Definition ha_config.h:138
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition ha_config.h:275
int getState() const
Returns identifier of the state.
Definition ha_config.h:270
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
Definition ha_config.cc:120
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
Definition ha_config.cc:115
StateConfig(const int state)
Constructor.
Definition ha_config.cc:110
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition ha_config.cc:135
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition ha_config.cc:154
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition ha_config.h:842
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition ha_config.h:849
static HAConfigPtr create()
Instantiates a HAConfig.
Definition ha_config.cc:181
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition ha_config.h:837
HAMode getHAMode() const
Returns mode of operation.
Definition ha_config.h:370
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition ha_config.h:722
std::string getThisServerName() const
Returns name of this server.
Definition ha_config.h:359
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:621
bool require_client_certs_
Require client certs flag.
Definition ha_config.h:854
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:477
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition ha_config.h:848
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition ha_config.h:679
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition ha_config.h:729
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition ha_config.h:793
void validate()
Validates configuration.
Definition ha_config.cc:286
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition ha_config.h:665
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition ha_config.h:839
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition ha_config.h:515
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition ha_config.cc:274
bool getRequireClientCerts() const
Returns require-client-certs.
Definition ha_config.h:734
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:461
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
Definition ha_config.h:845
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition ha_config.h:258
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:611
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:578
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition ha_config.h:705
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition ha_config.h:338
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition ha_config.cc:216
HAMode ha_mode_
Mode of operation.
Definition ha_config.h:833
bool send_lease_updates_
Send lease updates to partner?
Definition ha_config.h:834
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition ha_config.h:570
HAMode
Mode of operation.
Definition ha_config.h:57
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition ha_config.h:672
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition ha_config.h:399
void setRequireClientCerts(bool flag)
Sets require-client-certs.
Definition ha_config.h:741
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition ha_config.h:546
bool getRestrictCommands() const
Returns restrict-commands.
Definition ha_config.h:746
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition ha_config.h:693
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition ha_config.h:431
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition ha_config.h:844
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:562
PeerConfigMap peers_
Map of peers' configurations.
Definition ha_config.h:856
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition ha_config.h:504
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition ha_config.h:843
util::Optional< std::string > cert_file_
Certificate file.
Definition ha_config.h:852
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition ha_config.h:438
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition ha_config.h:418
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:630
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition ha_config.h:526
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition ha_config.h:535
bool restrict_commands_
Restrict commands to HA flag.
Definition ha_config.h:855
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition ha_config.cc:204
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition ha_config.cc:279
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition ha_config.h:412
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition ha_config.h:445
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition ha_config.cc:261
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition ha_config.cc:251
util::Optional< std::string > key_file_
Private key file.
Definition ha_config.h:853
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition ha_config.h:710
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition ha_config.cc:186
void setRestrictCommands(bool flag)
Sets restrict-commands.
Definition ha_config.h:753
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:597
bool sync_leases_
Synchronize databases on startup?
Definition ha_config.h:835
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition ha_config.h:846
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition ha_config.h:554
StateMachineConfigPtr state_machine_
State machine configuration.
Definition ha_config.h:857
HAConfig()
Constructor.
Definition ha_config.cc:168
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition ha_config.h:851
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition ha_config.cc:221
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition ha_config.h:717
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:493
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition ha_config.h:800
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition ha_config.h:686
uint32_t http_client_threads_
Number of HTTP client threads.
Definition ha_config.h:850
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition ha_config.h:698
uint32_t sync_timeout_
Timeout for syncing lease database (ms).
Definition ha_config.h:836
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition ha_config.h:306
bool enable_multi_threading_
Enable multi-threading.
Definition ha_config.h:847
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition ha_config.h:841
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition ha_config.h:453
static std::string getSubnetServerName(const dhcp::ConstSubnetPtr &subnet)
Convenience function extracting a value of the ha-server-name parameter from a subnet context.
Definition ha_config.cc:527
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition ha_config.cc:236
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition ha_config.h:637
std::string this_server_name_
This server name.
Definition ha_config.h:832
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition ha_config.h:645
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition ha_config.h:656
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition ha_config.h:255
Holds associations between objects and HA relationships.
Represents an URL.
Definition url.h:22
A template representing an optional value.
Definition optional.h:37
TLS API.
boost::shared_ptr< const Subnet > ConstSubnetPtr
A generic pointer to either const Subnet4 or const Subnet6 object.
Definition subnet.h:449
boost::shared_ptr< HAConfigMapper > HAConfigMapperPtr
Pointer to an object mapping HAConfig to relationships.
Definition ha_config.h:45
HARelationshipMapper< HAConfig > HAConfigMapper
Type of an object mapping HAConfig to relationships.
Definition ha_config.h:42
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition ha_config.h:39
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.
boost::shared_ptr< BasicHttpAuthConfig > BasicHttpAuthConfigPtr
Type of shared pointers to basic HTTP authentication configuration.
StatePausing
State machine pausing modes.
Definition state_model.h:48
Defines the logger used by the top-level component of kea-lfc.
This file defines the class StateModel.