44 string hwaddr_txt =
getString(lease_info,
"hw-address");
51 if (lease_info->contains(
"subnet-id")) {
52 subnet_id =
getUint32(lease_info,
"subnet-id");
56 if (lease_info->contains(
"pool-id")) {
57 pool_id =
getUint32(lease_info,
"pool-id");
64 subnet = cfg->getCfgSubnets4()->getBySubnetId(subnet_id);
67 << subnet_id <<
" currently configured.");
71 if (!subnet->inRange(addr)) {
73 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
78 subnet = cfg->getCfgSubnets4()->selectSubnet(addr);
81 <<
" subnet for address " << addr);
83 subnet_id = subnet->getID();
88 if (lease_info->contains(
"client-id")) {
89 string txt =
getString(lease_info,
"client-id");
95 uint32_t valid_lft = 0;
96 if (lease_info->contains(
"valid-lft")) {
97 valid_lft =
getUint32(lease_info,
"valid-lft");
99 valid_lft = subnet->getValid();
109 if (lease_info->contains(
"expire")) {
110 int64_t expire_time =
getInteger(lease_info,
"expire");
111 if (expire_time <= 0) {
115 }
else if (expire_time < valid_lft) {
117 " for address " << addr);
119 cltt =
static_cast<time_t
>(expire_time - valid_lft);
124 bool fqdn_fwd =
false;
125 if (lease_info->contains(
"fqdn-fwd")) {
126 fqdn_fwd =
getBoolean(lease_info,
"fqdn-fwd");
128 bool fqdn_rev =
false;
129 if (lease_info->contains(
"fqdn-rev")) {
130 fqdn_rev =
getBoolean(lease_info,
"fqdn-rev");
133 if (lease_info->contains(
"hostname")) {
134 hostname =
getString(lease_info,
"hostname");
136 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
138 " fqdn was set to true.");
142 if (lease_info->contains(
"state")) {
143 state =
getUint8(lease_info,
"state");
149 "values are: 0 (default), 1 (declined), 2 (expired-reclaimed)"
150 " and 3 (released)");
157 <<
"' is not a JSON map.");
163 if (ctx && ctx->contains(
"comment")) {
165 <<
"' in user context '" << ctx->str() <<
"'");
169 copied =
copy(ctx, 0);
173 copied->set(
"comment", comment);
180 fqdn_fwd, fqdn_rev, hostname));
183 l->pool_id_ = pool_id;
187 auto check = cfg->getConsistency()->getExtendedInfoSanityCheck();
194 force_create =
false;
195 if (lease_info->contains(
"force-create")) {
196 force_create =
getBoolean(lease_info,
"force-create");
205 bool& force_create) {
217 string duid_txt =
getString(lease_info,
"duid");
222 uint8_t prefix_len = 128;
223 if (lease_info->contains(
"type")) {
224 string txt =
getString(lease_info,
"type");
225 if (txt ==
"IA_NA") {
227 }
else if (txt ==
"IA_TA") {
229 }
else if (txt ==
"IA_PD") {
232 prefix_len =
getUint8(lease_info,
"prefix-len");
235 "supported values are: IA_NA and IA_PD");
242 if (lease_info->contains(
"subnet-id")) {
243 subnet_id =
getUint32(lease_info,
"subnet-id");
246 uint32_t pool_id = 0;
247 if (lease_info->contains(
"pool-id")) {
248 pool_id =
getUint32(lease_info,
"pool-id");
255 subnet = cfg->getCfgSubnets6()->getBySubnetId(subnet_id);
258 << subnet_id <<
" currently configured.");
264 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
270 " address leases only, not prefix leases.");
273 subnet = cfg->getCfgSubnets6()->selectSubnet(addr);
276 "subnet for address " << addr);
278 subnet_id = subnet->getID();
281 uint32_t iaid =
getUint32(lease_info,
"iaid");
285 if (lease_info->contains(
"hw-address")) {
286 string hwaddr_txt =
getString(lease_info,
"hw-address");
293 uint32_t valid_lft = 0;
294 if (lease_info->contains(
"valid-lft")) {
295 valid_lft =
getUint32(lease_info,
"valid-lft");
297 valid_lft = subnet->getValid();
302 uint32_t pref_lft = 0;
303 if (lease_info->contains(
"preferred-lft")) {
304 pref_lft =
getUint32(lease_info,
"preferred-lft");
306 pref_lft = subnet->getValid();
316 if (lease_info->contains(
"expire")) {
317 int64_t expire_time =
getInteger(lease_info,
"expire");
318 if (expire_time <= 0) {
322 }
else if (expire_time < valid_lft) {
324 " for address " << addr);
327 cltt =
static_cast<time_t
>(expire_time - valid_lft);
332 bool fqdn_fwd =
false;
333 if (lease_info->contains(
"fqdn-fwd")) {
334 fqdn_fwd =
getBoolean(lease_info,
"fqdn-fwd");
336 bool fqdn_rev =
false;
337 if (lease_info->contains(
"fqdn-rev")) {
338 fqdn_rev =
getBoolean(lease_info,
"fqdn-rev");
341 if (lease_info->contains(
"hostname")) {
342 hostname =
getString(lease_info,
"hostname");
344 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
346 " fqdn was set to true.");
350 if (lease_info->contains(
"state")) {
351 state =
getUint8(lease_info,
"state");
357 "values are: 0 (default), 1 (declined), 2 (expired-reclaimed)"
358 " and 3 (released)");
363 "Invalid declined state for PD prefix.");
370 <<
"' is not a JSON map.");
376 if (ctx && ctx->contains(
"comment")) {
378 <<
"' in user context '" << ctx->str() <<
"'");
382 copied =
copy(ctx, 0);
386 copied->set(
"comment", comment);
391 if (prefix_len == 0 || prefix_len > 128) {
393 <<
static_cast<unsigned>(prefix_len));
396 if (prefix_len != 128) {
398 if (first_address != addr) {
400 <<
" exceeds prefix/prefix-len pair: " << first_address
401 <<
"/" <<
static_cast<uint32_t
>(prefix_len));
406 Lease6Ptr l(
new Lease6(type, addr, duid_ptr, iaid, pref_lft, valid_lft,
407 subnet_id, fqdn_fwd, fqdn_rev, hostname,
408 hwaddr_ptr, prefix_len));
412 l->pool_id_ = pool_id;
416 auto check = cfg->getConsistency()->getExtendedInfoSanityCheck();
422 force_create =
false;
423 if (lease_info->contains(
"force-create")) {
424 force_create =
getBoolean(lease_info,
"force-create");
Exception thrown when a command failed due to a conflict.
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 if a function is called in a prohibited way.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
bool isV4() const
Convenience function to check for an IPv4 address.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
uint8_t getUint8(ConstElementPtr scope, const std::string &name)
Get an uint8_t value.
static isc::asiolink::IOAddress getAddress(const ConstElementPtr &scope, const std::string &name)
Returns a IOAddress parameter from a scope.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
uint32_t getUint32(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint32_t.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
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 bool upgradeLease6ExtendedInfo(const Lease6Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
Upgrade a V6 lease user context to the new extended info entry.
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
static bool upgradeLease4ExtendedInfo(const Lease4Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
The following queries are used to fulfill Bulk Lease Query queries.
virtual isc::dhcp::Lease4Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
virtual isc::dhcp::Lease6Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
An abstract API for lease database.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
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< const SrvConfig > ConstSrvConfigPtr
Const pointer to the SrvConfig.
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
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< ClientId > ClientIdPtr
Shared pointer to a Client ID.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Defines the logger used by the top-level component of kea-lfc.
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.
Structure that holds a lease for IPv4 address.
Structure that holds a lease for IPv6 address and/or prefix.
static const uint32_t STATE_DECLINED
Declined lease.
static const uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
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