Kea  2.3.2-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 
20 using namespace isc::dhcp;
21 using namespace isc::hooks;
22 using namespace isc::process;
23 using namespace isc::stat_cmds;
24 
25 extern "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 
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);
72  return (0);
73 }
74 
78 int unload() {
80  return (0);
81 }
82 
87  return (1);
88 }
89 
90 } // end extern "C"
const isc::log::MessageID STAT_CMDS_INIT_OK
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Implements the logic for processing commands pertaining to stat manipulation.
Definition: stat_cmds.h:25
Per-packet callout handle.
uint16_t getFamily() const
Returns address family.
Definition: cfgmgr.h:280
A generic exception that is thrown when an unexpected error condition occurs.
int stat_lease4_get(CalloutHandle &handle)
This is a command callout for &#39;stat-lease4-get&#39; command.
int load(LibraryHandle &handle)
This function is called when the library is loaded.
int statLease4GetHandler(hooks::CalloutHandle &handle)
stat-lease4-get command handler
Definition: stat_cmds.cc:718
int stat_lease6_get(CalloutHandle &handle)
This is a command callout for &#39;stat-lease6-get&#39; command.
int statLease6GetHandler(hooks::CalloutHandle &handle)
stat-lease6-get command handler
Definition: stat_cmds.cc:731
This file contains several functions and constants that are used for handling commands and responses ...
int unload()
This function is called when the library is unloaded.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
const isc::log::MessageID STAT_CMDS_DEINIT_OK
isc::log::Logger stat_cmds_logger("stat-cmds-hooks")
Definition: stat_cmds_log.h:17