Kea 2.6.0
ha_config.h
Go to the documentation of this file.
1// Copyright (C) 2018-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 HA_CONFIG_H
8#define HA_CONFIG_H
9
11#include <asiolink/crypto_tls.h>
12#include <dhcpsrv/subnet.h>
14#include <http/basic_auth.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
55 enum HAMode {
59 };
60
66 class PeerConfig {
67 public:
68
83 enum Role {
87 BACKUP
88 };
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
154 return (tls_context_);
155 }
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
228
229 private:
230
231 std::string name_;
232 http::Url url_;
233 util::Optional<std::string> trust_anchor_;
234 util::Optional<std::string> cert_file_;
236 Role role_;
237 bool auto_failover_;
238 http::BasicHttpAuthPtr basic_auth_;
239 };
240
242 typedef boost::shared_ptr<PeerConfig> PeerConfigPtr;
243
245 typedef std::map<std::string, PeerConfigPtr> PeerConfigMap;
246
249 public:
250
254 explicit StateConfig(const int state);
255
257 int getState() const {
258 return (state_);
259 }
260
263 return (pausing_);
264 }
265
270 void setPausing(const std::string& pausing);
271
276 static util::StatePausing stringToPausing(const std::string& pausing);
277
281 static std::string pausingToString(const util::StatePausing& pausing);
282
283 private:
284
286 int state_;
287
289 util::StatePausing pausing_;
290 };
291
293 typedef boost::shared_ptr<StateConfig> StateConfigPtr;
294
301 public:
302
305 : states_() {
306 }
307
316 StateConfigPtr getStateConfig(const int state);
317
318 private:
319
321 std::map<int, StateConfigPtr> states_;
322 };
323
325 typedef boost::shared_ptr<StateMachineConfig> StateMachineConfigPtr;
326
328 HAConfig();
329
331 static HAConfigPtr create();
332
343 PeerConfigPtr selectNextPeerConfig(const std::string& name);
344
346 std::string getThisServerName() const {
347 return (this_server_name_);
348 }
349
354 void setThisServerName(const std::string& this_server_name);
355
358 return (ha_mode_);
359 }
360
369 void setHAMode(const std::string& ha_mode);
370
376 static HAMode stringToHAMode(const std::string& ha_mode);
377
382 static std::string HAModeToString(const HAMode& ha_mode);
383
387 return (send_lease_updates_);
388 }
389
399 void setSendLeaseUpdates(const bool send_lease_updates) {
400 send_lease_updates_ = send_lease_updates;
401 }
402
405 bool amSyncingLeases() const {
406 return (sync_leases_);
407 }
408
418 void setSyncLeases(const bool sync_leases) {
419 sync_leases_ = sync_leases;
420 }
421
425 uint32_t getSyncTimeout() const {
426 return (sync_timeout_);
427 }
428
432 void setSyncTimeout(const uint32_t sync_timeout) {
433 sync_timeout_ = sync_timeout;
434 }
435
440 uint32_t getSyncPageLimit() const {
441 return (sync_page_limit_);
442 }
443
448 void setSyncPageLimit(const uint32_t sync_page_limit) {
449 sync_page_limit_ = sync_page_limit;
450 }
451
464 uint32_t getDelayedUpdatesLimit() const {
465 return (delayed_updates_limit_);
466 }
467
480 void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
481 delayed_updates_limit_ = delayed_updates_limit;
482 }
483
492 return (delayed_updates_limit_ > 0);
493 }
494
502 uint32_t getHeartbeatDelay() const {
503 return (heartbeat_delay_);
504 }
505
513 void setHeartbeatDelay(const uint32_t heartbeat_delay) {
514 heartbeat_delay_ = heartbeat_delay;
515 }
516
522 uint32_t getMaxResponseDelay() const {
523 return (max_response_delay_);
524 }
525
533 void setMaxResponseDelay(const uint32_t max_response_delay) {
534 max_response_delay_ = max_response_delay;
535 }
536
541 uint32_t getMaxAckDelay() const {
542 return (max_ack_delay_);
543 }
544
549 void setMaxAckDelay(const uint32_t max_ack_delay) {
550 max_ack_delay_ = max_ack_delay;
551 }
552
557 uint32_t getMaxUnackedClients() const {
558 return (max_unacked_clients_);
559 }
560
565 void setMaxUnackedClients(const uint32_t max_unacked_clients) {
566 max_unacked_clients_ = max_unacked_clients;
567 }
568
584 uint32_t getMaxRejectedLeaseUpdates() const {
586 }
587
598 void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates) {
599 max_rejected_lease_updates_ = max_rejected_lease_updates;
600 }
601
608 void setWaitBackupAck(const bool wait_backup_ack) {
609 wait_backup_ack_ = wait_backup_ack;
610 }
611
617 bool amWaitingBackupAck() const {
618 return (wait_backup_ack_);
619 }
620
626 }
627
632 void setEnableMultiThreading(bool enable_multi_threading) {
633 enable_multi_threading_ = enable_multi_threading;
634 }
635
645 }
646
652 void setHttpDedicatedListener(bool http_dedicated_listener) {
653 http_dedicated_listener_ = http_dedicated_listener;
654 }
655
660 return (http_listener_threads_);
661 }
662
666 void setHttpListenerThreads(uint32_t http_listener_threads) {
667 http_listener_threads_ = http_listener_threads;
668 }
669
674 return (http_client_threads_);
675 }
676
680 void setHttpClientThreads(uint32_t http_client_threads) {
681 http_client_threads_ = http_client_threads;
682 }
683
686 return (trust_anchor_);
687 }
688
693 trust_anchor_ = ca;
694 }
695
698 return (cert_file_);
699 }
700
705 cert_file_ = cert;
706 }
707
710 return (key_file_);
711 }
712
717 key_file_ = key;
718 }
719
722 return (require_client_certs_);
723 }
724
728 void setRequireClientCerts(bool flag) {
730 }
731
733 bool getRestrictCommands() const {
734 return (restrict_commands_);
735 }
736
740 void setRestrictCommands(bool flag) {
741 restrict_commands_ = flag;
742 }
743
750 PeerConfigPtr getPeerConfig(const std::string& name) const;
751
763
768
776
781 return (peers_);
782 }
783
788 return (state_machine_);
789 }
790
805 void validate();
806
817 static std::string getSubnetServerName(const dhcp::SubnetPtr& subnet);
818
819 std::string this_server_name_;
823 uint32_t sync_timeout_;
830 uint32_t max_ack_delay_;
845};
846
847} // end of namespace isc::ha
848} // end of namespace isc
849
850#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:28
HAConfigValidationError(const char *file, size_t line, const char *what)
Definition: ha_config.h:30
HA peer configuration.
Definition: ha_config.h:66
std::string getLogLabel() const
Returns a string identifying a server used in logging.
Definition: ha_config.cc:55
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:99
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:227
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:50
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
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:82
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
Definition: ha_config.cc:62
void setName(const std::string &name)
Sets server name.
Definition: ha_config.cc:39
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
Configuration specific to a single HA state.
Definition: ha_config.h:248
util::StatePausing getPausing() const
Returns pausing mode for the given state.
Definition: ha_config.h:262
int getState() const
Returns identifier of the state.
Definition: ha_config.h:257
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
Definition: ha_config.cc:117
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
Definition: ha_config.cc:112
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
Definition: ha_config.cc:132
State machine configuration information.
Definition: ha_config.h:300
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
Definition: ha_config.cc:151
Storage for High Availability configuration.
Definition: ha_config.h:46
uint32_t max_response_delay_
Max delay in response to heartbeats.
Definition: ha_config.h:829
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition: ha_config.h:836
static HAConfigPtr create()
Instantiates a HAConfig.
Definition: ha_config.cc:178
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:824
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:357
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition: ha_config.h:709
std::string getThisServerName() const
Returns name of this server.
Definition: ha_config.h:346
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:608
bool require_client_certs_
Require client certs flag.
Definition: ha_config.h:841
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:464
bool http_dedicated_listener_
Enable use of own HTTP listener.
Definition: ha_config.h:835
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition: ha_config.h:666
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition: ha_config.h:716
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:780
HAMode
Mode of operation.
Definition: ha_config.h:55
void validate()
Validates configuration.
Definition: ha_config.cc:283
void setHttpDedicatedListener(bool http_dedicated_listener)
Sets whether or not the server is configured to use its own HTTP listener.
Definition: ha_config.h:652
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition: ha_config.h:826
uint32_t getHeartbeatDelay() const
Returns heartbeat delay in milliseconds.
Definition: ha_config.h:502
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
Definition: ha_config.cc:271
bool getRequireClientCerts() const
Returns require-client-certs.
Definition: ha_config.h:721
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:448
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
Definition: ha_config.h:832
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:245
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:598
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:565
void setTrustAnchor(const util::Optional< std::string > &ca)
Sets global trust-anchor.
Definition: ha_config.h:692
boost::shared_ptr< StateMachineConfig > StateMachineConfigPtr
Pointer to a state machine configuration.
Definition: ha_config.h:325
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
Definition: ha_config.cc:213
HAMode ha_mode_
Mode of operation.
Definition: ha_config.h:820
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:821
uint32_t getMaxUnackedClients() const
Returns maximum number of clients which may fail to communicate with the DHCP server before entering ...
Definition: ha_config.h:557
uint32_t getHttpListenerThreads()
Fetches the number of threads the HTTP listener should use.
Definition: ha_config.h:659
bool amSendingLeaseUpdates() const
Returns boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:386
void setRequireClientCerts(bool flag)
Sets require-client-certs.
Definition: ha_config.h:728
void setMaxResponseDelay(const uint32_t max_response_delay)
Sets new max response delay.
Definition: ha_config.h:533
bool getRestrictCommands() const
Returns restrict-commands.
Definition: ha_config.h:733
static std::string getSubnetServerName(const dhcp::SubnetPtr &subnet)
Convenience function extracting a value of the ha-server-name parameter from a subnet context.
Definition: ha_config.cc:524
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition: ha_config.h:680
void setSyncLeases(const bool sync_leases)
Sets boolean flag indicating whether the active servers should synchronize their lease databases upon...
Definition: ha_config.h:418
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Definition: ha_config.h:831
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:549
PeerConfigMap peers_
Map of peers' configurations.
Definition: ha_config.h:843
bool amAllowingCommRecovery() const
Convenience function checking if communication recovery is allowed.
Definition: ha_config.h:491
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
Definition: ha_config.h:830
util::Optional< std::string > cert_file_
Certificate file.
Definition: ha_config.h:839
uint32_t getSyncTimeout() const
Returns timeout for lease database synchronization.
Definition: ha_config.h:425
bool amSyncingLeases() const
Returns boolean flag indicating whether the active servers should synchronize their lease databases u...
Definition: ha_config.h:405
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:617
void setHeartbeatDelay(const uint32_t heartbeat_delay)
Sets new heartbeat delay in milliseconds.
Definition: ha_config.h:513
uint32_t getMaxResponseDelay() const
Returns max response delay.
Definition: ha_config.h:522
bool restrict_commands_
Restrict commands to HA flag.
Definition: ha_config.h:842
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
Definition: ha_config.cc:201
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
Definition: ha_config.cc:276
void setSendLeaseUpdates(const bool send_lease_updates)
Sets boolean flag indicating whether lease updates should be sent to the partner.
Definition: ha_config.h:399
void setSyncTimeout(const uint32_t sync_timeout)
Sets new lease database syncing timeout in milliseconds.
Definition: ha_config.h:432
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
Definition: ha_config.cc:258
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:248
util::Optional< std::string > key_file_
Private key file.
Definition: ha_config.h:840
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition: ha_config.h:697
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
Definition: ha_config.cc:183
void setRestrictCommands(bool flag)
Sets restrict-commands.
Definition: ha_config.h:740
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:584
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:822
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition: ha_config.h:833
uint32_t getMaxAckDelay() const
Returns maximum time for a client trying to communicate with DHCP server to complete the transaction.
Definition: ha_config.h:541
StateMachineConfigPtr state_machine_
State machine configuration.
Definition: ha_config.h:844
HAConfig()
Constructor.
Definition: ha_config.cc:165
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition: ha_config.h:838
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
Definition: ha_config.cc:218
void setCertFile(const util::Optional< std::string > &cert)
Sets global cert-file.
Definition: ha_config.h:704
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:480
StateMachineConfigPtr getStateMachineConfig() const
Returns state machine configuration.
Definition: ha_config.h:787
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition: ha_config.h:673
uint32_t http_client_threads_
Number of HTTP client threads.
Definition: ha_config.h:837
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition: ha_config.h:685
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:823
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:293
bool enable_multi_threading_
Enable multi-threading.
Definition: ha_config.h:834
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:828
uint32_t getSyncPageLimit() const
Returns maximum number of leases per page to be fetched during database synchronization.
Definition: ha_config.h:440
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
Definition: ha_config.cc:233
bool getEnableMultiThreading()
Checks if the server is configured for multi-threaded operation.
Definition: ha_config.h:624
std::string this_server_name_
This server name.
Definition: ha_config.h:819
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition: ha_config.h:632
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition: ha_config.h:643
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
Definition: ha_config.h:242
Holds associations between objects and HA relationships.
Represents an URL.
Definition: url.h:20
A template representing an optional value.
Definition: optional.h:36
TLS API.
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or 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.
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.