Kea 3.3.1
radius_backend.cc
Go to the documentation of this file.
1// Copyright (C) 2020-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
7#include <config.h>
8
11#include <radius.h>
12#include <radius_backend.h>
13#include <radius_log.h>
14#include <util/str.h>
15
16using namespace std;
17using namespace isc;
18using namespace isc::util::str;
19using namespace isc::asiolink;
20using namespace isc::dhcp;
21
22namespace isc {
23namespace radius {
24
27
30
33 const uint8_t* /*identifier_begin*/,
34 const size_t /*identifier_len*/) const {
35 return (ConstHostCollection());
36}
37
39RadiusBackend::getAll4(const isc::dhcp::SubnetID& /*subnet_id*/) const {
40 return (ConstHostCollection());
41}
42
44RadiusBackend::getAll6(const isc::dhcp::SubnetID& /*subnet_id*/) const {
45 return (ConstHostCollection());
46}
47
49RadiusBackend::getAllbyHostname(const std::string& /*hostname*/) const {
50 return (ConstHostCollection());
51}
52
54RadiusBackend::getAllbyHostname4(const std::string& /*hostname*/,
55 const dhcp::SubnetID& /*subnet_id*/) const {
56 return (ConstHostCollection());
57}
58
60RadiusBackend::getAllbyHostname6(const std::string& /*hostname*/,
61 const dhcp::SubnetID& /*subnet_id*/) const {
62 return (ConstHostCollection());
63}
64
67 size_t& /*source_index*/,
68 uint64_t /*lower_host_id*/,
69 const dhcp::HostPageSize& /*page_size*/) const {
70 return (ConstHostCollection());
71}
72
75 size_t& /*source_index*/,
76 uint64_t /*lower_host_id*/,
77 const dhcp::HostPageSize& /*page_size*/) const {
78 return (ConstHostCollection());
79}
80
82RadiusBackend::getPage4(size_t& /*source_index*/,
83 uint64_t /*lower_host_id*/,
84 const dhcp::HostPageSize& /*page_size*/) const {
85 return (ConstHostCollection());
86}
87
89RadiusBackend::getPage6(size_t& /*source_index*/,
90 uint64_t /*lower_host_id*/,
91 const dhcp::HostPageSize& /*page_size*/) const {
92 return (ConstHostCollection());
93}
94
97 return (ConstHostCollection());
98}
99
102 const isc::dhcp::Host::IdentifierType& identifier_type,
103 const uint8_t* identifier_begin,
104 const size_t identifier_len) const {
105 return (impl_->get4(subnet_id, identifier_type, identifier_begin,
106 identifier_len));
107}
108
111 const isc::asiolink::IOAddress& /*address*/) const {
112 return (ConstHostPtr());
113}
114
117 const isc::asiolink::IOAddress& /*address*/) const {
118 return (ConstHostCollection());
119}
120
123 const isc::dhcp::Host::IdentifierType& identifier_type,
124 const uint8_t* identifier_begin,
125 const size_t identifier_len) const {
126 return (impl_->get6(subnet_id, identifier_type, identifier_begin,
127 identifier_len));
128}
129
132 const uint8_t /*prefix_len*/) const {
133 return (ConstHostPtr());
134}
135
138 const isc::asiolink::IOAddress& /*address*/) const {
139 return (ConstHostPtr());
140}
141
144 const isc::asiolink::IOAddress& /*address*/) const {
145 return (ConstHostCollection());
146}
147
150 return (ConstHostCollection());
151}
152
153void
154RadiusBackend::add(const HostPtr& /*host*/) {
155}
156
157bool
158RadiusBackend::del(const SubnetID& /*subnet_id*/,
159 const IOAddress& /*address */) {
160 return (false);
161}
162
163bool
164RadiusBackend::del4(const SubnetID& /*subnet_id*/,
165 const Host::IdentifierType& /*identifier_type*/,
166 const uint8_t* /*identifier_begin*/,
167 const size_t /*identifier_len*/) {
168 return (false);
169}
170
171bool
172RadiusBackend::del6(const SubnetID& /*subnet_id*/,
173 const Host::IdentifierType& /*identifier_type*/,
174 const uint8_t* /*identifier_begin*/,
175 const size_t /*identifier_len*/) {
176 return (false);
177}
178
179bool
181 // This backend does not support the mode in which multiple reservations
182 // for the same IP address are created. If selecting this mode is
183 // attempted this function returns false to indicate that this is
184 // not allowed.
185 return (unique);
186}
187
188size_t
190 return (impl_->xcount4_);
191}
192
193size_t
195 return (impl_->xcount6_);
196}
197
200
203
206 const Host::IdentifierType& identifier_type,
207 const uint8_t* identifier_begin,
208 const size_t identifier_len) {
209 if (identifier_type != RadiusImpl::instance().id_type4_) {
210 // Not handle by us. Either it is used by host reservations
211 // in the configuration or it was left by accident (i.e. forgotten)
212 // in host-reservation-identifiers.
213 return (ConstHostPtr());
214 }
215 if (InHook::check()) {
216 // get4Any() was called for an entry not (yet) cached.
217 return (ConstHostPtr());
218 }
219 // Unexpected call.
220 ++xcount4_;
222 .arg(subnet_id)
223 .arg(dumpAsHex(identifier_begin, identifier_len))
224 .arg(Host::getIdentifierName(identifier_type));
225 return (ConstHostPtr());
226}
227
230 const Host::IdentifierType& identifier_type,
231 const uint8_t* identifier_begin,
232 const size_t identifier_len) {
233 if (identifier_type != RadiusImpl::instance().id_type6_) {
234 // Not handle by us. Either it is used by host reservations
235 // in the configuration or it was left by accident (i.e. forgotten)
236 // in host-reservation-identifiers.
237 return (ConstHostPtr());
238 }
239 if (InHook::check()) {
240 // get6Any() was called for an entry not (yet) cached.
241 return (ConstHostPtr());
242 }
243 // Unexpected call.
244 ++xcount6_;
246 .arg(subnet_id)
247 .arg(dumpAsHex(identifier_begin, identifier_len))
248 .arg(Host::getIdentifierName(identifier_type));
249 return (ConstHostPtr());
250}
251
252} // namespace radius
253} // namespace isc
Wraps value holding size of the page with host reservations.
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:356
IdentifierType
Type of the host identifier.
Definition host.h:337
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:729
Implementation of host backend for Radius.
size_t xcount4_
Unexpected call counter - IPv4.
size_t xcount6_
Unexpected call counter - IPv6.
isc::dhcp::ConstHostPtr get6(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Returns a host connected to the IPv6 subnet.
isc::dhcp::ConstHostPtr get4(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Host backend method in not const variant.
virtual ~RadiusBackendImpl()
Destructor.
virtual ~RadiusBackend()
Destructor.
virtual isc::dhcp::ConstHostCollection getAllbyHostname4(const std::string &hostname, const isc::dhcp::SubnetID &subnet_id) const override
Return all hosts with a hostname in a DHCPv4 subnet.
virtual isc::dhcp::ConstHostCollection getAllbyHostname6(const std::string &hostname, const isc::dhcp::SubnetID &subnet_id) const override
Return all hosts with a hostname in a DHCPv6 subnet.
virtual isc::dhcp::ConstHostCollection getAllbyHostname(const std::string &hostname) const override
Return all hosts with a hostname.
virtual isc::dhcp::ConstHostCollection getPage6(const isc::dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const override
Return range of hosts in a specified DHCPv6 subnet.
boost::shared_ptr< RadiusBackendImpl > impl_
Implementation.
virtual void add(const isc::dhcp::HostPtr &host) override
Adds a new host to the collection.
virtual bool del6(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) override
Attempts to delete a host by (subnet-id6, identifier, identifier-type).
virtual isc::dhcp::ConstHostCollection getAll6(const isc::dhcp::SubnetID &subnet_id) const override
Return all hosts in a specified DHCPv6 subnet.
virtual isc::dhcp::ConstHostCollection getAll(const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
From base class.
virtual isc::dhcp::ConstHostPtr get4(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
Returns a host connected to the IPv4 subnet.
size_t getUnexpected4() const
Return unexpected calls for IPv4.
virtual bool del4(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) override
Attempts to delete a host by (subnet-id4, identifier, identifier-type).
virtual bool setIPReservationsUnique(const bool unique) override
Controls whether IP reservations are unique or non-unique.
virtual bool del(const isc::dhcp::SubnetID &subnet_id, const isc::asiolink::IOAddress &addr) override
Attempts to delete a host by (subnet-id, address).
virtual isc::dhcp::ConstHostPtr get6(const isc::dhcp::SubnetID &subnet_id, const isc::dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
Returns a host connected to the IPv6 subnet.
virtual isc::dhcp::ConstHostCollection getAll4(const isc::dhcp::SubnetID &subnet_id) const override
Return all hosts in a specified DHCPv4 subnet.
virtual isc::dhcp::ConstHostCollection getPage4(const isc::dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const override
Return range of hosts in a specified DHCPv4 subnet.
size_t getUnexpected6() const
Return unexpected calls for IPv6.
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:192
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:843
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
const int RADIUS_DBG_TRACE
Radius logging levels.
Definition radius_log.h:26
const isc::log::MessageID RADIUS_BACKEND_GET6
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
Definition radius_log.h:35
const isc::log::MessageID RADIUS_BACKEND_GET4
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
Definition str.cc:330
Defines the logger used by the top-level component of kea-lfc.