Kea 2.7.6
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>
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
34 StatCmds stat_cmds;
35 return(stat_cmds.statLease4GetHandler(handle));
36}
37
45 StatCmds stat_cmds;
46 return(stat_cmds.statLease6GetHandler(handle));
47}
48
53int 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);
72 return (0);
73}
74
78int unload() {
80 return (0);
81}
82
87 return (1);
88}
89
90} // end extern "C"
A generic exception that is thrown when an unexpected error condition occurs.
uint16_t getFamily() const
Returns address family.
Definition cfgmgr.h:235
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:28
Per-packet callout handle.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:129
Implements the logic for processing commands pertaining to stat manipulation.
Definition stat_cmds.h:25
int statLease4GetHandler(hooks::CalloutHandle &handle)
stat-lease4-get command handler
Definition stat_cmds.cc:743
int statLease6GetHandler(hooks::CalloutHandle &handle)
stat-lease6-get command handler
Definition stat_cmds.cc:756
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
isc::log::Logger stat_cmds_logger("stat-cmds-hooks")
int stat_lease6_get(CalloutHandle &handle)
This is a command callout for 'stat-lease6-get' command.
int stat_lease4_get(CalloutHandle &handle)
This is a command callout for 'stat-lease4-get' command.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int unload()
This function is called when the library is unloaded.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
const isc::log::MessageID STAT_CMDS_DEINIT_OK
const isc::log::MessageID STAT_CMDS_INIT_OK