Kea 3.1.1
lease4_callouts.cc File Reference
#include <config.h>
#include <asiolink/asio_wrapper.h>
#include <cc/data.h>
#include <dhcp/pkt4.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_subnets4.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 lease4_callouts.cc:

Go to the source code of this file.

Functions

std::string genLease4Entry (CalloutHandle &handle, const Pkt4Ptr &query, const Pkt4Ptr &response, const Lease4Ptr &lease, const Action &action)
 Creates legal store entry for a DHCPv4 Lease.
 
bool getCustomEntry (CalloutHandle &handle, const Pkt4Ptr &query, const Pkt4Ptr &response, const Lease4Ptr &, std::string &value)
 Create custom log entry for the current lease.
 
int lease4_decline (CalloutHandle &handle)
 This callout is called at the "lease4_decline" hook.
 
int lease4_release (CalloutHandle &handle)
 This callout is called at the "lease4_release" hook.
 
int leases4_committed (CalloutHandle &handle)
 This callout is called at the "leases4_committed" hook.
 
int legalLog4Handler (CalloutHandle &handle, const Action &action)
 Produces an DHCPv4 legal log entry from a callout handle.
 
int pkt4_receive (CalloutHandle &handle)
 This callout is called at the "pkt4_receive" hook.
 
int pkt4_send (CalloutHandle &handle)
 This callout is called at the "pkt4_send" hook.
 

Function Documentation

◆ genLease4Entry()

std::string genLease4Entry ( CalloutHandle & handle,
const Pkt4Ptr & query,
const Pkt4Ptr & response,
const Lease4Ptr & lease,
const Action & action )

Creates legal store entry for a DHCPv4 Lease.

Creates an entry based on the given DHCPREQUEST and corresponding DHCPv4 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>{client-info}{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 IPv4 address 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 hardware address shown as numerical type and hex digit string.
  • client-info - the DHCP client id option (61) if present, shown as hex digit string and eventually its printable content.
  • relay-info - for relayed packets the giaddr and the RAI circuit id and remote 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 CET Address: 192.2.1.100 has been renewed
for 1 hrs 52 min 15 secs to a device with hardware address:
hwtype=1 08:00:2b:02:3f:4e, client-id: 17:34:e2:ff:09:92:54
connected via relay at address: 192.2.16.33, identified by
circuit-id: 68:6f:77:64:79 (howdy) and remote-id: 87:f6:79:77:ef"
Parameters
handleCalloutHandle which provides access to context.
queryDHCPv4 query packet for which the lease was generated
responseDHCPv4 response packet
leaseDHCPv4 lease for which the entry should be created
actionKind of event to log.

Definition at line 93 of file lease4_callouts.cc.

References isc::dhcp::actionToVerb(), isc::dhcp::DHO_DHCP_AGENT_OPTIONS, isc::dhcp::LegalLogMgr::genDurationString(), getCustomEntry(), isc::util::str::isPrintable(), isc::asiolink::IOAddress::isV4Zero(), isc::dhcp::RAI_OPTION_AGENT_CIRCUIT_ID, isc::dhcp::RAI_OPTION_REMOTE_ID, isc::dhcp::RAI_OPTION_SUBSCRIBER_ID, isc::dhcp::RELEASE, isc::asiolink::IOAddress::toText(), isc::dhcp::LegalLogMgr::vectorDump(), and isc::dhcp::LegalLogMgr::vectorHexDump().

Referenced by legalLog4Handler().

+ Here is the call graph for this function:

◆ getCustomEntry()

bool getCustomEntry ( CalloutHandle & handle,
const Pkt4Ptr & query,
const Pkt4Ptr & response,
const Lease4Ptr & ,
std::string & value )

Create custom log entry for the current lease.

Parameters
handleCalloutHandle which provides access to context.
queryThe query received by the server.
responseThe response of the server.
leaseThe current lease generating this log entry.
[out]valueThe value of the custom log entry after parser execution.

Definition at line 38 of file lease4_callouts.cc.

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

Referenced by genLease4Entry().

+ Here is the call graph for this function:

◆ lease4_decline()

int lease4_decline ( CalloutHandle & handle)

This callout is called at the "lease4_decline" hook.

Generates an entry in the legal log for a lease decline if the callout context value "lease4" is not an empty pointer.

Parameters
handleCalloutHandle which provides access to context.
Returns
0 upon success, non-zero otherwise.

Definition at line 380 of file lease4_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getStatus(), legalLog4Handler(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, isc::dhcp::RELEASE, isc::hooks::CalloutHandle::setArgument(), and isc::hooks::CalloutHandle::setContext().

+ Here is the call graph for this function:

◆ lease4_release()

int lease4_release ( CalloutHandle & handle)

This callout is called at the "lease4_release" hook.

Generates an entry in the legal log for a lease release if the callout context value "lease4" is not an empty pointer.

Parameters
handleCalloutHandle which provides access to context.
Returns
0 upon success, non-zero otherwise.

Definition at line 355 of file lease4_callouts.cc.

References isc::hooks::CalloutHandle::getArgument(), isc::hooks::CalloutHandle::getStatus(), legalLog4Handler(), CalloutHandle::NEXT_STEP_DROP, CalloutHandle::NEXT_STEP_SKIP, isc::dhcp::RELEASE, isc::hooks::CalloutHandle::setArgument(), and isc::hooks::CalloutHandle::setContext().

+ Here is the call graph for this function:

◆ leases4_committed()

int leases4_committed ( CalloutHandle & handle)

This callout is called at the "leases4_committed" hook.

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

Parameters
handleCalloutHandle which provides access to context.
Returns
0 upon success, non-zero otherwise.

Definition at line 284 of file lease4_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:

◆ legalLog4Handler()

int legalLog4Handler ( CalloutHandle & handle,
const Action & action )

Produces an DHCPv4 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
handleCalloutHandle which provides access to context.
actionKind of event to log.
Returns
returns 0 upon success, non-zero otherwise

Definition at line 217 of file lease4_callouts.cc.

References genLease4Entry(), 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_LEASE4_NO_LEGAL_STORE, LEGAL_LOG_LEASE4_WRITE_ERROR, isc::legal_log::legal_log_logger, and LOG_ERROR.

Referenced by lease4_decline(), lease4_release(), and pkt4_send().

+ Here is the call graph for this function:

◆ pkt4_receive()

int pkt4_receive ( CalloutHandle & handle)

This callout is called at the "pkt4_receive" hook.

Creates context with empty "lease4" value.

Parameters
handleCalloutHandle which provides access to context.
Returns
0 upon success, non-zero otherwise.

Definition at line 269 of file lease4_callouts.cc.

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

+ Here is the call graph for this function:

◆ pkt4_send()

int pkt4_send ( CalloutHandle & handle)

This callout is called at the "pkt4_send" hook.

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

Parameters
handleCalloutHandle which provides access to context.
Returns
0 upon success, non-zero otherwise.

Definition at line 309 of file lease4_callouts.cc.

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

+ Here is the call graph for this function: