Kea 3.3.3
radius_status.cc
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#include <config.h>
8
12#include <radius/radius_tls.h>
13
14#include <sstream>
15
16#include <radius_log.h>
17
18using namespace isc::asiolink;
19using namespace isc::dhcp;
20using namespace isc::radius;
21using namespace std;
22namespace ph = std::placeholders;
23
24namespace isc {
25namespace radius {
26
28 const CallbackStatus& handler)
29 : RadiusStatus() {
30 AttributesPtr attrs;
31 if (send_attrs) {
32 attrs.reset(new Attributes(*send_attrs));
33 } else {
34 attrs.reset(new Attributes());
35 }
36 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
37 "to-be-set", attrs));
38 unsigned maxretries = RadiusImpl::instance().retries_;
39 Servers servers = RadiusImpl::instance().auth_->servers_;
41 request, maxretries, servers,
43 handler, ph::_1),
44 RadiusImpl::instance().proto_);
45}
46
47void
49 AttributesPtr send_attrs;
50 MessagePtr request = exchange_->getRequest();
51 if (request) {
52 send_attrs = request->getAttributes();
53 }
55 .arg(send_attrs ? send_attrs->toText() : "no attributes");
56
58}
59
60void
62 const ExchangePtr exchange) {
63 // Should not happen...
64 if (!exchange) {
65 return;
66 }
67 int result = exchange->getRC();
68 if (result == OK_RC) {
72
73 MessagePtr response = exchange->getResponse();
74 AttributesPtr resp_attrs;
75 uint8_t code = 0;
76 if (response) {
77 resp_attrs = response->getAttributes();
78 code = response->getCode();
79 }
80 if (((code != 0) && (code != PW_ACCESS_ACCEPT)) ||
81 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
83 .arg(msgCodeToText(code))
84 .arg(static_cast<unsigned>(code))
85 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
86 }
87 } else {
90 .arg(result)
91 .arg(exchangeRCtoText(result));
92 }
93
94 if (callback) {
95 try {
96 callback(result);
97 } catch (...) {
98 }
99 }
100 exchange->shutdown();
102}
103
105 const CallbackStatus& handler)
106 : RadiusStatus() {
107 AttributesPtr attrs;
108 if (send_attrs) {
109 attrs.reset(new Attributes(*send_attrs));
110 } else {
111 attrs.reset(new Attributes());
112 }
113 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
114 "to-be-set", attrs));
115 unsigned maxretries = RadiusImpl::instance().retries_;
116 Servers servers = RadiusImpl::instance().acct_->servers_;
118 request, maxretries, servers,
120 handler, ph::_1),
121 RadiusImpl::instance().proto_);
122}
123
124void
126 AttributesPtr send_attrs;
127 MessagePtr request = exchange_->getRequest();
128 if (request) {
129 send_attrs = request->getAttributes();
130 }
132 .arg(send_attrs ? send_attrs->toText() : "no attributes");
133
135}
136
137void
139 const ExchangePtr exchange) {
140 // Should not happen...
141 if (!exchange) {
142 return;
143 }
144 int result = exchange->getRC();
145 if (result == OK_RC) {
149
150 MessagePtr response = exchange->getResponse();
151 AttributesPtr resp_attrs;
152 uint8_t code = 0;
153 if (response) {
154 resp_attrs = response->getAttributes();
155 code = response->getCode();
156 }
157 if (((code != 0) && (code != PW_ACCOUNTING_RESPONSE)) ||
158 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
160 .arg(msgCodeToText(code))
161 .arg(static_cast<unsigned>(code))
162 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
163 }
164 } else {
167 .arg(result)
168 .arg(exchangeRCtoText(result));
169 }
170
171 if (callback) {
172 try {
173 callback(result);
174 } catch (...) {
175 }
176 }
177 exchange->shutdown();
179}
180
182 const CallbackStatus& handler)
183 : RadiusStatus() {
184 AttributesPtr attrs;
185 if (send_attrs) {
186 attrs.reset(new Attributes(*send_attrs));
187 } else {
188 attrs.reset(new Attributes());
189 }
190 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
191 "to-be-set", attrs));
192 unsigned maxretries = RadiusImpl::instance().retries_;
193 Servers servers = RadiusImpl::instance().tls_->servers_;
195 request, maxretries, servers,
197 handler, ph::_1),
199}
200
201void
203 AttributesPtr send_attrs;
204 MessagePtr request = exchange_->getRequest();
205 if (request) {
206 send_attrs = request->getAttributes();
207 }
209 .arg(send_attrs ? send_attrs->toText() : "no attributes");
210
212}
213
214void
216 const ExchangePtr exchange) {
217 // Should not happen...
218 if (!exchange) {
219 return;
220 }
221 int result = exchange->getRC();
222 if (result == OK_RC) {
225
226 MessagePtr response = exchange->getResponse();
227 AttributesPtr resp_attrs;
228 uint8_t code = 0;
229 if (response) {
230 resp_attrs = response->getAttributes();
231 code = response->getCode();
232 }
233 if (((code != 0) && (code != PW_ACCESS_ACCEPT)) ||
234 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
236 .arg(msgCodeToText(code))
237 .arg(static_cast<unsigned>(code))
238 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
239 }
240 } else {
242 .arg(result)
243 .arg(exchangeRCtoText(result));
244 }
245
246 if (callback) {
247 try {
248 callback(result);
249 } catch (...) {
250 }
251 }
252}
253
254} // end of namespace radius
255} // end of namespace isc
Collection of attributes.
static ExchangePtr create(const asiolink::IOServicePtr io_service, const MessagePtr &request, unsigned maxretries, const Servers &servers, Handler handler, RadiusProtocol protocol=PW_PROTO_UDP)
Factory.
RADIUS Message.
RadiusAcctStatus(const AttributesPtr &send_attrs, const CallbackStatus &handler)
Constructor.
virtual void start() override
Start communication.
static void invokeCallback(const CallbackStatus &callback, const ExchangePtr exchange)
Invoke accounting status callback.
static void invokeCallback(const CallbackStatus &callback, const ExchangePtr exchange)
Invoke access status callback.
RadiusAuthStatus(const AttributesPtr &send_attrs, const CallbackStatus &handler)
Constructor.
virtual void start() override
Start communication.
boost::shared_ptr< RadiusTls > tls_
Pointer to tls (never null).
Definition radius.h:296
void setAccountingIdleTimer()
Set the accounting idle timer.
Definition radius.cc:458
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:233
boost::shared_ptr< RadiusAccess > auth_
Pointer to access (never null).
Definition radius.h:299
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
Definition radius.h:302
unsigned retries_
Retries.
Definition radius.h:335
void setAccessIdleTimer()
Set the access idle timer.
Definition radius.cc:446
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:194
virtual void start()
Start communication.
ExchangePtr exchange_
Exchange.
RadiusTlsStatus(const AttributesPtr &send_attrs, const CallbackStatus &handler)
Constructor.
static void invokeCallback(const CallbackStatus &callback, const ExchangePtr exchange)
Invoke access status callback.
virtual void start() override
Start communication.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition macros.h:32
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition macros.h:14
std::function< void(int)> CallbackStatus
Type of callback for status termination.
const isc::log::MessageID RADIUS_AUTHENTICATION_STATUS
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
const isc::log::MessageID RADIUS_TLS_STATUS_SUCCEED
const isc::log::MessageID RADIUS_ACCOUNTING_STATUS_FAILED
std::function< void(int)> CallbackAcct
Type of callback for accounting termination.
const isc::log::MessageID RADIUS_TLS_STATUS_FAILED
string exchangeRCtoText(const int rc)
ExchangeRC value -> name function.
const isc::log::MessageID RADIUS_ACCOUNTING_STATUS
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
string msgCodeToText(const uint8_t code)
MsgCode value -> name function.
const int RADIUS_DBG_TRACE
Radius logging levels.
Definition radius_log.h:26
const isc::log::MessageID RADIUS_AUTHENTICATION_STATUS_ERROR
const isc::log::MessageID RADIUS_AUTHENTICATION_STATUS_SUCCEED
const isc::log::MessageID RADIUS_ACCOUNTING_STATUS_ERROR
const isc::log::MessageID RADIUS_ACCOUNTING_STATUS_SUCCEED
const isc::log::MessageID RADIUS_TLS_STATUS
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
Definition radius_log.h:35
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
const isc::log::MessageID RADIUS_AUTHENTICATION_STATUS_FAILED
const isc::log::MessageID RADIUS_TLS_STATUS_ERROR
Defines the logger used by the top-level component of kea-lfc.