Kea 2.2.0
flex_option_callouts.cc
Go to the documentation of this file.
1// Copyright (C) 2019-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#include <config.h>
8
9#include <flex_option.h>
10#include <flex_option_log.h>
12#include <hooks/hooks.h>
13#include <dhcp/pkt4.h>
14#include <dhcp/pkt6.h>
15
16namespace isc {
17namespace flex_option {
18
20
21} // end of namespace flex_option
22} // end of namespace isc
23
24using namespace isc;
25using namespace isc::data;
26using namespace isc::dhcp;
27using namespace isc::hooks;
28using namespace isc::flex_option;
29
30// Functions accessed by the hooks framework use C linkage to avoid the name
31// mangling that accompanies use of the C++ compiler as well as to avoid
32// issues related to namespaces.
33extern "C" {
34
46 if (status == CalloutHandle::NEXT_STEP_DROP) {
47 return (0);
48 }
49
50 // Sanity.
51 if (!impl) {
52 return (0);
53 }
54
55 // Get the parameters.
56 Pkt4Ptr query;
57 Pkt4Ptr response;
58 handle.getArgument("query4", query);
59 handle.getArgument("response4", response);
60
61 if (status == CalloutHandle::NEXT_STEP_SKIP) {
62 isc_throw(InvalidOperation, "packet pack already handled");
63 }
64
65 try {
66 impl->process<Pkt4Ptr>(Option::V4, query, response);
67 } catch (const std::exception& ex) {
69 .arg(query->getLabel())
70 .arg(ex.what());
71 }
72
73 return (0);
74}
75
87 if (status == CalloutHandle::NEXT_STEP_DROP) {
88 return (0);
89 }
90
91 // Sanity.
92 if (!impl) {
93 return (0);
94 }
95
96 if (status == CalloutHandle::NEXT_STEP_SKIP) {
97 isc_throw(InvalidOperation, "packet pack already handled");
98 }
99
100 // Get the parameters.
101 Pkt6Ptr query;
102 Pkt6Ptr response;
103 handle.getArgument("query6", query);
104 handle.getArgument("response6", response);
105
106 try {
107 impl->process<Pkt6Ptr>(Option::V6, query, response);
108 } catch (const std::exception& ex) {
110 .arg(query->getLabel())
111 .arg(ex.what());
112 }
113
114 return (0);
115}
116
121int load(LibraryHandle& handle) {
122 try {
123 impl.reset(new FlexOptionImpl());
124 ConstElementPtr options = handle.getParameter("options");
125 impl->configure(options);
126 } catch (const std::exception& ex) {
128 .arg(ex.what());
129 return (1);
130 }
131
132 return (0);
133}
134
138int unload() {
139 impl.reset();
141 return (0);
142}
143
148 return (1);
149}
150
151} // end extern "C"
A generic exception that is thrown if a function is called in a prohibited way.
Flex Option implementation.
Definition: flex_option.h:37
Per-packet callout handle.
CalloutNextStep
Specifies allowed next steps.
CalloutNextStep getStatus() const
Returns the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
isc::data::ConstElementPtr getParameter(const std::string &name)
Returns configuration parameter for the library.
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.
int multi_threading_compatible()
This function is called to retrieve the multi-threading compatibility.
int pkt6_send(CalloutHandle &handle)
This callout is called at the "pkt6_send" hook.
int pkt4_send(CalloutHandle &handle)
This callout is called at the "pkt4_send" hook.
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 FLEX_OPTION_PROCESS_ERROR
const isc::log::MessageID FLEX_OPTION_LOAD_ERROR
const isc::log::MessageID FLEX_OPTION_UNLOAD
#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:27
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:544
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
FlexOptionImplPtr impl
isc::log::Logger flex_option_logger("flex-option-hooks")
boost::shared_ptr< FlexOptionImpl > FlexOptionImplPtr
The type of shared pointers to Flex Option implementations.
Definition: flex_option.h:645
Defines the logger used by the top-level component of kea-lfc.