25#include <unordered_set>
104 return (type_str ==
"IA_PD" || type_str ==
"2");
121 int64_t duration = 0;
147 copied =
copy(ctx, 0);
151 copied->set(
"comment", comment);
155 os <<
", context: " << ctx->str();
169 int64_t subnet_id_value = 0;
170 if (
getOptionalInt(arguments,
"subnet-id", subnet_id_value) && (subnet_id_value > 0)) {
206 if (origin ==
"ha-partner") {
209 os <<
"Administrator";
211 if ((name ==
"lease4-add") || name ==
"lease4-update") {
212 if (name ==
"lease4-add") {
213 os <<
" added a lease of address: ";
215 os <<
" updated information on the lease of address: ";
219 <<
" to a device with hardware address: "
224 os <<
", client-id: " << client_id;
238 }
else if (name ==
"lease4-del") {
242 os <<
" deleted the lease for address: "
245 os <<
" deleted a lease for a device identified by: "
252 }
catch (
const exception& ex) {
270 int64_t subnet_id_value = 0;
271 if (
getOptionalInt(arguments,
"subnet-id", subnet_id_value) && (subnet_id_value > 0)) {
307 if (origin ==
"ha-partner") {
310 os <<
"Administrator";
312 if ((name ==
"lease6-add") || name ==
"lease6-update") {
313 if (name ==
"lease6-add") {
314 os <<
" added a lease of";
316 os <<
" updated information on the lease of";
332 os <<
" to a device with DUID: "
337 os <<
", hardware address: " << hw_address;
342 }
else if (name ==
"lease6-del") {
346 os <<
" deleted the lease for address: "
349 os <<
" deleted a lease for a device identified by: "
353 }
else if (name ==
"lease6-bulk-apply") {
355 auto deleted_leases = arguments->get(
"deleted-leases");
356 auto leases = arguments->get(
"leases");
358 if (!deleted_leases && !leases) {
364 if (deleted_leases && (deleted_leases->getType() !=
Element::list)) {
376 auto response_args = response->get(
"arguments");
379 failed_deleted_leases = response_args->get(
"failed-deleted-leases");
380 failed_leases = response_args->get(
"failed-leases");
385 if (deleted_leases) {
386 unordered_set<string> failed_deleted_leases_set;
387 if (failed_deleted_leases) {
392 auto leases_list = failed_deleted_leases->listValue();
394 for (
auto const& lease_params : leases_list) {
395 auto address = lease_params->get(
"ip-address");
397 failed_deleted_leases_set.emplace(address->stringValue());
402 auto leases_list = deleted_leases->listValue();
403 for (
auto const& lease_params : leases_list) {
404 auto address = lease_params->get(
"ip-address");
405 if (address && failed_deleted_leases_set.count(address->stringValue()) == 0) {
407 if (!origin.empty()) {
415 string cmd_name(
"lease6-del");
425 unordered_set<string> failed_leases_set;
431 auto leases_list = failed_leases->listValue();
433 for (
auto const& lease_params : leases_list) {
434 auto address = lease_params->get(
"ip-address");
436 failed_leases_set.emplace(address->stringValue());
440 auto leases_list = leases->listValue();
441 for (
auto const& lease_params : leases_list) {
442 auto address = lease_params->get(
"ip-address");
443 if (address && failed_leases_set.count(address->stringValue()) == 0) {
445 if (!origin.empty()) {
453 string cmd_name(
"lease6-update");
465 }
catch (
const exception& ex) {
509 static unordered_set<string>
const supported = {
510 "lease4-add",
"lease4-update",
"lease4-del",
"lease6-add",
511 "lease6-update",
"lease6-del",
"lease6-bulk-apply"
513 if (supported.count(name) == 0) {
520 if (name.find(
"lease4-") != string::npos) {
522 }
else if (name.find(
"lease6-") != string::npos) {
526 }
catch (
const exception& ex) {
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
static LegalLogMgrPtr & instance(ManagerID id=0)
Returns the forensic backend manager with specified ID.
static std::string genDurationString(const uint32_t secs)
Translates seconds into a text string of days, hours, minutes and seconds.
static std::string vectorDump(const std::vector< uint8_t > &bytes)
Creates a string from a vector of printable bytes.
Per-packet callout handle.
void getArgument(const std::string &name, T &value) const
Get argument.
int getCurrentLibrary() const
Get current library index.
bool getOptionalInt(ConstElementPtr &arguments, const string &name, int64_t &value)
Fetch value for a integer element if it is an element scope.
int handleLease4Cmds(CalloutHandle &handle, string &name, ConstElementPtr &arguments, ConstElementPtr &)
Handle lease4 related commands.
bool getOptionalString(ConstElementPtr &arguments, const string &name, string &value)
Fetch value for a string element if it is an element scope.
int command_processed(CalloutHandle &handle)
This callout is called at the "command_processed" hook point.
bool isPrefix(ConstElementPtr arguments)
Returns true if an element scope describes a prefix delegation.
void addDuration(CalloutHandle &handle, ostringstream &os, ConstElementPtr &arguments)
Outputs text describing lease duration to a stream.
void addContext(ostringstream &os, ConstElementPtr &arguments)
Outputs text describing lease optional user context to a stream.
bool checkLoggingEnabledSubnet6(ConstElementPtr &arguments)
Check if command has optional subnet-id parameter and if it does, check that the respective subnet ha...
int handleLease6Cmds(CalloutHandle &handle, string &name, ConstElementPtr &arguments, ConstElementPtr &response)
Handle lease6 related commands.
bool checkLoggingEnabledSubnet4(ConstElementPtr &arguments)
Check if command has optional subnet-id parameter and if it does, check that the respective subnet ha...
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const isc::log::MessageID LEGAL_LOG_COMMAND_NO_LEGAL_STORE
const isc::log::MessageID LEGAL_LOG_COMMAND_WRITE_ERROR
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
boost::shared_ptr< CfgSubnets6 > CfgSubnets6Ptr
Non-const pointer.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< CfgSubnets4 > CfgSubnets4Ptr
Non-const pointer.
isc::log::Logger legal_log_logger("legal-log-hooks")
Legal Log Logger.
bool isLoggingDisabled(const SubnetPtrType &subnet)
Checks if legal logging is disabled for a subnet.
bool isPrintable(const string &content)
Check if a string is printable.
Defines the logger used by the top-level component of kea-lfc.