23 namespace lease_cmds {
34 IOAddress addr = getAddress(lease_info,
"ip-address");
40 string hwaddr_txt = getString(lease_info,
"hw-address");
41 HWAddr hwaddr = HWAddr::fromText(hwaddr_txt);
47 if (lease_info->contains(
"subnet-id")) {
48 subnet_id = getUint32(lease_info,
"subnet-id");
53 subnet = cfg->getCfgSubnets4()->getSubnet(subnet_id);
56 << subnet_id <<
" currently configured.");
59 if (!subnet->inRange(addr)) {
61 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
66 subnet = cfg->getCfgSubnets4()->selectSubnet(addr);
69 <<
" subnet for address " << addr);
71 subnet_id = subnet->getID();
76 if (lease_info->contains(
"client-id")) {
77 string txt = getString(lease_info,
"client-id");
78 client_id = ClientId::fromText(txt);
83 uint32_t valid_lft = 0;
84 if (lease_info->contains(
"valid-lft")) {
85 valid_lft = getUint32(lease_info,
"valid-lft");
87 valid_lft = subnet->getValid();
97 if (lease_info->contains(
"expire")) {
98 int64_t expire_time = getInteger(lease_info,
"expire");
99 if (expire_time <= 0) {
103 }
else if (expire_time < valid_lft) {
105 " for address " << addr);
107 cltt =
static_cast<time_t
>(expire_time - valid_lft);
112 bool fqdn_fwd =
false;
113 if (lease_info->contains(
"fqdn-fwd")) {
114 fqdn_fwd = getBoolean(lease_info,
"fqdn-fwd");
116 bool fqdn_rev =
false;
117 if (lease_info->contains(
"fqdn-rev")) {
118 fqdn_rev = getBoolean(lease_info,
"fqdn-rev");
121 if (lease_info->contains(
"hostname")) {
122 hostname = getString(lease_info,
"hostname");
124 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
126 " fqdn was set to true.");
130 if (lease_info->contains(
"state")) {
131 state = getUint8(lease_info,
"state");
135 if (state > Lease::STATE_EXPIRED_RECLAIMED) {
137 "values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
142 if (ctx && (ctx->getType() != Element::map)) {
144 <<
"' is not a JSON map.");
150 if (ctx && ctx->contains(
"comment")) {
152 <<
"' in user context '" << ctx->str() <<
"'");
156 copied =
copy(ctx, 0);
158 copied = Element::createMap();
160 copied->set(
"comment", comment);
168 fqdn_fwd, fqdn_rev, hostname));
174 force_create =
false;
175 if (lease_info->contains(
"force-create")) {
176 force_create = getBoolean(lease_info,
"force-create");
185 bool& force_create) {
191 IOAddress addr = getAddress(lease_info,
"ip-address");
197 string duid_txt = getString(lease_info,
"duid");
198 DUID duid = DUID::fromText(duid_txt);
202 uint8_t prefix_len = 128;
203 if (lease_info->contains(
"type")) {
204 string txt = getString(lease_info,
"type");
205 if (txt ==
"IA_NA") {
206 type = Lease::TYPE_NA;
207 }
else if (txt ==
"IA_TA") {
208 type = Lease::TYPE_TA;
209 }
else if (txt ==
"IA_PD") {
210 type = Lease::TYPE_PD;
212 prefix_len = getUint8(lease_info,
"prefix-len");
215 "supported values are: na, ta and pd");
222 if (lease_info->contains(
"subnet-id")) {
223 subnet_id = getUint32(lease_info,
"subnet-id");
230 subnet = cfg->getCfgSubnets6()->getSubnet(subnet_id);
233 << subnet_id <<
" currently configured.");
237 if ((type == Lease::TYPE_NA) && !subnet->inRange(addr)) {
239 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
243 if (type != Lease::TYPE_NA) {
245 " address leases only, not prefix leases.");
247 subnet = cfg->getCfgSubnets6()->selectSubnet(addr);
250 "subnet for address " << addr);
252 subnet_id = subnet->getID();
255 uint32_t iaid = getUint32(lease_info,
"iaid");
259 if (lease_info->contains(
"hw-address")) {
260 string hwaddr_txt = getString(lease_info,
"hw-address");
261 HWAddr hwaddr = HWAddr::fromText(hwaddr_txt);
267 uint32_t valid_lft = 0;
268 if (lease_info->contains(
"valid-lft")) {
269 valid_lft = getUint32(lease_info,
"valid-lft");
271 valid_lft = subnet->getValid();
276 uint32_t pref_lft = 0;
277 if (lease_info->contains(
"preferred-lft")) {
278 pref_lft = getUint32(lease_info,
"preferred-lft");
280 pref_lft = subnet->getValid();
290 if (lease_info->contains(
"expire")) {
291 int64_t expire_time = getInteger(lease_info,
"expire");
292 if (expire_time <= 0) {
296 }
else if (expire_time < valid_lft) {
298 " for address " << addr);
301 cltt =
static_cast<time_t
>(expire_time - valid_lft);
306 bool fqdn_fwd =
false;
307 if (lease_info->contains(
"fqdn-fwd")) {
308 fqdn_fwd = getBoolean(lease_info,
"fqdn-fwd");
310 bool fqdn_rev =
false;
311 if (lease_info->contains(
"fqdn-rev")) {
312 fqdn_rev = getBoolean(lease_info,
"fqdn-rev");
315 if (lease_info->contains(
"hostname")) {
316 hostname = getString(lease_info,
"hostname");
318 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
320 " fqdn was set to true.");
324 if (lease_info->contains(
"state")) {
325 state = getUint8(lease_info,
"state");
329 if (state > Lease::STATE_EXPIRED_RECLAIMED) {
331 "values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
334 if ((state == Lease::STATE_DECLINED) && (type == Lease::TYPE_PD)) {
336 "Invalid declined state for PD prefix.");
341 if (ctx && (ctx->getType() != Element::map)) {
343 <<
"' is not a JSON map.");
349 if (ctx && ctx->contains(
"comment")) {
351 <<
"' in user context '" << ctx->str() <<
"'");
355 copied =
copy(ctx, 0);
357 copied = Element::createMap();
359 copied->set(
"comment", comment);
365 Lease6Ptr l(
new Lease6(type, addr, duid_ptr, iaid, pref_lft, valid_lft,
366 subnet_id, fqdn_fwd, fqdn_rev, hostname,
367 hwaddr_ptr, prefix_len));
374 force_create =
false;
375 if (lease_info->contains(
"force-create")) {
376 force_create = getBoolean(lease_info,
"force-create");
boost::shared_ptr< DUID > DuidPtr
Structure that holds a lease for IPv4 address.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
boost::shared_ptr< Element > ElementPtr
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< const SrvConfig > ConstSrvConfigPtr
Const pointer to the SrvConfig.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
boost::shared_ptr< const Element > ConstElementPtr
Structure that holds a lease for IPv6 address and/or prefix.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Type
Type of lease or pool.
A generic exception that is thrown if a function is called in a prohibited way.
std::string toText() const
Convert the address to a string.
Hardware type that represents information from DHCPv4 packet.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
The IOAddress class represents an IP addresses (version agnostic)
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)