Kea: radius_request.h Source File

| Kea 3.2.0-git

radius_request.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_REQUEST_H
8#define RADIUS_REQUEST_H
9
10#include <client_exchange.h>
11#include <radius.h>
12#include <dhcp/iface_mgr.h>
13#include <dhcpsrv/subnet_id.h>
14#include <dhcpsrv/timer_mgr.h>
15
16#include <functional>
17#include <sstream>
18
19namespace isc {
20namespace radius {
21
26 typedef std::function<void(int, AttributesPtr)> CallbackAuth;
27
31 typedef std::function<void(int)> CallbackAcct;
32
41uint32_t getNASPort(uint32_t subnet_id);
42
47 class RadiusRequest {
48public:
49
57 RadiusRequest(const MsgCode code,
58 uint32_t subnet_id,
59 const AttributesPtr& send_attrs,
60 bool sync,
61 const Exchange::Handler& handler);
62
64 virtual ~RadiusRequest() = default;
65
70 virtual void start() {
71 exchange_->start();
72 }
73
77 int getRC() const {
78 return (exchange_->getRC());
79 }
80
84 AttributesPtr getReqAttrs() const {
85 MessagePtr request = exchange_->getRequest();
86 if (request) {
87 return (request->getAttributes());
88 }
89 return (AttributesPtr());
90 }
91
95 AttributesPtr getRespAttrs() const {
96 MessagePtr response = exchange_->getResponse();
97 if (response) {
98 return (response->getAttributes());
99 }
100 return (AttributesPtr());
101 }
102
106 ExchangePtr getExchange() {
107 return (exchange_);
108 }
109
110protected:
112 uint32_t nas_port_;
113
115 ExchangePtr exchange_;
116};
117
119 class RadiusAuth : public RadiusRequest {
120public:
121
128 RadiusAuth(uint32_t subnet_id,
129 const AttributesPtr& send_attrs,
130 bool sync,
131 const Exchange::Handler& handler)
132 : RadiusRequest(PW_ACCESS_REQUEST, subnet_id, send_attrs, sync,
133 handler) {
134 }
135
137 virtual ~RadiusAuth() = default;
138};
139
141 class RadiusSyncAuth : public RadiusAuth {
142public:
143
149 RadiusSyncAuth(uint32_t subnet_id,
150 const AttributesPtr& send_attrs,
151 const CallbackAuth& callback)
152 : RadiusAuth(subnet_id, send_attrs, true, Exchange::Handler()),
153 callback_(callback) {
154 }
155
157 virtual ~RadiusSyncAuth() = default;
158
160 virtual void start() override;
161
162protected:
164 CallbackAuth callback_;
165};
166
168 typedef boost::shared_ptr<RadiusSyncAuth> RadiusSyncAuthPtr;
169
171 class RadiusAsyncAuth : public RadiusAuth {
172public:
173
179 RadiusAsyncAuth(uint32_t subnet_id,
180 const AttributesPtr& send_attrs,
181 const CallbackAuth& callback);
182
184 virtual ~RadiusAsyncAuth() = default;
185
187 virtual void start() override;
188
193 static void invokeCallback(const CallbackAuth& callback,
194 const ExchangePtr exchange);
195};
196
198 typedef boost::shared_ptr<RadiusAsyncAuth> RadiusAsyncAuthPtr;
199
201 class RadiusAcct : public RadiusRequest {
202public:
203
210 RadiusAcct(uint32_t subnet_id,
211 const AttributesPtr& send_attrs,
212 bool sync,
213 const Exchange::Handler& handler)
214 : RadiusRequest(PW_ACCOUNTING_REQUEST, subnet_id, send_attrs, sync,
215 handler) {
216 }
217
219 virtual ~RadiusAcct() = default;
220};
221
223 class RadiusSyncAcct : public RadiusAcct {
224public:
225
231 RadiusSyncAcct(uint32_t subnet_id,
232 const AttributesPtr& send_attrs,
233 const CallbackAcct& callback)
234 : RadiusAcct(subnet_id, send_attrs, true, Exchange::Handler()), callback_(callback) {
235 }
236
238 virtual ~RadiusSyncAcct() = default;
239
241 virtual void start() override;
242
243protected:
245 CallbackAcct callback_;
246};
247
249 typedef boost::shared_ptr<RadiusSyncAcct> RadiusSyncAcctPtr;
250
252 class RadiusAsyncAcct : public RadiusAcct {
253public:
254
260 RadiusAsyncAcct(uint32_t subnet_id,
261 const AttributesPtr& send_attrs,
262 const CallbackAcct& callback);
263
265 virtual ~RadiusAsyncAcct() = default;
266
268 virtual void start() override;
269
274 static void invokeCallback(const CallbackAcct& callback,
275 const ExchangePtr exchange);
276};
277
279 typedef boost::shared_ptr<RadiusAsyncAcct> RadiusAsyncAcctPtr;
280
281} // end of namespace radius
282} // end of namespace isc
283#endif // RADIUS_REQUEST_H
isc::radius::Exchange
RADIUS Base Exchange.
Definition client_exchange.h:58
isc::radius::Exchange::Handler
std::function< void(const ExchangePtr ex)> Handler
Termination handler.
Definition client_exchange.h:71
isc::radius::RadiusAcct::RadiusAcct
RadiusAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
Definition radius_request.h:210
isc::radius::RadiusAcct::~RadiusAcct
virtual ~RadiusAcct()=default
Destructor.
isc::radius::RadiusAsyncAcct::invokeCallback
static void invokeCallback(const CallbackAcct &callback, const ExchangePtr exchange)
Invoke accounting communication callback.
Definition radius_request.cc:230
isc::radius::RadiusAsyncAcct::start
virtual void start() override
Start communication.
Definition radius_request.cc:216
isc::radius::RadiusAsyncAcct::~RadiusAsyncAcct
virtual ~RadiusAsyncAcct()=default
Destructor.
isc::radius::RadiusAsyncAcct::RadiusAsyncAcct
RadiusAsyncAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAcct &callback)
Constructor.
Definition radius_request.cc:207
isc::radius::RadiusAsyncAuth::invokeCallback
static void invokeCallback(const CallbackAuth &callback, const ExchangePtr exchange)
Invoke authentication communication callback.
Definition radius_request.cc:134
isc::radius::RadiusAsyncAuth::start
virtual void start() override
Start communication.
Definition radius_request.cc:120
isc::radius::RadiusAsyncAuth::~RadiusAsyncAuth
virtual ~RadiusAsyncAuth()=default
Destructor.
isc::radius::RadiusAsyncAuth::RadiusAsyncAuth
RadiusAsyncAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAuth &callback)
Constructor.
Definition radius_request.cc:111
isc::radius::RadiusAuth::~RadiusAuth
virtual ~RadiusAuth()=default
Destructor.
isc::radius::RadiusAuth::RadiusAuth
RadiusAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
Definition radius_request.h:128
isc::radius::RadiusRequest::~RadiusRequest
virtual ~RadiusRequest()=default
Destructor.
isc::radius::RadiusRequest::getRC
int getRC() const
Get the error code.
Definition radius_request.h:77
isc::radius::RadiusRequest::RadiusRequest
RadiusRequest(const MsgCode code, uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
Definition radius_request.cc:37
isc::radius::RadiusRequest::getExchange
ExchangePtr getExchange()
Get the exchange.
Definition radius_request.h:106
isc::radius::RadiusRequest::getRespAttrs
AttributesPtr getRespAttrs() const
Get response attributes.
Definition radius_request.h:95
isc::radius::RadiusRequest::start
virtual void start()
Start communication.
Definition radius_request.h:70
isc::radius::RadiusRequest::nas_port_
uint32_t nas_port_
Client/NAS port (from Subnet Id).
Definition radius_request.h:112
isc::radius::RadiusRequest::getReqAttrs
AttributesPtr getReqAttrs() const
Get request attributes.
Definition radius_request.h:84
isc::radius::RadiusRequest::exchange_
ExchangePtr exchange_
Exchange.
Definition radius_request.h:115
isc::radius::RadiusSyncAcct::start
virtual void start() override
Start communication.
Definition radius_request.cc:174
isc::radius::RadiusSyncAcct::~RadiusSyncAcct
virtual ~RadiusSyncAcct()=default
Destructor.
isc::radius::RadiusSyncAcct::RadiusSyncAcct
RadiusSyncAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAcct &callback)
Constructor.
Definition radius_request.h:231
isc::radius::RadiusSyncAcct::callback_
CallbackAcct callback_
Accounting termination callback.
Definition radius_request.h:245
isc::radius::RadiusSyncAuth::RadiusSyncAuth
RadiusSyncAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAuth &callback)
Constructor.
Definition radius_request.h:149
isc::radius::RadiusSyncAuth::~RadiusSyncAuth
virtual ~RadiusSyncAuth()=default
Destructor.
isc::radius::RadiusSyncAuth::callback_
CallbackAuth callback_
Authentication termination callback.
Definition radius_request.h:164
isc::radius::RadiusSyncAuth::start
virtual void start() override
Start communication.
Definition radius_request.cc:71
client_exchange.h
iface_mgr.h
isc::radius
Definition cfg_attribute.cc:21
isc::radius::AttributesPtr
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
Definition client_attribute.h:963
isc::radius::CallbackAcct
std::function< void(int)> CallbackAcct
Type of callback for accounting termination.
Definition radius_request.h:31
isc::radius::RadiusAsyncAuthPtr
boost::shared_ptr< RadiusAsyncAuth > RadiusAsyncAuthPtr
Pointer to asynchronous authentication.
Definition radius_request.h:198
isc::radius::RadiusSyncAcctPtr
boost::shared_ptr< RadiusSyncAcct > RadiusSyncAcctPtr
Pointer to synchronous accounting.
Definition radius_request.h:249
isc::radius::ExchangePtr
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
Definition client_exchange.h:55
isc::radius::RadiusSyncAuthPtr
boost::shared_ptr< RadiusSyncAuth > RadiusSyncAuthPtr
Pointer to synchronous authentication.
Definition radius_request.h:168
isc::radius::CallbackAuth
std::function< void(int, AttributesPtr)> CallbackAuth
Type of callback for authentication termination.
Definition radius_request.h:26
isc::radius::MessagePtr
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
Definition client_message.h:262
isc::radius::MsgCode
MsgCode
Standard RADIUS message code.
Definition client_message.h:21
isc::radius::PW_ACCOUNTING_REQUEST
@ PW_ACCOUNTING_REQUEST
Definition client_message.h:25
isc::radius::PW_ACCESS_REQUEST
@ PW_ACCESS_REQUEST
Definition client_message.h:22
isc::radius::getNASPort
uint32_t getNASPort(uint32_t subnet_id)
Remap a subnet ID to a NAS port.
Definition radius_request.cc:24
isc::radius::RadiusAsyncAcctPtr
boost::shared_ptr< RadiusAsyncAcct > RadiusAsyncAcctPtr
Pointer to asynchronous accounting.
Definition radius_request.h:279
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
radius.h
subnet_id.h
timer_mgr.h