Kea: lease6_callouts.cc File Reference

| Kea 3.2.0-git

lease6_callouts.cc File Reference
`#include <config.h>`
`#include <asiolink/asio_wrapper.h>`
`#include <cc/data.h>`
`#include <dhcp/dhcp6.h>`
`#include <dhcp/option_custom.h>`
`#include <dhcp/option6_ia.h>`
`#include <dhcp/option6_iaaddr.h>`
`#include <dhcp/option6_iaprefix.h>`
`#include <dhcp/pkt6.h>`
`#include <dhcpsrv/cfgmgr.h>`
`#include <dhcpsrv/cfg_subnets6.h>`
`#include <dhcpsrv/lease.h>`
`#include <eval/evaluate.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 dependency graph for lease6_callouts.cc:

Go to the source code of this file.

## Classes
class | isc::dhcp::TokenFilterIA_NA
| Filter all IA_NA so that no option is matched by the expression. More...
class | isc::dhcp::TokenFilterIA_NASuboption
| Filter all IA_NA so that no sub-option is matched by the expression. More...
class | isc::dhcp::TokenFilterIA_PD
| Filter all IA_PD so that no option is matched by the expression. More...
class | isc::dhcp::TokenFilterIA_PDSuboption
| Filter all IA_PD so that no sub-option is matched by the expression. More...
class | isc::dhcp::TokenLeaseIA_NA
| Filter the IA_NA (3) option containing the OPTION_IAADDR (5) option matching the respective lease. More...
class | isc::dhcp::TokenLeaseIA_NASuboption
| Filter the IA_NA (3) option containing the OPTION_IAADDR (5) option matching the respective lease. More...
class | isc::dhcp::TokenLeaseIA_PD
| Filter the IA_PD (25) option containing the OPTION_IAPREFIX (25) option matching the respective lease. More...
class | isc::dhcp::TokenLeaseIA_PDSuboption
| Filter the IA_PD (25) option containing the OPTION_IAPREFIX (25) option matching the respective lease. More...

## Namespaces
namespace | isc
| Defines the logger used by the top-level component of kea-lfc.
namespace | isc::dhcp

## Functions
void | filterLeaseIA_NA (isc::dhcp::Expression &expression, const Lease6Ptr &lease)
| Replace TokenOption and TokenSubOption expression tokens with the IA_NA (3) option containing the OPTION_IAADDR (5) option matching the respective lease.
void | filterLeaseIA_PD (isc::dhcp::Expression &expression, const Lease6Ptr &lease)
| Replace TokenOption and TokenSubOption expression tokens with the IA_PD (25) option containing the OPTION_IAPREFIX (25) option matching the respective lease.
std::string | genLease6Addr (const Lease6Ptr &lease)
| Creates legal store address column for a DHCPv6 Lease.
std::string | genLease6Entry (CalloutHandle &handle, const Pkt6Ptr &query, const Pkt6Ptr &response, const Lease6Ptr &lease, const Action &action)
| Creates legal store entry for a DHCPv6 Lease.
bool | getCustomEntry (CalloutHandle &handle, const Pkt6Ptr &query, const Pkt6Ptr &response, const Lease6Ptr &lease, std::string &value)
| Create custom log entry for the current lease.
std::string | hwaddrSourceToString (uint32_t source)
| Function which converts hardware address source to a string.
int | lease6_decline (CalloutHandle &handle)
| This callout is called at the "lease6_decline" hook.
int | lease6_release (CalloutHandle &handle)
| This callout is called at the "lease6_release" hook.
int | leases6_committed (CalloutHandle &handle)
| This callout is called at the "leases6_committed" hook.
int | legalLog6Handler (CalloutHandle &handle, const Action &action)
| Produces an DHCPv6 legal log entry from a callout handle.
int | pkt6_receive (CalloutHandle &handle)
| This callout is called at the "pkt6_receive" hook.
int | pkt6_send (CalloutHandle &handle)
| This callout is called at the "pkt6_send" hook.
void | replaceTokensForLease (isc::dhcp::ExpressionPtr &expression, const Lease6Ptr &lease)
| Replace TokenOption and TokenSubOption expression tokens for all IA_NA and IA_PD options and sub-options filtering by the current lease.

## Function Documentation

## ◆ filterLeaseIA_NA()

void filterLeaseIA_NA | ( | isc::dhcp::Expression & | expression,
|  | const Lease6Ptr & | lease )

Replace TokenOption and TokenSubOption expression tokens with the IA_NA (3) option containing the OPTION_IAADDR (5) option matching the respective lease.

Parameters

  expression | The expression that needs to be updated with filtering tokens.
  lease | The lease used to match any OPTION_IAADDR option in the IA_NA packet options.

Definition at line 394 of file lease6_callouts.cc.

References D6O_IA_NA, D6O_IA_PD, D6O_IAADDR, and D6O_IAPREFIX.

Referenced by replaceTokensForLease().

## ◆ filterLeaseIA_PD()

void filterLeaseIA_PD | ( | isc::dhcp::Expression & | expression,
|  | const Lease6Ptr & | lease )

Replace TokenOption and TokenSubOption expression tokens with the IA_PD (25) option containing the OPTION_IAPREFIX (25) option matching the respective lease.

Parameters

  expression | The expression that needs to be updated with filtering tokens.
  lease | The lease used to match any OPTION_IAPREFIX option in the IA_PD packet options.

Definition at line 429 of file lease6_callouts.cc.

References D6O_IA_NA, D6O_IA_PD, D6O_IAADDR, and D6O_IAPREFIX.

Referenced by replaceTokensForLease().

## ◆ genLease6Addr()

std::string genLease6Addr | ( | const Lease6Ptr & | lease | ) |

Creates legal store address column for a DHCPv6 Lease.

Parameters

  lease | DHCPv6 lease for which the entry should be created

Definition at line 72 of file lease6_callouts.cc.

References isc::dhcp::Lease::TYPE_PD.

Referenced by legalLog6Handler().

## ◆ genLease6Entry()

std::string genLease6Entry | ( | CalloutHandle & | handle,
|  | const Pkt6Ptr & | query,
|  | const Pkt6Ptr & | response,
|  | const Lease6Ptr & | lease,
|  | const Action & | action )

Creates legal store entry for a DHCPv6 Lease.

Creates an entry based on the given DHCPv6 queries and corresponding DHCPv6 lease. The entry is returned as a single string with no embedded EOL markers, a prepended timestamp and has the following sections:

"<timestamp><address><duration><device-id>{relay-info}*{user-context}*"

Where:

- timestamp - the current date and time the log entry was written in "%Y-%m-%d %H:%M:%S %Z" strftime format.
- address - the leased IPv6 address or prefix given out and whether it was assigned or renewed.
- duration - the lease lifetime expressed as in days (if present), hours, minutes and seconds. A lease lifetime of 0xFFFFFFFF will be denoted with the text "infinite duration".
- device-id - the client's DUID and hardware address (if present)
- relay-info - for relayed packets the content of relay agent messages, remote id and subscriber id options (x and xx) if present.
- user-context - the optional user context.

For example (on multiple lines for readibility):

"2018-01-06 01:02:03 PST Address:2001:db8:1:: has been assigned
for 0 hrs 11 mins 53 secs to a device with DUID:
17:34:e2:ff:09:92:54 and hardware address: hwtype=1
08:00:2b:02:3f:4e (from Raw Socket) connected via relay at
address: fe80::abcd for client on link address: 3001::1, hop
count: 1, identified by remote-id: 01:02:03:04:0a:0b:0c:0d:0e:0f
and subscriber-id: 1a:2b:3c:4d:5e:6f"

Parameters

  handle | CalloutHandle which provides access to context.
  query | DHCPv6 query packet for which the lease was generated
  response | DHCPv6 response packet
  lease | DHCPv6 lease for which the entry should be created
  action | Kind of event to log.

Definition at line 541 of file lease6_callouts.cc.

References isc::dhcp::actionToVerb(), D6O_INTERFACE_ID, D6O_REMOTE_ID, D6O_SUBSCRIBER_ID, isc::dhcp::LegalLogMgr::genDurationString(), getCustomEntry(), isc::dhcp::Pkt6::RelayInfo::hop_count_, hwaddrSourceToString(), isc::util::str::isPrintable(), isc::dhcp::Pkt6::RelayInfo::linkaddr_, isc::dhcp::Pkt6::RelayInfo::peeraddr_, isc::dhcp::Pkt6::RELAY_SEARCH_FROM_CLIENT, isc::dhcp::RELEASE, isc::asiolink::IOAddress::toText(), isc::dhcp::Lease::TYPE_PD, isc::dhcp::LegalLogMgr::vectorDump(), and isc::dhcp::LegalLogMgr::vectorHexDump().

Referenced by legalLog6Handler().

Here is the call graph for this function:

## ◆ getCustomEntry()

bool getCustomEntry | ( | CalloutHandle & | handle,
|  | const Pkt6Ptr & | query,
|  | const Pkt6Ptr & | response,
|  | const Lease6Ptr & | lease,
|  | std::string & | value )

Create custom log entry for the current lease.

Parameters

  | handle | CalloutHandle which provides access to context.
  | query | The query received by the server.
  | response | The response of the server.
  | lease | The current lease generating this log entry.
  [out] | value | The value of the custom log entry after parser execution.

Definition at line 483 of file lease6_callouts.cc.

References isc::dhcp::evaluateString(), isc::hooks::CalloutHandle::getCurrentLibrary(), isc::dhcp::LegalLogMgrFactory::instance(), and replaceTokensForLease().

Referenced by genLease6Entry().

Here is the call graph for this function:

## ◆ hwaddrSourceToString()

std::string hwaddrSourceToString | ( | uint32_t | source | ) |

Function which converts hardware address source to a string.

Parameters

  source | integer value to convert

Returns
  string label for the value or "UNKNOWN" if not recognized.

Definition at line 40 of file lease6_callouts.cc.

References isc::dhcp::HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_CMTS, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_MODEM, isc::dhcp::HWAddr::HWADDR_SOURCE_DUID, isc::dhcp::HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL, isc::dhcp::HWAddr::HWADDR_SOURCE_RAW, isc::dhcp::HWAddr::HWADDR_SOURCE_REMOTE_ID, and isc::dhcp::HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID.

Referenced by genLease6Entry().

## ◆ lease6_decline()

int lease6_decline | ( | CalloutHandle & | handle | ) |

This callout is called at the "lease6_decline" hook.

Generates an entry in the legal log for a lease decline if the callout context values "leases6" and "deleted_leases6" are not empty.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 836 of file lease6_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getStatus(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, and isc::hooks::CalloutHandle::setContext().

Here is the call graph for this function:

## ◆ lease6_release()

int lease6_release | ( | CalloutHandle & | handle | ) |

This callout is called at the "lease6_release" hook.

Generates an entry in the legal log for a lease release if the callout context values "leases6" and "deleted_leases6" are not empty.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 808 of file lease6_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getStatus(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, and isc::hooks::CalloutHandle::setContext().

Here is the call graph for this function:

## ◆ leases6_committed()

int leases6_committed | ( | CalloutHandle & | handle | ) |

This callout is called at the "leases6_committed" hook.

Stores the leases so that the logging option stored on the subnet context can be available on pkt6_send hook.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 737 of file lease6_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getStatus(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, and isc::hooks::CalloutHandle::setContext().

Here is the call graph for this function:

## ◆ legalLog6Handler()

int legalLog6Handler | ( | CalloutHandle & | handle,
|  | const Action & | action )

Produces an DHCPv6 legal log entry from a callout handle.

Extracts the inbound packet and lease from the Callout, generates the log entry text and writes it to the legal store. If the the legal store has not been instantiated or writing to it fails, the function log the error and return failure.

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.
  action | Kind of event to log.

Returns
  returns 0 upon success, non-zero otherwise

Definition at line 671 of file lease6_callouts.cc.

References genLease6Addr(), genLease6Entry(), isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getContext(), isc::dhcp::CfgMgr::getCurrentCfg(), isc::hooks::CalloutHandle::getCurrentLibrary(), isc::dhcp::CfgMgr::instance(), isc::dhcp::LegalLogMgrFactory::instance(), isc::legal_log::isLoggingDisabled(), LEGAL_LOG_LEASE6_NO_LEGAL_STORE, LEGAL_LOG_LEASE6_WRITE_ERROR, isc::legal_log::legal_log_logger, and LOG_ERROR.

Referenced by pkt6_send().

Here is the call graph for this function:

## ◆ pkt6_receive()

int pkt6_receive | ( | CalloutHandle & | handle | ) |

This callout is called at the "pkt6_receive" hook.

Creates context with empty "lease6" value.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 722 of file lease6_callouts.cc.

References isc::hooks::CalloutHandle::setContext().

Here is the call graph for this function:

## ◆ pkt6_send()

int pkt6_send | ( | CalloutHandle & | handle | ) |

This callout is called at the "pkt6_send" hook.

Generates an entry in the legal log for a lease renewal if the callout context values "leases6" and "deleted_leases6" are not empty.

Parameters

  handle | CalloutHandle which provides access to context.

Returns
  0 upon success, non-zero otherwise.

Definition at line 762 of file lease6_callouts.cc.

References isc::dhcp::ASSIGN, isc::hooks::CalloutHandle::getContext(), isc::hooks::CalloutHandle::getStatus(), legalLog6Handler(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, isc::dhcp::RELEASE, and isc::hooks::CalloutHandle::setContext().

Here is the call graph for this function:

## ◆ replaceTokensForLease()

void replaceTokensForLease | ( | isc::dhcp::ExpressionPtr & | expression,
|  | const Lease6Ptr & | lease )

Replace TokenOption and TokenSubOption expression tokens for all IA_NA and IA_PD options and sub-options filtering by the current lease.

Parameters

  expression | The expression which is updated to contain only TokenOption and TokenSubOption expression tokens for IA_NA or IA_PD which have an OPTION_IAADDR or an OPTION_IAPREFIX that matches the respective lease.
  lease | The lease used to match any OPTION_IAADDR or OPTION_IAPREFIX option in the packet.

Definition at line 465 of file lease6_callouts.cc.

References filterLeaseIA_NA(), filterLeaseIA_PD(), isc::dhcp::Lease::TYPE_NA, and isc::dhcp::Lease::TYPE_PD.

Referenced by getCustomEntry().

Here is the call graph for this function: