Kea 3.1.7
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
9#include <radius_access.h>
10#include <radius_accounting.h>
11#include <radius_status.h>
12#include <radius_log.h>
13#include <radius_tls.h>
14#include <sstream>
15
16using namespace isc::asiolink;
17using namespace isc::dhcp;
18using namespace isc::radius;
19using namespace std;
20namespace ph = std::placeholders;
21
22namespace isc {
23namespace radius {
24
26 const CallbackStatus& handler)
27 : RadiusStatus() {
28 AttributesPtr attrs;
29 if (send_attrs) {
30 attrs.reset(new Attributes(*send_attrs));
31 } else {
32 attrs.reset(new Attributes());
33 }
34 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
35 "to-be-set", attrs));
36 unsigned maxretries = RadiusImpl::instance().retries_;
37 Servers servers = RadiusImpl::instance().auth_->servers_;
39 request, maxretries, servers,
41 handler, ph::_1),
42 RadiusImpl::instance().proto_);
43}
44
45void
47 AttributesPtr send_attrs;
48 MessagePtr request = exchange_->getRequest();
49 if (request) {
50 send_attrs = request->getAttributes();
51 }
53 .arg(send_attrs ? send_attrs->toText() : "no attributes");
54
56}
57
58void
60 const ExchangePtr exchange) {
61 // Should not happen...
62 if (!exchange) {
63 return;
64 }
65 int result = exchange->getRC();
66 if (result == OK_RC) {
70
71 MessagePtr response = exchange->getResponse();
72 AttributesPtr resp_attrs;
73 uint8_t code = 0;
74 if (response) {
75 resp_attrs = response->getAttributes();
76 code = response->getCode();
77 }
78 if (((code != 0) && (code != PW_ACCESS_ACCEPT)) ||
79 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
81 .arg(msgCodeToText(code))
82 .arg(static_cast<unsigned>(code))
83 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
84 }
85 } else {
88 .arg(result)
89 .arg(exchangeRCtoText(result));
90 }
91
92 if (callback) {
93 try {
94 callback(result);
95 } catch (...) {
96 }
97 }
98 exchange->shutdown();
100}
101
103 const CallbackStatus& handler)
104 : RadiusStatus() {
105 AttributesPtr attrs;
106 if (send_attrs) {
107 attrs.reset(new Attributes(*send_attrs));
108 } else {
109 attrs.reset(new Attributes());
110 }
111 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
112 "to-be-set", attrs));
113 unsigned maxretries = RadiusImpl::instance().retries_;
114 Servers servers = RadiusImpl::instance().acct_->servers_;
116 request, maxretries, servers,
118 handler, ph::_1),
119 RadiusImpl::instance().proto_);
120}
121
122void
124 AttributesPtr send_attrs;
125 MessagePtr request = exchange_->getRequest();
126 if (request) {
127 send_attrs = request->getAttributes();
128 }
130 .arg(send_attrs ? send_attrs->toText() : "no attributes");
131
133}
134
135void
137 const ExchangePtr exchange) {
138 // Should not happen...
139 if (!exchange) {
140 return;
141 }
142 int result = exchange->getRC();
143 if (result == OK_RC) {
147
148 MessagePtr response = exchange->getResponse();
149 AttributesPtr resp_attrs;
150 uint8_t code = 0;
151 if (response) {
152 resp_attrs = response->getAttributes();
153 code = response->getCode();
154 }
155 if (((code != 0) && (code != PW_ACCOUNTING_RESPONSE)) ||
156 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
158 .arg(msgCodeToText(code))
159 .arg(static_cast<unsigned>(code))
160 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
161 }
162 } else {
165 .arg(result)
166 .arg(exchangeRCtoText(result));
167 }
168
169 if (callback) {
170 try {
171 callback(result);
172 } catch (...) {
173 }
174 }
175 exchange->shutdown();
177}
178
180 const CallbackStatus& handler)
181 : RadiusStatus() {
182 AttributesPtr attrs;
183 if (send_attrs) {
184 attrs.reset(new Attributes(*send_attrs));
185 } else {
186 attrs.reset(new Attributes());
187 }
188 MessagePtr request(new Message(PW_STATUS_SERVER, 0, vector<uint8_t>(),
189 "to-be-set", attrs));
190 unsigned maxretries = RadiusImpl::instance().retries_;
191 Servers servers = RadiusImpl::instance().tls_->servers_;
193 request, maxretries, servers,
195 handler, ph::_1),
197}
198
199void
201 AttributesPtr send_attrs;
202 MessagePtr request = exchange_->getRequest();
203 if (request) {
204 send_attrs = request->getAttributes();
205 }
207 .arg(send_attrs ? send_attrs->toText() : "no attributes");
208
210}
211
212void
214 const ExchangePtr exchange) {
215 // Should not happen...
216 if (!exchange) {
217 return;
218 }
219 int result = exchange->getRC();
220 if (result == OK_RC) {
223
224 MessagePtr response = exchange->getResponse();
225 AttributesPtr resp_attrs;
226 uint8_t code = 0;
227 if (response) {
228 resp_attrs = response->getAttributes();
229 code = response->getCode();
230 }
231 if (((code != 0) && (code != PW_ACCESS_ACCEPT)) ||
232 (resp_attrs && (resp_attrs->count(PW_ERROR_CAUSE) > 0))) {
234 .arg(msgCodeToText(code))
235 .arg(static_cast<unsigned>(code))
236 .arg(resp_attrs ? resp_attrs->toText() : "no attributes");
237 }
238 } else {
240 .arg(result)
241 .arg(exchangeRCtoText(result));
242 }
243
244 if (callback) {
245 try {
246 callback(result);
247 } catch (...) {
248 }
249 }
250}
251
252} // end of namespace radius
253} // 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:281
void setAccountingIdleTimer()
Set the accounting idle timer.
Definition radius.cc:420
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
Definition radius.cc:202
boost::shared_ptr< RadiusAccess > auth_
Pointer to access (never null).
Definition radius.h:284
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
Definition radius.h:287
unsigned retries_
Retries.
Definition radius.h:320
void setAccessIdleTimer()
Set the access idle timer.
Definition radius.cc:408
static RadiusImpl & instance()
RadiusImpl is a singleton class.
Definition radius.cc:163
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.