14#include <boost/algorithm/string.hpp> 
   15#include <boost/scoped_ptr.hpp> 
   45             uint32_t valid_lft, 
SubnetID subnet_id, time_t cltt,
 
   46             const bool fqdn_fwd, 
const bool fqdn_rev,
 
   47             const std::string& hostname, 
const HWAddrPtr& hwaddr)
 
 
   61       return string(
"IA_NA");
 
   63       return string(
"IA_TA");
 
   65       return string(
"IA_PD");
 
   69       tmp << 
"unknown (" << type << 
")";
 
 
   80    } 
else  if (text == 
"IA_NA") {
 
   83    } 
else if (text == 
"IA_TA") {
 
   86    } 
else if (text == 
"IA_PD") {
 
 
  101        return (
"expired-reclaimed");
 
  105        return (
"registered");
 
  110    std::ostringstream s;
 
  111    s << 
"unknown (" << state << 
")";
 
 
  165                  " or it is not a string");
 
  168    boost::scoped_ptr<asiolink::IOAddress> io_address;
 
  172    } 
catch (
const std::exception& ex) {
 
  174                  << 
" in the parsed lease");
 
  177    lease->addr_ = *io_address;
 
  183                  " or it is not an integer");
 
  186    if (subnet_id->intValue() <= 0) {
 
  188                  << 
" a positive integer");
 
  189    } 
else if (subnet_id->intValue() > numeric_limits<uint32_t>::max()) {
 
  191                  << 
" a 32 bit unsigned integer");
 
  194    lease->subnet_id_ = 
SubnetID(subnet_id->intValue());
 
  203        if (pool_id->intValue() <= 0) {
 
  205                      << 
" a positive integer");
 
  206        } 
else if (pool_id->intValue() > numeric_limits<uint32_t>::max()) {
 
  208                      << 
" a 32 bit unsigned integer");
 
  211        lease->pool_id_ = pool_id->intValue();
 
  226        } 
catch (
const std::exception& ex) {
 
  228                      << hw_address->stringValue() << 
" in the parsed lease");
 
  236                  " or it is not an integer");
 
  239    if (cltt->intValue() <= 0) {
 
  241                  " positive integer in the parsed lease");
 
  244    lease->cltt_ = 
static_cast<time_t
>(cltt->intValue());
 
  250                  " or it is not an integer");
 
  253    if (valid_lifetime->intValue() < 0) {
 
  255                  << 
" is negative in the parsed lease");
 
  258    lease->valid_lft_ = valid_lifetime->intValue();
 
  264                  " or it is not a boolean value");
 
  267    lease->fqdn_fwd_ = fqdn_fwd->boolValue();
 
  273                  " or it is not a boolean value");
 
  276    lease->fqdn_rev_ = fqdn_rev->boolValue();
 
  282                  " or it is not a string value");
 
  285    lease->hostname_ = hostname->stringValue();
 
  286    boost::algorithm::to_lower(lease->hostname_);
 
  292                  " or it is not an integer");
 
  297                  << 
" must be in range [0.." 
  301    lease->state_ = state->intValue();
 
  309        lease->setContext(ctx);
 
  312    lease->updateCurrentExpirationTime();
 
 
  329               const uint32_t valid_lifetime,
 
  334               const std::string& hostname)
 
  335    : 
