22#include <boost/make_shared.hpp>
23#include <boost/static_assert.hpp>
48 "DELETE FROM lease4 WHERE address = $1 AND expire = $2" },
52 "delete_lease4_state_expired",
54 "WHERE state = $1 AND expire < $2" },
59 "DELETE FROM lease6 WHERE address = cast($1 as inet) AND expire = $2"},
63 "delete_lease6_state_expired",
65 "WHERE state = $1 AND expire < $2" },
70 "SELECT address, hwaddr, client_id, "
71 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
72 "fqdn_fwd, fqdn_rev, hostname, "
73 "state, user_context, relay_id, remote_id, pool_id "
79 "SELECT address, hwaddr, client_id, "
80 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
81 "fqdn_fwd, fqdn_rev, hostname, "
82 "state, user_context, relay_id, remote_id, pool_id "
84 "WHERE address = $1" },
88 "get_lease4_clientid",
89 "SELECT address, hwaddr, client_id, "
90 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
91 "fqdn_fwd, fqdn_rev, hostname, "
92 "state, user_context, relay_id, remote_id, pool_id "
94 "WHERE client_id = $1" },
98 "get_lease4_clientid_subid",
99 "SELECT address, hwaddr, client_id, "
100 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
101 "fqdn_fwd, fqdn_rev, hostname, "
102 "state, user_context, relay_id, remote_id, pool_id "
104 "WHERE client_id = $1 AND subnet_id = $2" },
109 "SELECT address, hwaddr, client_id, "
110 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
111 "fqdn_fwd, fqdn_rev, hostname, "
112 "state, user_context, relay_id, remote_id, pool_id "
114 "WHERE hwaddr = $1" },
118 "get_lease4_hwaddr_subid",
119 "SELECT address, hwaddr, client_id, "
120 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
121 "fqdn_fwd, fqdn_rev, hostname, "
122 "state, user_context, relay_id, remote_id, pool_id "
124 "WHERE hwaddr = $1 AND subnet_id = $2" },
129 "SELECT address, hwaddr, client_id, "
130 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
131 "fqdn_fwd, fqdn_rev, hostname, "
132 "state, user_context, relay_id, remote_id, pool_id "
134 "WHERE address > $1 "
140 "get_lease4_uctx_page",
141 "SELECT address, hwaddr, client_id, "
142 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
143 "fqdn_fwd, fqdn_rev, hostname, "
144 "state, user_context, relay_id, remote_id, pool_id "
146 "WHERE address > $1 AND user_context IS NOT NULL "
153 "SELECT address, hwaddr, client_id, "
154 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
155 "fqdn_fwd, fqdn_rev, hostname, "
156 "state, user_context, relay_id, remote_id, pool_id "
158 "WHERE subnet_id = $1" },
162 "get_lease4_hostname",
163 "SELECT address, hwaddr, client_id, "
164 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
165 "fqdn_fwd, fqdn_rev, hostname, "
166 "state, user_context, relay_id, remote_id, pool_id "
168 "WHERE lower(hostname) = $1" },
173 "SELECT address, hwaddr, client_id, "
174 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
175 "fqdn_fwd, fqdn_rev, hostname, "
176 "state, user_context, relay_id, remote_id, pool_id "
178 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
184 "get_lease4_relayid",
185 "SELECT address, hwaddr, client_id, "
186 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
187 "fqdn_fwd, fqdn_rev, hostname, "
188 "state, user_context, relay_id, remote_id, pool_id "
190 "WHERE relay_id = $1 and address > $2 "
196 "get_lease4_relayid_qst",
197 "SELECT address, hwaddr, client_id, "
198 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
199 "fqdn_fwd, fqdn_rev, hostname, "
200 "state, user_context, relay_id, remote_id, pool_id "
202 "WHERE relay_id = $1 and address > $2 "
203 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
204 "THEN 0 ELSE valid_lifetime END) >= $3 "
210 "get_lease4_relayid_qset",
211 "SELECT address, hwaddr, client_id, "
212 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
213 "fqdn_fwd, fqdn_rev, hostname, "
214 "state, user_context, relay_id, remote_id, pool_id "
216 "WHERE relay_id = $1 and address > $2 "
217 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
218 "THEN 0 ELSE valid_lifetime END) >= $3 "
219 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
220 "THEN 0 ELSE valid_lifetime END) <= $4 "
226 "get_lease4_relayid_qet",
227 "SELECT address, hwaddr, client_id, "
228 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
229 "fqdn_fwd, fqdn_rev, hostname, "
230 "state, user_context, relay_id, remote_id, pool_id "
232 "WHERE relay_id = $1 and address > $2 "
233 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
234 "THEN 0 ELSE valid_lifetime END) <= $3 "
240 "get_lease4_remoteid",
241 "SELECT address, hwaddr, client_id, "
242 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
243 "fqdn_fwd, fqdn_rev, hostname, "
244 "state, user_context, relay_id, remote_id, pool_id "
246 "WHERE remote_id = $1 and address > $2 "
252 "get_lease4_remoteid_qst",
253 "SELECT address, hwaddr, client_id, "
254 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
255 "fqdn_fwd, fqdn_rev, hostname, "
256 "state, user_context, relay_id, remote_id, pool_id "
258 "WHERE remote_id = $1 and address > $2 "
259 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
260 "THEN 0 ELSE valid_lifetime END) >= $3 "
266 "get_lease4_remoteid_qset",
267 "SELECT address, hwaddr, client_id, "
268 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
269 "fqdn_fwd, fqdn_rev, hostname, "
270 "state, user_context, relay_id, remote_id, pool_id "
272 "WHERE remote_id = $1 and address > $2 "
273 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
274 "THEN 0 ELSE valid_lifetime END) >= $3 "
275 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
276 "THEN 0 ELSE valid_lifetime END) <= $4 "
282 "get_lease4_remoteid_qet",
283 "SELECT address, hwaddr, client_id, "
284 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
285 "fqdn_fwd, fqdn_rev, hostname, "
286 "state, user_context, relay_id, remote_id, pool_id "
288 "WHERE remote_id = $1 and address > $2 "
289 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
290 "THEN 0 ELSE valid_lifetime END) <= $3 "
297 "SELECT host(address), duid, valid_lifetime, "
298 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
299 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
300 "hwaddr, hwtype, hwaddr_source, "
301 "state, user_context, pool_id "
303 "ORDER BY address "},
308 "SELECT host(address), duid, valid_lifetime, "
309 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
310 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
311 "hwaddr, hwtype, hwaddr_source, "
312 "state, user_context, pool_id "
314 "WHERE address = cast($1 as inet) AND lease_type = $2"},
318 "get_lease6_duid_iaid",
319 "SELECT host(address), duid, valid_lifetime, "
320 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
321 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
322 "hwaddr, hwtype, hwaddr_source, "
323 "state, user_context, pool_id "
325 "WHERE duid = $1 AND iaid = $2 AND lease_type = $3" },
329 "get_lease6_duid_iaid_subid",
330 "SELECT host(address), duid, valid_lifetime, "
331 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
332 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
333 "hwaddr, hwtype, hwaddr_source, "
334 "state, user_context, pool_id "
336 "WHERE lease_type = $1 "
337 "AND duid = $2 AND iaid = $3 AND subnet_id = $4" },
342 "SELECT host(address), duid, valid_lifetime, "
343 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
344 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
345 "hwaddr, hwtype, hwaddr_source, "
346 "state, user_context, pool_id "
348 "WHERE address > cast($1 as inet) "
354 "get_lease6_uctx_page",
355 "SELECT host(address), duid, valid_lifetime, "
356 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
357 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
358 "hwaddr, hwtype, hwaddr_source, "
359 "state, user_context, pool_id "
361 "WHERE address > cast($1 as inet) AND user_context IS NOT NULL "
368 "SELECT host(address), duid, valid_lifetime, "
369 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
370 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
371 "hwaddr, hwtype, hwaddr_source, "
372 "state, user_context, pool_id "
374 "WHERE subnet_id = $1" },
378 "get_lease6_subid_page",
379 "SELECT host(address), duid, valid_lifetime, "
380 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
381 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
382 "hwaddr, hwtype, hwaddr_source, "
383 "state, user_context, pool_id "
385 "WHERE subnet_id = $1 AND address > cast($2 as inet) "
392 "SELECT host(address), duid, valid_lifetime, "
393 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
394 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
395 "hwaddr, hwtype, hwaddr_source, "
396 "state, user_context, pool_id "
402 "get_lease6_hostname",
403 "SELECT host(address), duid, valid_lifetime, "
404 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
405 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
406 "hwaddr, hwtype, hwaddr_source, "
407 "state, user_context, pool_id "
409 "WHERE lower(hostname) = $1" },
414 "SELECT host(address), duid, valid_lifetime, "
415 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
416 "lease_type, iaid, prefix_len, "
417 "fqdn_fwd, fqdn_rev, hostname, "
418 "hwaddr, hwtype, hwaddr_source, "
419 "state, user_context, pool_id "
421 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
430 "INSERT INTO lease4(address, hwaddr, client_id, "
431 "valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "
432 "state, user_context, relay_id, remote_id, pool_id) "
433 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" },
441 "INSERT INTO lease6(address, duid, valid_lifetime, "
442 "expire, subnet_id, pref_lifetime, "
443 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
444 "hwaddr, hwtype, hwaddr_source, "
445 "state, user_context, pool_id) "
446 "VALUES (cast($1 as inet), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)" },
453 "UPDATE lease4 SET address = $1, hwaddr = $2, "
454 "client_id = $3, valid_lifetime = $4, expire = $5, "
455 "subnet_id = $6, fqdn_fwd = $7, fqdn_rev = $8, hostname = $9, "
456 "state = $10, user_context = $11, relay_id = $12, remote_id = $13, pool_id = $14 "
457 "WHERE address = $15 AND expire = $16" },
465 "UPDATE lease6 SET address = cast($1 as inet), duid = $2, "
466 "valid_lifetime = $3, expire = $4, subnet_id = $5, "
467 "pref_lifetime = $6, lease_type = $7, iaid = $8, "
468 "prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, "
469 "hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
470 "state = $16, user_context = $17, pool_id = $18 "
471 "WHERE address = cast($19 as inet) AND expire = $20" },
476 "SELECT subnet_id, state, leases as state_count"
477 " FROM lease4_stat ORDER BY subnet_id, state" },
481 "subnet_lease4_stats",
482 "SELECT subnet_id, state, leases as state_count"
484 " WHERE subnet_id = $1 "
489 "subnet_range_lease4_stats",
490 "SELECT subnet_id, state, leases as state_count"
492 " WHERE subnet_id >= $1 and subnet_id <= $2 "
493 " ORDER BY subnet_id, state" },
497 "all_pool_lease4_stats",
498 "SELECT subnet_id, pool_id, state, leases as state_count"
499 " FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state" },
504 "SELECT subnet_id, lease_type, state, leases as state_count"
505 " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
509 "subnet_lease6_stats",
510 "SELECT subnet_id, lease_type, state, leases as state_count"
512 " WHERE subnet_id = $1 "
513 " ORDER BY lease_type, state" },
517 "subnet_range_lease6_stats",
518 "SELECT subnet_id, lease_type, state, leases as state_count"
520 " WHERE subnet_id >= $1 and subnet_id <= $2 "
521 " ORDER BY subnet_id, lease_type, state" },
525 "all_pool_lease6_stats",
526 "SELECT subnet_id, pool_id, lease_type, state, leases as state_count"
527 " FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state" },
531 "check_lease4_limits",
532 "SELECT checkLease4Limits($1)" },
536 "check_lease6_limits",
537 "SELECT checkLease6Limits($1)" },
542 "SELECT isJsonSupported()" },
546 "get_lease4_count_by_class",
548 "FROM lease4_stat_by_client_class "
549 "WHERE client_class = $1" },
553 "get_lease6_count_by_class",
555 "FROM lease6_stat_by_client_class "
556 "WHERE client_class = $1 AND lease_type = $2" },
561 "DELETE FROM lease6_relay_id" },
566 "DELETE FROM lease6_remote_id" },
571 "DELETE FROM lease6_relay_id WHERE lease_addr = cast($1 as inet)" },
576 "DELETE FROM lease6_remote_id WHERE lease_addr = cast($1 as inet)" },
581 "INSERT INTO lease6_relay_id(relay_id, lease_addr) "
582 "VALUES ($1, cast($2 as inet))" },
587 "INSERT INTO lease6_remote_id(remote_id, lease_addr) "
588 "VALUES ($1, cast($2 as inet))" },
593 "SELECT DISTINCT ON(l.address) "
594 "host(l.address), l.duid, l.valid_lifetime, "
595 "extract(epoch from l.expire)::bigint, l.subnet_id, l.pref_lifetime, "
596 "l.lease_type, l.iaid, l.prefix_len, l.fqdn_fwd, l.fqdn_rev, "
597 "l.hostname, l.hwaddr, l.hwtype, l.hwaddr_source, "
598 "l.state, l.user_context, l.pool_id "
600 "INNER JOIN lease6_relay_id AS r "
601 " ON l.address = r.lease_addr "
602 " WHERE r.relay_id = $1 AND r.lease_addr > cast($2 as inet) "
603 "ORDER BY l.address "
609 "SELECT DISTINCT ON(l.address) "
610 "host(l.address), l.duid, l.valid_lifetime, "
611 "extract(epoch from l.expire)::bigint, l.subnet_id, l.pref_lifetime, "
612 "l.lease_type, l.iaid, l.prefix_len, l.fqdn_fwd, l.fqdn_rev, "
613 "l.hostname, l.hwaddr, l.hwtype, l.hwaddr_source, "
614 "l.state, l.user_context, l.pool_id "
616 "INNER JOIN lease6_remote_id AS r "
617 " ON l.address = r.lease_addr "
618 " WHERE r.remote_id = $1 AND r.lease_addr > cast($2 as inet) "
619 "ORDER BY l.address "
625 "SELECT COUNT(*) FROM lease6_relay_id" },
630 "SELECT COUNT(*) FROM lease6_remote_id" },
694 static const size_t ADDRESS_COL = 0;
695 static const size_t HWADDR_COL = 1;
696 static const size_t CLIENT_ID_COL = 2;
697 static const size_t VALID_LIFETIME_COL = 3;
698 static const size_t EXPIRE_COL = 4;
699 static const size_t SUBNET_ID_COL = 5;
700 static const size_t FQDN_FWD_COL = 6;
701 static const size_t FQDN_REV_COL = 7;
702 static const size_t HOSTNAME_COL = 8;
703 static const size_t STATE_COL = 9;
704 static const size_t USER_CONTEXT_COL = 10;
705 static const size_t RELAY_ID_COL = 11;
706 static const size_t REMOTE_ID_COL = 12;
707 static const size_t POOL_ID_COL = 13;
710 static const size_t LEASE_COLUMNS = 14;
716 : lease_(), addr4_(0), client_id_length_(0),
717 relay_id_length_(0), remote_id_length_(0) {
719 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
722 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
723 memset(relay_id_buffer_, 0,
sizeof(relay_id_buffer_));
724 memset(remote_id_buffer_, 0,
sizeof(remote_id_buffer_));
730 columns_.push_back(
"valid_lifetime");
764 addr_str_ = boost::lexical_cast<std::string>(lease->addr_.toUint32());
767 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
772 << lease_->hwaddr_->hwaddr_.size()
773 <<
" exceeds maximum allowed of: "
776 bind_array.
add(lease->hwaddr_->hwaddr_);
781 if (lease->client_id_) {
782 bind_array.
add(lease->client_id_->getClientId());
804 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
807 bind_array.
add(lease->fqdn_fwd_);
809 bind_array.
add(lease->fqdn_rev_);
811 bind_array.
add(lease->hostname_);
813 state_str_ = boost::lexical_cast<std::string>(lease->state_);
824 if (!lease->relay_id_.empty()) {
825 bind_array.
add(lease->relay_id_);
830 if (!lease->remote_id_.empty()) {
831 bind_array.
add(lease->remote_id_);
836 pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
838 }
catch (
const std::exception& ex) {
840 "Could not create bind array from Lease4: "
841 << lease_->addr_.toText() <<
", reason: " << ex.what());
861 sizeof(client_id_buffer_), client_id_length_);
895 <<
"' is not a JSON map");
900 sizeof(relay_id_buffer_), relay_id_length_);
903 sizeof(remote_id_buffer_), remote_id_length_);
920 if (relay_id_length_) {
921 result->relay_id_.assign(relay_id_buffer_,
922 relay_id_buffer_ + relay_id_length_);
925 if (remote_id_length_) {
926 result->remote_id_.assign(remote_id_buffer_,
927 remote_id_buffer_ + remote_id_length_);
933 }
catch (
const std::exception& ex) {
935 "Could not convert data to Lease4, reason: "
949 size_t client_id_length_;
951 size_t relay_id_length_;
953 size_t remote_id_length_;
966 static const size_t ADDRESS_COL = 0;
967 static const size_t DUID_COL = 1;
968 static const size_t VALID_LIFETIME_COL = 2;
969 static const size_t EXPIRE_COL = 3;
970 static const size_t SUBNET_ID_COL = 4;
971 static const size_t PREF_LIFETIME_COL = 5;
972 static const size_t LEASE_TYPE_COL = 6;
973 static const size_t IAID_COL = 7;
974 static const size_t PREFIX_LEN_COL = 8;
975 static const size_t FQDN_FWD_COL = 9;
976 static const size_t FQDN_REV_COL = 10;
977 static const size_t HOSTNAME_COL = 11;
978 static const size_t HWADDR_COL = 12;
979 static const size_t HWTYPE_COL = 13;
980 static const size_t HWADDR_SOURCE_COL = 14;
981 static const size_t STATE_COL = 15;
982 static const size_t USER_CONTEXT_COL = 16;
983 static const size_t POOL_ID_COL = 17;
986 static const size_t LEASE_COLUMNS = 18;
1007 return (boost::lexical_cast<std::string>(
ival_));
1015 : lease_(), duid_length_(0), duid_(duid_length_), iaid_u_(0),
1016 iaid_str_(
""), lease_type_(
Lease6::TYPE_NA), lease_type_str_(
""),
1017 prefix_len_(0), prefix_len_str_(
""), pref_lifetime_(0),
1018 preferred_lifetime_str_(
""), hwtype_(0), hwtype_str_(
""),
1019 hwaddr_source_(0), hwaddr_source_str_(
"") {
1021 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1023 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
1028 columns_.push_back(
"valid_lifetime");
1031 columns_.push_back(
"pref_lifetime");
1040 columns_.push_back(
"hwaddr_source");
1042 columns_.push_back(
"user_context");
1069 if (lease_->duid_) {
1070 bind_array.
add(lease_->duid_->getDuid());
1088 lease_->valid_lft_);
1092 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
1095 preferred_lifetime_str_ = boost::lexical_cast<std::string>(lease_->preferred_lft_);
1096 bind_array.
add(preferred_lifetime_str_);
1098 lease_type_str_ = boost::lexical_cast<std::string>(lease_->type_);
1099 bind_array.
add(lease_type_str_);
1104 iaid_u_.uval_ = lease_->iaid_;
1105 iaid_str_ = iaid_u_.dbInputString();
1106 bind_array.
add(iaid_str_);
1108 prefix_len_str_ = boost::lexical_cast<std::string>
1109 (
static_cast<unsigned int>(lease_->prefixlen_));
1110 bind_array.
add(prefix_len_str_);
1112 bind_array.
add(lease->fqdn_fwd_);
1114 bind_array.
add(lease->fqdn_rev_);
1116 bind_array.
add(lease->hostname_);
1118 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
1123 << lease_->hwaddr_->hwaddr_.size()
1124 <<
" exceeds maximum allowed of: "
1127 bind_array.
add(lease->hwaddr_->hwaddr_);
1132 if (lease->hwaddr_) {
1133 hwtype_str_ = boost::lexical_cast<std::string>
1134 (
static_cast<unsigned int>(lease_->hwaddr_->htype_));
1135 hwaddr_source_str_ = boost::lexical_cast<std::string>
1136 (
static_cast<unsigned int>(lease_->hwaddr_->source_));
1138 hwtype_str_ = boost::lexical_cast<std::string>
1140 hwaddr_source_str_ = boost::lexical_cast<std::string>
1144 bind_array.
add(hwtype_str_);
1146 bind_array.
add(hwaddr_source_str_);
1148 state_str_ = boost::lexical_cast<std::string>(lease->state_);
1159 pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
1161 }
catch (
const std::exception& ex) {
1163 "Could not create bind array from Lease6: "
1164 << lease_->addr_.toText() <<
", reason: " << ex.what());
1189 convertFromBytea(r, row, DUID_COL, duid_buffer_,
sizeof(duid_buffer_), duid_length_);
1190 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1233 hwaddr->source_ = hwaddr_source_;
1245 <<
"' is not a JSON map");
1262 hwaddr, prefix_len_));
1276 }
catch (
const std::exception& ex) {
1278 "Could not convert data to Lease6, reason: "
1297 uint32_t raw_value = 0;
1299 switch (raw_value) {
1320 size_t duid_length_;
1321 std::vector<uint8_t> duid_;
1323 union Uiaid iaid_u_;
1324 std::string iaid_str_;
1326 std::string lease_type_str_;
1327 uint8_t prefix_len_;
1328 std::string prefix_len_str_;
1329 uint32_t pref_lifetime_;
1330 std::string preferred_lifetime_str_;
1332 std::string hwtype_str_;
1333 uint32_t hwaddr_source_;
1334 std::string hwaddr_source_str_;
1356 const bool fetch_type,
const bool fetch_pool =
false)
1370 const bool fetch_type,
const SubnetID& subnet_id)
1386 const bool fetch_type,
const SubnetID& first_subnet_id,
1468 uint32_t lease_type;
1532 :
conn_(parameters, io_service_accessor, db_reconnect_callback) {
1537PgSqlLeaseMgr::PgSqlLeaseContextAlloc::PgSqlLeaseContextAlloc(
1544 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1545 if (!mgr_.pool_->pool_.empty()) {
1546 ctx_ = mgr_.pool_->pool_.back();
1547 mgr_.pool_->pool_.pop_back();
1551 ctx_ = mgr_.createContext();
1555 if (mgr_.pool_->pool_.empty()) {
1556 isc_throw(Unexpected,
"No available PostgreSQL lease context?!");
1558 ctx_ = mgr_.pool_->pool_.back();
1562PgSqlLeaseMgr::PgSqlLeaseContextAlloc::~PgSqlLeaseContextAlloc() {
1565 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1566 mgr_.pool_->pool_.push_back(ctx_);
1573PgSqlLeaseMgr::PgSqlLeaseTrackingContextAlloc::PgSqlLeaseTrackingContextAlloc(
1580 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1581 if (mgr_.hasCallbacks() && !mgr_.tryLock(lease)) {
1582 isc_throw(DbOperationError,
"unable to lock the lease " << lease->addr_);
1584 if (!mgr_.pool_->pool_.empty()) {
1585 ctx_ = mgr_.pool_->pool_.back();
1586 mgr_.pool_->pool_.pop_back();
1590 ctx_ = mgr_.createContext();
1594 if (mgr_.pool_->pool_.empty()) {
1595 isc_throw(Unexpected,
"No available PostgreSQL lease context?!");
1597 ctx_ = mgr_.pool_->pool_.back();
1601PgSqlLeaseMgr::PgSqlLeaseTrackingContextAlloc::~PgSqlLeaseTrackingContextAlloc() {
1604 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1605 if (mgr_.hasCallbacks()) {
1606 mgr_.unlock(lease_);
1608 mgr_.pool_->pool_.push_back(ctx_);
1623 tls += parameters.count(
"trust-anchor");
1624 tls += parameters.count(
"cert-file");
1625 tls += parameters.count(
"key-file");
1626 tls += parameters.count(
"cipher-list");
1627#ifdef HAVE_PGSQL_SSL
1639 <<
"backend (built with this feature disabled)");
1644 timer_name_ =
"PgSqlLeaseMgr[";
1645 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1646 timer_name_ +=
"]DbReconnectTimer";
1668 bool reopened =
false;
1670 const std::string timer_name = db_reconnect_ctl->timerName();
1671 bool check = db_reconnect_ctl->checkRetries();
1678 }
catch (
const std::exception& ex) {
1697 .arg(db_reconnect_ctl->maxRetries());
1710 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1711 .arg(db_reconnect_ctl->maxRetries())
1712 .arg(db_reconnect_ctl->retryInterval());
1718 db_reconnect_ctl->retryInterval(),
1739 ctx->conn_.openDatabase();
1743 for (; tagged_statements[i].text != NULL; ++i) {
1744 ctx->conn_.prepareStatement(tagged_statements[i]);
1763 std::stringstream tmp;
1766 tmp <<
", library " << PQlibVersion();
1772 StatementIndex stindex,
1774 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
1775 tagged_statements[stindex].nbparams,
1780 int s = PQresultStatus(r);
1782 if (s != PGRES_COMMAND_OK) {
1789 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1798 .arg(lease->addr_.toText());
1801 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
1805 ctx->exchange4_->createBindForSend(lease, bind_array);
1810 lease->updateCurrentExpirationTime();
1823 .arg(lease->addr_.toText())
1829 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
1833 ctx->exchange6_->createBindForSend(lease, bind_array);
1839 lease->updateCurrentExpirationTime();
1853template <
typename Exchange,
typename LeaseCollection>
1856 StatementIndex stindex,
1860 bool single)
const {
1861 const int n = tagged_statements[stindex].nbparams;
1863 tagged_statements[stindex].name, n,
1864 n > 0 ? &bind_array.
values_[0] : NULL,
1865 n > 0 ? &bind_array.
lengths_[0] : NULL,
1866 n > 0 ? &bind_array.
formats_[0] : NULL, 0));
1868 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1870 int rows = PQntuples(r);
1871 if (single && rows > 1) {
1873 "database where only one was expected for query "
1874 << tagged_statements[stindex].name);
1877 for(
int i = 0; i < rows; ++i) {
1878 result.push_back(exchange->convertFromDatabase(r, i));
1892 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange4_,
1896 if (collection.empty()) {
1899 result = *collection.begin();
1913 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange6_,
1917 if (collection.empty()) {
1920 result = *collection.begin();
1933 std::string addr_str = boost::lexical_cast<std::string>(addr.
toUint32());
1934 bind_array.
add(addr_str);
1940 PgSqlLeaseContextAlloc get_context(*
this);
1957 if (!hwaddr.
hwaddr_.empty()) {
1967 PgSqlLeaseContextAlloc get_context(*
this);
1985 if (!hwaddr.
hwaddr_.empty()) {
1992 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1993 bind_array.
add(subnet_id_str);
1999 PgSqlLeaseContextAlloc get_context(*
this);
2022 PgSqlLeaseContextAlloc get_context(*
this);
2043 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2044 bind_array.
add(subnet_id_str);
2050 PgSqlLeaseContextAlloc get_context(*
this);
2067 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2068 bind_array.
add(subnet_id_str);
2074 PgSqlLeaseContextAlloc get_context(*
this);
2091 bind_array.
add(hostname);
2097 PgSqlLeaseContextAlloc get_context(*
this);
2115 PgSqlLeaseContextAlloc get_context(*
this);
2127 if (!lower_bound_address.
isV4()) {
2129 "retrieving leases from the lease database, got "
2130 << lower_bound_address);
2135 .arg(lower_bound_address.
toText());
2141 std::string lb_address_data = boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
2142 bind_array.
add(lb_address_data);
2145 std::string page_size_data = boost::lexical_cast<std::string>(page_size.
page_size_);
2146 bind_array.
add(page_size_data);
2152 PgSqlLeaseContextAlloc get_context(*
this);
2171 std::string addr_str = addr.
toText();
2172 bind_array.
add(addr_str);
2175 std::string type_str_ = boost::lexical_cast<std::string>(lease_type);
2176 bind_array.
add(type_str_);
2182 PgSqlLeaseContextAlloc get_context(*
this);
2192 uint32_t iaid)
const {
2206 bind_array.
add(iaid_str);
2209 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
2210 bind_array.
add(lease_type_str);
2216 PgSqlLeaseContextAlloc get_context(*
this);
2226 uint32_t iaid,
SubnetID subnet_id)
const {
2237 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
2238 bind_array.
add(lease_type_str);
2245 bind_array.
add(iaid_str);
2248 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2249 bind_array.
add(subnet_id_str);
2255 PgSqlLeaseContextAlloc get_context(*
this);
2272 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2273 bind_array.
add(subnet_id_str);
2279 PgSqlLeaseContextAlloc get_context(*
this);
2294 .arg(lower_bound_address.
toText())
2298 if (!lower_bound_address.
isV6()) {
2300 "retrieving leases from the lease database, got "
2301 << lower_bound_address);
2309 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2310 bind_array.
add(subnet_id_str);
2313 std::string lb_address_str = lower_bound_address.
toText();
2314 bind_array.
add(lb_address_str);
2317 std::string page_size_data =
2318 boost::lexical_cast<std::string>(page_size.
page_size_);
2319 bind_array.
add(page_size_data);
2322 PgSqlLeaseContextAlloc get_context(*
this);
2344 PgSqlLeaseContextAlloc get_context(*
this);
2362 bind_array.
add(hostname);
2368 PgSqlLeaseContextAlloc get_context(*
this);
2386 PgSqlLeaseContextAlloc get_context(*
this);
2398 if (!lower_bound_address.
isV6()) {
2400 "retrieving leases from the lease database, got "
2401 << lower_bound_address);
2406 .arg(lower_bound_address.
toText());
2412 std::string lb_address_data = lower_bound_address.
toText();
2413 bind_array.
add(lb_address_data);
2416 std::string page_size_data =
2417 boost::lexical_cast<std::string>(page_size.
page_size_);
2418 bind_array.
add(page_size_data);
2424 PgSqlLeaseContextAlloc get_context(*
this);
2434 const size_t max_leases)
const {
2442 const size_t max_leases)
const {
2448template<
typename LeaseCollection>
2450PgSqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2451 const size_t max_leases,
2452 StatementIndex statement_index)
const {
2457 bind_array.
add(state_str);
2461 bind_array.
add(timestamp_str);
2465 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2466 std::numeric_limits<uint32_t>::max();
2467 std::string limit_str = boost::lexical_cast<std::string>(limit);
2468 bind_array.
add(limit_str);
2471 PgSqlLeaseContextAlloc get_context(*
this);
2475 getLeaseCollection(ctx, statement_index, bind_array, expired_leases);
2478template<
typename LeasePtr>
2481 StatementIndex stindex,
2484 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2485 tagged_statements[stindex].nbparams,
2490 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2492 int affected_rows = boost::lexical_cast<int>(PQcmdTuples(r));
2495 if (affected_rows == 1) {
2500 if (affected_rows == 0) {
2502 lease->addr_.toText() <<
" either because the lease does not exist, "
2503 "it has been deleted or it has changed in the database.");
2508 isc_throw(DbOperationError,
"apparently updated more than one lease "
2509 "that had the address " << lease->addr_.toText());
2517 .arg(lease->addr_.toText());
2520 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2525 ctx->exchange4_->createBindForSend(lease, bind_array);
2528 std::string addr4_str = boost::lexical_cast<std::string>(lease->addr_.toUint32());
2529 bind_array.
add(addr4_str);
2531 std::string expire_str;
2537 lease->current_valid_lft_);
2539 bind_array.
add(expire_str);
2542 updateLeaseCommon(ctx, stindex, bind_array, lease);
2545 lease->updateCurrentExpirationTime();
2558 .arg(lease->addr_.toText())
2566 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2571 ctx->exchange6_->createBindForSend(lease, bind_array);
2574 std::string addr_str = lease->addr_.
toText();
2575 bind_array.
add(addr_str);
2577 std::string expire_str;
2583 lease->current_valid_lft_);
2585 bind_array.
add(expire_str);
2588 updateLeaseCommon(ctx, stindex, bind_array, lease);
2591 lease->updateCurrentExpirationTime();
2595 switch (recorded_action) {
2618 StatementIndex stindex,
2620 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2621 tagged_statements[stindex].nbparams,
2626 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2627 int affected_rows = boost::lexical_cast<int>(PQcmdTuples(r));
2629 return (affected_rows);
2641 std::string addr4_str = boost::lexical_cast<std::string>(addr.
toUint32());
2642 bind_array.
add(addr4_str);
2644 std::string expire_str;
2650 lease->current_valid_lft_);
2652 bind_array.
add(expire_str);
2655 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2658 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE4, bind_array);
2661 if (affected_rows == 1) {
2669 if (affected_rows == 0) {
2676 "that had the address " << lease->addr_.toText());
2691 std::string addr6_str = addr.
toText();
2692 bind_array.
add(addr6_str);
2694 std::string expire_str;
2700 lease->current_valid_lft_);
2702 bind_array.
add(expire_str);
2705 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2708 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE6, bind_array);
2711 if (affected_rows == 1) {
2723 if (affected_rows == 0) {
2730 "that had the address " << lease->addr_.toText());
2748PgSqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
2749 StatementIndex statement_index) {
2754 bind_array.
add(state_str);
2758 static_cast<time_t
>(secs));
2759 bind_array.
add(expiration_str);
2762 PgSqlLeaseContextAlloc get_context(*
this);
2766 return (deleteLeaseCommon(ctx, statement_index, bind_array));
2770PgSqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
2772 if (!user_context) {
2777 PgSqlLeaseContextAlloc get_context(*
this);
2782 std::string
const user_context_str(user_context->str());
2783 bind_array.
add(user_context_str);
2787 tagged_statements[stindex].name,
2788 tagged_statements[stindex].nbparams,
2792 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2812 PgSqlLeaseContextAlloc get_context(*
this);
2817 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2819 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2821 bool json_supported;
2823 return json_supported;
2830 PgSqlLeaseContextAlloc get_context(*
this);
2835 bind_array.
add(client_class);
2837 bind_array.
add(ltype);
2844 tagged_statements[stindex].name,
2845 tagged_statements[stindex].nbparams,
2849 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2851 int rows = PQntuples(r);
2890 PgSqlLeaseContextAlloc get_context(*
this);
2903 PgSqlLeaseContextAlloc get_context(*
this);
2916 PgSqlLeaseContextAlloc get_context(*
this);
2931 PgSqlLeaseContextAlloc get_context(*
this);
2946 PgSqlLeaseContextAlloc get_context(*
this);
2959 PgSqlLeaseContextAlloc get_context(*
this);
2972 PgSqlLeaseContextAlloc get_context(*
this);
2987 PgSqlLeaseContextAlloc get_context(*
this);
3012 PgSqlLeaseContextAlloc get_context(*
this);
3015 std::string name =
"";
3017 name = ctx->conn_.getParameter(
"name");
3026 return (std::string(
"PostgreSQL Database"));
3029std::pair<uint32_t, uint32_t>
3051 deleteRelayId6(addr);
3052 deleteRemoteId6(addr);
3056PgSqlLeaseMgr::deleteRelayId6(
const IOAddress& addr) {
3060 std::string addr_data = addr.
toText();
3061 bind_array.
add(addr_data);
3064 PgSqlLeaseContextAlloc get_context(*
this);
3070 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3071 tagged_statements[stindex].nbparams,
3076 int s = PQresultStatus(r);
3078 if (s != PGRES_COMMAND_OK) {
3079 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3084PgSqlLeaseMgr::deleteRemoteId6(
const IOAddress& addr) {
3088 std::string addr_data = addr.
toText();
3089 bind_array.
add(addr_data);
3092 PgSqlLeaseContextAlloc get_context(*
this);
3098 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3099 tagged_statements[stindex].nbparams,
3104 int s = PQresultStatus(r);
3106 if (s != PGRES_COMMAND_OK) {
3107 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3113 const vector<uint8_t>& relay_id) {
3118 if (relay_id.empty()) {
3121 bind_array.
add(relay_id);
3124 std::string lease_addr_data = lease_addr.
toText();
3125 bind_array.
add(lease_addr_data);
3128 PgSqlLeaseContextAlloc get_context(*
this);
3134 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3135 tagged_statements[stindex].nbparams,
3140 int s = PQresultStatus(r);
3142 if (s != PGRES_COMMAND_OK) {
3143 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3149 const vector<uint8_t>& remote_id) {
3154 if (remote_id.empty()) {
3157 bind_array.
add(remote_id);
3160 std::string lease_addr_data = lease_addr.
toText();
3161 bind_array.
add(lease_addr_data);
3164 PgSqlLeaseContextAlloc get_context(*
this);
3170 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3171 tagged_statements[stindex].nbparams,
3176 int s = PQresultStatus(r);
3178 if (s != PGRES_COMMAND_OK) {
3179 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3187 std::stringstream tmp;
3190 for (
auto const& it :
id) {
3194 tmp << std::setw(2) << std::setfill(
'0')
3195 <<
static_cast<unsigned int>(it);
3207 const time_t& qry_start_time ,
3208 const time_t& qry_end_time ) {
3210 if (!lower_bound_address.
isV4()) {
3212 "retrieving leases from the lease database, got "
3213 << lower_bound_address);
3217 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3221 bool have_qst = (qry_start_time > 0);
3222 bool have_qet = (qry_end_time > 0);
3225 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
3232 .arg(lower_bound_address.
toText())
3233 .arg(idToText(relay_id))
3234 .arg(qry_start_time)
3241 if (!relay_id.empty()) {
3242 bind_array.
add(relay_id);
3248 std::string lb_address_data =
3249 boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
3250 bind_array.
add(lb_address_data);
3253 std::string start_time_str;
3255 start_time_str = boost::lexical_cast<std::string>(qry_start_time);
3256 bind_array.
add(start_time_str);
3260 std::string end_time_str;
3262 end_time_str = boost::lexical_cast<std::string>(qry_end_time);
3263 bind_array.
add(end_time_str);
3267 std::string page_size_data =
3268 boost::lexical_cast<std::string>(page_size.
page_size_);
3269 bind_array.
add(page_size_data);
3272 if (have_qst && !have_qet) {
3274 }
else if (have_qst && have_qet) {
3276 }
else if (!have_qst && have_qet) {
3284 PgSqlLeaseContextAlloc get_context(*
this);
3287 getLeaseCollection(ctx, stindex, bind_array,
result);
3296 const time_t& qry_start_time ,
3297 const time_t& qry_end_time ) {
3299 if (!lower_bound_address.
isV4()) {
3301 "retrieving leases from the lease database, got "
3302 << lower_bound_address);
3306 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3310 bool have_qst = (qry_start_time > 0);
3311 bool have_qet = (qry_end_time > 0);
3314 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
3321 .arg(lower_bound_address.
toText())
3322 .arg(idToText(remote_id))
3323 .arg(qry_start_time)
3330 if (!remote_id.empty()) {
3331 bind_array.
add(remote_id);
3337 std::string lb_address_data =
3338 boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
3339 bind_array.
add(lb_address_data);
3342 std::string start_time_str;
3344 start_time_str = boost::lexical_cast<std::string>(qry_start_time);
3345 bind_array.
add(start_time_str);
3349 std::string end_time_str;
3351 end_time_str = boost::lexical_cast<std::string>(qry_end_time);
3352 bind_array.
add(end_time_str);
3356 std::string page_size_data =
3357 boost::lexical_cast<std::string>(page_size.
page_size_);
3358 bind_array.
add(page_size_data);
3361 if (have_qst && !have_qet) {
3363 }
else if (have_qst && have_qet) {
3365 }
else if (!have_qst && have_qet) {
3373 PgSqlLeaseContextAlloc get_context(*
this);
3376 getLeaseCollection(ctx, stindex, bind_array,
result);
3384 getConsistency()->getExtendedInfoSanityCheck();
3393 .arg(start_addr.
toText())
3400 uint32_t start_addr_data = start_addr.
toUint32();
3401 bind_array.
add(start_addr_data);
3404 std::string page_size_data =
3405 boost::lexical_cast<std::string>(page_size.
page_size_);
3406 bind_array.
add(page_size_data);
3412 PgSqlLeaseContextAlloc get_context(*
this);
3418 if (leases.empty()) {
3424 start_addr = leases.back()->addr_;
3425 for (
auto const& lease : leases) {
3427 vector<uint8_t> previous_relay_id = lease->relay_id_;
3428 vector<uint8_t> previous_remote_id = lease->remote_id_;
3429 if (!previous_user_context &&
3430 previous_relay_id.empty() &&
3431 previous_remote_id.empty()) {
3436 lease->relay_id_.clear();
3437 lease->remote_id_.clear();
3440 (previous_relay_id != lease->relay_id_) ||
3441 (previous_remote_id != lease->remote_id_)) {
3449 }
catch (
const std::exception& ex) {
3453 .arg(lease->addr_.toText())
3473 .arg(lower_bound_address.
toText())
3477 if (!lower_bound_address.
isV6()) {
3479 "retrieving leases from the lease database, got "
3480 << lower_bound_address);
3483 std::vector<uint8_t> relay_id_data = relay_id.
getDuid();
3484 if (relay_id_data.size() == 0) {
3492 bind_array.
add(relay_id_data);
3495 std::string lb_addr_data = lower_bound_address.
toText();
3496 bind_array.
add(lb_addr_data);
3499 std::string page_size_data =
3500 boost::lexical_cast<std::string>(page_size.
page_size_);
3501 bind_array.
add(page_size_data);
3504 PgSqlLeaseContextAlloc get_context(*
this);
3519 .arg(lower_bound_address.
toText())
3520 .arg(idToText(remote_id));
3523 if (!lower_bound_address.
isV6()) {
3525 "retrieving leases from the lease database, got "
3526 << lower_bound_address);
3529 if (remote_id.size() == 0) {
3537 bind_array.
add(remote_id);
3540 std::string lb_addr_data = lower_bound_address.
toText();
3541 bind_array.
add(lb_addr_data);
3544 std::string page_size_data =
3545 boost::lexical_cast<std::string>(page_size.
page_size_);
3546 bind_array.
add(page_size_data);
3549 PgSqlLeaseContextAlloc get_context(*
this);
3560 getConsistency()->getExtendedInfoSanityCheck();
3574 .arg(start_addr.
toText())
3581 std::string start_addr_str = start_addr.
toText();
3582 bind_array.
add(start_addr_str);
3585 std::string page_size_data =
3586 boost::lexical_cast<std::string>(page_size.
page_size_);
3587 bind_array.
add(page_size_data);
3593 PgSqlLeaseContextAlloc get_context(*
this);
3599 if (leases.empty()) {
3605 start_addr = leases.back()->addr_;
3606 for (
auto const& lease : leases) {
3614 if (modified || added) {
3621 }
catch (
const std::exception& ex) {
3625 .arg(lease->addr_.toText())
3641 PgSqlLeaseContextAlloc get_context(*
this);
3646 PgSqlResult r1(PQexecPrepared(ctx->conn_, tagged_statements[stindex1].name,
3648 ctx->conn_.checkStatementError(r1, tagged_statements[stindex1]);
3652 PgSqlResult r2(PQexecPrepared(ctx->conn_, tagged_statements[stindex2].name,
3654 ctx->conn_.checkStatementError(r2, tagged_statements[stindex2]);
3660 PgSqlLeaseContextAlloc get_context(*
this);
3665 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3667 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3670 return (
static_cast<size_t>(count));
3676 PgSqlLeaseContextAlloc get_context(*
this);
3681 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3683 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3686 return (
static_cast<size_t>(count));
when the call the UDPServer carries on at the same position As a result
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 a function is not implemented.
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database.
Exception thrown on failure to execute a database function.
Invalid address family used as input to Lease Manager.
Multiple lease records found where one expected.
Common PgSql Connector Pool.
static bool warned_about_tls
Emit the TLS support warning only once.
static const char DUPLICATE_KEY[]
Define the PgSql error state for a duplicate key error.
static void ensureSchemaVersion(const ParameterMap ¶meters, const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string())
Retrieve schema version, validate it against the hardcoded version, and attempt to initialize the sch...
static std::pair< uint32_t, uint32_t > getVersion(const ParameterMap ¶meters, const IOServiceAccessorPtr &ac=IOServiceAccessorPtr(), const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string(), unsigned int id=0)
Get the schema version.
static const char * getRawColumnValue(const PgSqlResult &r, const int row, const size_t col)
Gets a pointer to the raw column value in a result set row.
PgSqlExchange(const size_t num_columns=0)
Constructor.
static std::string convertToDatabaseTime(const time_t input_time)
Converts UTC time_t value to a text representation in local time.
static std::string getColumnLabel(const PgSqlResult &r, const size_t col)
Fetches the name of the column in a result set.
static void convertFromBytea(const PgSqlResult &r, const int row, const size_t col, uint8_t *buffer, const size_t buffer_size, size_t &bytes_converted)
Converts a column in a row in a result set to a binary bytes.
static void getColumnValue(const PgSqlResult &r, const int row, const size_t col, std::string &value)
Fetches text column value as a string.
static time_t convertFromDatabaseTime(const std::string &db_time_val)
Converts time stamp from the database to a time_t.
std::vector< std::string > columns_
Stores text labels for columns, currently only used for logging and errors.
static isc::asiolink::IOAddress getIPv6Value(const PgSqlResult &r, const int row, const size_t col)
Converts a column in a row in a result set into IPv6 address.
RAII wrapper for PostgreSQL Result sets.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds Client identifier or client IPv4 address.
static constexpr size_t MAX_CLIENT_ID_LEN
Maximum size of a client ID.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Holds DUID (DHCPv6 Unique Identifier)
static constexpr size_t MAX_DUID_LEN
maximum duid size
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
std::string toText() const
Returns textual representation of the identifier (e.g.
static void recreate(const std::string &dbaccess, bool preserve_callbacks=true)
Recreate an instance of a lease manager with optionally preserving registered callbacks.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
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.
bool getExtendedInfoTablesEnabled() const
Returns the setting indicating if lease6 extended info tables are enabled.
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 bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
SubnetID getLastSubnetID() const
Returns the value of last subnet ID specified (or zero)
SubnetID getFirstSubnetID() const
Returns the value of first subnet ID specified (or zero)
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
static const unsigned int DB_CONNECTION
The network state is being altered by the DB connection recovery mechanics.
Attempt to update lease that was not there.
Supports exchanging IPv4 leases with PostgreSQL.
Lease4Ptr convertFromDatabase(const PgSqlResult &r, int row)
Creates a Lease4 object from a given row in a result set.
PgSqlLease4Exchange()
Constructor.
void createBindForSend(const Lease4Ptr &lease, PsqlBindArray &bind_array)
Creates the bind array for sending Lease4 data to the database.
Supports exchanging IPv6 leases with PostgreSQL.
void createBindForSend(const Lease6Ptr &lease, PsqlBindArray &bind_array)
Creates the bind array for sending Lease6 data to the database.
void getLeaseTypeColumnValue(const PgSqlResult &r, const int row, const size_t col, Lease6::Type &value) const
Fetches an integer text column as a Lease6::Type.
Lease6Ptr convertFromDatabase(const PgSqlResult &r, int row)
Creates a Lease6 object from a given row in a result set.
PostgreSQL Lease Context Pool.
PostgreSQL Lease Context.
PgSqlLeaseContext(const db::DatabaseConnection::ParameterMap ¶meters, db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback)
Constructor.
db::PgSqlConnection conn_
PostgreSQL connection.
std::string valid_lifetime_str_
std::vector< uint8_t > addr_bin_
uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN]
virtual ~PgSqlLeaseExchange()
std::string subnet_id_str_
std::vector< uint8_t > hwaddr_
std::string user_context_
std::string addr_str_
Common Instance members used for binding and conversion.
PostgreSQL Lease Manager.
virtual void recountClassLeases6() override
Recount the leases per class for V6 leases.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
PgSqlLeaseContextPtr createContext() const
Create a new context.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
virtual Lease4Collection getLeases4ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
Returns existing IPv4 leases with a given remote-id.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query for all subnets and pools.
virtual std::string checkLimits6(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv6 lease limits set in the given user context are exceeded.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
static std::string getDBVersion()
Local version of getDBVersion() class method.
virtual std::string checkLimits4(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv4 lease limits set in the given user context are exceeded.
virtual size_t byRemoteId6size() const override
Return the by-remote-id table size.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id) override
Add lease6 extended info into by-relay-id table.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Extended information / Bulk Lease Query shared interface.
virtual void recountClassLeases4() override
Recount the leases per class for V4 leases.
virtual size_t upgradeExtendedInfo4(const LeasePageSize &page_size) override
Upgrade extended info (v4).
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual std::pair< uint32_t, uint32_t > getVersion(const std::string &timer_name=std::string()) const override
Returns backend version.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
virtual std::string getDescription() const override
Returns description of the backend.
virtual void wipeExtendedInfoTables6() override
Wipe extended info table (v6).
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual size_t upgradeExtendedInfo6(const LeasePageSize &page_size) override
Upgrade extended info (v6).
virtual size_t byRelayId6size() const override
Return the by-relay-id table size.
virtual Lease4Collection getLeases4ByRelayId(const OptionBuffer &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
The following queries are used to fulfill Bulk Lease Query queries.
virtual void commit() override
Commit Transactions.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id) override
Add lease6 extended info into by-remote-id table.
StatementIndex
Statement Tags.
@ SUBNET_RANGE_LEASE4_STATS
@ GET_LEASE4_REMOTEID_QST
@ SUBNET_RANGE_LEASE6_STATS
@ GET_LEASE4_COUNT_BY_CLASS
@ GET_LEASE6_DUID_IAID_SUBID
@ GET_LEASE6_COUNT_BY_CLASS
@ GET_LEASE4_HWADDR_SUBID
@ GET_LEASE4_REMOTEID_QET
@ GET_LEASE4_CLIENTID_SUBID
@ DELETE_LEASE6_STATE_EXPIRED
@ GET_LEASE4_RELAYID_QSET
@ DELETE_LEASE4_STATE_EXPIRED
@ GET_LEASE4_REMOTEID_QSET
virtual void rollback() override
Rollback Transactions.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query for all subnets and pools.
virtual void writeLeases6(const std::string &) override
Write V6 leases to a file.
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
virtual std::string getName() const override
Returns backend name.
PgSqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns an IPv4 lease for specified IPv4 address.
virtual void clearClassLeaseCounts() override
Clears the class-lease count map.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
virtual ~PgSqlLeaseMgr()
Destructor (closes database)
virtual bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
virtual size_t getClassLeaseCount(const ClientClass &client_class, const Lease::Type <ype=Lease::TYPE_V4) const override
Returns the class lease count for a given class and lease type.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual void writeLeases4(const std::string &) override
Write V4 leases to a file.
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
Base PgSql derivation of the statistical lease data query.
bool fetch_type_
Indicates if query supplies lease type.
boost::shared_ptr< PgSqlResult > result_set_
The result set returned by Postgres.
PgSqlLeaseStatsQuery(PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor to query for the stats for a range of subnets.
PgSqlConnection & conn_
Database connection to use to execute the query.
virtual ~PgSqlLeaseStatsQuery()
Destructor.
PgSqlTaggedStatement & statement_
The query's prepared statement.
static bool negative_count_
Received negative state count showing a problem.
bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
bool fetch_pool_
Indicates if query requires pool data.
PgSqlLeaseStatsQuery(PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const bool fetch_pool=false)
Constructor to query for all subnets' stats.
PgSqlLeaseStatsQuery(PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const SubnetID &subnet_id)
Constructor to query for a single subnet's stats.
void start()
Creates the lease statistical data result set.
uint32_t next_row_
Index of the next row to fetch.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
void trackAddLease(const LeasePtr &lease)
Invokes the callbacks when a new lease is added.
void trackUpdateLease(const LeasePtr &lease)
Invokes the callbacks when a lease is updated.
void trackDeleteLease(const LeasePtr &lease)
Invokes the callbacks when a lease is deleted.
TrackingLeaseMgr()
Constructor.
bool hasCallbacks() const
Checks if any callbacks have been registered.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static const uint32_t HWADDR_SOURCE_UNKNOWN
Used when actual origin is not known, e.g.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
const size_t OID_NONE
Constants for PostgreSQL data types These are defined by PostgreSQL in <catalog/pg_type....
const size_t OID_TIMESTAMP
const uint32_t PGSQL_SCHEMA_VERSION_MINOR
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
std::function< isc::asiolink::IOServicePtr()> IOServiceAccessor
Function which returns the IOService that can be used to recover the connection.
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR
Define the PostgreSQL backend version.
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID4
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR4
std::string ClientClass
Defines a single class name.
const isc::log::MessageID DHCPSRV_PGSQL_GET_REMOTEID6
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO6_PAGE
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_CLIENTID
const isc::log::MessageID DHCPSRV_PGSQL_GET_ADDR6
const isc::log::MessageID DHCPSRV_PGSQL_GET_DUID
const isc::log::MessageID DHCPSRV_PGSQL_GET6
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID6
const isc::log::MessageID DHCPSRV_PGSQL_GET_PAGE4
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
boost::shared_ptr< DUID > DuidPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME6
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_SUBID_DUID
const isc::log::MessageID DHCPSRV_PGSQL_GET_ADDR4
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO6
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO6_ERROR
const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME4
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_PGSQL_ROLLBACK
const isc::log::MessageID DHCPSRV_PGSQL_GET_HWADDR
const isc::log::MessageID DHCPSRV_PGSQL_NO_TLS_SUPPORT
const isc::log::MessageID DHCPSRV_PGSQL_GET_PAGE6
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4
const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_HWADDR
const isc::log::MessageID DHCPSRV_PGSQL_GET_VERSION
const isc::log::MessageID DHCPSRV_PGSQL_GET_REMOTEID4
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_PAGE
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
const isc::log::MessageID DHCPSRV_PGSQL_TLS_SUPPORT
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
const isc::log::MessageID DHCPSRV_PGSQL_GET4
const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR6
const isc::log::MessageID DHCPSRV_PGSQL_GET_CLIENTID
const isc::log::MessageID DHCPSRV_PGSQL_GET_RELAYID6
const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_DUID
const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR6
const isc::log::MessageID DHCPSRV_PGSQL_GET_RELAYID4
boost::shared_ptr< PgSqlLeaseContext > PgSqlLeaseContextPtr
Type of pointers to contexts.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_FAILED
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const isc::log::MessageID DHCPSRV_PGSQL_UPGRADE_EXTENDED_INFO4_ERROR
@ HTYPE_UNDEFINED
not specified or undefined
@ HTYPE_ETHER
Ethernet 10Mbps.
const isc::log::MessageID DHCPSRV_PGSQL_NEGATIVE_LEASES_STAT
const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED4
const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_SCHEDULE
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_ADDR
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const isc::log::MessageID DHCPSRV_PGSQL_COMMIT
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_PAGE6
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6
PerfMonMgrPtr mgr
PerfMonMgr singleton.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.
Define a PostgreSQL statement.
void addTempString(const std::string &str)
Binds the given string to the bind array.
std::vector< const char * > values_
Vector of pointers to the data values.
std::vector< int > formats_
Vector of "format" for each value.
void add(const char *value)
Adds a char array to bind array based.
size_t size() const
Fetches the number of entries in the array.
void addNull(const int format=PsqlBindArray::TEXT_FMT)
Adds a NULL value to the bind array.
std::string toText() const
Dumps the contents of the array to a string.
std::vector< int > lengths_
Vector of data lengths for each value.
Hardware type that represents information from DHCPv4 packet.
static const size_t MAX_HWADDR_LEN
Maximum size of a hardware address.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
Structure that holds a lease for IPv6 address and/or prefix.
ExtendedInfoAction
Action on extended info tables.
@ ACTION_UPDATE
update extended info tables.
@ ACTION_DELETE
delete reference to the lease
@ ACTION_IGNORE
ignore extended info,
Contains a single row of lease statistical data.
uint32_t pool_id_
The pool ID to which this data applies.
int64_t state_count_
state_count The count of leases in the lease state
uint32_t lease_state_
The lease_state to which the count applies.
SubnetID subnet_id_
The subnet ID to which this data applies.
Lease::Type lease_type_
The lease_type to which the count applies.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
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
Union for marshalling IAID into and out of the database IAID is defined in the RFC as 4 octets,...
Uiaid(uint32_t val)
Constructor.
std::string dbInputString()
Return a string representing the signed 32-bit value.
Uiaid(int32_t val)
Constructor.