Kea 3.1.1
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
25typedef std::function<void(int, AttributesPtr)> CallbackAuth;
26
29typedef std::function<void(int)> CallbackAcct;
30
39uint32_t getNASPort(uint32_t subnet_id);
40
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
79 MessagePtr request = exchange_->getRequest();
80 if (request) {
81 return (request->getAttributes());
82 }
83 return (AttributesPtr());
84 }
85
90 MessagePtr response = exchange_->getResponse();
91 if (response) {
92 return (response->getAttributes());
93 }
94 return (AttributesPtr());
95 }
96
101 return (exchange_);
102 }
103
104protected:
106 uint32_t nas_port_;
107
110};
111
113class 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
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:
159};
160
162typedef boost::shared_ptr<RadiusSyncAuth> RadiusSyncAuthPtr;
163
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
192typedef boost::shared_ptr<RadiusAsyncAuth> RadiusAsyncAuthPtr;
193
195class 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
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:
240};
241
243typedef boost::shared_ptr<RadiusSyncAcct> RadiusSyncAcctPtr;
244
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
273typedef boost::shared_ptr<RadiusAsyncAcct> RadiusAsyncAcctPtr;
274
275} // end of namespace radius
276} // end of namespace isc
277#endif // RADIUS_REQUEST_H
std::function< void(const ExchangePtr ex)> Handler
Termination handler.
RadiusAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
virtual ~RadiusAcct()=default
Destructor.
static void invokeCallback(const CallbackAcct &callback, const ExchangePtr exchange)
Invoke accounting communication callback.
virtual void start() override
Start communication.
virtual ~RadiusAsyncAcct()=default
Destructor.
RadiusAsyncAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAcct &callback)
Constructor.
static void invokeCallback(const CallbackAuth &callback, const ExchangePtr exchange)
Invoke authentication communication callback.
virtual void start() override
Start communication.
virtual ~RadiusAsyncAuth()=default
Destructor.
RadiusAsyncAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAuth &callback)
Constructor.
virtual ~RadiusAuth()=default
Destructor.
RadiusAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
virtual ~RadiusRequest()=default
Destructor.
int getRC() const
Get the error code.
RadiusRequest(const MsgCode code, uint32_t subnet_id, const AttributesPtr &send_attrs, bool sync, const Exchange::Handler &handler)
Constructor.
ExchangePtr getExchange()
Get the exchange.
AttributesPtr getRespAttrs() const
Get response attributes.
virtual void start()
Start communication.
uint32_t nas_port_
Client/NAS port (from Subnet Id).
AttributesPtr getReqAttrs() const
Get request attributes.
ExchangePtr exchange_
Exchange.
virtual void start() override
Start communication.
virtual ~RadiusSyncAcct()=default
Destructor.
RadiusSyncAcct(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAcct &callback)
Constructor.
CallbackAcct callback_
Accounting termination callback.
RadiusSyncAuth(uint32_t subnet_id, const AttributesPtr &send_attrs, const CallbackAuth &callback)
Constructor.
virtual ~RadiusSyncAuth()=default
Destructor.
CallbackAuth callback_
Authentication termination callback.
virtual void start() override
Start communication.
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
std::function< void(int)> CallbackAcct
Type of callback for accounting termination.
boost::shared_ptr< RadiusAsyncAuth > RadiusAsyncAuthPtr
Pointer to asynchronous authentication.
boost::shared_ptr< RadiusSyncAcct > RadiusSyncAcctPtr
Pointer to synchronous accounting.
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
boost::shared_ptr< RadiusSyncAuth > RadiusSyncAuthPtr
Pointer to synchronous authentication.
std::function< void(int, AttributesPtr)> CallbackAuth
Type of callback for authentication termination.
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
MsgCode
Standard RADIUS message code.
uint32_t getNASPort(uint32_t subnet_id)
Remap a subnet ID to a NAS port.
boost::shared_ptr< RadiusAsyncAcct > RadiusAsyncAcctPtr
Pointer to asynchronous accounting.
Defines the logger used by the top-level component of kea-lfc.