49    impl_->setMaximum(maximum);
 
 
   54    return (
impl_->getMaximum());
 
 
   60                  const size_t )
 const {
 
 
  110                    const dhcp:: HostPageSize& )
 const {
 
 
  129                const uint8_t* identifier_begin,
 
  130                const size_t identifier_len)
 const {
 
  141        host = 
impl_->get4(subnet_id, identifier_type,
 
  142                           identifier_begin, identifier_len);
 
  150            .arg(host->toText());
 
 
  164    if (!address.
isV4()) {
 
  170        host = 
impl_->get4(subnet_id, address);
 
  177            .arg(host->toText());
 
 
  191                const uint8_t* identifier_begin,
 
  192                const size_t identifier_len)
 const {
 
  203        host = 
impl_->get6(subnet_id, identifier_type,
 
  204                           identifier_begin, identifier_len);
 
  212            .arg(host->toText());
 
 
  219                const uint8_t prefix_len)
 const {
 
  223        .arg(
static_cast<int>(prefix_len));
 
  228        host = 
impl_->get6(prefix, prefix_len);
 
  234            .arg(
static_cast<int>(prefix_len))
 
  235            .arg(host->toText());
 
 
  249    if (!address.
isV6()) {
 
  256        host = 
impl_->get6(subnet_id, address);
 
  263            .arg(host->toText());
 
 
  286    if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
 
  287        host->getIPv6SubnetID() == SUBNET_ID_UNUSED) {
 
  294        ret = 
impl_->add(host);
 
  298            .arg(host->toText());
 
  302            .arg(host->toText());
 
 
  313            txt = 
impl_->del4(subnet_id, addr);
 
  322    } 
else if (addr.
isV6()) {
 
  325            txt = 
impl_->del6(subnet_id, addr);
 
 
  341                const uint8_t* identifier_begin,
 
  342                const size_t identifier_len) {
 
  346        txt = 
impl_->del4(subnet_id, identifier_type,
 
  347                          identifier_begin, identifier_len);
 
 
  364                const uint8_t* identifier_begin,
 
  365                const size_t identifier_len) {
 
  369        txt = 
impl_->del6(subnet_id, identifier_type,
 
  370                          identifier_begin, identifier_len);
 
 
  402    return (
impl_->toElement());
 
 
  408    return (
impl_->insert(host, overwrite));
 
 
  414    return (
impl_->remove(host));
 
 
  430    return (
impl_->size());
 
 
  436    return (
impl_->capacity());
 
 
  441               const uint8_t* identifier_begin,
 
  442               const size_t identifier_len)
 const {
 
  444    return (
impl_->get(identifier_type, identifier_begin, identifier_len));
 
 
  454        count = 
impl_->size();
 
  455    } 
catch (
const std::exception& ex) {
 
  465    msg << count << 
" entries.";
 
 
  482    } 
catch (
const std::exception& ex) {
 
 
  499    size_t before = 
impl_->size();
 
  500    string txt = 
"(missing parameters)";
 
  515                      "please use cache-clear command");
 
  526        how_many = 
static_cast<size_t>(val);
 
  527        impl_->flush(how_many);
 
  528    } 
catch (
const std::exception& ex) {
 
  538    msg << 
"Cache flushed (" << before - 
impl_->size() << 
" entries removed).";
 
 
  552        dump = 
impl_->toElement();
 
  553        count = dump->size();
 
  554    } 
catch (
const std::exception& ex) {
 
  564    msg << count << 
" entries returned.";
 
 
  575    vector<uint8_t> ident;
 
  576    string txt = 
"(missing parameters)";
 
  595        unsigned have_ident = 0;
 
  597        for (
auto const& cfg : map) {
 
  598            if (cfg.first == 
"hw-address") {
 
  601                ident_txt = cfg.second->stringValue();
 
  602            } 
else if (cfg.first == 
"duid") {
 
  605                ident_txt = cfg.second->stringValue();
 
  606            } 
else if (cfg.first == 
"circuit-id") {
 
  609                ident_txt = cfg.second->stringValue();
 
  610            } 
else if (cfg.first == 
"client-id") {
 
  613                ident_txt = cfg.second->stringValue();
 
  614            } 
else if (cfg.first == 
"flex-id") {
 
  617                ident_txt = cfg.second->stringValue();
 
  620                          "unknown parameter '" << cfg.first << 
"'");
 
  625        if (have_ident == 0) {
 
  628        if (have_ident > 1) {
 
  631        if (ident_txt.empty()) {
 
  647            hosts = 
impl_->get(id_type, &ident[0], ident.size());
 
  649        for (
auto const& host : hosts) {
 
  652        count = result->size();
 
  653    } 
catch (
const std::exception& ex) {
 
  663    msg << count << 
" entries returned.";
 
 
  675    size_t overwritten = 0;
 
  676    string txt = 
"(missing parameters)";
 
  694                overwritten += 
impl_->insert(entry, 
true);
 
  695            } 
catch (
const std::exception& ex) {
 
  697                          "Insert host (" << entry->toText()
 
  698                          << 
") failed: " << ex.what());
 
  704            for (
auto const& entry : entries) {
 
  708                    overwritten += 
impl_->insert(entry, 
true);
 
  709                } 
catch (
const std::exception& ex) {
 
  711                              << 
" host (" << entry->toText()
 
  712                              << 
"): " << ex.what());
 
  716    } 
catch (
const std::exception& ex) {
 
  728    msg << count << 
" entries inserted (" << overwritten
 
  729        << 
" overwritten by more recent entries).";
 
 
  741    string txt = 
"(missing parameters)";
 
  762        } 
catch (
const std::exception& ex) {
 
  766        ofstream out(filename, ios::trunc);
 
  769                      << 
"' for writing.");
 
  772        dump = 
impl_->toElement();
 
  773        count = dump->size();
 
  776    } 
catch (
const std::exception& ex) {
 
  787    msg << count << 
" entries dumped to '" << filename << 
"'.";
 
 
  798    size_t overwritten = 0;
 
  799    string txt = 
"(missing parameters)";
 
  815        if (filename.empty()) {
 
  826        for (
auto const& entry : entries) {
 
  829                overwritten += 
impl_->insert(entry, 
true);
 
  830            } 
catch (
const std::exception& ex) {
 
  832                          << 
" host ( " << entry->toText()
 
  833                          << 
"): " << ex.what());
 
  836    } 
catch (
const std::exception& ex) {
 
  848    msg << count << 
" entries loaded from '" << filename << 
"' (" 
  849        << overwritten << 
" overwritten by more recent entries).";
 
 
  856    uint16_t family = AF_UNIX;
 
  860    vector<uint8_t> ident;
 
  861    string txt = 
"(missing parameters)";
 
  879        bool have_ident = 
false;
 
  882        for (
auto const& cfg : map) {
 
  883            if (cfg.first == 
"subnet-id") {
 
  884                if (family != AF_UNIX) {
 
  888                subnet_id = 
static_cast<uint32_t
>(cfg.second->intValue());
 
  889            } 
else if (cfg.first == 
"subnet-id4") {
 
  890                if (family != AF_UNIX) {
 
  894                subnet_id = 
static_cast<uint32_t
>(cfg.second->intValue());
 
  895            } 
else if (cfg.first == 
"subnet-id6") {
 
  896                if (family != AF_UNIX) {
 
  900                subnet_id = 
static_cast<uint32_t
>(cfg.second->intValue());
 
  901            } 
else if (cfg.first == 
"ip-address") {
 
  902                addr_txt = cfg.second->stringValue();
 
  903            } 
else if (cfg.first == 
"hw-address") {
 
  909                ident_txt = cfg.second->stringValue();
 
  910            } 
else if (cfg.first == 
"duid") {
 
  916                ident_txt = cfg.second->stringValue();
 
  917            } 
else if (cfg.first == 
"circuit-id") {
 
  923                ident_txt = cfg.second->stringValue();
 
  924            } 
else if (cfg.first == 
"client-id") {
 
  930                ident_txt = cfg.second->stringValue();
 
  931            } 
else if (cfg.first == 
"flex-id") {
 
  937                ident_txt = cfg.second->stringValue();
 
  940                          "unknown parameter '" << cfg.first << 
"'");
 
  946        if (valid && !addr_txt.empty()) {
 
  950            if (family == AF_UNIX) {
 
  955                if (family == AF_INET6) {
 
  962            } 
else if (addr.
isV6()) {
 
  963                if (family == AF_INET) {
 
  972                          "invalid ip-address '" << addr_txt << 
"'");
 
  977                          "either ip-address or an identifier is required");
 
  979            if (ident_txt.empty()) {
 
  982            if ((family != AF_INET) && (family != AF_INET6)) {
 
  984                          "either subnet-id4 or subnet-id6 is required");
 
  993                          "invalid identifier '" << ident_txt << 
"'");
 
 1004        if (!addr_txt.empty()) {
 
 1005            if (family == AF_INET) {
 
 1006                del_txt = 
impl_->del4(subnet_id, addr);
 
 1008                del_txt = 
impl_->del6(subnet_id, addr);
 
 1010        } 
else if (family == AF_INET) {
 
 1011            del_txt = 
impl_->del4(subnet_id, id_type, &ident[0], ident.size());
 
 1013            del_txt = 
impl_->del6(subnet_id, id_type, &ident[0], ident.size());
 
 1015    } 
catch (
const std::exception& ex) {
 
 1025    if (!del_txt.empty()) {
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr fromJSONFile(const std::string &file_name, bool preproc=false)
Reads contents of specified file and interprets it as JSON.
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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)
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
std::string toText() const
Convert the address to a string.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
void setSuccessResponse(hooks::CalloutHandle &handle, const std::string &text)
Set the callout argument "response" to indicate success.
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
Database duplicate entry error.
std::string validatePath(const std::string data_path) const
Validates a file path against the supported directory for DHDP data.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
@ IDENT_FLEX
Flexible host identifier.
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Per-packet callout handle.
Configuration parser for Host Cache.
static const int64_t MAXIMUM
Absolute maximum number of elements.
void parse(HostCache &hcref, const data::ConstElementPtr &config)
Parses Host Cache configuration.
Host cache content parser.
dhcp::HostCollection parse(const data::ConstElementPtr &entry_list)
Parses Host Cache entries.
dhcp::HostPtr parse(const data::ConstElementPtr &entry)
Parses Host Cache entry.
Host Cache hooks library implementation.
virtual size_t size() const
Return the number of entries.
virtual void configure(const data::ConstElementPtr &config)
Parses configuration.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
boost::shared_ptr< HostCacheImpl > impl_
Implementation.
virtual size_t getMaximum() const
Get maximum number of cached hosts.
virtual void flush(size_t count)
Flush entries.
int cacheLoadHandler(hooks::CalloutHandle &handle)
cache-load command handler.
virtual dhcp::ConstHostCollection getAll(const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
BaseHostDataSource methods.
virtual bool del6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet-id6, identifier, identifier-type)
virtual bool del4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet-id4, identifier, identifier-type)
virtual dhcp::ConstHostCollection getAllbyHostname4(const std::string &hostname, const dhcp::SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
virtual ~HostCache()
Destructor.
void update(isc::dhcp::HostPtr const &host)
Implements isc::dhcp::BaseHostDataSource::update() for HostCache.
virtual dhcp::ConstHostPtr get6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv6 subnet.
int cacheRemoveHandler(hooks::CalloutHandle &handle)
cache-remove command handler.
virtual size_t capacity() const
Return the maximum number of entries.
virtual void setMaximum(size_t maximum)
Set maximum number of cached hosts (0 means unbound).
virtual void add(const dhcp::HostPtr &host)
Adds a new host to the collection.
int cacheInsertHandler(hooks::CalloutHandle &handle)
cache-insert command handler.
boost::scoped_ptr< std::mutex > mutex_
mutex
virtual bool del(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id, address)
virtual size_t insert(const dhcp::ConstHostPtr &host, bool overwrite)
Insert a host into the cache.
int cacheGetByIdHandler(hooks::CalloutHandle &handle)
cache-get-by-id command handler.
int cacheWriteHandler(hooks::CalloutHandle &handle)
cache-write command handler.
virtual dhcp::ConstHostCollection getPage4(const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
Return range of hosts in a DHCPv4 subnet.
virtual dhcp::ConstHostCollection getAll6(const dhcp::SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
virtual dhcp::ConstHostCollection getAll4(const dhcp::SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
int cacheFlushHandler(hooks::CalloutHandle &handle)
cache-flush command handler.
virtual dhcp::ConstHostCollection getAllbyHostname6(const std::string &hostname, const dhcp::SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
virtual dhcp::ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
virtual dhcp::ConstHostCollection get(const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
int cacheSizeHandler(hooks::CalloutHandle &handle)
Command handlers.
virtual bool remove(const dhcp::HostPtr &host)
Remove a host from the cache.
virtual data::ElementPtr toElement() const
Returns the whole content of the cache as Element tree.
virtual dhcp::ConstHostCollection getPage6(const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
Return range of hosts in a DHCPv6 subnet.
virtual dhcp::ConstHostPtr get4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv4 subnet.
int cacheGetHandler(hooks::CalloutHandle &handle)
cache-get command handler.
int cacheClearHandler(hooks::CalloutHandle &handle)
cache-clear command handler.
RAII class creating a critical section.
A generic exception that is thrown if a parameter given violates security check but enforcement is la...
#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.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
std::vector< HostPtr > HostCollection
Collection of the Host objects.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS4_HOST
const isc::log::MessageID HOST_CACHE_ADD_DUPLICATE
const isc::log::MessageID HOST_CACHE_COMMAND_REMOVE_FAILED
const isc::log::MessageID HOST_CACHE_COMMAND_CLEAR_FAILED
const isc::log::MessageID HOST_CACHE_COMMAND_GET_BY_ID
const isc::log::MessageID HOST_CACHE_COMMAND_FLUSH
const isc::log::MessageID HOST_CACHE_COMMAND_LOAD_FAILED
const isc::log::MessageID HOST_CACHE_COMMAND_GET
const isc::log::MessageID HOST_CACHE_ADD
const int HOST_CACHE_DBG_RESULTS
Records the results of the lookups.
const isc::log::MessageID HOST_CACHE_COMMAND_INSERT
const isc::log::MessageID HOST_CACHE_COMMAND_WRITE_FAILED
const isc::log::MessageID HOST_CACHE_DEL_SUBNET_ID_IDENTIFIER4
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER_HOST
const isc::log::MessageID HOST_CACHE_COMMAND_SIZE_FAILED
const isc::log::MessageID HOST_CACHE_COMMAND_FLUSH_FAILED
const isc::log::MessageID HOST_CACHE_COMMAND_LOAD
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER
const isc::log::MessageID HOST_CACHE_DEL_SUBNET_ID_ADDRESS4
const isc::log::MessageID HOST_CACHE_GET_ONE_PREFIX
const isc::log::MessageID HOST_CACHE_COMMAND_GET_BY_ID_FAILED
const isc::log::MessageID HOST_CACHE_DEL_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOST_CACHE_GET_ONE_PREFIX_HOST
const isc::log::MessageID HOST_CACHE_COMMAND_CLEAR
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOST_CACHE_COMMAND_SIZE
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS4
const isc::log::MessageID HOST_CACHE_COMMAND_REMOVE
const isc::log::MessageID HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS6_HOST
const isc::log::MessageID HOST_CACHE_COMMAND_GET_FAILED
ElementPtr toElement(const ConstHostPtr &host)
Unparse a host cache entry.
const isc::log::MessageID HOST_CACHE_COMMAND_WRITE
const int HOST_CACHE_DBG_TRACE
Host Cache hooks library logging levels.
const isc::log::MessageID HOST_CACHE_COMMAND_INSERT_FAILED
const isc::log::MessageID HOST_CACHE_PATH_SECURITY_WARNING
const isc::log::MessageID HOST_CACHE_DEL_SUBNET_ID_IDENTIFIER6
isc::log::Logger host_cache_logger("host-cache-hooks")
Host Cache Logger.
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
vector< uint8_t > quotedStringToBinary(const string "ed_string)
Converts a string in quotes into vector.
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.