Kea 3.1.1
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>
14#include <cc/data.h>
16#include <asiolink/io_service.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
44
46class RadiusImpl;
47typedef boost::shared_ptr<RadiusImpl> RadiusImplPtr;
48
50class RadiusImpl : public data::CfgToElement, public boost::noncopyable {
51public:
52
57 static RadiusImpl& instance();
58
61
63 void reset();
64
70
75
85
97 bool checkHostBackends();
98
102 void startServices();
103
108 return (io_context_);
109 }
110
115 io_context_ = io_service;
116 }
117
122 return (io_service_);
123 }
124
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
161
164
166 std::string bindaddr_;
167
170
173
176
178 unsigned deadtime_;
179
182
185
188
190 unsigned retries_;
191
194
197
199 unsigned timeout_;
200
203
206
209
211 static std::atomic<bool> shutdown_;
212
213protected:
215 RadiusImpl();
216
220 static const RadiusImplPtr& instancePtr();
221
223 void cleanup();
224
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
259class 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
IdentifierType
Type of the host identifier.
Definition host.h:337
~InHook()
Destructor.
Definition radius.cc:502
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:511
InHook()
Constructor.
Definition radius.cc:493
Radius access class.
Radius accounting class.
Radius hooks library implementation.
Definition radius.h:50
static std::atomic< bool > shutdown_
Flag which indicates that the instance is shutting down.
Definition radius.h:211
unsigned thread_pool_size_
Thread pool size.
Definition radius.h:196
void resumeThreadPool()
Resume the thread pool.
Definition radius.cc:244
~RadiusImpl()
Destructor.
Definition radius.cc:58
void checkSharedNetworks()
Check shared network server configuration.
Definition radius.cc:323
std::string dictionary_
Dictionary path.
Definition radius.h:148
bool checkHostBackends()
Check host backends (cache and radius).
Definition radius.cc:377
RadiusImpl()
Protected constructor.
Definition radius.cc:47
dhcp::CacheHostDataSourcePtr cache_
Host cache.
Definition radius.h:160
std::string bindaddr_
bindaddr.
Definition radius.h:166
bool clientid_pop0_
Client Id pop leading zero(s).
Definition radius.h:172
isc::asiolink::IOServicePtr getIOContext()
Get the hook I/O service.
Definition radius.h:107
dhcp::Host::IdentifierType id_type4_
Identifier type for IPv4.
Definition radius.h:202
void reset()
Reset the state as it was just created.
Definition radius.cc:124
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:72
void pauseThreadPool()
Pause the thread pool.
Definition radius.cc:229
bool reselect_subnet_address_
Reselect subnet using address.
Definition radius.h:187
void init(data::ElementPtr &config)
Initialize.
Definition radius.cc:130
void registerExchange(ExchangePtr exchange)
Register Exchange.
Definition radius.cc:67
boost::shared_ptr< RadiusAccess > auth_
Definition radius.h:154
bool extract_duid_
Extract Duid from Client Id.
Definition radius.h:181
void startServices()
Start the I/O mechanisms.
Definition radius.cc:155
unsigned timeout_
Timeout.
Definition radius.h:199
dhcp::Host::IdentifierType id_type6_
Identifier type for IPv6.
Definition radius.h:205
bool canonical_mac_address_
Canonical MAC address.
Definition radius.h:169
unsigned deadtime_
Deadtime.
Definition radius.h:178
RadiusBackendPtr backend_
Radius backend.
Definition radius.h:163
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
Definition radius.h:157
void cleanup()
Clean up members.
Definition radius.cc:77
asiolink::IoServiceThreadPoolPtr thread_pool_
Thread pool.
Definition radius.h:208
data::ElementPtr toElement() const override
Unparse implementation configuration.
Definition radius.cc:411
unsigned retries_
Retries.
Definition radius.h:190
std::map< uint32_t, uint32_t > remap_
Subnet ID to NAS port map.
Definition radius.h:151
static const RadiusImplPtr & instancePtr()
Returns pointer to the sole instance of radius implementation.
Definition radius.cc:42
std::string session_history_filename_
Session history filename.
Definition radius.h:193
void setIOContext(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:114
bool reselect_subnet_pool_
Reselect subnet using pool.
Definition radius.h:184
void checkEarlyGlobalResvLookup()
Check the early global host reservations lookup flag.
Definition radius.cc:314
bool clientid_printable_
Client Id try printable.
Definition radius.h:175
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:128
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
Definition radius.h:121
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:37
void checkPausePermissions()
Check if the current thread can transition the thread pool to the paused state.
Definition radius.cc:209
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
boost::shared_ptr< RadiusImpl > RadiusImplPtr
Definition radius.h:47
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
boost::shared_ptr< RadiusBackend > RadiusBackendPtr
Pointer to host backend.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.