Kea 3.1.8
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
26typedef std::function<void(int, AttributesPtr)> CallbackAuth;
27
31typedef std::function<void(int)> CallbackAcct;
32
41uint32_t getNASPort(uint32_t subnet_id);
42
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
85 MessagePtr request = exchange_->getRequest();
86 if (request) {
87 return (request->getAttributes());
88 }
89 return (AttributesPtr());
90 }
91
96 MessagePtr response = exchange_->getResponse();
97 if (response) {
98 return (response->getAttributes());
99 }
100 return (AttributesPtr());
101 }
102
107 return (exchange_);
108 }
109
110protected:
112 uint32_t nas_port_;
113
116};
117
119class 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
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:
165};
166
168typedef boost::shared_ptr<RadiusSyncAuth> RadiusSyncAuthPtr;
169
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
198typedef boost::shared_ptr<RadiusAsyncAuth> RadiusAsyncAuthPtr;
199
201class 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
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:
246};
247
249typedef boost::shared_ptr<RadiusSyncAcct> RadiusSyncAcctPtr;
250
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
279typedef boost::shared_ptr<RadiusAsyncAcct> RadiusAsyncAcctPtr;
280
281} // end of namespace radius
282} // end of namespace isc
283#endif // RADIUS_REQUEST_H
RADIUS Base Exchange.
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.