Kea 3.3.1
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
11#include <asiolink/crypto_tls.h>
12#include <dhcpsrv/subnet.h>
16#include <http/url.h>
17#include <util/optional.h>
18#include <util/state_model.h>
19#include <boost/shared_ptr.hpp>
20#include <cstdint>
21#include <map>
22#include <string>
23
24namespace isc {
25namespace ha {
26
29public:
30 HAConfigValidationError(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) { }
32};
33
34class HAConfig;
35
37typedef boost::shared_ptr<HAConfig> HAConfigPtr;
38
41
43typedef boost::shared_ptr<HAConfigMapper> HAConfigMapperPtr;
44
46class HAConfig {
47public:
48
60
66 class PeerConfig {
67 public:
68
89
91 PeerConfig();
92
94 std::string getName() const {
95 return (name_);
96 }
97
102 void setName(const std::string& name);
103
106 return (url_);
107 }
108
112 void setUrl(const http::Url& url) {
113 url_ = url;
114 }
115
118 return (trust_anchor_);
119 }
120
125 trust_anchor_ = ca;
126 }
127
130 return (cert_file_);
131 }
132
137 cert_file_ = cert;
138 }
139
142 return (key_file_);
143 }
144
149 key_file_ = key;
150 }
151
156
162 std::string getLogLabel() const;
163
165 Role getRole() const {
166 return (role_);
167 }
168
178 void setRole(const std::string& role);
179
185 static Role stringToRole(const std::string& role);
186
191 static std::string roleToString(const HAConfig::PeerConfig::Role& role);
192
197 bool isAutoFailover() const {
198 return (auto_failover_);
199 }
200
205 void setAutoFailover(const bool auto_failover) {
206 auto_failover_ = auto_failover;
207 }
208
211 return (basic_auth_);
212 }
213
216 return (basic_auth_);
217 }
218
222
225 return (basic_auth_config_);
226 }
227
230 return (basic_auth_config_);
231 }
232
238
239 private:
240
241 std::string name_;
242 http::Url url_;
243 util::Optional<std::string> trust_anchor_;
244 util::Optional<std::string> cert_file_;
246 Role role_;
247 bool auto_failover_;
248 http::BasicHttpAuthPtr basic_auth_;
249 http::BasicHttpAuthConfigPtr basic_auth_config_;
250 };
251
253 typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
254
256 typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
257
260 public:
261
265 explicit StateConfig(const int state);
266
268 int getState() const {
269 return (state_);
270 }
271
274 return (pausing_);
275 }
276
281 void setPausing(const std::string& pausing);
282
287 static util::StatePausing stringToPausing(const std::string& pausing);
288
292 static std::string pausingToString(const util::StatePausing& pausing);
293
294 private:
295
297 int state_;
298
300 util::StatePausing pausing_;
301 };
302
304 typedef boost::shared_ptr<StateConfig> StateConfigPtr;
305
312 public:
313
316 : states_() {
317 }
318
327 StateConfigPtr getStateConfig(const int state);
328
329 private:
330
332 std::map<int, StateConfigPtr> states_;
333 };
334
336 typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
337
339 HAConfig();
340
342 static HAConfigPtr create();
343
354 PeerConfigPtr selectNextPeerConfig(const std::string& name);
355
357 std::string getThisServerName() const {
358 return (this_server_name_);
359 }
360
365 void setThisServerName(const std::string& this_server_name);
366
369 return (ha_mode_);
370 }
371
380 void setHAMode(const std::string& ha_mode);
381
387 static HAMode stringToHAMode(const std::string& ha_mode);
388
393 static std::string HAModeToString(const HAMode& ha_mode);
394
398 return (send_lease_updates_);
399 }
400
410 void setSendLeaseUpdates(const bool send_lease_updates) {
411 send_lease_updates_ = send_lease_updates;
412 }
413
416 bool amSyncingLeases() const {
417 return (sync_leases_);
418 }
419
429 void setSyncLeases(const bool sync_leases) {
430 sync_leases_ = sync_leases;
431 }
432
436 uint32_t getSyncTimeout() const {
437 return (sync_timeout_);
438 }
439
443 void setSyncTimeout(const uint32_t sync_timeout) {
444 sync_timeout_ = sync_timeout;
445 }
446
451 uint32_t getSyncPageLimit() const {
452 return (sync_page_limit_);
453 }
454
459 void setSyncPageLimit(const uint32_t sync_page_limit) {
460 sync_page_limit_ = sync_page_limit;
461 }
462
475 uint32_t getDelayedUpdatesLimit() const {
476 return (delayed_updates_limit_);
477 }
478
491 void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
492 delayed_updates_limit_ = delayed_updates_limit;
493 }
494
503 return (delayed_updates_limit_ > 0);
504 }
505
513 uint32_t getHeartbeatDelay() const {
514 return (heartbeat_delay_);
515 }
516
524 void setHeartbeatDelay(const uint32_t heartbeat_delay) {
525 heartbeat_delay_ = heartbeat_delay;
526 }
527
533 uint32_t getMaxResponseDelay() const {
534 return (max_response_delay_);
535 }
536
544 void setMaxResponseDelay(const uint32_t max_response_delay) {
545 max_response_delay_ = max_response_delay;
546 }
547
552 uint32_t getMaxAckDelay() const {
553 return (max_ack_delay_);
554 }
555
560 void setMaxAckDelay(const uint32_t max_ack_delay) {
561 max_ack_delay_ = max_ack_delay;
562 }
563
568 uint32_t getMaxUnackedClients() const {
569 return (max_unacked_clients_);
570 }
571
576 void setMaxUnackedClients(const uint32_t max_unacked_clients) {
577 max_unacked_clients_ = max_unacked_clients;
578 }
579
595 uint32_t getMaxRejectedLeaseUpdates() const {
597 }
598
609 void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates) {
610 max_rejected_lease_updates_ = max_rejected_lease_updates;
611 }
612
619 void setWaitBackupAck(const bool wait_backup_ack) {
620 wait_backup_ack_ = wait_backup_ack;
621 }
622
628 bool amWaitingBackupAck() const {
629 return (wait_backup_ack_);
630 }
631
638
643 void setEnableMultiThreading(bool enable_multi_threading) {
644 enable_multi_threading_ = enable_multi_threading;
645 }
646
657
663 void setHttpDedicatedListener(bool http_dedicated_listener) {
664 http_dedicated_listener_ = http_dedicated_listener;
665 }
666
671 return (http_listener_threads_);
672 }
673
677 void setHttpListenerThreads(uint32_t http_listener_threads) {
678 http_listener_threads_ = http_listener_threads;
679 }
680
685 return (http_client_threads_);
686 }
687
691 void setHttpClientThreads(uint32_t http_client_threads) {
692 http_client_threads_ = http_client_threads;
693 }
694
699
706
711
716 cert_file_ = cert;
717 }
718
721 return (key_file_);
722 }
723
728 key_file_ = key;
729 }
730
733 return (require_client_certs_);
734 }
735
739 void setRequireClientCerts(bool flag) {
741 }
742
744 bool getRestrictCommands() const {
745 return (restrict_commands_);
746 }
747
751 void setRestrictCommands(bool flag) {
752 restrict_commands_ = flag;
753 }
754
761 PeerConfigPtr getPeerConfig(const std::string& name) const;
762
774
779
787
792 return (peers_);
793 }
794
801
816 void validate();
817
828 static std::string getSubnetServerName(const dhcp::ConstSubnetPtr& subnet);
829
830 std::string this_server_name_;
834 uint32_t sync_timeout_;
841 uint32_t max_ack_delay_;
856};
857
858} // end of namespace isc::ha
859} // end of namespace isc
860
861#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:30
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition ha_config.cc:56
const http::BasicHttpAuthConfigPtr & getBasicAuthConfig() const
Returns const basic HTTP authentication configuration.
Definition ha_config.h:229
Role getRole() const
Returns server's role.
Definition ha_config.h:165
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition ha_config.h:117
void setKeyFile(const util::Optional< std::string > &key)
Sets server's key-file.
Definition ha_config.h:148
void setAutoFailover(const bool auto_failover)
Enables/disables auto-failover function for the server.
Definition ha_config.h:205
void setUrl(const http::Url &url)
Sets server's URL.
Definition ha_config.h:112
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
Definition ha_config.cc:100
bool isAutoFailover() const
Checks if the auto-failover function is enabled for the server.
Definition ha_config.h:197
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition ha_config.h:141
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition ha_config.h:237
Role
Server's role in the High Availability setup.
Definition ha_config.h:83
void setRole(const std::string &role)
Sets servers role.
Definition ha_config.cc:51
const http::BasicHttpAuthPtr & getBasicAuth() const
Returns const basic HTTP authentication.
Definition ha_config.h:215
std::string getName() const
Returns server name.
Definition ha_config.h:94
http::BasicHttpAuthConfigPtr & getBasicAuthConfig()
Returns non-const basic HTTP authentication configuration.
Definition ha_config.h:224
asiolink::TlsContextPtr getTlsContext() const
Returns a pointer to the server's TLS context.
Definition ha_config.h:153
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Definition ha_config.cc:83
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition ha_config.cc:63
void setName(const std::string &name)
Sets server name.
Definition ha_config.cc:40
util::Optional< std::string > getCertFile() const
Returns server's cert-file.
Definition ha_config.h:129
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition ha_config.h:210
http::Url getUrl() const
Returns URL of the server's control channel.
Definition ha_config.h:105
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets server's trust-anchor.
Definition ha_config.h:124
void setCertFile(const util::Optional< std::string > &cert)
Sets server's cert-file.
Definition ha_config.h:136
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition ha_config.h:273
int getState() const
Returns identifier of the state.
Definition ha_config.h:268
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
Definition ha_config.cc:118
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
Definition ha_config.cc:113
StateConfig(const int state)
Constructor.
Definition ha_config.cc:108
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition ha_config.cc:133
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition ha_config.cc:152
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition ha_config.h:840
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition ha_config.h:847
static HAConfigPtr create()
Instantiates a HAConfig.
Definition ha_config.cc:179
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition ha_config.h:835
HAMode getHAMode() const
Returns mode of operation.
Definition ha_config.h:368
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition ha_config.h:720
std::string getThisServerName() const
Returns name of this server.
Definition ha_config.h:357
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:619
bool require_client_certs_
Require client certs flag.
Definition ha_config.h:852
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:475
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition ha_config.h:846
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition ha_config.h:677
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition ha_config.h:727
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition ha_config.h:791
HAMode
Mode of operation.
Definition ha_config.h:55
void validate()
Validates configuration.
Definition ha_config.cc:284
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition ha_config.h:663
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition ha_config.h:837
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition ha_config.h:513
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition ha_config.cc:272
bool getRequireClientCerts() const
Returns require-client-certs.
Definition ha_config.h:732
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:459
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
Definition ha_config.h:843
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition ha_config.h:256
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:609
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:576
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition ha_config.h:703
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition ha_config.h:336
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition ha_config.cc:214
HAMode ha_mode_
Mode of operation.
Definition ha_config.h:831
bool send_lease_updates_
Send lease updates to partner?
Definition ha_config.h:832
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition ha_config.h:568
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition ha_config.h:670
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition ha_config.h:397
void setRequireClientCerts(bool flag)
Sets require-client-certs.
Definition ha_config.h:739
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition ha_config.h:544
bool getRestrictCommands() const
Returns restrict-commands.
Definition ha_config.h:744
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition ha_config.h:691
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition ha_config.h:429
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition ha_config.h:842
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:560
PeerConfigMap peers_
Map of peers' configurations.
Definition ha_config.h:854
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition ha_config.h:502
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition ha_config.h:841
util::Optional< std::string > cert_file_
Certificate file.
Definition ha_config.h:850
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition ha_config.h:436
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition ha_config.h:416
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:628
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition ha_config.h:524
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition ha_config.h:533
bool restrict_commands_
Restrict commands to HA flag.
Definition ha_config.h:853
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition ha_config.cc:202
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition ha_config.cc:277
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition ha_config.h:410
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition ha_config.h:443
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition ha_config.cc:259
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition ha_config.cc:249
util::Optional< std::string > key_file_
Private key file.
Definition ha_config.h:851
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition ha_config.h:708
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition ha_config.cc:184
void setRestrictCommands(bool flag)
Sets restrict-commands.
Definition ha_config.h:751
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:595
bool sync_leases_
Synchronize databases on startup?
Definition ha_config.h:833
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition ha_config.h:844
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition ha_config.h:552
StateMachineConfigPtr state_machine_
State machine configuration.
Definition ha_config.h:855
HAConfig()
Constructor.
Definition ha_config.cc:166
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition ha_config.h:849
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition ha_config.cc:219
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition ha_config.h:715
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:491
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition ha_config.h:798
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition ha_config.h:684
uint32_t http_client_threads_
Number of HTTP client threads.
Definition ha_config.h:848
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition ha_config.h:696
uint32_t sync_timeout_
Timeout for syncing lease database (ms).
Definition ha_config.h:834
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition ha_config.h:304
bool enable_multi_threading_
Enable multi-threading.
Definition ha_config.h:845
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition ha_config.h:839
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition ha_config.h:451
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:525
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition ha_config.cc:234
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition ha_config.h:635
std::string this_server_name_
This server name.
Definition ha_config.h:830
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition ha_config.h:643
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition ha_config.h:654
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition ha_config.h:253
Holds associations between objects and HA relationships.
Represents an URL.
Definition url.h:20
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:43
HARelationshipMapper< HAConfig > HAConfigMapper
Type of an object mapping HAConfig to relationships.
Definition ha_config.h:40
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition ha_config.h:37
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:45
Defines the logger used by the top-level component of kea-lfc.
This file defines the class StateModel.