Lease(address, valid_lifetime, subnet_id, cltt, fqdn_fwd,
 
  336            fqdn_rev, hostname, hw_address),
 
 
  348const std::vector<uint8_t>&
 
  351        static std::vector<uint8_t> empty_vec;
 
 
  358const std::vector<uint8_t>&
 
  361        static std::vector<uint8_t> empty_vec;
 
 
  433    if (!lease->addr_.isV4()) {
 
  438    if (!lease->hwaddr_) {
 
  453        } 
catch (
const std::exception& ex) {
 
  455                      << client_id->stringValue() << 
" in the parsed lease");
 
 
  463               DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
 
  465    : 
Lease(addr, valid, subnet_id, 0, false, false, 
"", hwaddr),
 
  473    if (prefixlen != 128) {
 
 
  484               DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
 
  485               SubnetID subnet_id, 
const bool fqdn_fwd, 
const bool fqdn_rev,
 
  486               const std::string& hostname, 
const HWAddrPtr& hwaddr,
 
  488    : 
Lease(addr, valid, subnet_id, 0,
 
  489            fqdn_fwd, fqdn_rev, hostname, hwaddr),
 
  498    if (prefixlen != 128) {
 
 
  520const std::vector<uint8_t>&
 
  523        static std::vector<uint8_t> empty_vec;
 
  527    return (
duid_->getDuid());
 
 
  545    ostringstream stream;
 
  549           << 
static_cast<int>(
type_) << 
")\n" 
  550           << 
"Address:       " << 
addr_ << 
"\n" 
  551           << 
"Prefix length: " << 
static_cast<int>(
prefixlen_) << 
"\n" 
  552           << 
"IAID:          " << 
iaid_ << 
"\n" 
  555           << 
"Cltt:          " << 
cltt_ << 
"\n" 
  556           << 
"DUID:          " << (
duid_?
duid_->toText():
"(none)") << 
"\n" 
  557           << 
"Hardware addr: " << (
hwaddr_?
hwaddr_->toText(
false):
"(none)") << 
"\n" 
  563        stream << 
"User context:  " << 
getContext()->str() << 
"\n";
 
  566    return (stream.str());
 
 
  571    ostringstream stream;
 
  573    stream << 
"Address:       " << 
addr_ << 
"\n" 
  575           << 
"Cltt:          " << 
cltt_ << 
"\n" 
  576           << 
"Hardware addr: " << (
hwaddr_ ? 
hwaddr_->toText(
false) : 
"(none)") << 
"\n" 
  581           << 
"Relay ID:      " << (
relay_id_.empty() ? 
"(none)" :
 
  583           << 
"Remote ID:     " << (
remote_id_.empty() ? 
"(none)" :
 
  587        stream << 
"User context:  " << 
getContext()->str() << 
"\n";
 
  590    return (stream.str());
 
 
  678    if (!lease->addr_.isV6()) {
 
  686                  " or it is not a string value");
 
  689    lease->type_ = 
textToType(lease_type->stringValue());
 
  693        lease->prefixlen_ = 128;
 
  698                      " or it is not an integer");
 
  701        if ((prefix_len->intValue() < 1) || (prefix_len->intValue() > 128)) {
 
  703                      << 
" must be in range of [1..128]");
 
  706        lease->prefixlen_ = 
static_cast<uint8_t
>(prefix_len->intValue());
 
  713                  " or it is not an integer");
 
  716    if (iaid->intValue() < 0) {
 
  720    lease->iaid_ = 
static_cast<uint32_t
>(iaid->intValue());
 
  726                  " or it is not a string");
 
  731        lease->duid_.reset(
new DUID(parsed_duid.
getDuid()));
 
  733    } 
catch (
const std::exception& ex) {
 
  735                  << duid->stringValue() << 
" in the parsed lease");
 
  742                  " or is not an integer");
 
  745    if (preferred_lft->intValue() < 0) {
 
  747                  << 
" must not be negative");
 
  750    lease->preferred_lft_ = 
static_cast<uint32_t
>(preferred_lft->intValue());
 
 
  761    if (user_context && (user_context->getType() == 
Element::map)) {
 
  762        mutable_user_context = 
copy(user_context, 0);
 
  777    bool changed = 
false;
 
  779    if (!old_values || (*old_values != *new_values)) {
 
  781        mutable_isc->set(elem_name, new_values);
 
  782        mutable_user_context->set(
"ISC", mutable_isc);
 
 
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
Holds DUID (DHCPv6 Unique Identifier)
static DUID fromText(const std::string &text)
Create DUID from the textual format.
static const DUID & EMPTY()
Defines the constant "empty" DUID.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A wrapper interface for the ASIO library.
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< DUID > DuidPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
@ HTYPE_ETHER
Ethernet 10Mbps.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
bool nullOrEqualValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are both null or both are non-null and they point to equal value...
bool equalValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are non-null and values are equal.
Defines the logger used by the top-level component of kea-lfc.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
void setContext(const data::ConstElementPtr &ctx)
Sets user context.
Hardware type that represents information from DHCPv4 packet.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
std::vector< uint8_t > hwaddr_
ClientIdPtr client_id_
Client identifier.
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Lease4(const isc::asiolink::IOAddress &addr, const HWAddrPtr &hwaddr, const uint8_t *clientid, size_t clientid_len, uint32_t valid_lft, time_t cltt, uint32_t subnet_id, const bool fqdn_fwd=false, const bool fqdn_rev=false, const std::string &hostname="")
Constructor.
bool operator==(const Lease4 &other) const
Compare two leases for equality.
std::vector< uint8_t > remote_id_
Remote identifier for Bulk Lease Query.
std::vector< uint8_t > relay_id_
Relay identifier for Bulk Lease Query.
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
bool belongsToClient(const HWAddrPtr &hw_address, const ClientIdPtr &client_id) const
Check if the lease belongs to the client with the given identifiers.
Lease4()
Default constructor.
virtual std::string toText() const
Convert lease to printable form.
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
ExtendedInfoAction extended_info_action_
Record the action on extended info tables in the lease.
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
ExtendedInfoAction
Action on extended info tables.
@ ACTION_IGNORE
ignore extended info,
virtual std::string toText() const
Convert Lease to Printable Form.
Lease6(Lease::Type type, const isc::asiolink::IOAddress &addr, DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid, SubnetID subnet_id, const HWAddrPtr &hwaddr=HWAddrPtr(), uint8_t prefixlen=128)
Constructor.
bool operator==(const Lease6 &other) const
Compare two leases for equality.
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Lease::Type type_
Lease type.
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
uint32_t iaid_
Identity Association Identifier (IAID)
uint32_t preferred_lft_
Preferred lifetime.
DuidPtr duid_
Client identifier.
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
uint8_t prefixlen_
IPv6 prefix length.
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
a common structure for IPv4 and IPv6 leases
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
static const uint32_t STATE_DEFAULT
A lease in the default state.
uint32_t current_valid_lft_
Current valid lifetime.
SubnetID subnet_id_
Subnet identifier.
uint32_t pool_id_
The pool id.
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
uint32_t valid_lft_
Valid lifetime.
bool stateRegistered() const
Indicates if the lease is in the "registered" state.
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
static const uint32_t STATE_DECLINED
Declined lease.
bool expired() const
returns true if the lease is expired
static const uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Lease(const isc::asiolink::IOAddress &addr, uint32_t valid_lft, SubnetID subnet_id, time_t cltt, const bool fqdn_fwd, const bool fqdn_rev, const std::string &hostname, const HWAddrPtr &hwaddr)
Constructor.
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
static void syncCurrentExpirationTime(const Lease &from, Lease &to)
Sync lease current expiration time with new value from another lease, so that additional operations c...
std::string hostname_
Client hostname.
uint32_t state_
Holds the lease state(s).
int64_t getExpirationTime() const
Returns lease expiration time.
static const uint32_t STATE_REGISTERED
Registered self-generated lease.
bool fqdn_fwd_
Forward zone updated?
time_t cltt_
Client last transmission time.
bool updateUserContextISC(const std::string elem_name, data::ConstElementPtr new_values)
Update the ISC entry in the lease's user-context.
virtual std::string toText() const =0
Convert Lease to Printable Form.
static void fromElementCommon(const LeasePtr &lease, const data::ConstElementPtr &element)
Sets common (for v4 and v6) properties of the lease object.
static std::string typeToText(Type type)
returns text representation of a lease type
static Type textToType(const std::string &text)
Converts type name to the actual type.
HWAddrPtr hwaddr_
Client's MAC/hardware address.
bool fqdn_rev_
Reverse zone updated?
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
time_t current_cltt_
Current client last transmission time.