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);
165 uint32_t t1 = subnet->getT1();
166 uint32_t t2 = subnet->getT2();
170 fqdn_fwd, fqdn_rev, hostname));
176 force_create =
false;
177 if (lease_info->contains(
"force-create")) {
178 force_create = getBoolean(lease_info,
"force-create");
187 bool& force_create) {
193 IOAddress addr = getAddress(lease_info,
"ip-address");
199 string duid_txt = getString(lease_info,
"duid");
200 DUID duid = DUID::fromText(duid_txt);
204 uint8_t prefix_len = 128;
205 if (lease_info->contains(
"type")) {
206 string txt = getString(lease_info,
"type");
207 if (txt ==
"IA_NA") {
208 type = Lease::TYPE_NA;
209 }
else if (txt ==
"IA_TA") {
210 type = Lease::TYPE_TA;
211 }
else if (txt ==
"IA_PD") {
212 type = Lease::TYPE_PD;
214 prefix_len = getUint8(lease_info,
"prefix-len");
217 "supported values are: na, ta and pd");
224 if (lease_info->contains(
"subnet-id")) {
225 subnet_id = getUint32(lease_info,
"subnet-id");
232 subnet = cfg->getCfgSubnets6()->getSubnet(subnet_id);
235 << subnet_id <<
" currently configured.");
239 if ((type == Lease::TYPE_NA) && !subnet->inRange(addr)) {
241 "to subnet " << subnet->toText() <<
", subnet-id=" << subnet_id);
245 if (type != Lease::TYPE_NA) {
247 " address leases only, not prefix leases.");
249 subnet = cfg->getCfgSubnets6()->selectSubnet(addr);
252 "subnet for address " << addr);
254 subnet_id = subnet->getID();
257 uint32_t iaid = getUint32(lease_info,
"iaid");
261 if (lease_info->contains(
"hw-address")) {
262 string hwaddr_txt = getString(lease_info,
"hw-address");
263 HWAddr hwaddr = HWAddr::fromText(hwaddr_txt);
269 uint32_t valid_lft = 0;
270 if (lease_info->contains(
"valid-lft")) {
271 valid_lft = getUint32(lease_info,
"valid-lft");
273 valid_lft = subnet->getValid();
278 uint32_t pref_lft = 0;
279 if (lease_info->contains(
"preferred-lft")) {
280 pref_lft = getUint32(lease_info,
"preferred-lft");
282 pref_lft = subnet->getValid();
292 if (lease_info->contains(
"expire")) {
293 int64_t expire_time = getInteger(lease_info,
"expire");
294 if (expire_time <= 0) {
298 }
else if (expire_time < valid_lft) {
300 " for address " << addr);
303 cltt = static_cast<time_t>(expire_time - valid_lft);
308 bool fqdn_fwd =
false;
309 if (lease_info->contains(
"fqdn-fwd")) {
310 fqdn_fwd = getBoolean(lease_info,
"fqdn-fwd");
312 bool fqdn_rev =
false;
313 if (lease_info->contains(
"fqdn-rev")) {
314 fqdn_rev = getBoolean(lease_info,
"fqdn-rev");
317 if (lease_info->contains(
"hostname")) {
318 hostname = getString(lease_info,
"hostname");
320 if (hostname.empty() && (fqdn_fwd || fqdn_rev)) {
322 " fqdn was set to true.");
326 if (lease_info->contains(
"state")) {
327 state = getUint8(lease_info,
"state");
331 if (state > Lease::STATE_EXPIRED_RECLAIMED) {
333 "values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
338 if (ctx && (ctx->getType() != Element::map)) {
340 <<
"' is not a JSON map.");
346 if (ctx && ctx->contains(
"comment")) {
348 <<
"' in user context '" << ctx->str() <<
"'");
352 copied =
copy(ctx, 0);
354 copied = Element::createMap();
356 copied->set(
"comment", comment);
361 uint32_t t1 = subnet->getT1();
362 uint32_t t2 = subnet->getT2();
364 Lease6Ptr l(
new Lease6(type, addr, duid_ptr, iaid, pref_lft, valid_lft, t1, t2,
365 subnet_id, fqdn_fwd, fqdn_rev, hostname,
366 hwaddr_ptr, prefix_len));
373 force_create =
false;
374 if (lease_info->contains(
"force-create")) {
375 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
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.
bool isV4() const
Convenience function to check for an IPv4 address.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string toText() const
Convert the address to a string.
Type
Type of lease or pool.
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)