30using namespace std::chrono;
31namespace ph = std::placeholders;
41 return (
"bad response");
51 return (
"temporarily unavailable");
53 result << (rc < 0 ?
"error " :
"unknown ") << rc;
54 return (result.str());
76 if (servers.empty()) {
77 isc_throw(BadValue,
"no server");
99 if (servers.empty()) {
100 isc_throw(BadValue,
"no server");
120 if (rv.size() !=
sizeof(uint32_t)) {
124 memmove(&ri, &rv[0],
sizeof(uint32_t));
126 rs << hex << setfill(
'0') << setw(8) << ri;
144 .arg(
static_cast<int>(
received_->getIdentifier()))
146 .arg(attr->toString());
217 sent_->randomIdentifier();
233 sent_->setAttributes(attrs);
240 seconds secs = duration_cast<seconds>(delta);
242 static_cast<uint32_t
>(secs.count())));
248 if (family == AF_INET) {
252 }
else if (family == AF_INET6) {
288 if ((
server_->getDeadtime() > 0) &&
293 shared_from_this()));
300 shared_from_this()));
354 .arg(
ep_->getAddress().toText())
355 .arg(
ep_->getPort());
374 shared_from_this()));
383 unsigned deadtime =
server_->getDeadtime();
396 shared_from_this()));
406 shared_from_this()));
412 shared_from_this()));
470 shared_from_this()));
477 const boost::system::error_code ec,
490 if (ex->terminated_) {
497 .arg(ex->identifier_)
501 ex->socket_->close();
510 .arg(ex->identifier_)
514 ex->size_ = ex->buffer_.size();
515 ex->socket_->asyncReceive(&(ex->buffer_)[0], ex->size_, 0, ex->ep_.get(),
523 const boost::system::error_code ec,
539 ex->socket_->close();
543 if (ex->terminated_) {
550 .arg(ex->identifier_)
558 (ex->server_->getDeadtime() > 0) &&
559 (ex->server_->getDeadtimeEnd() > ex->start_time_)) {
560 ex->server_->setDeadtimeEnd(ex->start_time_);
565 .arg(ex->identifier_)
567 ex->buffer_.resize(size);
568 ex->received_.reset(
new Message(ex->buffer_, ex->sent_->getAuth(),
569 ex->server_->getSecret()));
578 ex->received_->decode();
579 unsigned got = ex->received_->getIdentifier();
580 unsigned expected = ex->sent_->getIdentifier();
581 if (got != expected) {
583 .arg(ex->identifier_)
591 .arg(ex->identifier_);
595 .arg(ex->identifier_)
602 .arg(ex->identifier_);
607 .arg(ex->identifier_)
614 .arg(ex->identifier_);
619 .arg(ex->identifier_)
626 .arg(ex->identifier_)
633 ex->logReplyMessages();
681 handler(shared_from_this());
683 handler(shared_from_this());
708 .arg(ex->identifier_);
712 ex->socket_->cancel();
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
short getFamily() const
Returns the address family.
The IOService class is a wrapper for the ASIO io_context class.
The IntervalTimer class is a wrapper for the ASIO boost::asio::deadline_timer class.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
static AttributePtr fromInt(const uint8_t type, const uint32_t value)
From integer with type.
static AttributePtr fromIpAddr(const uint8_t type, const asiolink::IOAddress &value)
From IPv4 address with type.
static AttributePtr fromIpv6Addr(const uint8_t type, const asiolink::IOAddress &value)
From IPv6 address with type.
Collection of attributes.
std::list< size_t > postponed_
List of postponed server indexes.
asiolink::UDPSocket< const SocketCallback > RadiusSocket
Type of RADIUS UDP sockets.
Servers servers_
Servers (a copy which is what we need).
virtual ~Exchange()
Destructor.
virtual void start()
Start.
Handler handler_
Termination handler.
MessagePtr request_
Request message.
Exchange(const asiolink::IOServicePtr io_service, const MessagePtr &request, unsigned maxretries, const Servers &servers, Handler handler)
Constructor.
size_t size_
Number of transmitted octests;.
ServerPtr server_
Current server.
asiolink::IntervalTimerPtr timer_
Interval timer.
std::function< void(const ExchangePtr ex)> Handler
Termination handler.
bool sync_
Sync / async flag.
void buildRequest()
Build request.
static void sentHandler(ExchangePtr ex, const boost::system::error_code ec, const size_t size)
Sent handler.
static constexpr size_t BUF_LEN
Receive buffer size.
void createIdentifier()
Create identifier.
MessagePtr received_
Received message.
void terminate()
Terminate.
void setTimer()
Set timer.
boost::scoped_ptr< std::mutex > mutex_
State change mutex.
int rc_
Error/return code.
bool started_
Started flag.
boost::scoped_ptr< asiolink::UDPEndpoint > ep_
UDP endpoint.
static void openNext(ExchangePtr ex)
Class open / open next.
std::chrono::steady_clock::time_point start_time_
Start time.
static void receivedHandler(ExchangePtr ex, const boost::system::error_code ec, const size_t size)
Received handler.
std::string identifier_
The identifier (random value in hexadecimal).
boost::scoped_ptr< RadiusSocket > socket_
Socket.
std::function< void(const boost::system::error_code ec, const size_t size)> SocketCallback
Type of UDP socket callback functions.
MessagePtr sent_
Sent message.
bool terminated_
Terminated flag.
virtual void shutdown()
Shutdown.
void open()
Instance open.
virtual void shutdownInternal()
Shutdown.
asiolink::IOServicePtr io_service_
IO service (argument for async or internal for sync).
static void timeoutHandler(ExchangePtr ex)
Timeout handler.
std::vector< uint8_t > buffer_
Buffer.
void logReplyMessages() const
Log reply messages.
void cancelTimer()
Cancel timer.
size_t idx_
Current server index.
unsigned retries_
Retry counter.
unsigned maxretries_
Maximum number of retries for a server.
static std::atomic< bool > shutdown_
Flag which indicates that the instance is shutting down.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
std::vector< uint8_t > random(size_t len)
Generate random value.
@ PW_ACCT_DELAY_TIME
integer.
@ PW_NAS_IPV6_ADDRESS
ipv6addr.
@ PW_NAS_IP_ADDRESS
ipaddr.
@ PW_REPLY_MESSAGE
string.
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_MISMATCH
const isc::log::MessageID RADIUS_EXCHANGE_OPEN_FAILED
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::shared_ptr< const Attribute > ConstAttributePtr
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_ACCESS_REJECT
const isc::log::MessageID RADIUS_EXCHANGE_FAILED
const isc::log::MessageID RADIUS_EXCHANGE_SENT
string exchangeRCtoText(const int rc)
ExchangeRC value -> name function.
const isc::log::MessageID RADIUS_EXCHANGE_TIMEOUT
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_ACCESS_ACCEPT
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED
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.
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_ACCOUNTING_RESPONSE
const isc::log::MessageID RADIUS_EXCHANGE_SEND_NEW
const isc::log::MessageID RADIUS_REPLY_MESSAGE_ATTRIBUTE
const isc::log::MessageID RADIUS_EXCHANGE_SEND_RETRY
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
boost::shared_ptr< Message > MessagePtr
Shared pointers to message.
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_UNEXPECTED
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_BAD_RESPONSE
const isc::log::MessageID RADIUS_EXCHANGE_SYNC_RETURN
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVED_RESPONSE
const isc::log::MessageID RADIUS_EXCHANGE_START
const isc::log::MessageID RADIUS_EXCHANGE_SEND_FAILED
const isc::log::MessageID RADIUS_EXCHANGE_TERMINATE
const isc::log::MessageID RADIUS_EXCHANGE_RECEIVE_FAILED
Defines the logger used by the top-level component of kea-lfc.
RAII lock object to protect the code in the same scope with a mutex.