Kea: radius.h Source File

| Kea 3.0.3-git

radius.h
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#ifndef RADIUS_H
8#define RADIUS_H
9
10#include <cfg_attribute.h>
11#include <client_exchange.h>
12#include <radius_backend.h>
13#include <exceptions/exceptions.h>
14#include <cc/data.h>
15#include <asiolink/asio_wrapper.h>
16#include <asiolink/io_service.h>
17#include <asiolink/io_service_thread_pool.h>
18#include <dhcpsrv/cache_host_data_source.h>
19#include <dhcpsrv/host.h>
20
21#include <boost/noncopyable.hpp>
22#include <boost/shared_ptr.hpp>
23
24#include <atomic>
25#include <list>
26#include <map>
27#include <mutex>
28#include <thread>
29#include <unordered_set>
30#include <vector>
31
32namespace isc {
33namespace radius {
34
37static const uint32_t SUBNET_ID_DEFAULT = 0;
38
40class RadiusAccess;
41
43class RadiusAccounting;
44
46class RadiusImpl;
47 typedef boost::shared_ptr<RadiusImpl> RadiusImplPtr;
48
50 class RadiusImpl : public data::CfgToElement, public boost::noncopyable {
51public:
52
57 static RadiusImpl& instance();
58
60 ~RadiusImpl();
61
63 void reset();
64
69 void init(data::ElementPtr& config);
70
74 void checkEarlyGlobalResvLookup();
75
84 void checkSharedNetworks();
85
97 bool checkHostBackends();
98
102 void startServices();
103
107 isc::asiolink::IOServicePtr getIOContext() {
108 return (io_context_);
109 }
110
114 void setIOContext(isc::asiolink::IOServicePtr io_service) {
115 io_context_ = io_service;
116 }
117
121 isc::asiolink::IOServicePtr getIOService() {
122 return (io_service_);
123 }
124
128 void setIOService(isc::asiolink::IOServicePtr io_service) {
129 io_service_ = io_service;
130 }
131
135 data::ElementPtr toElement() const override;
136
140 void registerExchange(ExchangePtr exchange);
141
145 void unregisterExchange(ExchangePtr exchange);
146
148 std::string dictionary_;
149
151 std::map<uint32_t, uint32_t> remap_;
152
153 // @brief Pointer to access (never null).
154 boost::shared_ptr<RadiusAccess> auth_;
155
157 boost::shared_ptr<RadiusAccounting> acct_;
158
160 dhcp::CacheHostDataSourcePtr cache_;
161
163 RadiusBackendPtr backend_;
164
166 std::string bindaddr_;
167
169 bool canonical_mac_address_;
170
172 bool clientid_pop0_;
173
175 bool clientid_printable_;
176
178 unsigned deadtime_;
179
181 bool extract_duid_;
182
184 bool reselect_subnet_pool_;
185
187 bool reselect_subnet_address_;
188
190 unsigned retries_;
191
193 std::string session_history_filename_;
194
196 unsigned thread_pool_size_;
197
199 unsigned timeout_;
200
202 dhcp::Host::IdentifierType id_type4_;
203
205 dhcp::Host::IdentifierType id_type6_;
206
208 asiolink::IoServiceThreadPoolPtr thread_pool_;
209
211 static std::atomic<bool> shutdown_;
212
213protected:
215 RadiusImpl();
216
220 static const RadiusImplPtr& instancePtr();
221
223 void cleanup();
224
231 void checkPausePermissions();
232
236 void pauseThreadPool();
237
241 void resumeThreadPool();
242
243private:
244
246 isc::asiolink::IOServicePtr io_context_;
247
249 isc::asiolink::IOServicePtr io_service_;
250
252 std::list<ExchangePtr> exchange_list_;
253
255 std::mutex mutex_;
256};
257
259 class InHook {
260public:
264 InHook();
265
269 ~InHook();
270
272 static bool check();
273
274private:
276 static std::unordered_set<std::thread::id> set_;
277
279 static std::mutex mutex_;
280};
281
282} // end of namespace isc::radius
283} // end of namespace isc
284
285#endif
asio_wrapper.h
cache_host_data_source.h
cfg_attribute.h
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
isc::radius::InHook::~InHook
~InHook()
Destructor.
Definition radius.cc:502
isc::radius::InHook::check
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:511
isc::radius::InHook::InHook
InHook()
Constructor.
Definition radius.cc:493
isc::radius::RadiusAccess
Radius access class.
Definition radius_access.h:164
isc::radius::RadiusAccounting
Radius accounting class.
Definition radius_accounting.h:180
isc::radius::RadiusImpl
Radius hooks library implementation.
Definition radius.h:50
isc::radius::RadiusImpl::shutdown_
static std::atomic< bool > shutdown_
Flag which indicates that the instance is shutting down.
Definition radius.h:211
isc::radius::RadiusImpl::thread_pool_size_
unsigned thread_pool_size_
Thread pool size.
Definition radius.h:196
isc::radius::RadiusImpl::resumeThreadPool
void resumeThreadPool()
Resume the thread pool.
Definition radius.cc:244
isc::radius::RadiusImpl::~RadiusImpl
~RadiusImpl()
Destructor.
Definition radius.cc:58
isc::radius::RadiusImpl::checkSharedNetworks
void checkSharedNetworks()
Check shared network server configuration.
Definition radius.cc:323
isc::radius::RadiusImpl::dictionary_
std::string dictionary_
Dictionary path.
Definition radius.h:148
isc::radius::RadiusImpl::checkHostBackends
bool checkHostBackends()
Check host backends (cache and radius).
Definition radius.cc:377
isc::radius::RadiusImpl::RadiusImpl
RadiusImpl()
Protected constructor.
Definition radius.cc:47
isc::radius::RadiusImpl::cache_
dhcp::CacheHostDataSourcePtr cache_
Host cache.
Definition radius.h:160
isc::radius::RadiusImpl::bindaddr_
std::string bindaddr_
bindaddr.
Definition radius.h:166
isc::radius::RadiusImpl::clientid_pop0_
bool clientid_pop0_
Client Id pop leading zero(s).
Definition radius.h:172
isc::radius::RadiusImpl::getIOContext
isc::asiolink::IOServicePtr getIOContext()
Get the hook I/O service.
Definition radius.h:107
isc::radius::RadiusImpl::id_type4_
dhcp::Host::IdentifierType id_type4_
Identifier type for IPv4.
Definition radius.h:202
isc::radius::RadiusImpl::reset
void reset()
Reset the state as it was just created.
Definition radius.cc:124
isc::radius::RadiusImpl::unregisterExchange
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:72
isc::radius::RadiusImpl::pauseThreadPool
void pauseThreadPool()
Pause the thread pool.
Definition radius.cc:229
isc::radius::RadiusImpl::reselect_subnet_address_
bool reselect_subnet_address_
Reselect subnet using address.
Definition radius.h:187
isc::radius::RadiusImpl::init
void init(data::ElementPtr &config)
Initialize.
Definition radius.cc:130
isc::radius::RadiusImpl::registerExchange
void registerExchange(ExchangePtr exchange)
Register Exchange.
Definition radius.cc:67
isc::radius::RadiusImpl::auth_
boost::shared_ptr< RadiusAccess > auth_
Definition radius.h:154
isc::radius::RadiusImpl::extract_duid_
bool extract_duid_
Extract Duid from Client Id.
Definition radius.h:181
isc::radius::RadiusImpl::startServices
void startServices()
Start the I/O mechanisms.
Definition radius.cc:155
isc::radius::RadiusImpl::timeout_
unsigned timeout_
Timeout.
Definition radius.h:199
isc::radius::RadiusImpl::id_type6_
dhcp::Host::IdentifierType id_type6_
Identifier type for IPv6.
Definition radius.h:205
isc::radius::RadiusImpl::canonical_mac_address_
bool canonical_mac_address_
Canonical MAC address.
Definition radius.h:169
isc::radius::RadiusImpl::deadtime_
unsigned deadtime_
Deadtime.
Definition radius.h:178
isc::radius::RadiusImpl::backend_
RadiusBackendPtr backend_
Radius backend.
Definition radius.h:163
isc::radius::RadiusImpl::acct_
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
Definition radius.h:157
isc::radius::RadiusImpl::cleanup
void cleanup()
Clean up members.
Definition radius.cc:77
isc::radius::RadiusImpl::thread_pool_
asiolink::IoServiceThreadPoolPtr thread_pool_
Thread pool.
Definition radius.h:208
isc::radius::RadiusImpl::toElement
data::ElementPtr toElement() const override
Unparse implementation configuration.
Definition radius.cc:411
isc::radius::RadiusImpl::retries_
unsigned retries_
Retries.
Definition radius.h:190
isc::radius::RadiusImpl::remap_
std::map< uint32_t, uint32_t > remap_
Subnet ID to NAS port map.
Definition radius.h:151
isc::radius::RadiusImpl::instancePtr
static const RadiusImplPtr & instancePtr()
Returns pointer to the sole instance of radius implementation.
Definition radius.cc:42
isc::radius::RadiusImpl::session_history_filename_
std::string session_history_filename_
Session history filename.
Definition radius.h:193
isc::radius::RadiusImpl::setIOContext
void setIOContext(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:114
isc::radius::RadiusImpl::reselect_subnet_pool_
bool reselect_subnet_pool_
Reselect subnet using pool.
Definition radius.h:184
isc::radius::RadiusImpl::checkEarlyGlobalResvLookup
void checkEarlyGlobalResvLookup()
Check the early global host reservations lookup flag.
Definition radius.cc:314
isc::radius::RadiusImpl::clientid_printable_
bool clientid_printable_
Client Id try printable.
Definition radius.h:175
isc::radius::RadiusImpl::setIOService
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:128
isc::radius::RadiusImpl::getIOService
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
Definition radius.h:121
isc::radius::RadiusImpl::instance
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:37
isc::radius::RadiusImpl::checkPausePermissions
void checkPausePermissions()
Check if the current thread can transition the thread pool to the paused state.
Definition radius.cc:209
client_exchange.h
data.h
exceptions.h
host.h
io_service.h
io_service_thread_pool.h
isc::asiolink::IoServiceThreadPoolPtr
boost::shared_ptr< IoServiceThreadPool > IoServiceThreadPoolPtr
Defines a pointer to a thread pool.
Definition io_service_thread_pool.h:260
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:28
isc::config
Definition command_interpreter.cc:23
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::dhcp::CacheHostDataSourcePtr
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
Definition cache_host_data_source.h:63
isc::radius
Definition cfg_attribute.cc:21
isc::radius::RadiusImplPtr
boost::shared_ptr< RadiusImpl > RadiusImplPtr
Definition radius.h:47
isc::radius::ExchangePtr
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
Definition client_exchange.h:55
isc::radius::RadiusBackendPtr
boost::shared_ptr< RadiusBackend > RadiusBackendPtr
Pointer to host backend.
Definition radius_backend.h:349
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
radius_backend.h
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition cfg_to_element.h:29