Kea: command_callouts.cc File Reference

| Kea 3.2.0-git

command_callouts.cc File Reference

Defines lease4_select and lease4_renew callout functions. More...

`#include <config.h>`
`#include <cc/command_interpreter.h>`
`#include <cc/data.h>`
`#include <cc/simple_parser.h>`
`#include <dhcpsrv/cfgmgr.h>`
`#include <dhcpsrv/cfg_subnets4.h>`
`#include <dhcpsrv/cfg_subnets6.h>`
`#include <dhcpsrv/subnet.h>`
`#include <hooks/callout_manager.h>`
`#include <hooks/hooks.h>`
`#include <util/str.h>`
`#include <legal_log_log.h>`
`#include <dhcpsrv/legal_log_mgr_factory.h>`
`#include <subnets_user_context.h>`
`#include <sstream>`
`#include <unordered_set>`
Include dependency graph for command_callouts.cc:

Go to the source code of this file.

## Functions
void | addContext (ostringstream &os, ConstElementPtr &arguments)
| Outputs text describing lease optional user context to a stream.
void | addDuration (CalloutHandle &handle, ostringstream &os, ConstElementPtr &arguments)
| Outputs text describing lease duration to a stream.
bool | checkLoggingEnabledSubnet4 (ConstElementPtr &arguments)
| Check if command has optional subnet-id parameter and if it does, check that the respective subnet has logging enabled.
bool | checkLoggingEnabledSubnet6 (ConstElementPtr &arguments)
| Check if command has optional subnet-id parameter and if it does, check that the respective subnet has logging enabled.
int | command_processed (CalloutHandle &handle)
| This callout is called at the "command_processed" hook point.
bool | getOptionalInt (ConstElementPtr &arguments, const string &name, int64_t &value)
| Fetch value for a integer element if it is an element scope.
bool | getOptionalString (ConstElementPtr &arguments, const string &name, string &value)
| Fetch value for a string element if it is an element scope.
int | handleLease4Cmds (CalloutHandle &handle, string &name, ConstElementPtr &arguments, ConstElementPtr &)
| Handle lease4 related commands.
int | handleLease6Cmds (CalloutHandle &handle, string &name, ConstElementPtr &arguments, ConstElementPtr &response)
| Handle lease6 related commands.
bool | isPrefix (ConstElementPtr arguments)
| Returns true if an element scope describes a prefix delegation.

## Detailed Description

Defines lease4_select and lease4_renew callout functions.

Definition in file command_callouts.cc.

## Function Documentation

## ◆ addContext()

void addContext | ( | ostringstream & | os,
|  | ConstElementPtr & | arguments )

Outputs text describing lease optional user context to a stream.

Looks for an user context or a comment and display it

Parameters

  os | output stream to which the text is output
  arguments | element scope which may contain user context or comment

Definition at line 138 of file command_callouts.cc.

References isc::data::copy(), and Element::createMap().

Referenced by handleLease4Cmds(), and handleLease6Cmds().

Here is the call graph for this function:

## ◆ addDuration()

void addDuration | ( | CalloutHandle & | handle,
|  | ostringstream & | os,
|  | ConstElementPtr & | arguments )

Outputs text describing lease duration to a stream.

Looks for either a lease valid lifetime or expiry from which to generate the duration text using isc::dhcp::LegalLogMgr::genDurationString().

Parameters

  handle | CalloutHandle which provides access to context.
  os | output stream to which the text is output
  arguments | element scope which may contain duration values

Definition at line 117 of file command_callouts.cc.

References isc::dhcp::LegalLogMgr::genDurationString(), isc::hooks::CalloutHandle::getCurrentLibrary(), getOptionalInt(), and isc::dhcp::LegalLogMgrFactory::instance().

Referenced by handleLease4Cmds(), and handleLease6Cmds().

Here is the call graph for this function:

## ◆ checkLoggingEnabledSubnet4()

bool checkLoggingEnabledSubnet4 | ( | ConstElementPtr & | arguments | ) |

Check if command has optional subnet-id parameter and if it does, check that the respective subnet has logging enabled.

Parameters

  arguments | The command arguments.

Returns
  true if logging is enabled (default), false otherwise.

Definition at line 163 of file command_callouts.cc.

References isc::dhcp::CfgMgr::getCurrentCfg(), getOptionalInt(), isc::dhcp::CfgMgr::instance(), and isc::legal_log::isLoggingDisabled().

Referenced by handleLease4Cmds().

Here is the call graph for this function:

## ◆ checkLoggingEnabledSubnet6()

bool checkLoggingEnabledSubnet6 | ( | ConstElementPtr & | arguments | ) |

Check if command has optional subnet-id parameter and if it does, check that the respective subnet has logging enabled.

Parameters

  arguments | The command arguments.

Returns
  true if logging is enabled (default), false otherwise.

Definition at line 264 of file command_callouts.cc.

References isc::dhcp::CfgMgr::getCurrentCfg(), getOptionalInt(), isc::dhcp::CfgMgr::instance(), and isc::legal_log::isLoggingDisabled().

Referenced by handleLease6Cmds().

Here is the call graph for this function:

## ◆ command_processed()

