Kea 3.1.1
radius_backend.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2025 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
15using namespace std;
16using namespace isc;
17using namespace isc::asiolink;
18using namespace isc::dhcp;
19
20namespace isc {
21namespace radius {
22
25
28
31 const uint8_t* /*identifier_begin*/,
32 const size_t /*identifier_len*/) const {
33 return (ConstHostCollection());
34}
35
37RadiusBackend::getAll4(const isc::dhcp::SubnetID& /*subnet_id*/) const {
38 return (ConstHostCollection());
39}
40
42RadiusBackend::getAll6(const isc::dhcp::SubnetID& /*subnet_id*/) const {
43 return (ConstHostCollection());
44}
45
47RadiusBackend::getAllbyHostname(const std::string& /*hostname*/) const {
48 return (ConstHostCollection());
49}
50
52RadiusBackend::getAllbyHostname4(const std::string& /*hostname*/,
53 const dhcp::SubnetID& /*subnet_id*/) const {
54 return (ConstHostCollection());
55}
56
58RadiusBackend::getAllbyHostname6(const std::string& /*hostname*/,
59 const dhcp::SubnetID& /*subnet_id*/) const {
60 return (ConstHostCollection());
61}
62
65 size_t& /*source_index*/,
66 uint64_t /*lower_host_id*/,
67 const dhcp::HostPageSize& /*page_size*/) const {
68 return (ConstHostCollection());
69}
70
73 size_t& /*source_index*/,
74 uint64_t /*lower_host_id*/,
75 const dhcp::HostPageSize& /*page_size*/) const {
76 return (ConstHostCollection());
77}
78
80RadiusBackend::getPage4(size_t& /*source_index*/,
81 uint64_t /*lower_host_id*/,
82 const dhcp::HostPageSize& /*page_size*/) const {
83 return (ConstHostCollection());
84}
85
87RadiusBackend::getPage6(size_t& /*source_index*/,
88 uint64_t /*lower_host_id*/,
89 const dhcp::HostPageSize& /*page_size*/) const {
90 return (ConstHostCollection());
91}
92
95 return (ConstHostCollection());
96}
97
100 const isc::dhcp::Host::IdentifierType& identifier_type,
101 const uint8_t* identifier_begin,
102 const size_t identifier_len) const {
103 return (impl_->get4(subnet_id, identifier_type, identifier_begin,
104 identifier_len));
105}
106
109 const isc::asiolink::IOAddress& /*address*/) const {
110 return (ConstHostPtr());
111}
112
115 const isc::asiolink::IOAddress& /*address*/) const {
116 return (ConstHostCollection());
117}
118
121 const isc::dhcp::Host::IdentifierType& identifier_type,
122 const uint8_t* identifier_begin,
123 const size_t identifier_len) const {
124 return (impl_->get6(subnet_id, identifier_type, identifier_begin,
125 identifier_len));
126}
127
130 const uint8_t /*prefix_len*/) const {
131 return (ConstHostPtr());
132}
133
136 const isc::asiolink::IOAddress& /*address*/) const {
137 return (ConstHostPtr());
138}
139
142 const isc::asiolink::IOAddress& /*address*/) const {
143 return (ConstHostCollection());
144}
145
148 return (ConstHostCollection());
149}
150
151void
152RadiusBackend::add(const HostPtr& /*host*/) {
153}
154
155bool
156RadiusBackend::del(const SubnetID& /*subnet_id*/,
157 const IOAddress& /*address */) {
158 return (false);
159}
160
161bool
162RadiusBackend::del4(const SubnetID& /*subnet_id*/,
163 const Host::IdentifierType& /*identifier_type*/,
164 const uint8_t* /*identifier_begin*/,
165 const size_t /*identifier_len*/) {
166 return (false);
167}
168
169bool
170RadiusBackend::del6(const SubnetID& /*subnet_id*/,
171 const Host::IdentifierType& /*identifier_type*/,
172 const uint8_t* /*identifier_begin*/,
173 const size_t /*identifier_len*/) {
174 return (false);
175}
176
177bool
179 // This backend does not support the mode in which multiple reservations
180 // for the same IP address are created. If selecting this mode is
181 // attempted this function returns false to indicate that this is
182 // not allowed.
183 return (unique);
184}
185
186size_t
188 return (impl_->xcount4_);
189}
190
191size_t
193 return (impl_->xcount6_);
194}
195
198
201
204 const Host::IdentifierType& identifier_type,
205 const uint8_t* identifier_begin,
206 const size_t identifier_len) {
207 if (identifier_type != RadiusImpl::instance().id_type4_) {
208 // Not handle by us. Either it is used by host reservations
209 // in the configuration or it was left by accident (i.e. forgotten)
210 // in host-reservation-identifiers.
211 return (ConstHostPtr());
212 }
213 if (InHook::check()) {
214 // get4Any() was called for an entry not (yet) cached.
215 return (ConstHostPtr());
216 }
217 // Unexpected call.
218 ++xcount4_;
219 ostringstream id;
220 for (unsigned i = 0; i < identifier_len; ++i) {
221 if (i > 0) {
222 id << ':';
223 }
224 id << hex << setfill('0') << setw(2) << identifier_begin[i];
225 }
227 .arg(subnet_id)
228 .arg(id.str())
229 .arg(Host::getIdentifierName(identifier_type));
230 return (ConstHostPtr());
231}
232
235 const Host::IdentifierType& identifier_type,
236 const uint8_t* identifier_begin,
237 const size_t identifier_len) {
238 if (identifier_type != RadiusImpl::instance().id_type6_) {
239 // Not handle by us. Either it is used by host reservations
240 // in the configuration or it was left by accident (i.e. forgotten)
241 // in host-reservation-identifiers.
242 return (ConstHostPtr());
243 }
244 if (InHook::check()) {
245 // get6Any() was called for an entry not (yet) cached.
246 return (ConstHostPtr());
247 }
248 // Unexpected call.
249 ++xcount6_;
250 ostringstream id;
251 for (unsigned i = 0; i < identifier_len; ++i) {
252 if (i > 0) {
253 id << ':';
254 }
255 id << hex << setfill('0') << setw(2) << identifier_begin[i];
256 }
258 .arg(subnet_id)
259 .arg(id.str())
260 .arg(Host::getIdentifierName(identifier_type));
261 return (ConstHostPtr());
262}
263
264} // namespace radius
265} // namespace isc
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
Definition host.h:337
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:349
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:511
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:37
#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
Defines the logger used by the top-level component of kea-lfc.