55      io_context_(new 
IOService()), io_service_(io_context_) {
 
 
   61    } 
catch(exception 
const& exception) {
 
   63            .arg(exception.what());
 
 
   69    exchange_list_.push_back(exchange);
 
 
   74    exchange_list_.remove(exchange);
 
 
  106        for (
auto const& exchange : exchange_list_) {
 
  107            exchange->shutdown();
 
  112        for (
auto const& exchange : exchange_list_) {
 
  113            exchange->shutdown();
 
  117    exchange_list_.clear();
 
  121    io_service_ = io_context_;
 
 
  126    std::unique_ptr<void, void(*)(
void*)> p(
static_cast<void*
>(
this), [](
void*) { 
RadiusImpl::shutdown_ = 
false; });
 
 
  137    if (
auth_->enabled_) {
 
  149    if (
acct_->enabled_) {
 
 
  159    bool multi_threaded(
false);
 
  160    uint32_t dhcp_threads(0);
 
  161    uint32_t dummy_queue_size(0);
 
  165    if (multi_threaded) {
 
  170            if (dhcp_threads == 0) {
 
  171                uint32_t 
const hardware_threads(
 
  173                if (hardware_threads == 0) {
 
  177                    thread_pool_size = hardware_threads;
 
  180                thread_pool_size = dhcp_threads;
 
  186        io_service_->post([
this, thread_pool_size]() {
 
  203                .arg(thread_pool_size);
 
 
  222    } 
catch (
const exception& ex) {
 
 
  237    } 
catch (
const exception& ex) {
 
 
  251    } 
catch (
const exception& ex) {
 
 
  270    if (!subnet_hr_global.unspecified() && !subnet_hr_subnet.unspecified()) {
 
  271        return (subnet_hr_global && !subnet_hr_subnet);
 
  273    if (!subnet_hr_global.unspecified() || !subnet_hr_subnet.unspecified()) {
 
  278    if (!network_hr_global.unspecified() && !network_hr_subnet.unspecified()) {
 
  279        return (network_hr_global && !network_hr_subnet);
 
  281    if (!network_hr_global.unspecified() || !network_hr_subnet.unspecified()) {
 
  286        getConfiguredGlobal(
"reservations-global");
 
  288    if (!global_hr_mode_elem) {
 
  292        getConfiguredGlobal(
"reservations-in-subnet");
 
  294    if (!subnet_hr_mode_elem) {
 
  298        isc_throw(Unexpected, 
"'reservations-global' global value must be a boolean");
 
  300    if (!global_hr_mode_elem->boolValue()) {
 
  304        isc_throw(Unexpected, 
"'reservations-in-subnet' global value must be a boolean");
 
  306    if (subnet_hr_mode_elem->boolValue()) {
 
  317    if (flag && (flag->boolValue())) {
 
  319                  "compatible with RADIUS");
 
 
  324    bool need_disable_single_query = 
false;
 
  327            getCfgSharedNetworks4()->getAll();
 
  328        if (networks->empty()) {
 
  331        need_disable_single_query = 
true;
 
  332        for (
auto const& network : *networks) {
 
  333            auto subnets = network->getAllSubnets();
 
  334            if (subnets->size() <= 1) {
 
  337            for (
auto const& subnet : *subnets) {
 
  338                if (!isHostReservationModeGlobal(subnet, network)) {
 
  340                              << 
" '" << subnet->toText() << 
"' of shared " 
  341                              << 
"network " << network->getName()
 
  342                              << 
" does not use only global host reservations " 
  343                              << 
"which are required for subnets in " 
  344                              << 
"shared networks by RADIUS");
 
  350            getCfgSharedNetworks6()->getAll();
 
  351        if (networks->empty()) {
 
  354        need_disable_single_query = 
true;
 
  355        for (
auto const& network : *networks) {
 
  356            auto subnets = network->getAllSubnets();
 
  357            if (subnets->size() <= 1) {
 
  360            for (
auto const& subnet : *subnets) {
 
  361                if (!isHostReservationModeGlobal(subnet, network)) {
 
  363                              << 
" '" << subnet->toText() << 
"' of shared " 
  364                              << 
"network " << network->getName()
 
  365                              << 
" does not use only global host reservations " 
  366                              << 
"which are required for subnets in " 
  367                              << 
"shared networks by RADIUS");
 
  372    if (need_disable_single_query) {
 
 
  382    static bool already_tried = 
false;
 
  386    already_tried = 
true;
 
  395    } 
catch (
const std::exception& ex) {
 
  403    cache_ = boost::dynamic_pointer_cast<CacheHostDataSource>(cache);
 
 
  421    result->set(
"canonical-mac-address",
 
  437    result->set(
"identifier-type4",
 
  441    result->set(
"identifier-type6",
 
  447    result->set(
"reselect-subnet-address",
 
  451    result->set(
"reselect-subnet-pool",
 
  467    result->set(
"access", 
auth_->toElement());
 
  468    result->set(
"accounting", 
acct_->toElement());
 
  473        for (
auto const& item : 
remap_) {
 
  475            if (item.first != 0) {
 
  476                entry->set(
"subnet-id",
 
  483        result->set(
"nas-ports", ports);
 
 
  489unordered_set<thread::id> InHook::set_;
 
  494    const auto& 
id = this_thread::get_id();
 
  496    auto ret = set_.insert(
id);
 
  498        std::cerr << 
"InHook insert error on " << 
id << 
"\n";
 
 
  503    const auto& 
id = this_thread::get_id();
 
  505    size_t ret = set_.erase(
id);
 
  507        std::cerr << 
"InHook erase error on " << 
id << 
"\n";
 
 
  512    const auto& 
id = this_thread::get_id();
 
  514    size_t ret = set_.count(
id);
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
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 resumeThreadPool()
Resume the thread pool.
void checkSharedNetworks()
Check shared network server configuration.
std::string dictionary_
Dictionary path.
bool checkHostBackends()
Check host backends (cache and radius).
RadiusImpl()
Protected constructor.
dhcp::CacheHostDataSourcePtr cache_
Host cache.
std::string bindaddr_
bindaddr.
bool clientid_pop0_
Client Id pop leading zero(s).
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.
void pauseThreadPool()
Pause the thread pool.
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_
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.
RadiusBackendPtr backend_
Radius backend.
boost::shared_ptr< RadiusAccounting > acct_
Pointer to accounting (never null).
void cleanup()
Clean up members.
asiolink::IoServiceThreadPoolPtr thread_pool_
Thread pool.
data::ElementPtr toElement() const override
Unparse implementation configuration.
unsigned retries_
Retries.
std::map< uint32_t, uint32_t > remap_
Subnet ID to NAS port map.
static const RadiusImplPtr & instancePtr()
Returns pointer to the sole instance of radius implementation.
std::string session_history_filename_
Session history filename.
bool reselect_subnet_pool_
Reselect subnet using pool.
void checkEarlyGlobalResvLookup()
Check the early global host reservations lookup flag.
bool clientid_printable_
Client Id try printable.
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
static RadiusImpl & instance()
RadiusImpl is a singleton class.
void checkPausePermissions()
Check if the current thread can transition the thread pool to the paused state.
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
boost::shared_ptr< Exchange > ExchangePtr
Type of shared pointers to RADIUS exchange object.
const isc::log::MessageID RADIUS_CLEANUP_EXCEPTION
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.