34    return (getCfgHostsForEdit());
 
   42using namespace isc::asiolink;
 
   43using namespace isc::db;
 
   45boost::scoped_ptr<HostMgr>&
 
   46HostMgr::getHostMgrPtr() {
 
   47    static boost::scoped_ptr<HostMgr> host_mgr_ptr;
 
   48    return (host_mgr_ptr);
 
   53    getHostMgrPtr().reset(
new HostMgr());
 
 
   63    if (getHostMgrPtr()->cache_ptr_ &&
 
   64        getHostMgrPtr()->cache_ptr_->getType() == db_type) {
 
   65        getHostMgrPtr()->cache_ptr_.reset();
 
 
   75                                       db_type, access, if_unusable));
 
 
   80    getHostMgrPtr()->alternate_sources_.clear();
 
 
   85    if (alternate_sources_.empty()) {
 
   88    return (alternate_sources_[0]);
 
 
   93    if (getHostMgrPtr()->cache_ptr_) {
 
   97    if (sources.empty()) {
 
  101        boost::dynamic_pointer_cast<CacheHostDataSource>(sources[0]);
 
  103        getHostMgrPtr()->cache_ptr_ = cache_ptr;
 
  106                .arg(cache_ptr->getType());
 
 
  115    boost::scoped_ptr<HostMgr>& host_mgr_ptr = getHostMgrPtr();
 
  119    return (*host_mgr_ptr);
 
 
  124                const uint8_t* identifier_begin,
 
  125                const size_t identifier_len,
 
  129        hosts = getCfgHosts()->getAll(identifier_type, identifier_begin,
 
  133        for (
auto const& source : alternate_sources_) {
 
  135                source->getAll(identifier_type, identifier_begin, identifier_len);
 
  136            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  144                const uint8_t* identifier_begin,
 
  145                const size_t identifier_len)
 const {
 
  146    return getAll(identifier_type, identifier_begin, identifier_len,
 
 
  154        hosts = getCfgHosts()->getAll4(subnet_id);
 
  157        for (
auto const& source : alternate_sources_) {
 
  159            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  174        hosts = getCfgHosts()->getAll6(subnet_id);
 
  177        for (
auto const& source : alternate_sources_) {
 
  179            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  194        hosts = getCfgHosts()->getAllbyHostname(hostname);
 
  197        for (
auto const& source : alternate_sources_) {
 
  199            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  216        hosts = getCfgHosts()->getAllbyHostname4(hostname, subnet_id);
 
  219        for (
auto const& source : alternate_sources_) {
 
  222            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  240        hosts = getCfgHosts()->getAllbyHostname6(hostname, subnet_id);
 
  243        for (
auto const& source : alternate_sources_) {
 
  246            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  260                  size_t& source_index,
 
  261                  uint64_t lower_host_id,
 
  264    if (source_index > alternate_sources_.size()) {
 
  270    if (source_index == 0) {
 
  271        hosts = getCfgHosts()->
 
  272            getPage4(subnet_id, source_index, lower_host_id, page_size);
 
  274        hosts = alternate_sources_[source_index - 1]->
 
  275            getPage4(subnet_id, source_index, lower_host_id, page_size);
 
  279    if (!hosts.empty()) {
 
  286    return (
getPage4(subnet_id, source_index, 0UL, page_size));
 
 
  291                  size_t& source_index,
 
  292                  uint64_t lower_host_id,
 
  295    if (source_index > alternate_sources_.size()) {
 
  301    if (source_index == 0) {
 
  302        hosts = getCfgHosts()->
 
  303            getPage6(subnet_id, source_index, lower_host_id, page_size);
 
  305        hosts = alternate_sources_[source_index - 1]->
 
  306            getPage6(subnet_id, source_index, lower_host_id, page_size);
 
  310    if (!hosts.empty()) {
 
  317    return (
getPage6(subnet_id, source_index, 0UL, page_size));
 
 
  322                  uint64_t lower_host_id,
 
  325    if (source_index > alternate_sources_.size()) {
 
  331    if (source_index == 0) {
 
  332        hosts = getCfgHosts()->
 
  333            getPage4(source_index, lower_host_id, page_size);
 
  335        hosts = alternate_sources_[source_index - 1]->
 
  336            getPage4(source_index, lower_host_id, page_size);
 
  340    if (!hosts.empty()) {
 
  347    return (
getPage4(source_index, 0UL, page_size));
 
 
  352                  uint64_t lower_host_id,
 
  355    if (source_index > alternate_sources_.size()) {
 
  361    if (source_index == 0) {
 
  362        hosts = getCfgHosts()->
 
  363            getPage6(source_index, lower_host_id, page_size);
 
  365        hosts = alternate_sources_[source_index - 1]->
 
  366            getPage6(source_index, lower_host_id, page_size);
 
  370    if (!hosts.empty()) {
 
  377    return (
getPage6(source_index, 0UL, page_size));
 
 
  384        hosts = getCfgHosts()->getAll4(address);
 
  387        for (
auto const& source : alternate_sources_) {
 
  389            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  403                 const uint8_t* identifier_begin,
 
  404                 const size_t identifier_len,
 
  408        host = getCfgHosts()->get4(subnet_id, identifier_type,
 
  409                                   identifier_begin, identifier_len);
 
  427    for (
auto const& source : alternate_sources_) {
 
  428        host = source->get4(subnet_id, identifier_type,
 
  429                           identifier_begin, identifier_len);
 
  438                .arg(source->getType())
 
  439                .arg(host->toText());
 
  441            if (source != cache_ptr_) {
 
 
  458                 const uint8_t* identifier_begin,
 
  459                 const size_t identifier_len)
 const {
 
  460    return get4Any(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  467              const uint8_t* identifier_begin,
 
  468              const size_t identifier_len,
 
  471                                identifier_begin, identifier_len, target);
 
  472    if (host && host->getNegative()) {
 
  476                      identifier_type, identifier_begin, identifier_len);
 
 
  484              const uint8_t* identifier_begin,
 
  485              const size_t identifier_len)
 const {
 
  486    return get4(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  496        host = getCfgHosts()->get4(subnet_id, address);
 
  506    for (
auto const& source : alternate_sources_) {
 
  507        host = source->get4(subnet_id, address);
 
  508        if (host && host->getNegative()) {
 
  511        if (host && source != cache_ptr_) {
 
 
  533        hosts = getCfgHosts()->getAll4(subnet_id, address);
 
  542        for (
auto const& source : alternate_sources_) {
 
  543            auto hosts_plus = source->getAll4(subnet_id, address);
 
  544            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  561        host = getCfgHosts()->get6(prefix, prefix_len);
 
  568        .arg(
static_cast<int>(prefix_len));
 
  569    for (
auto const& source : alternate_sources_) {
 
  570        host = source->get6(prefix, prefix_len);
 
  571        if (host && host->getNegative()) {
 
  574        if (host && source != cache_ptr_) {
 
 
  592                 const uint8_t* identifier_begin,
 
  593                 const size_t identifier_len,
 
  597        host = getCfgHosts()->get6(subnet_id, identifier_type,
 
  598                                   identifier_begin, identifier_len);
 
  610    for (
auto const& source : alternate_sources_) {
 
  611        host = source->get6(subnet_id, identifier_type,
 
  612                           identifier_begin, identifier_len);
 
  621                    .arg(source->getType())
 
  622                    .arg(host->toText());
 
  624                if (source != cache_ptr_) {
 
 
  643                 const uint8_t* identifier_begin,
 
  644                 const size_t identifier_len)
 const {
 
  645    return get6Any(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  652              const uint8_t* identifier_begin,
 
  653              const size_t identifier_len,
 
  656                                identifier_begin, identifier_len, target);
 
  657    if (host && host->getNegative()) {
 
  661                      identifier_type, identifier_begin, identifier_len);
 
 
  669              const uint8_t* identifier_begin,
 
  670              const size_t identifier_len)
 const {
 
  671    return get6(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  681        host = getCfgHosts()->get6(subnet_id, addr);
 
  690    for (
auto const& source : alternate_sources_) {
 
  691        host = source->get6(subnet_id, addr);
 
  692        if (host && host->getNegative()) {
 
  695        if (host && source != cache_ptr_) {
 
 
  718        hosts = getCfgHosts()->getAll6(subnet_id, address);
 
  727        for (
auto const& source : alternate_sources_) {
 
  728            auto hosts_plus = source->getAll6(subnet_id, address);
 
  729            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  750        hosts = getCfgHosts()->getAll6(address);
 
  754        for (
auto const& source : alternate_sources_) {
 
  756            hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
 
 
  766        getCfgHostsForEdit()->add(host);
 
  773                    "no hosts-database configured.");
 
  777        for (
auto const& source : alternate_sources_) {
 
 
  796    size_t erased = 
false;
 
  799        erased = getCfgHostsForEdit()->del(subnet_id, addr);
 
  806                    "no hosts-database configured.");
 
  809        for (
auto const& source : alternate_sources_) {
 
  810            bool alternate_erased = source->del(subnet_id, addr);
 
  811            erased = alternate_erased || erased;
 
 
  825              const uint8_t* identifier_begin, 
const size_t identifier_len,
 
  827    bool success = 
false;
 
  830        if (getCfgHostsForEdit()->
del4(subnet_id, identifier_type,
 
  831                                       identifier_begin, identifier_len)) {
 
  840                    "no hosts-database configured.");
 
  843        for (
auto const& source : alternate_sources_) {
 
  844            if (source->del4(subnet_id, identifier_type,
 
  845                             identifier_begin, identifier_len)) {
 
 
  855              const uint8_t* identifier_begin, 
const size_t identifier_len) {
 
  856    return del4(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  862              const uint8_t* identifier_begin, 
const size_t identifier_len,
 
  864    bool success = 
false;
 
  867        if (getCfgHostsForEdit()->
del6(subnet_id, identifier_type,
 
  868                                       identifier_begin, identifier_len)) {
 
  877                    "no hosts-database configured.");
 
  880        for (
auto const& source : alternate_sources_) {
 
  881            if (source->del6(subnet_id, identifier_type,
 
  882                             identifier_begin, identifier_len)) {
 
 
  892              const uint8_t* identifier_begin, 
const size_t identifier_len) {
 
  893    return del6(subnet_id, identifier_type, identifier_begin, identifier_len,
 
 
  900        getCfgHostsForEdit()->update(host);
 
  907                    "Unable to update existing host because there is no hosts-database configured.");
 
  911            source->update(host);
 
 
  930        if (!host || host->getNegative()) {
 
  935        cache_ptr_->insert(host, 
true);
 
 
  943                       const uint8_t* identifier_begin,
 
  944                       const size_t identifier_len)
 const {
 
  946        HostPtr host(
new Host(identifier_begin, identifier_len,
 
  948                              ipv4_subnet_id, ipv6_subnet_id,
 
  950        host->setNegative(
true);
 
  953        cache_ptr_->insert(host, 
false);
 
 
  961    for (
auto const& source : alternate_sources_) {
 
  962        if (!source->setIPReservationsUnique(unique)) {
 
  966            ip_reservations_unique_ = 
true;
 
  968                .arg(source->getType());
 
  969            for (
auto const& src : alternate_sources_) {
 
  970                src->setIPReservationsUnique(
true);
 
  978    ip_reservations_unique_ = unique;
 
 
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
std::string toText() const
Convert the address to a string.
static CfgMgr & instance()
returns a single instance of Configuration Manager
static void add(HostDataSourceList &sources, const std::string &dbaccess)
Create and add an instance of a host data source.
static bool del(HostDataSourceList &sources, const std::string &db_type)
Delete a host data source.
ConstHostCollection getAll6(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv6 subnet.
ConstHostCollection getAll4(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv4 subnet.
static void delAllBackends()
Delete all alternate backends.
static void create()
Creates new instance of the HostMgr.
bool negative_caching_
The negative caching flag.
virtual void cacheNegative(const SubnetID &ipv4_subnet_id, const SubnetID &ipv6_subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Cache a negative answer.
virtual ConstHostCollection getPage6(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv6 subnet.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
ConstHostPtr get6Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv6 subnet.
ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv4 subnet.
bool del4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet4-id, identifier, identifier-type, operation-target)
virtual void cache(ConstHostPtr host) const
Cache an answer.
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).
ConstHostCollection getAll(const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
ConstHostPtr get4Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv4 subnet.
bool del6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet6-id, identifier, identifier-type, operation-target)
void add(const HostPtr &host, const HostMgrOperationTarget target)
Adds a new host to the alternate data source.
bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr, const HostMgrOperationTarget target)
Attempts to delete hosts by address.
ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv6 subnet.
virtual ConstHostCollection getPage4(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv4 subnet.
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
void update(HostPtr const &host, const HostMgrOperationTarget target)
Implements BaseHostDataSource::update() for alternate sources.
ConstHostCollection getAllbyHostname(const std::string &hostname, const HostMgrOperationTarget target) const
Return all hosts with a hostname.
ConstHostPtr get4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv4 subnet.
ConstHostPtr get6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv6 subnet.
Wraps value holding size of the page with host reservations.
Represents a device with IPv4 and/or IPv6 reservations.
IdentifierType
Type of the host identifier.
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
No host data source instance exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#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.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_NULL
isc::log::Logger hosts_logger("hosts")
Logger for the HostMgr and the code it calls.
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_PREFIX
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_HOST
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_HOST
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
const isc::log::MessageID HOSTS_CFG_CACHE_HOST_DATA_SOURCE
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4
const int HOSTS_DBG_TRACE
Logging levels for the host reservations management.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID HOSTS_MGR_NON_UNIQUE_IP_UNSUPPORTED
boost::shared_ptr< CfgHosts > CfgHostsPtr
Non-const pointer.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS4
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_NULL
const int HOSTS_DBG_RESULTS
Records the results of the lookups.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER
Defines the logger used by the top-level component of kea-lfc.