Kea: radius_request.h Source File

| Kea 3.0.3-git

radius_request.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_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
25 typedef std::function<void(int, AttributesPtr)> CallbackAuth;
26
29 typedef std::function<void(int)> CallbackAcct;
30
39uint32_t getNASPort(uint32_t subnet_id);
40
44 class RadiusRequest {
45public:
46
54 RadiusRequest(const MsgCode code,
55 uint32_t subnet_id,
56 const AttributesPtr& send_attrs,
57 bool sync,
58 const Exchange::Handler& handler);
59
61 virtual ~RadiusRequest() = default;
62
66 virtual void start() {
67 exchange_->start();
68 }
69
71 int getRC() const {
72 return (exchange_->getRC());
73 }
74
78 AttributesPtr getReqAttrs() const {
79 MessagePtr request = exchange_->getRequest();
80 if (request) {
81 return (request->getAttributes());
82 }
83 return (AttributesPtr());
84 }
85
89 AttributesPtr getRespAttrs() const {
90 MessagePtr response = exchange_->getResponse();
91 if (response) {
92 return (response->getAttributes());
93 }
94 return (AttributesPtr());
95 }
96
100 ExchangePtr getExchange() {
101 return (exchange_);
102 }
103
104protected:
106 uint32_t nas_port_;
107
109 ExchangePtr exchange_;
110};
111
113 class RadiusAuth : public RadiusRequest {
114public:
115
122 RadiusAuth(uint32_t subnet_id,
123 const AttributesPtr& send_attrs,
124 bool sync,
125 const Exchange::Handler& handler)
126 : RadiusRequest(PW_ACCESS_REQUEST, subnet_id, send_attrs, sync,
127 handler) {
128 }
129
131 virtual ~RadiusAuth() = default;
132};
133
135 class RadiusSyncAuth : public RadiusAuth {
136public:
137
143 RadiusSyncAuth(uint32_t subnet_id,
144 const AttributesPtr& send_attrs,
145 const CallbackAuth& callback)
146 : RadiusAuth(subnet_id, send_attrs, true, Exchange::Handler()),
147 callback_(callback) {
148 }
149
151 virtual ~RadiusSyncAuth() = default;
152
154 virtual void start() override;
155
156protected:
158 CallbackAuth callback_;
159};
160
162 typedef boost::shared_ptr<RadiusSyncAuth> RadiusSyncAuthPtr;
163
165 class RadiusAsyncAuth : public RadiusAuth {
166public:
167
173 RadiusAsyncAuth(uint32_t subnet_id,
174 const AttributesPtr& send_attrs,
175 const CallbackAuth& callback);
176
178 virtual ~RadiusAsyncAuth() = default;
179
181 virtual void start() override;
182
187 static void invokeCallback(const CallbackAuth& callback,
188 const ExchangePtr exchange);
189};
190
192 typedef boost::shared_ptr<RadiusAsyncAuth> RadiusAsyncAuthPtr;
193
195 class RadiusAcct : public RadiusRequest {
196public:
197
204 RadiusAcct(uint32_t subnet_id,
205 const AttributesPtr& send_attrs,
206 bool sync,
207 const Exchange::Handler& handler)
208 : RadiusRequest(PW_ACCOUNTING_REQUEST, subnet_id, send_attrs, sync,
209 handler) {
210 }
211
213 virtual ~RadiusAcct() = default;
214};
215
217 class RadiusSyncAcct : public RadiusAcct {
218public:
219
225 RadiusSyncAcct(uint32_t subnet_id,
226 const AttributesPtr& send_attrs,
227 const CallbackAcct& callback)
228 : RadiusAcct(subnet_id, send_attrs, true, Exchange::Handler()), callback_(callback) {
229 }
230
232 virtual ~RadiusSyncAcct() = default;
233
235 virtual void start() override;
236
237protected:
239 CallbackAcct callback_;
240};
241
243 typedef boost::shared_ptr<RadiusSyncAcct> RadiusSyncAcctPtr;
244
246 class RadiusAsyncAcct : public RadiusAcct {
247public:
248
254 RadiusAsyncAcct(uint32_t subnet_id,
255 const AttributesPtr& send_attrs,
256 const CallbackAcct& callback);
257
259 virtual ~RadiusAsyncAcct() = default;
260
262 virtual void start() override;
263
268 static void invokeCallback(const CallbackAcct& callback,
269 const ExchangePtr exchange);
270};
271
273 typedef boost::shared_ptr<RadiusAsyncAcct> RadiusAsyncAcctPtr;
274
275} // end of namespace radius
276} // end of namespace isc
277#endif // RADIUS_REQUEST_H
isc::radius::Exchange
RADIUS 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:204
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:224
isc::radius::RadiusAsyncAcct::start
virtual void start() override
Start communication.
Definition radius_request.cc:210
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:201
isc::radius::RadiusAsyncAuth::invokeCallback
static void invokeCallback(const CallbackAuth &callback, const ExchangePtr exchange)
Invoke authentication communication callback.
Definition radius_request.cc:132
isc::radius::RadiusAsyncAuth::start
virtual void start() override
Start communication.
Definition radius_request.cc:118
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:109
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:122
isc::radius::RadiusRequest::~RadiusRequest
virtual ~RadiusRequest()=default
Destructor.
isc::radius::RadiusRequest::getRC
int getRC() const
Get the error code.
Definition radius_request.h:71
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:100
isc::radius::RadiusRequest::getRespAttrs
AttributesPtr getRespAttrs() const
Get response attributes.
Definition radius_request.h:89
isc::radius::RadiusRequest::start
virtual void start()
Start communication.
Definition radius_request.h:66
isc::radius::RadiusRequest::nas_port_
uint32_t nas_port_
Client/NAS port (from Subnet Id).
Definition radius_request.h:106
isc::radius::RadiusRequest::getReqAttrs
AttributesPtr getReqAttrs() const
Get request attributes.
Definition radius_request.h:78
isc::radius::RadiusRequest::exchange_
ExchangePtr exchange_
Exchange.
Definition radius_request.h:109
isc::radius::RadiusSyncAcct::start
virtual void start() override
Start communication.
Definition radius_request.cc:169
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:225
isc::radius::RadiusSyncAcct::callback_
CallbackAcct callback_
Accounting termination callback.
Definition radius_request.h:239
isc::radius::RadiusSyncAuth::RadiusSyncAuth
RadiusSyncAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAuth &callback)
Constructor.
Definition radius_request.h:143
isc::radius::RadiusSyncAuth::~RadiusSyncAuth
virtual ~RadiusSyncAuth()=default
Destructor.
isc::radius::RadiusSyncAuth::callback_
CallbackAuth callback_
Authentication termination callback.
Definition radius_request.h:158
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:799
isc::radius::CallbackAcct
std::function< void(int)> CallbackAcct
Type of callback for accounting termination.
Definition radius_request.h:29
isc::radius::RadiusAsyncAuthPtr
boost::shared_ptr< RadiusAsyncAuth > RadiusAsyncAuthPtr
Pointer to asynchronous authentication.
Definition radius_request.h:192
isc::radius::RadiusSyncAcctPtr
boost::shared_ptr< RadiusSyncAcct > RadiusSyncAcctPtr
Pointer to synchronous accounting.
Definition radius_request.h:243
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:162
isc::radius::CallbackAuth
std::function< void(int, AttributesPtr)> CallbackAuth
Type of callback for authentication termination.
Definition radius_request.h:25
isc::radius::MessagePtr
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
Definition client_message.h:251
isc::radius::MsgCode
MsgCode
Standard RADIUS message code.
Definition client_message.h:20
isc::radius::PW_ACCOUNTING_REQUEST
@ PW_ACCOUNTING_REQUEST
Definition client_message.h:24
isc::radius::PW_ACCESS_REQUEST
@ PW_ACCESS_REQUEST
Definition client_message.h:21
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:273
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
radius.h
subnet_id.h
timer_mgr.h