25 namespace lease_cmds {
36 IOAddress addr = getAddress(lease_info,
"ip-address");
42 string hwaddr_txt = getString(lease_info,
"hw-address");
43 HWAddr hwaddr = HWAddr::fromText(hwaddr_txt);
49 if (lease_info->contains(
"subnet-id")) {
50 subnet_id = getUint32(lease_info,
"subnet-id");
54 if (lease_info->contains(
"pool-id")) {
55 pool_id = getUint32(lease_info,
"pool-id");
61 subnet = cfg->getCfgSubnets4()->getBySubnetId(subnet_id);
64 << subnet_id <<
" currently configured.");
67 if (!subnet->inRange(addr)) {
69 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
74 subnet = cfg->getCfgSubnets4()->selectSubnet(addr);
77 <<
" subnet for address " << addr);
79 subnet_id = subnet->getID();
84 if (lease_info->contains(
"client-id")) {
85 string txt = getString(lease_info,
"client-id");
86 client_id = ClientId::fromText(txt);
91 uint32_t valid_lft = 0;
92 if (lease_info->contains(
"valid-lft")) {
93 valid_lft = getUint32(lease_info,
"valid-lft");
95 valid_lft = subnet->getValid();
105 if (lease_info->contains(
"expire")) {
106 int64_t expire_time = getInteger(lease_info,
"expire");
107 if (expire_time <= 0) {
111 }
else if (expire_time < valid_lft) {
113 " for address " << addr);
115 cltt =
static_cast<time_t
>(expire_time - valid_lft);
120 bool fqdn_fwd =
false;
121 if (lease_info->contains(
"fqdn-fwd")) {
122 fqdn_fwd = getBoolean(lease_info,
"fqdn-fwd");
124 bool fqdn_rev =
false;
125 if (lease_info->contains(
"fqdn-rev")) {
126 fqdn_rev = getBoolean(lease_info,
"fqdn-rev");
129 if (lease_info->contains(
"hostname")) {
130 hostname = getString(lease_info,
"hostname");
132 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
134 " fqdn was set to true.");
138 if (lease_info->contains(
"state")) {
139 state = getUint8(lease_info,
"state");
143 if (state > Lease::STATE_EXPIRED_RECLAIMED) {
145 "values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
150 if (ctx && (ctx->getType() != Element::map)) {
152 <<
"' is not a JSON map.");
158 if (ctx && ctx->contains(
"comment")) {
160 <<
"' in user context '" << ctx->str() <<
"'");
164 copied =
copy(ctx, 0);
166 copied = Element::createMap();
168 copied->set(
"comment", comment);
176 fqdn_fwd, fqdn_rev, hostname));
179 l->pool_id_ = pool_id;
183 auto check = cfg->getConsistency()->getExtendedInfoSanityCheck();
184 LeaseMgr::upgradeLease4ExtendedInfo(l, check);
185 LeaseMgr::extractLease4ExtendedInfo(l);
190 force_create =
false;
191 if (lease_info->contains(
"force-create")) {
192 force_create = getBoolean(lease_info,
"force-create");
201 bool& force_create) {
207 IOAddress addr = getAddress(lease_info,
"ip-address");
213 string duid_txt = getString(lease_info,
"duid");
214 DUID duid = DUID::fromText(duid_txt);
218 uint8_t prefix_len = 128;
219 if (lease_info->contains(
"type")) {
220 string txt = getString(lease_info,
"type");
221 if (txt ==
"IA_NA") {
222 type = Lease::TYPE_NA;
223 }
else if (txt ==
"IA_TA") {
224 type = Lease::TYPE_TA;
225 }
else if (txt ==
"IA_PD") {
226 type = Lease::TYPE_PD;
228 prefix_len = getUint8(lease_info,
"prefix-len");
231 "supported values are: na, ta and pd");
238 if (lease_info->contains(
"subnet-id")) {
239 subnet_id = getUint32(lease_info,
"subnet-id");
242 uint32_t pool_id = 0;
243 if (lease_info->contains(
"pool-id")) {
244 pool_id = getUint32(lease_info,
"pool-id");
251 subnet = cfg->getCfgSubnets6()->getBySubnetId(subnet_id);
254 << subnet_id <<
" currently configured.");
258 if ((type == Lease::TYPE_NA) && !subnet->inRange(addr)) {
260 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
264 if (type != Lease::TYPE_NA) {
266 " address leases only, not prefix leases.");
268 subnet = cfg->getCfgSubnets6()->selectSubnet(addr);
271 "subnet for address " << addr);
273 subnet_id = subnet->getID();
276 uint32_t iaid = getUint32(lease_info,
"iaid");
280 if (lease_info->contains(
"hw-address")) {
281 string hwaddr_txt = getString(lease_info,
"hw-address");
282 HWAddr hwaddr = HWAddr::fromText(hwaddr_txt);
288 uint32_t valid_lft = 0;
289 if (lease_info->contains(
"valid-lft")) {
290 valid_lft = getUint32(lease_info,
"valid-lft");
292 valid_lft = subnet->getValid();
297 uint32_t pref_lft = 0;
298 if (lease_info->contains(
"preferred-lft")) {
299 pref_lft = getUint32(lease_info,
"preferred-lft");
301 pref_lft = subnet->getValid();
311 if (lease_info->contains(
"expire")) {
312 int64_t expire_time = getInteger(lease_info,
"expire");
313 if (expire_time <= 0) {
317 }
else if (expire_time < valid_lft) {
319 " for address " << addr);
322 cltt =
static_cast<time_t
>(expire_time - valid_lft);
327 bool fqdn_fwd =
false;
328 if (lease_info->contains(
"fqdn-fwd")) {
329 fqdn_fwd = getBoolean(lease_info,
"fqdn-fwd");
331 bool fqdn_rev =
false;
332 if (lease_info->contains(
"fqdn-rev")) {
333 fqdn_rev = getBoolean(lease_info,
"fqdn-rev");
336 if (lease_info->contains(
"hostname")) {
337 hostname = getString(lease_info,
"hostname");
339 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
341 " fqdn was set to true.");
345 if (lease_info->contains(
"state")) {
346 state = getUint8(lease_info,
"state");
350 if (state > Lease::STATE_EXPIRED_RECLAIMED) {
352 "values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
355 if ((state == Lease::STATE_DECLINED) && (type == Lease::TYPE_PD)) {
357 "Invalid declined state for PD prefix.");
362 if (ctx && (ctx->getType() != Element::map)) {
364 <<
"' is not a JSON map.");
370 if (ctx && ctx->contains(
"comment")) {
372 <<
"' in user context '" << ctx->str() <<
"'");
376 copied =
copy(ctx, 0);
378 copied = Element::createMap();
380 copied->set(
"comment", comment);
386 Lease6Ptr l(
new Lease6(type, addr, duid_ptr, iaid, pref_lft, valid_lft,
387 subnet_id, fqdn_fwd, fqdn_rev, hostname,
388 hwaddr_ptr, prefix_len));
392 l->pool_id_ = pool_id;
396 auto check = cfg->getConsistency()->getExtendedInfoSanityCheck();
397 LeaseMgr::upgradeLease6ExtendedInfo(l, check);
402 force_create =
false;
403 if (lease_info->contains(
"force-create")) {
404 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.
Holds DUID (DHCPv6 Unique Identifier)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
An abstract API for lease database.
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.
Structure that holds a lease for IPv4 address.
Structure that holds a lease for IPv6 address and/or prefix.
Type
Type of lease or pool.