Kea: stat_cmds_callouts.cc Source File

| Kea 3.0.3-git

stat_cmds_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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 <stat_cmds.h>
14#include <stat_cmds_log.h>
15#include <cc/command_interpreter.h>
16#include <dhcpsrv/cfgmgr.h>
17#include <hooks/hooks.h>
18#include <process/daemon.h>
19
20using namespace isc::dhcp;
21using namespace isc::hooks;
22using namespace isc::process;
23using namespace isc::stat_cmds;
24
25extern "C" {
26
33 int stat_lease4_get(CalloutHandle& handle) {
34 StatCmds stat_cmds;
35 return(stat_cmds.statLease4GetHandler(handle));
36}
37
44 int stat_lease6_get(CalloutHandle& handle) {
45 StatCmds stat_cmds;
46 return(stat_cmds.statLease6GetHandler(handle));
47}
48
53 int load(LibraryHandle& handle) {
54 // Make the hook library not loadable by d2 or ca.
55 uint16_t family = CfgMgr::instance().getFamily();
56 const std::string& proc_name = Daemon::getProcName();
57 if (family == AF_INET) {
58 if (proc_name != "kea-dhcp4") {
59 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
60 << ", expected kea-dhcp4");
61 }
62 } else {
63 if (proc_name != "kea-dhcp6") {
64 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
65 << ", expected kea-dhcp6");
66 }
67 }
68
69 handle.registerCommandCallout("stat-lease4-get", stat_lease4_get);
70 handle.registerCommandCallout("stat-lease6-get", stat_lease6_get);
71 LOG_INFO(stat_cmds_logger, STAT_CMDS_INIT_OK);
72 return (0);
73}
74
78 int unload() {
79 LOG_INFO(stat_cmds_logger, STAT_CMDS_DEINIT_OK);
80 return (0);
81}
82
86 int multi_threading_compatible() {
87 return (1);
88}
89
90} // end extern "C"
cfgmgr.h
isc::Unexpected
A generic exception that is thrown when an unexpected error condition occurs.
Definition exceptions/exceptions.h:153
isc::dhcp::CfgMgr::getFamily
uint16_t getFamily() const
Returns address family.
Definition cfgmgr.h:246
isc::dhcp::CfgMgr::instance
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
isc::hooks::CalloutHandle
Per-packet callout handle.
Definition callout_handle.h:78
isc::hooks::LibraryHandle
Library handle.
Definition library_handle.h:60
isc::hooks::LibraryHandle::registerCommandCallout
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
Definition library_handle.cc:36
isc::process::Daemon::getProcName
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:151
isc::stat_cmds::StatCmds
Implements the logic for processing commands pertaining to stat manipulation.
Definition stat_cmds.h:25
command_interpreter.h
This file contains several functions and constants that are used for handling commands and responses ...
daemon.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
hooks.h
LOG_INFO
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::hooks
Definition callout_handle.cc:21
isc::process
Definition cb_ctl_base.h:22
isc::stat_cmds
Definition stat_cmds.cc:38
isc::stat_cmds::stat_cmds_logger
isc::log::Logger stat_cmds_logger("stat-cmds-hooks")
Definition stat_cmds_log.h:17
stat_cmds.h
stat_lease6_get
int stat_lease6_get(CalloutHandle &handle)
This is a command callout for 'stat-lease6-get' command.
Definition stat_cmds_callouts.cc:44
stat_lease4_get
int stat_lease4_get(CalloutHandle &handle)
This is a command callout for 'stat-lease4-get' command.
Definition stat_cmds_callouts.cc:33
multi_threading_compatible
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
Definition stat_cmds_callouts.cc:86
unload
int unload()
This function is called when the library is unloaded.
Definition stat_cmds_callouts.cc:78
load
int load(LibraryHandle &handle)
This function is called when the library is loaded.
Definition stat_cmds_callouts.cc:53
stat_cmds_log.h
STAT_CMDS_DEINIT_OK
const isc::log::MessageID STAT_CMDS_DEINIT_OK
STAT_CMDS_INIT_OK
const isc::log::MessageID STAT_CMDS_INIT_OK