45 service_ = boost::make_shared<HAService>(io_service, network_state,
49 io_service->post([&]() {
service_->startClientAndListener(); } );
70 if (callout_handle.
getStatus() != CalloutHandle::NEXT_STEP_SKIP) {
81 }
catch (
const std::exception& ex) {
84 .arg(query4->getRemoteAddr().toText())
85 .arg(query4->getLocalAddr().toText())
86 .arg(query4->getIface())
91 static_cast<int64_t>(1));
93 static_cast<int64_t>(1));
96 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
103 .arg(query4->getLabel());
104 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
109 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_SKIP);
118 if (!
config_->amSendingLeaseUpdates()) {
135 callout_handle.
getArgument(
"deleted_leases4", deleted_leases4);
138 if (leases4->empty() && deleted_leases4->empty()) {
140 .arg(query4->getLabel());
150 parking_lot->reference(query4);
157 if (
service_->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
159 parking_lot->dereference(query4);
164 parking_lot->dereference(query4);
171 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_PARK);
184 if (callout_handle.
getStatus() != CalloutHandle::NEXT_STEP_SKIP) {
195 }
catch (
const std::exception& ex) {
198 .arg(query6->getRemoteAddr().toText())
199 .arg(query6->getLocalAddr().toText())
200 .arg(query6->getIface())
205 static_cast<int64_t>(1));
207 static_cast<int64_t>(1));
210 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
217 .arg(query6->getLabel());
218 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
223 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_SKIP);
232 if (!
config_->amSendingLeaseUpdates()) {
249 callout_handle.
getArgument(
"deleted_leases6", deleted_leases6);
252 if (leases6->empty() && deleted_leases6->empty()) {
254 .arg(query6->getLabel());
264 parking_lot->reference(query6);
271 if (
service_->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
273 parking_lot->dereference(query6);
278 parking_lot->dereference(query6);
285 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_PARK);
290 std::string command_name;
292 if (command_name ==
"status-get") {
296 if (!response || (response->getType() != Element::map)) {
301 if (!resp_args || (resp_args->getType() != Element::map)) {
306 boost::const_pointer_cast<
Element>(resp_args);
311 auto ha_relationships = Element::createList();
312 auto ha_relationship = Element::createMap();
314 ha_relationship->set(
"ha-servers", ha_servers);
316 ha_relationships->add(ha_relationship);
317 mutable_resp_args->set(
"high-availability", ha_relationships);
338 unsigned int max_period_value = 0;
347 if (args->getType() != Element::map) {
353 server_name = args->get(
"server-name");
359 if (server_name->getType() != Element::string) {
367 if ((max_period->getType() != Element::integer) ||
368 (max_period->intValue() <= 0)) {
369 isc_throw(
BadValue,
"'max-period' must be a positive integer in the 'ha-sync' command");
372 max_period_value =
static_cast<unsigned int>(max_period->intValue());
375 }
catch (
const std::exception& ex) {
399 std::vector<std::string> scopes_vector;
408 if (args->getType() != Element::map) {
419 if (scopes->getType() != Element::list) {
425 for (
size_t i = 0; i < scopes->size(); ++i) {
427 if (!scope || scope->getType() != Element::string) {
430 scopes_vector.push_back(scope->stringValue());
433 }
catch (
const std::exception& ex) {
464 isc_throw(
BadValue,
"'cancel' is mandatory for the 'ha-maintenance-notify' command");
467 if (cancel_op->getType() != Element::boolean) {
468 isc_throw(
BadValue,
"'cancel' must be a boolean in the 'ha-maintenance-notify' command");
const isc::log::MessageID HA_BUFFER6_RECEIVE_UNPACK_FAILED
const isc::log::MessageID HA_BUFFER6_RECEIVE_PACKET_OPTIONS_SKIPPED
void setStatus(const CalloutNextStep next)
Sets the next processing step.
void startService(const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAServerType &server_type)
Creates high availability service using current configuration.
void parse(const HAConfigPtr &config_storage, const data::ConstElementPtr &config)
Parses HA configuration.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
void synchronizeHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-sync command.
Configuration parser for High Availability.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
Exception thrown during option unpacking This exception is thrown when an error has occurred...
void maintenanceCancelHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-cancel command.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
boost::shared_ptr< Element > ElementPtr
void maintenanceNotifyHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-notify command.
HAServicePtr service_
Pointer to the high availability service (state machine).
void maintenanceStartHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-start command.
ParkingLotHandlePtr getParkingLotHandlePtr() const
Returns pointer to the parking lot handle for this hook point.
HAServerType
Lists possible server types for which HA service is created.
const isc::log::MessageID HA_BUFFER4_RECEIVE_NOT_FOR_US
static StatsMgr & instance()
Statistics Manager accessor method.
void buffer6Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer6_receive" callout.
const isc::log::MessageID HA_LEASES6_COMMITTED_NOTHING_TO_UPDATE
const isc::log::MessageID HA_BUFFER4_RECEIVE_PACKET_OPTIONS_SKIPPED
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Per-packet callout handle.
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< const Element > ConstElementPtr
void haResetHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-reset command.
void setArgument(const std::string &name, T value)
Set argument.
void scopesHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-scopes command.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void continueHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-continue command.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void configure(const data::ConstElementPtr &input_config)
Parses configuration.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
void leases4Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases4_committed" callout.
const isc::log::MessageID HA_BUFFER4_RECEIVE_UNPACK_FAILED
This file contains several functions and constants that are used for handling commands and responses ...
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
HAConfigPtr config_
Holds parsed configuration.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
The Element class represents a piece of data, used by the command channel and configuration parts...
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
isc::log::Logger ha_logger("ha-hooks")
void getArgument(const std::string &name, T &value) const
Get argument.
void buffer4Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer4_receive" callout.
void commandProcessed(hooks::CalloutHandle &callout_handle)
Implementation of the "command_processed" callout.
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
const isc::log::MessageID HA_LEASES4_COMMITTED_NOTHING_TO_UPDATE
void leases6Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases6_committed" callout.
const isc::log::MessageID HA_BUFFER6_RECEIVE_NOT_FOR_US
void heartbeatHandler(hooks::CalloutHandle &callout_handle)
Implements handle for the heartbeat command.
CalloutNextStep getStatus() const
Returns the next processing step.
Storage for High Availability configuration.