37 : io_service_(io_service), thread_pool_size_(thread_pool_size) {
39 if (thread_pool_size == 0) {
44 thread_io_service_.reset(
new IOService());
46 boost::make_shared<IoServiceThreadPool>(thread_io_service_,
52 [
this]() {
pause(); },
62 return (thread_pool_size_);
67 return (thread_io_service_);
76 .arg(thread_pool_size_);
85 for (
auto const& exchange : exchange_list_) {
88 thread_pool_->getIOService()->stopAndPoll();
91 for (
auto const& exchange : exchange_list_) {
94 io_service_->stopAndPoll();
96 exchange_list_.clear();
105 thread_pool_->checkPausePermissions();
113 }
catch (
const exception& ex) {
126 thread_pool_->pause();
128 }
catch (
const exception& ex) {
142 }
catch (
const exception& ex) {
151 exchange_list_.push_back(exchange);
157 exchange_list_.remove(exchange);
184 io_context_(new
IOService()), io_service_(io_context_) {
190 }
catch(exception
const& exception) {
192 .arg(exception.what());
260 io_service_ = io_context_;
265 std::unique_ptr<void, void(*)(
void*)> p(
static_cast<void*
>(
this), [](
void*) {
RadiusImpl::shutdown_ =
false; });
277 if (
auth_->enabled_) {
289 if (
acct_->enabled_) {
299 bool multi_threaded(
false);
300 unsigned thread_pool_size(0);
301 uint32_t dhcp_threads(0);
302 uint32_t dummy_queue_size(0);
306 if (multi_threaded) {
310 if (dhcp_threads == 0) {
311 uint32_t
const hardware_threads(
313 if (hardware_threads == 0) {
315 multi_threaded =
false;
316 thread_pool_size = 0;
318 thread_pool_size = hardware_threads;
321 thread_pool_size = dhcp_threads;
328 if (multi_threaded) {
332 io_service_->post([
this, thread_pool_size]() {
341 io_service_->post([
this, multi_threaded, thread_pool_size]() {
392 return (
auth_->servers_);
394 return (
tls_->servers_);
401 return (
acct_->servers_);
403 return (
tls_->servers_);
413 auth_->setIdleTimer();
415 tls_->setIdleTimer();
425 acct_->setIdleTimer();
427 tls_->setIdleTimer();
444 if (!subnet_hr_global.unspecified() && !subnet_hr_subnet.unspecified()) {
445 return (subnet_hr_global && !subnet_hr_subnet);
447 if (!subnet_hr_global.unspecified() || !subnet_hr_subnet.unspecified()) {
452 if (!network_hr_global.unspecified() && !network_hr_subnet.unspecified()) {
453 return (network_hr_global && !network_hr_subnet);
455 if (!network_hr_global.unspecified() || !network_hr_subnet.unspecified()) {
460 getConfiguredGlobal(
"reservations-global");
462 if (!global_hr_mode_elem) {
466 getConfiguredGlobal(
"reservations-in-subnet");
468 if (!subnet_hr_mode_elem) {
472 isc_throw(Unexpected,
"'reservations-global' global value must be a boolean");
474 if (!global_hr_mode_elem->boolValue()) {
478 isc_throw(Unexpected,
"'reservations-in-subnet' global value must be a boolean");
480 if (subnet_hr_mode_elem->boolValue()) {
491 if (flag && (flag->boolValue())) {
493 "compatible with RADIUS");
498 bool need_disable_single_query =
false;
501 getCfgSharedNetworks4()->getAll();
502 if (networks->empty()) {
505 need_disable_single_query =
true;
506 for (
auto const& network : *networks) {
507 auto subnets = network->getAllSubnets();
508 if (subnets->size() <= 1) {
511 for (
auto const& subnet : *subnets) {
512 if (!isHostReservationModeGlobal(subnet, network)) {
514 <<
" '" << subnet->toText() <<
"' of shared "
515 <<
"network " << network->getName()
516 <<
" does not use only global host reservations "
517 <<
"which are required for subnets in "
518 <<
"shared networks by RADIUS");
524 getCfgSharedNetworks6()->getAll();
525 if (networks->empty()) {
528 need_disable_single_query =
true;
529 for (
auto const& network : *networks) {
530 auto subnets = network->getAllSubnets();
531 if (subnets->size() <= 1) {
534 for (
auto const& subnet : *subnets) {
535 if (!isHostReservationModeGlobal(subnet, network)) {
537 <<
" '" << subnet->toText() <<
"' of shared "
538 <<
"network " << network->getName()
539 <<
" does not use only global host reservations "
540 <<
"which are required for subnets in "
541 <<
"shared networks by RADIUS");
546 if (need_disable_single_query) {
556 static bool already_tried =
false;
560 already_tried =
true;
569 }
catch (
const std::exception& ex) {
577 cache_ = boost::dynamic_pointer_cast<CacheHostDataSource>(cache);
598 result->set(
"canonical-mac-address",
614 result->set(
"identifier-type4",
618 result->set(
"identifier-type6",
622 result->set(
"reselect-subnet-address",
626 result->set(
"reselect-subnet-pool",
642 result->set(
"use-message-authenticator",
647 result->set(
"tls",
tls_->toElement());
649 result->set(
"access",
auth_->toElement());
650 result->set(
"accounting",
acct_->toElement());
655 for (
auto const& item :
remap_) {
657 if (item.first != 0) {
658 entry->set(
"subnet-id",
665 result->set(
"nas-ports", ports);
671unordered_set<thread::id> InHook::set_;
676 const auto&
id = this_thread::get_id();
678 auto ret = set_.insert(
id);
680 std::cerr <<
"InHook insert error on " <<
id <<
"\n";
685 const auto&
id = this_thread::get_id();
687 size_t ret = set_.erase(
id);
689 std::cerr <<
"InHook erase error on " <<
id <<
"\n";
694 const auto&
id = this_thread::get_id();
696 size_t ret = set_.count(
id);
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
An exception that is thrown if an error occurs while configuring any server.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown when a worker thread is trying to stop or pause the respective thread pool (which wo...
A generic exception that is thrown when an unexpected error condition occurs.
The IOService class is a wrapper for the ASIO io_context class.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
@ EARLY_GLOBAL_RESERVATIONS_LOOKUP
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
static void extract(data::ConstElementPtr value, bool &enabled, uint32_t &thread_count, uint32_t &queue_size)
Extract multi-threading parameters from a given configuration.
static bool deregisterFactory(const std::string &db_type, bool no_log=false)
Deregister a host data source factory.
static bool registerFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Register a host data source factory.
static bool registeredFactory(const std::string &db_type)
Check if a host data source factory was registered.
void setDisableSingleQuery(bool disable_single_query)
Sets the disable single query flag.
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Represents a device with IPv4 and/or IPv6 reservations.
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
static bool check()
Check if the current thread is in hook code or not.
Configuration parser for Radius.
void parse(data::ElementPtr &config)
Parses Radius configuration.
Radius hooks library implementation.
static std::atomic< bool > shutdown_
Flag which indicates that the instance is shutting down.
unsigned thread_pool_size_
Thread pool size.
void checkSharedNetworks()
Check shared network server configuration.
std::string dictionary_
Dictionary path.
bool checkHostBackends()
Check host backends (cache and radius).
RadiusImpl()
Protected constructor.
boost::shared_ptr< RadiusTls > tls_
Pointer to tls (never null).
dhcp::CacheHostDataSourcePtr cache_
Host cache.
std::string bindaddr_
bindaddr.
bool clientid_pop0_
Client Id pop leading zero(s).
isc::asiolink::IOServicePtr getIOContext()
Get the hook I/O service.
void setAccountingIdleTimer()
Set the accounting idle timer.
const Servers & getAccessServers() const
Get servers for access.
dhcp::Host::IdentifierType id_type4_
Identifier type for IPv4.
void reset()
Reset the state as it was just created.
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
bool reselect_subnet_address_
Reselect subnet using address.
void init(data::ElementPtr &config)
Initialize.
void registerExchange(ExchangePtr exchange)
Register Exchange.
boost::shared_ptr< RadiusAccess > auth_
Pointer to access (never null).
bool extract_duid_
Extract Duid from Client Id.
void startServices()
Start the I/O mechanisms.
unsigned timeout_
Timeout.
dhcp::Host::IdentifierType id_type6_
Identifier type for IPv6.
bool canonical_mac_address_
Canonical MAC address.
unsigned deadtime_
Deadtime.
bool serveAccounting() const
Check if accounting is served.
RadiusBackendPtr backend_
Radius backend.
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
void cleanup()
Clean up members.
data::ElementPtr toElement() const override
Unparse implementation configuration.
unsigned retries_
Retries.
std::map< uint32_t, uint32_t > remap_
Subnet ID to NAS port map.
UdpClientPtr udp_client_
UDP client.
static const RadiusImplPtr & instancePtr()
Returns pointer to the sole instance of radius implementation.
const Servers & getAccountingServers() const
Get servers for accounting.
std::string session_history_filename_
Session history filename.
void setAccessIdleTimer()
Set the access idle timer.
bool reselect_subnet_pool_
Reselect subnet using pool.
isc::tcp::TcpClientPtr tcp_client_
TCP client.
void checkEarlyGlobalResvLookup()
Check the early global host reservations lookup flag.
bool clientid_printable_
Client Id try printable.
RadiusProtocol proto_
Transport protocol.
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
static RadiusImpl & instance()
RadiusImpl is a singleton class.
bool serveAccess() const
Check if access is served.
bool use_message_authenticator_
Use Message-Authenticator attribute.
Radius service for TLS transport.
void registerExchange(ExchangePtr exchange)
Register Exchange.
void unregisterExchange(ExchangePtr exchange)
Unregister Exchange.
const asiolink::IOServicePtr getThreadIOService() const
Fetches a pointer to the internal IOService used to drive the thread-pool in multi-threaded mode.
void checkPermissions()
Check if the current thread can perform thread pool state transition.
void resume()
Resumes running the client's thread pool.
void stop()
Halts client-side IO activity.
UdpClient(const asiolink::IOServicePtr &io_service, unsigned thread_pool_size=0)
Constructor.
void pause()
Pauses the client's thread pool.
void start()
Starts running the client's thread pool, if multi-threaded.
unsigned getThreadPoolSize() const
Fetches the maximum size of the thread pool.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
void removeCriticalSectionCallbacks(const std::string &name)
Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks.
static uint32_t detectThreadCount()
The system current detected hardware concurrency thread count.
void addCriticalSectionCallbacks(const std::string &name, const CSCallbackSet::Callback &check_cb, const CSCallbackSet::Callback &entry_cb, const CSCallbackSet::Callback &exit_cb)
Adds a set of callbacks to the list of CriticalSection callbacks.
#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_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or Subnet6 object.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
const isc::log::MessageID RADIUS_ACCESS_HOST_BACKEND_ERROR
const isc::log::MessageID RADIUS_RESUME_FAILED
boost::shared_ptr< RadiusImpl > RadiusImplPtr
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
const isc::log::MessageID RADIUS_CLEANUP_EXCEPTION
string protocolToText(const int proto)
Transport protocol to text.
const isc::log::MessageID RADIUS_PAUSE_FAILED
const isc::log::MessageID RADIUS_ACCESS_NO_HOST_CACHE
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
const isc::log::MessageID RADIUS_THREAD_POOL_STARTED
const isc::log::MessageID RADIUS_PAUSE_ILLEGAL
const isc::log::MessageID RADIUS_PAUSE_PERMISSIONS_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.