int command_processed | ( | CalloutHandle & | handle | ) |

This callout is called at the "command_processed" hook point.

Generates an entry in the legal log for the given control channel command.

It is possible to disable logging for selected subnets by specifying a "legal-logging" boolean parameter within the subnet's user context. If this parameter is not specified it defaults to 'true', in which case the logging is performed. When this value is set to 'false' the log is not produced and the function returns.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 485 of file command_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getCurrentLibrary(), isc::data::SimpleParser::getInteger(), handleLease4Cmds(), handleLease6Cmds(), isc::dhcp::LegalLogMgrFactory::instance(), LEGAL_LOG_COMMAND_NO_LEGAL_STORE, LEGAL_LOG_COMMAND_WRITE_ERROR, isc::legal_log::legal_log_logger, and LOG_ERROR.

Here is the call graph for this function:

## ◆ getOptionalInt()

bool getOptionalInt | ( | ConstElementPtr & | arguments,
|  | const string & | name,
|  | int64_t & | value )

Fetch value for a integer element if it is an element scope.

Exception safe fetcher which looks for an integer element with the given name within an given element scope. Rather than throw if the element is not found, it returns true if found, false if not.

Parameters

  | arguments | element scope to search, assumed to be a map
  | name | name of the desired element
  [out] | value | reference to an integer in which the found value is returned. Will be set to 0 if the element is not found.

Returns
  true if the element was found, false if not

Definition at line 78 of file command_callouts.cc.

References isc::data::SimpleParser::getInteger().

Referenced by addDuration(), checkLoggingEnabledSubnet4(), and checkLoggingEnabledSubnet6().

Here is the call graph for this function:

## ◆ getOptionalString()

bool getOptionalString | ( | ConstElementPtr & | arguments,
|  | const string & | name,
|  | string & | value )

Fetch value for a string element if it is an element scope.

Exception safe fetcher which looks for a string element with the given name within an given element scope. Rather than throw if the element is not found, it returns true if found, false if not.

Parameters

  | arguments | element scope to search, assumed to be a map
  | name | name of the desired element
  [out] | value | reference to a string in which the found value is returned. Will be set to "" if the element is not found.

Returns
  true if the element was found, false if not

Definition at line 53 of file command_callouts.cc.

References isc::data::SimpleParser::getString().

Referenced by handleLease4Cmds(), handleLease6Cmds(), and isPrefix().

Here is the call graph for this function:

## ◆ handleLease4Cmds()

int handleLease4Cmds | ( | CalloutHandle & | handle,
|  | string & | name,
|  | ConstElementPtr & | arguments,
|  | ConstElementPtr & | )

Handle lease4 related commands.

Parameters

  handle | CalloutHandle which provides access to context.
  name | The command name.
  arguments | The command arguments.
  response | The command response.

Definition at line 189 of file command_callouts.cc.

References addContext(), addDuration(), checkLoggingEnabledSubnet4(), isc::dhcp::ClientId::fromText(), isc::hooks::CalloutHandle::getCurrentLibrary(), getOptionalString(), isc::data::SimpleParser::getString(), isc::dhcp::LegalLogMgrFactory::instance(), isc::util::str::isPrintable(), LEGAL_LOG_COMMAND_NO_LEGAL_STORE, LEGAL_LOG_COMMAND_WRITE_ERROR, isc::legal_log::legal_log_logger, LOG_ERROR, and isc::dhcp::LegalLogMgr::vectorDump().

Referenced by command_processed().

Here is the call graph for this function:

## ◆ handleLease6Cmds()

int handleLease6Cmds | ( | CalloutHandle & | handle,
|  | string & | name,
|  | ConstElementPtr & | arguments,
|  | ConstElementPtr & | response )

Handle lease6 related commands.

Parameters

  handle | CalloutHandle which provides access to context.
  name | The command name.
  arguments | The command arguments.
  response | The command response.

Definition at line 290 of file command_callouts.cc.

References addContext(), addDuration(), checkLoggingEnabledSubnet6(), isc::data::copy(), Element::create(), isc::hooks::CalloutHandle::getCurrentLibrary(), isc::data::SimpleParser::getInteger(), getOptionalString(), isc::data::SimpleParser::getString(), handleLease6Cmds(), isc::dhcp::LegalLogMgrFactory::instance(), isc_throw, isPrefix(), LEGAL_LOG_COMMAND_NO_LEGAL_STORE, LEGAL_LOG_COMMAND_WRITE_ERROR, isc::legal_log::legal_log_logger, Element::list, and LOG_ERROR.

Referenced by command_processed(), and handleLease6Cmds().

Here is the call graph for this function:

## ◆ isPrefix()

bool isPrefix | ( | ConstElementPtr | arguments | ) |

Returns true if an element scope describes a prefix delegation.

Searches the given scope of an lease type element, "type". If it exists and it's value is "IA_PD" or "2" return true, false otherwise.

Parameters

  arguments | element scope to search, assumed to be a map

Returns
  true if the scope describes a prefix delegation

Definition at line 99 of file command_callouts.cc.

References getOptionalString().

Referenced by handleLease6Cmds().

Here is the call graph for this function: