Kea 1.5.0
ha_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2018 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// Functions accessed by the hooks framework use C linkage to avoid the name
8// mangling that accompanies use of the C++ compiler as well as to avoid
9// issues related to namespaces.
10
11#include <config.h>
12
13#include <ha_impl.h>
14#include <ha_log.h>
15#include <asiolink/io_service.h>
18#include <hooks/hooks.h>
19
20namespace isc {
21namespace ha {
22
24
25} // end of namespace isc::ha
26} // end of namespace isc
27
28using namespace isc::config;
29using namespace isc::data;
30using namespace isc::ha;
31using namespace isc::hooks;
32
33extern "C" {
34
39 try {
41 handle.getArgument("io_context", io_service);
42 isc::dhcp::NetworkStatePtr network_state;
43 handle.getArgument("network_state", network_state);
44 impl->startService(io_service, network_state, HAServerType::DHCPv4);
45
46 } catch (const std::exception& ex) {
47 LOG_ERROR(ha_logger, HA_DHCP4_START_SERVICE_FAILED)
48 .arg(ex.what());
49 return (1);
50 }
51 return (0);
52}
53
58 try {
59 impl->buffer4Receive(handle);
60
61 } catch (const std::exception& ex) {
62 LOG_ERROR(ha_logger, HA_BUFFER4_RECEIVE_FAILED)
63 .arg(ex.what());
64 return (1);
65 }
66
67 return (0);
68}
69
74 try {
75 impl->leases4Committed(handle);
76
77 } catch (const std::exception& ex) {
78 LOG_ERROR(ha_logger, HA_LEASES4_COMMITTED_FAILED)
79 .arg(ex.what());
80 return (1);
81 }
82
83 return (0);
84}
85
90 try {
92 handle.getArgument("io_context", io_service);
93 isc::dhcp::NetworkStatePtr network_state;
94 handle.getArgument("network_state", network_state);
95 impl->startService(io_service, network_state, HAServerType::DHCPv6);
96
97 } catch (const std::exception& ex) {
98 LOG_ERROR(ha_logger, HA_DHCP6_START_SERVICE_FAILED)
99 .arg(ex.what());
100 return (1);
101 }
102 return (0);
103}
104
109 try {
110 impl->buffer6Receive(handle);
111
112 } catch (const std::exception& ex) {
113 LOG_ERROR(ha_logger, HA_BUFFER6_RECEIVE_FAILED)
114 .arg(ex.what());
115 return (1);
116 }
117
118 return (0);
119}
120
125 try {
126 impl->leases6Committed(handle);
127
128 } catch (const std::exception& ex) {
129 LOG_ERROR(ha_logger, HA_LEASES6_COMMITTED_FAILED)
130 .arg(ex.what());
131 return (1);
132 }
133
134 return (0);
135}
136
141 try {
142 impl->commandProcessed(handle);
143
144 } catch (const std::exception& ex) {
145 LOG_ERROR(ha_logger, HA_COMMAND_PROCESSED_FAILED)
146 .arg(ex.what());
147 return (1);
148 }
149
150 return (0);
151}
152
155 try {
156 impl->heartbeatHandler(handle);
157
158 } catch (const std::exception& ex) {
159 LOG_ERROR(ha_logger, HA_HEARTBEAT_HANDLER_FAILED)
160 .arg(ex.what());
161 return (1);
162 }
163
164 return (0);
165}
166
169 try {
170 impl->synchronizeHandler(handle);
171
172 } catch (const std::exception& ex) {
173 LOG_ERROR(ha_logger, HA_SYNC_HANDLER_FAILED)
174 .arg(ex.what());
175 }
176
177 return (0);
178}
179
182 try {
183 impl->scopesHandler(handle);
184
185 } catch (const std::exception& ex) {
186 LOG_ERROR(ha_logger, HA_SCOPES_HANDLER_FAILED)
187 .arg(ex.what());
188 }
189
190 return (0);
191}
192
195 try {
196 impl->continueHandler(handle);
197
198 } catch (const std::exception& ex) {
199 LOG_ERROR(ha_logger, HA_CONTINUE_HANDLER_FAILED)
200 .arg(ex.what());
201 }
202
203 return (0);
204}
205
210int load(LibraryHandle& handle) {
211 ConstElementPtr config = handle.getParameter("high-availability");
212 if (!config) {
213 LOG_ERROR(ha_logger, HA_MISSING_CONFIGURATION);
214 return (1);
215 }
216
217 try {
218 impl = boost::make_shared<HAImpl>();
219 impl->configure(config);
220
221 handle.registerCommandCallout("ha-heartbeat", heartbeat_command);
222 handle.registerCommandCallout("ha-sync", sync_command);
223 handle.registerCommandCallout("ha-scopes", scopes_command);
224 handle.registerCommandCallout("ha-continue", continue_command);
225
226 } catch (const std::exception& ex) {
227 LOG_ERROR(ha_logger, HA_CONFIGURATION_FAILED)
228 .arg(ex.what());
229 return (CONTROL_RESULT_ERROR);
230 }
231
232 LOG_INFO(ha_logger, HA_INIT_OK);
233 return (0);
234}
235
239int unload() {
240 LOG_INFO(ha_logger, HA_DEINIT_OK);
241 return (0);
242}
243
244
245} // end extern "C"
Per-packet callout handle.
void getArgument(const std::string &name, T &value) const
Get argument.
isc::data::ConstElementPtr getParameter(const std::string &name)
Returns configuration parameter for the library.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
This file contains several functions and constants that are used for handling commands and responses ...
int dhcp4_srv_configured(CalloutHandle &handle)
dhcp4_srv_configured callout implementation.
Definition: ha_callouts.cc:38
int leases6_committed(CalloutHandle &handle)
leases6_committed callout implementation.
Definition: ha_callouts.cc:124
int scopes_command(CalloutHandle &handle)
ha-scopes command handler implementation.
Definition: ha_callouts.cc:181
int heartbeat_command(CalloutHandle &handle)
Heartbeat command handler implementation.
Definition: ha_callouts.cc:154
int command_processed(CalloutHandle &handle)
comand_processed callout implementation.
Definition: ha_callouts.cc:140
int leases4_committed(CalloutHandle &handle)
leases4_committed callout implementation.
Definition: ha_callouts.cc:73
int unload()
This function is called when the library is unloaded.
Definition: ha_callouts.cc:239
int dhcp6_srv_configured(CalloutHandle &handle)
dhcp6_srv_configured callout implementation.
Definition: ha_callouts.cc:89
int buffer4_receive(CalloutHandle &handle)
buffer4_receive callout implementation.
Definition: ha_callouts.cc:57
int continue_command(CalloutHandle &handle)
ha-continue command handler implementation.
Definition: ha_callouts.cc:194
int buffer6_receive(CalloutHandle &handle)
buffer6_receive callout implementation.
Definition: ha_callouts.cc:108
int sync_command(CalloutHandle &handle)
ha-sync command handler implementation.
Definition: ha_callouts.cc:168
int load(LibraryHandle &handle)
This function is called when the library is loaded.
Definition: ha_callouts.cc:210
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition: macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< HAImpl > HAImplPtr
Pointer to the High Availability hooks library implementation.
Definition: ha_impl.h:156
isc::log::Logger ha_logger("ha-hooks")
Definition: ha_log.h:17
HAImplPtr impl
Definition: ha_callouts.cc:23
Defines the logger used by the top-level component of kea-dhcp-ddns.