Kea 3.3.3
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/radius.h>
13#include <util/str.h>
14
15#include <radius_log.h>
16
17using namespace std;
18using namespace isc;
19using namespace isc::util::str;
20using namespace isc::asiolink;
21using namespace isc::dhcp;
22
23namespace isc {
24namespace radius {
25
28
31
34 const uint8_t* /*identifier_begin*/,
35 const size_t /*identifier_len*/) const {
36 return (ConstHostCollection());
37}
38
40RadiusBackend::getAll4(const isc::dhcp::SubnetID& /*subnet_id*/) const {
41 return (ConstHostCollection());
42}
43
45RadiusBackend::getAll6(const isc::dhcp::SubnetID& /*subnet_id*/) const {
46 return (ConstHostCollection());
47}
48
50RadiusBackend::getAllbyHostname(const std::string& /*hostname*/) const {
51 return (ConstHostCollection());
52}
53
55RadiusBackend::getAllbyHostname4(const std::string& /*hostname*/,
56 const dhcp::SubnetID& /*subnet_id*/) const {
57 return (ConstHostCollection());
58}
59
61RadiusBackend::getAllbyHostname6(const std::string& /*hostname*/,
62 const dhcp::SubnetID& /*subnet_id*/) const {
63 return (ConstHostCollection());
64}
65
68 size_t& /*source_index*/,
69 uint64_t /*lower_host_id*/,
70 const dhcp::HostPageSize& /*page_size*/) const {
71 return (ConstHostCollection());
72}
73
76 size_t& /*source_index*/,
77 uint64_t /*lower_host_id*/,
78 const dhcp::HostPageSize& /*page_size*/) const {
79 return (ConstHostCollection());
80}
81
83RadiusBackend::getPage4(size_t& /*source_index*/,
84 uint64_t /*lower_host_id*/,
85 const dhcp::HostPageSize& /*page_size*/) const {
86 return (ConstHostCollection());
87}
88
90RadiusBackend::getPage6(size_t& /*source_index*/,
91 uint64_t /*lower_host_id*/,
92 const dhcp::HostPageSize& /*page_size*/) const {
93 return (ConstHostCollection());
94}
95
98 return (ConstHostCollection());
99}
100
103 const isc::dhcp::Host::IdentifierType& identifier_type,
104 const uint8_t* identifier_begin,
105 const size_t identifier_len) const {
106 return (impl_->get4(subnet_id, identifier_type, identifier_begin,
107 identifier_len));
108}
109
112 const isc::asiolink::IOAddress& /*address*/) const {
113 return (ConstHostPtr());
114}
115
118 const isc::asiolink::IOAddress& /*address*/) const {
119 return (ConstHostCollection());
120}
121
124 const isc::dhcp::Host::IdentifierType& identifier_type,
125 const uint8_t* identifier_begin,
126 const size_t identifier_len) const {
127 return (impl_->get6(subnet_id, identifier_type, identifier_begin,
128 identifier_len));
129}
130
133 const uint8_t /*prefix_len*/) const {
134 return (ConstHostPtr());
135}
136
139 const isc::asiolink::IOAddress& /*address*/) const {
140 return (ConstHostPtr());
141}
142
145 const isc::asiolink::IOAddress& /*address*/) const {
146 return (ConstHostCollection());
147}
148
151 return (ConstHostCollection());
152}
153
154void
155RadiusBackend::add(const HostPtr& /*host*/) {
156}
157
158bool
159RadiusBackend::del(const SubnetID& /*subnet_id*/,
160 const IOAddress& /*address */) {
161 return (false);
162}
163
164bool
165RadiusBackend::del4(const SubnetID& /*subnet_id*/,
166 const Host::IdentifierType& /*identifier_type*/,
167 const uint8_t* /*identifier_begin*/,
168 const size_t /*identifier_len*/) {
169 return (false);
170}
171
172bool
173RadiusBackend::del6(const SubnetID& /*subnet_id*/,
174 const Host::IdentifierType& /*identifier_type*/,
175 const uint8_t* /*identifier_begin*/,
176 const size_t /*identifier_len*/) {
177 return (false);
178}
179
180bool
182 // This backend does not support the mode in which multiple reservations
183 // for the same IP address are created. If selecting this mode is
184 // attempted this function returns false to indicate that this is
185 // not allowed.
186 return (unique);
187}
188
189size_t
191 return (impl_->xcount4_);
192}
193
194size_t
196 return (impl_->xcount6_);
197}
198
201
204
207 const Host::IdentifierType& identifier_type,
208 const uint8_t* identifier_begin,
209 const size_t identifier_len) {
210 if (identifier_type != RadiusImpl::instance().id_type4_) {
211 // Not handle by us. Either it is used by host reservations
212 // in the configuration or it was left by accident (i.e. forgotten)
213 // in host-reservation-identifiers.
214 return (ConstHostPtr());
215 }
216 if (InHook::check()) {
217 // get4Any() was called for an entry not (yet) cached.
218 return (ConstHostPtr());
219 }
220 // Unexpected call.
221 ++xcount4_;
223 .arg(subnet_id)
224 .arg(dumpAsHex(identifier_begin, identifier_len))
225 .arg(Host::getIdentifierName(identifier_type));
226 return (ConstHostPtr());
227}
228
231 const Host::IdentifierType& identifier_type,
232 const uint8_t* identifier_begin,
233 const size_t identifier_len) {
234 if (identifier_type != RadiusImpl::instance().id_type6_) {
235 // Not handle by us. Either it is used by host reservations
236 // in the configuration or it was left by accident (i.e. forgotten)
237 // in host-reservation-identifiers.
238 return (ConstHostPtr());
239 }
240 if (InHook::check()) {
241 // get6Any() was called for an entry not (yet) cached.
242 return (ConstHostPtr());
243 }
244 // Unexpected call.
245 ++xcount6_;
247 .arg(subnet_id)
248 .arg(dumpAsHex(identifier_begin, identifier_len))
249 .arg(Host::getIdentifierName(identifier_type));
250 return (ConstHostPtr());
251}
252
253} // namespace radius
254} // 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:340
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:731
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:194
#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:840
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:846
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:843
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.