Kea 3.3.3
forensic_log/load_unload.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2026 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
8
9#include <config.h>
10
11#include <asiolink/io_service.h>
13#include <cc/data.h>
15#include <dhcpsrv/cfgmgr.h>
19#include <hooks/hooks.h>
20#include <process/daemon.h>
21
22#include <sstream>
23#include <string>
24
25#include <boost/lexical_cast.hpp>
26
27#include <legal_syslog.h>
28
29using namespace isc;
30using namespace isc::asiolink;
31using namespace isc::data;
32using namespace isc::db;
33using namespace isc::dhcp;
34using namespace isc::hooks;
35using namespace isc::process;
36using namespace isc::legal_log;
37using namespace std;
38
39// Functions accessed by the hooks framework use C linkage to avoid the name
40// mangling that accompanies use of the C++ compiler as well as to avoid
41// issues related to namespaces.
42extern "C" {
43
50int load(LibraryHandle& handle) {
51 try {
52 // Make the hook library not loadable by d2.
53 uint16_t family = CfgMgr::instance().getFamily();
54 const string& proc_name = Daemon::getProcName();
55 if (family == AF_INET) {
56 if (proc_name != "kea-dhcp4") {
57 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
58 << ", expected kea-dhcp4");
59 }
60 } else {
61 if (proc_name != "kea-dhcp6") {
62 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
63 << ", expected kea-dhcp6");
64 }
65 }
66
69
70 // Get and decode parameters.
71 ConstElementPtr const& parameters(handle.getParameters());
73
74 try {
75 LegalLogMgr::parseConfig(parameters, map);
77 } catch (const isc::db::DbOpenErrorWithRetry& err) {
78 string redacted;
79 try {
81 } catch (...) {
82 }
84 .arg(redacted).arg(err.what());
85 }
86
87 } catch (const std::exception& ex) {
88 // Log the error and return failure.
90 .arg(ex.what());
91 return (1);
92 }
93
94 return (0);
95}
96
103int unload() {
104 try {
105 // Since it's "global" Let's explicitly destroy it now rather
106 // than indeterminately. Note, LegalLogMgr destructor will close
107 // the store.
109
112 } catch (const std::exception& ex) {
113 // On the off chance something goes awry, catch it and log it.
114 // @todo Not sure if we should return a non-zero result or not.
116 .arg(ex.what());
117 }
118
119 return (0);
120}
121
126 return (1);
127}
128
129}
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
static std::string redactedAccessString(const ParameterMap &parameters)
Redact database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database but permit retries.
uint16_t getFamily() const
Returns address family.
Definition cfgmgr.h:246
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition cfgmgr.cc:29
static bool unregisterBackendFactory(const std::string &db_type, bool no_log=false)
Unregisters the backend factory function for a given backend type.
static void addBackend(db::DatabaseConnection::ParameterMap &parameters, ManagerID id=0)
Create an instance of a forensic log backend.
static void delAllBackends()
Removes all backends from the pool.
static bool registerBackendFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Registers new backend factory function for a given backend type.
static void parseConfig(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
int getLibraryIndex() const
Get library index.
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
static isc::dhcp::LegalLogMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap &parameters)
Factory class method.
static isc::dhcp::LegalLogMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap &parameters)
Factory class method.
static std::string getProcName()
returns the process name This value is used as when forming the default PID file name
Definition daemon.cc:156
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int unload()
Called by the Hooks library manager when the library is unloaded.
int load(LibraryHandle &handle)
Called by the Hooks library manager when the library is loaded.
const isc::log::MessageID LEGAL_LOG_UNLOAD_ERROR
const isc::log::MessageID LEGAL_LOG_LOAD_ERROR
const isc::log::MessageID LEGAL_LOG_DB_OPEN_CONNECTION_WITH_RETRY_FAILED
Defines the abstract class for backend stores.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::log::Logger legal_log_logger("legal-log-hooks")
Legal Log Logger.
Defines the logger used by the top-level component of kea-lfc.
Defines the class, RotatingFile, which implements an appending text file that rotates to a new file o...