Kea  2.3.9
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>
11 #include <exceptions/exceptions.h>
12 #include <http/basic_auth.h>
13 #include <http/post_request_json.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 
22 namespace isc {
23 namespace ha {
24 
27 public:
28  HAConfigValidationError(const char* file, size_t line, const char* what) :
29  isc::Exception(file, line, what) { };
30 };
31 
33 class HAConfig {
34 public:
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_;
222  util::Optional<std::string> key_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 
235  class StateConfig {
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 
341  HAMode getHAMode() const {
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 
370  bool amSendingLeaseUpdates() const {
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 
475  bool amAllowingCommRecovery() const {
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 
568  uint32_t getMaxRejectedLeaseUpdates() const {
570  }
571 
582  void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates) {
583  max_rejected_lease_updates_ = max_rejected_lease_updates;
584  }
585 
592  void setWaitBackupAck(const bool wait_backup_ack) {
593  wait_backup_ack_ = wait_backup_ack;
594  }
595 
601  bool amWaitingBackupAck() const {
602  return (wait_backup_ack_);
603  }
604 
609  return (enable_multi_threading_);
610  }
611 
616  void setEnableMultiThreading(bool enable_multi_threading) {
617  enable_multi_threading_ = enable_multi_threading;
618  }
619 
628  return (http_dedicated_listener_);
629  }
630 
636  void setHttpDedicatedListener(bool http_dedicated_listener) {
637  http_dedicated_listener_ = http_dedicated_listener;
638  }
639 
644  return (http_listener_threads_);
645  }
646 
650  void setHttpListenerThreads(uint32_t http_listener_threads) {
651  http_listener_threads_ = http_listener_threads;
652  }
653 
657  uint32_t getHttpClientThreads() {
658  return (http_client_threads_);
659  }
660 
664  void setHttpClientThreads(uint32_t http_client_threads) {
665  http_client_threads_ = http_client_threads;
666  }
667 
670  return (trust_anchor_);
671  }
672 
677  trust_anchor_ = ca;
678  }
679 
682  return (cert_file_);
683  }
684 
689  cert_file_ = cert;
690  }
691 
694  return (key_file_);
695  }
696 
701  key_file_ = key;
702  }
703 
705  bool getRequireClientCerts() const {
706  return (require_client_certs_);
707  }
708 
712  void setRequireClientCerts(bool flag) {
713  require_client_certs_ = flag;
714  }
715 
717  bool getRestrictCommands() const {
718  return (restrict_commands_);
719  }
720 
724  void setRestrictCommands(bool flag) {
725  restrict_commands_ = flag;
726  }
727 
734  PeerConfigPtr getPeerConfig(const std::string& name) const;
735 
747 
752 
760 
765  return (peers_);
766  }
767 
772  return (state_machine_);
773  }
774 
789  void validate();
790 
791  std::string this_server_name_;
795  uint32_t sync_timeout_;
796  uint32_t sync_page_limit_;
800  uint32_t heartbeat_delay_;
802  uint32_t max_ack_delay_;
817 };
818 
820 typedef boost::shared_ptr<HAConfig> HAConfigPtr;
821 
822 } // end of namespace isc::ha
823 } // end of namespace isc
824 
825 #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
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
Definition: ha_config.h:197
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
asiolink::TlsContextPtr tls_context_
Server TLS context.
Definition: ha_config.h:214
util::Optional< std::string > getKeyFile() const
Returns server's key-file.
Definition: ha_config.h:128
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
util::Optional< std::string > getTrustAnchor() const
Returns server's trust-anchor.
Definition: ha_config.h:104
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
util::Optional< std::string > getCertFile() const
Returns server's cert-file.
Definition: ha_config.h:116
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
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:801
uint32_t http_listener_threads_
Number of HTTP listener threads.
Definition: ha_config.h:808
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
Definition: ha_config.h:796
HAMode getHAMode() const
Returns mode of operation.
Definition: ha_config.h:341
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:592
bool require_client_certs_
Require client certs flag.
Definition: ha_config.h:813
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:807
void setHttpListenerThreads(uint32_t http_listener_threads)
Sets the number of threads the HTTP listener should use.
Definition: ha_config.h:650
void setKeyFile(const util::Optional< std::string > &key)
Sets global key-file.
Definition: ha_config.h:700
PeerConfigMap getAllServersConfig() const
Returns configurations of all servers.
Definition: ha_config.h:764
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:636
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
Definition: ha_config.h:798
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:705
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
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
Definition: ha_config.h:804
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
Definition: ha_config.h:232
void setMaxRejectedLeaseUpdates(const uint32_t max_rejected_lease_updates)
Sets the maximum number of clients for which lease updates can fail due to other than general error.
Definition: ha_config.h:582
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:676
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:792
bool send_lease_updates_
Send lease updates to partner?
Definition: ha_config.h:793
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:643
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:712
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:717
void setHttpClientThreads(uint32_t http_client_threads)
Sets the number of threads the HTTP client should use.
Definition: ha_config.h:664
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:803
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:815
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:802
util::Optional< std::string > cert_file_
Certificate file.
Definition: ha_config.h:811
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:601
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:814
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
util::Optional< std::string > getKeyFile() const
Returns global key-file.
Definition: ha_config.h:693
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
Definition: ha_config.cc:240
util::Optional< std::string > getCertFile() const
Returns global cert-file.
Definition: ha_config.h:681
util::Optional< std::string > key_file_
Private key file.
Definition: ha_config.h:812
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:724
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:568
bool sync_leases_
Synchronize databases on startup?
Definition: ha_config.h:794
bool wait_backup_ack_
Wait for lease update ack from backup?
Definition: ha_config.h:805
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:816
HAConfig()
Constructor.
Definition: ha_config.cc:162
util::Optional< std::string > trust_anchor_
Trust anchor.
Definition: ha_config.h:810
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:688
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:771
uint32_t getHttpClientThreads()
Fetches the number of threads the HTTP client should use.
Definition: ha_config.h:657
uint32_t http_client_threads_
Number of HTTP client threads.
Definition: ha_config.h:809
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
Definition: ha_config.h:795
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
Definition: ha_config.h:280
util::Optional< std::string > getTrustAnchor() const
Returns global trust-anchor.
Definition: ha_config.h:669
bool enable_multi_threading_
Enable multi-threading.
Definition: ha_config.h:806
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
Definition: ha_config.h:800
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:608
std::string this_server_name_
This server name.
Definition: ha_config.h:791
void setEnableMultiThreading(bool enable_multi_threading)
Sets whether or not server is configured for multi-threaded operation.
Definition: ha_config.h:616
bool getHttpDedicatedListener()
Checks if the server is configured to use its own HTTP listener.
Definition: ha_config.h:627
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:820
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.