Kea 3.3.1
radius.h
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#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#include <tcp/tcp_client.h>
21
22#include <boost/noncopyable.hpp>
23#include <boost/shared_ptr.hpp>
24
25#include <atomic>
26#include <list>
27#include <map>
28#include <mutex>
29#include <thread>
30#include <unordered_set>
31#include <vector>
32
33namespace isc {
34namespace radius {
35
39class UdpClient {
40public:
47 UdpClient(const asiolink::IOServicePtr& io_service,
48 unsigned thread_pool_size = 0);
49
51 ~UdpClient();
52
54 void start();
55
60 void stop();
61
67 void checkPermissions();
68
72 void pause();
73
77 void resume();
78
85
89 unsigned getThreadPoolSize() const;
90
94 void registerExchange(ExchangePtr exchange);
95
99 void unregisterExchange(ExchangePtr exchange);
100
106
108 static size_t exchangeListMaxSize;
109
110private:
112 isc::asiolink::IOServicePtr io_service_;
113
115 unsigned thread_pool_size_;
116
118 isc::asiolink::IOServicePtr thread_io_service_;
119
122
124 std::list<ExchangePtr> exchange_list_;
125
127 std::mutex mutex_;
128};
129
131typedef boost::shared_ptr<UdpClient> UdpClientPtr;
132
135static const uint32_t SUBNET_ID_DEFAULT = 0;
136
138class RadiusTls;
139
141class RadiusAccess;
142
144class RadiusAccounting;
145
147class RadiusImpl;
148typedef boost::shared_ptr<RadiusImpl> RadiusImplPtr;
149
151class RadiusImpl : public data::CfgToElement, public boost::noncopyable {
152public:
153
158 static RadiusImpl& instance();
159
161 ~RadiusImpl();
162
164 void reset();
165
171
176
185 void checkSharedNetworks();
186
198 bool checkHostBackends();
199
203 void startServices();
204
208 bool serveAccess() const;
209
213 bool serveAccounting() const;
214
218 const Servers& getAccessServers() const;
219
223 const Servers& getAccountingServers() const;
224
226 void setAccessIdleTimer();
227
230
235 return (io_context_);
236 }
237
242 io_context_ = io_service;
243 }
244
249 return (io_service_);
250 }
251
256 io_service_ = io_service;
257 }
258
262 data::ElementPtr toElement() const override;
263
267 void registerExchange(ExchangePtr exchange);
268
272 void unregisterExchange(ExchangePtr exchange);
273
279
281 std::string dictionary_;
282
285
288
291
293 std::map<uint32_t, uint32_t> remap_;
294
296 boost::shared_ptr<RadiusTls> tls_;
297
299 boost::shared_ptr<RadiusAccess> auth_;
300
302 boost::shared_ptr<RadiusAccounting> acct_;
303
306
309
311 std::string bindaddr_;
312
315
318
321
323 unsigned deadtime_;
324
327
330
333
335 unsigned retries_;
336
339
342
344 unsigned timeout_;
345
348
351
354
356 static std::atomic<bool> shutdown_;
357
358protected:
360 RadiusImpl();
361
365 static const RadiusImplPtr& instancePtr();
366
368 void cleanup();
369
370private:
371
373 isc::asiolink::IOServicePtr io_context_;
374
376 isc::asiolink::IOServicePtr io_service_;
377};
378
380class InHook {
381public:
385 InHook();
386
390 ~InHook();
391
393 static bool check();
394
395private:
397 static std::unordered_set<std::thread::id> set_;
398
400 static std::mutex mutex_;
401};
402
403} // end of namespace isc::radius
404} // end of namespace isc
405
406#endif
IdentifierType
Type of the host identifier.
Definition host.h:337
~InHook()
Destructor.
Definition radius.cc:720
static bool check()
Check if the current thread is in hook code or not.
Definition radius.cc:729
InHook()
Constructor.
Definition radius.cc:711
Radius access class.
Radius accounting class.
Radius hooks library implementation.
Definition radius.h:151
static std::atomic< bool > shutdown_
Flag which indicates that the instance is shutting down.
Definition radius.h:356
unsigned thread_pool_size_
Thread pool size.
Definition radius.h:341
~RadiusImpl()
Destructor.
Definition radius.cc:216
void checkSharedNetworks()
Check shared network server configuration.
Definition radius.cc:533
std::string dictionary_
Dictionary path.
Definition radius.h:281
bool checkHostBackends()
Check host backends (cache and radius).
Definition radius.cc:587
RadiusImpl()
Protected constructor.
Definition radius.cc:202
boost::shared_ptr< RadiusTls > tls_
Pointer to tls (never null).
Definition radius.h:296
dhcp::CacheHostDataSourcePtr cache_
Host cache.
Definition radius.h:305
std::string bindaddr_
bindaddr.
Definition radius.h:311
bool clientid_pop0_
Client Id pop leading zero(s).
Definition radius.h:317
isc::asiolink::IOServicePtr getIOContext()
Get the hook I/O service.
Definition radius.h:234
void setAccountingIdleTimer()
Set the accounting idle timer.
Definition radius.cc:456
const Servers & getAccessServers() const
Get servers for access.
Definition radius.cc:426
dhcp::Host::IdentifierType id_type4_
Identifier type for IPv4.
Definition radius.h:347
void reset()
Reset the state as it was just created.
Definition radius.cc:299
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:231
bool reselect_subnet_address_
Reselect subnet using address.
Definition radius.h:332
void init(data::ElementPtr &config)
Initialize.
Definition radius.cc:305
void registerExchange(ExchangePtr exchange)
Register Exchange.
Definition radius.cc:225
boost::shared_ptr< RadiusAccess > auth_
Pointer to access (never null).
Definition radius.h:299
bool extract_duid_
Extract Duid from Client Id.
Definition radius.h:326
void startServices()
Start the I/O mechanisms.
Definition radius.cc:331
unsigned timeout_
Timeout.
Definition radius.h:344
dhcp::Host::IdentifierType id_type6_
Identifier type for IPv6.
Definition radius.h:350
bool canonical_mac_address_
Canonical MAC address.
Definition radius.h:314
unsigned deadtime_
Deadtime.
Definition radius.h:323
bool serveAccounting() const
Check if accounting is served.
Definition radius.cc:412
RadiusBackendPtr backend_
Radius backend.
Definition radius.h:308
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
Definition radius.h:302
void cleanup()
Clean up members.
Definition radius.cc:244
data::ElementPtr toElement() const override
Unparse implementation configuration.
Definition radius.cc:621
bool checkExchangeListRoom()
Check Exchange List Room.
Definition radius.cc:237
unsigned retries_
Retries.
Definition radius.h:335
std::map< uint32_t, uint32_t > remap_
Subnet ID to NAS port map.
Definition radius.h:293
UdpClientPtr udp_client_
UDP client.
Definition radius.h:287
static const RadiusImplPtr & instancePtr()
Returns pointer to the sole instance of radius implementation.
Definition radius.cc:197
const Servers & getAccountingServers() const
Get servers for accounting.
Definition radius.cc:435
std::string session_history_filename_
Session history filename.
Definition radius.h:338
void setIOContext(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:241
void setAccessIdleTimer()
Set the access idle timer.
Definition radius.cc:444
bool reselect_subnet_pool_
Reselect subnet using pool.
Definition radius.h:329
isc::tcp::TcpClientPtr tcp_client_
TCP client.
Definition radius.h:290
void checkEarlyGlobalResvLookup()
Check the early global host reservations lookup flag.
Definition radius.cc:524
bool clientid_printable_
Client Id try printable.
Definition radius.h:320
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition radius.h:255
RadiusProtocol proto_
Transport protocol.
Definition radius.h:284
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
Definition radius.h:248
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:192
bool serveAccess() const
Check if access is served.
Definition radius.cc:398
bool use_message_authenticator_
Use Message-Authenticator attribute.
Definition radius.h:353
Radius service for TLS transport.
Definition radius_tls.h:16
void registerExchange(ExchangePtr exchange)
Register Exchange.
Definition radius.cc:172
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:178
~UdpClient()
Destructor.
Definition radius.cc:79
const asiolink::IOServicePtr getThreadIOService() const
Fetches a pointer to the internal IOService used to drive the thread-pool in multi-threaded mode.
Definition radius.cc:89
void checkPermissions()
Check if the current thread can perform thread pool state transition.
Definition radius.cc:123
void resume()
Resumes running the client's thread pool.
Definition radius.cc:158
void stop()
Halts client-side IO activity.
Definition radius.cc:104
static size_t exchangeListMaxSize
Exchange List Maximum Size (currently the max(200,soft_limit/2)).
Definition radius.h:108
UdpClient(const asiolink::IOServicePtr &io_service, unsigned thread_pool_size=0)
Constructor.
Definition radius.cc:59
void pause()
Pauses the client's thread pool.
Definition radius.cc:143
void start()
Starts running the client's thread pool, if multi-threaded.
Definition radius.cc:94
bool checkExchangeListRoom()
Check Exchange List Room.
Definition radius.cc:184
unsigned getThreadPoolSize() const
Fetches the maximum size of the thread pool.
Definition radius.cc:84
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
boost::shared_ptr< RadiusImpl > RadiusImplPtr
Definition radius.h:148
boost::shared_ptr< UdpClient > UdpClientPtr
Pointer to UDP client.
Definition radius.h:131
RadiusProtocol
Transport protocols.
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
boost::shared_ptr< RadiusBackend > RadiusBackendPtr
Pointer to host backend.
boost::shared_ptr< TcpClient > TcpClientPtr
Defines a pointer to an TcpClient instance.
Definition tcp_client.h:346
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.