21#include <boost/make_shared.hpp>
22#include <boost/static_assert.hpp>
47 "DELETE FROM lease4 WHERE address = $1 AND expire = $2" },
51 "delete_lease4_state_expired",
53 "WHERE state = $1 AND expire < $2" },
58 "DELETE FROM lease6 WHERE address = cast($1 as inet) AND expire = $2"},
62 "delete_lease6_state_expired",
64 "WHERE state = $1 AND expire < $2" },
69 "SELECT address, hwaddr, client_id, "
70 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
71 "fqdn_fwd, fqdn_rev, hostname, "
72 "state, user_context, relay_id, remote_id, pool_id "
78 "SELECT address, hwaddr, client_id, "
79 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
80 "fqdn_fwd, fqdn_rev, hostname, "
81 "state, user_context, relay_id, remote_id, pool_id "
83 "WHERE address = $1" },
87 "get_lease4_clientid",
88 "SELECT address, hwaddr, client_id, "
89 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
90 "fqdn_fwd, fqdn_rev, hostname, "
91 "state, user_context, relay_id, remote_id, pool_id "
93 "WHERE client_id = $1" },
97 "get_lease4_clientid_subid",
98 "SELECT address, hwaddr, client_id, "
99 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
100 "fqdn_fwd, fqdn_rev, hostname, "
101 "state, user_context, relay_id, remote_id, pool_id "
103 "WHERE client_id = $1 AND subnet_id = $2" },
108 "SELECT address, hwaddr, client_id, "
109 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
110 "fqdn_fwd, fqdn_rev, hostname, "
111 "state, user_context, relay_id, remote_id, pool_id "
113 "WHERE hwaddr = $1" },
117 "get_lease4_hwaddr_subid",
118 "SELECT address, hwaddr, client_id, "
119 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
120 "fqdn_fwd, fqdn_rev, hostname, "
121 "state, user_context, relay_id, remote_id, pool_id "
123 "WHERE hwaddr = $1 AND subnet_id = $2" },
128 "SELECT address, hwaddr, client_id, "
129 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
130 "fqdn_fwd, fqdn_rev, hostname, "
131 "state, user_context, relay_id, remote_id, pool_id "
133 "WHERE address > $1 "
139 "get_lease4_uctx_page",
140 "SELECT address, hwaddr, client_id, "
141 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
142 "fqdn_fwd, fqdn_rev, hostname, "
143 "state, user_context, relay_id, remote_id, pool_id "
145 "WHERE address > $1 AND user_context IS NOT NULL "
152 "SELECT address, hwaddr, client_id, "
153 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
154 "fqdn_fwd, fqdn_rev, hostname, "
155 "state, user_context, relay_id, remote_id, pool_id "
157 "WHERE subnet_id = $1" },
161 "get_lease4_hostname",
162 "SELECT address, hwaddr, client_id, "
163 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
164 "fqdn_fwd, fqdn_rev, hostname, "
165 "state, user_context, relay_id, remote_id, pool_id "
167 "WHERE lower(hostname) = $1" },
172 "SELECT address, hwaddr, client_id, "
173 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
174 "fqdn_fwd, fqdn_rev, hostname, "
175 "state, user_context, relay_id, remote_id, pool_id "
177 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
183 "get_lease4_relayid",
184 "SELECT address, hwaddr, client_id, "
185 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
186 "fqdn_fwd, fqdn_rev, hostname, "
187 "state, user_context, relay_id, remote_id, pool_id "
189 "WHERE relay_id = $1 and address > $2 "
195 "get_lease4_relayid_qst",
196 "SELECT address, hwaddr, client_id, "
197 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
198 "fqdn_fwd, fqdn_rev, hostname, "
199 "state, user_context, relay_id, remote_id, pool_id "
201 "WHERE relay_id = $1 and address > $2 "
202 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
203 "THEN 0 ELSE valid_lifetime END) >= $3 "
209 "get_lease4_relayid_qset",
210 "SELECT address, hwaddr, client_id, "
211 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
212 "fqdn_fwd, fqdn_rev, hostname, "
213 "state, user_context, relay_id, remote_id, pool_id "
215 "WHERE relay_id = $1 and address > $2 "
216 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
217 "THEN 0 ELSE valid_lifetime END) >= $3 "
218 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
219 "THEN 0 ELSE valid_lifetime END) <= $4 "
225 "get_lease4_relayid_qet",
226 "SELECT address, hwaddr, client_id, "
227 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
228 "fqdn_fwd, fqdn_rev, hostname, "
229 "state, user_context, relay_id, remote_id, pool_id "
231 "WHERE relay_id = $1 and address > $2 "
232 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
233 "THEN 0 ELSE valid_lifetime END) <= $3 "
239 "get_lease4_remoteid",
240 "SELECT address, hwaddr, client_id, "
241 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
242 "fqdn_fwd, fqdn_rev, hostname, "
243 "state, user_context, relay_id, remote_id, pool_id "
245 "WHERE remote_id = $1 and address > $2 "
251 "get_lease4_remoteid_qst",
252 "SELECT address, hwaddr, client_id, "
253 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
254 "fqdn_fwd, fqdn_rev, hostname, "
255 "state, user_context, relay_id, remote_id, pool_id "
257 "WHERE remote_id = $1 and address > $2 "
258 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
259 "THEN 0 ELSE valid_lifetime END) >= $3 "
265 "get_lease4_remoteid_qset",
266 "SELECT address, hwaddr, client_id, "
267 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
268 "fqdn_fwd, fqdn_rev, hostname, "
269 "state, user_context, relay_id, remote_id, pool_id "
271 "WHERE remote_id = $1 and address > $2 "
272 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
273 "THEN 0 ELSE valid_lifetime END) >= $3 "
274 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
275 "THEN 0 ELSE valid_lifetime END) <= $4 "
281 "get_lease4_remoteid_qet",
282 "SELECT address, hwaddr, client_id, "
283 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
284 "fqdn_fwd, fqdn_rev, hostname, "
285 "state, user_context, relay_id, remote_id, pool_id "
287 "WHERE remote_id = $1 and address > $2 "
288 "and EXTRACT(EPOCH FROM expire) - (CASE valid_lifetime WHEN 4294967295 "
289 "THEN 0 ELSE valid_lifetime END) <= $3 "
296 "SELECT host(address), duid, valid_lifetime, "
297 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
298 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
299 "hwaddr, hwtype, hwaddr_source, "
300 "state, user_context, pool_id "
302 "ORDER BY address "},
307 "SELECT host(address), duid, valid_lifetime, "
308 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
309 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
310 "hwaddr, hwtype, hwaddr_source, "
311 "state, user_context, pool_id "
313 "WHERE address = cast($1 as inet) AND lease_type = $2"},
317 "get_lease6_duid_iaid",
318 "SELECT host(address), duid, valid_lifetime, "
319 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
320 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
321 "hwaddr, hwtype, hwaddr_source, "
322 "state, user_context, pool_id "
324 "WHERE duid = $1 AND iaid = $2 AND lease_type = $3" },
328 "get_lease6_duid_iaid_subid",
329 "SELECT host(address), duid, valid_lifetime, "
330 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
331 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
332 "hwaddr, hwtype, hwaddr_source, "
333 "state, user_context, pool_id "
335 "WHERE lease_type = $1 "
336 "AND duid = $2 AND iaid = $3 AND subnet_id = $4" },
341 "SELECT host(address), duid, valid_lifetime, "
342 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
343 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
344 "hwaddr, hwtype, hwaddr_source, "
345 "state, user_context, pool_id "
347 "WHERE address > cast($1 as inet) "
353 "get_lease6_uctx_page",
354 "SELECT host(address), duid, valid_lifetime, "
355 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
356 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
357 "hwaddr, hwtype, hwaddr_source, "
358 "state, user_context, pool_id "
360 "WHERE address > cast($1 as inet) AND user_context IS NOT NULL "
367 "SELECT host(address), duid, valid_lifetime, "
368 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
369 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
370 "hwaddr, hwtype, hwaddr_source, "
371 "state, user_context, pool_id "
373 "WHERE subnet_id = $1" },
377 "get_lease6_subid_page",
378 "SELECT host(address), duid, valid_lifetime, "
379 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
380 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
381 "hwaddr, hwtype, hwaddr_source, "
382 "state, user_context, pool_id "
384 "WHERE subnet_id = $1 AND address > cast($2 as inet) "
391 "SELECT host(address), duid, valid_lifetime, "
392 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
393 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
394 "hwaddr, hwtype, hwaddr_source, "
395 "state, user_context, pool_id "
401 "get_lease6_hostname",
402 "SELECT host(address), duid, valid_lifetime, "
403 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
404 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
405 "hwaddr, hwtype, hwaddr_source, "
406 "state, user_context, pool_id "
408 "WHERE lower(hostname) = $1" },
413 "SELECT host(address), duid, valid_lifetime, "
414 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
415 "lease_type, iaid, prefix_len, "
416 "fqdn_fwd, fqdn_rev, hostname, "
417 "hwaddr, hwtype, hwaddr_source, "
418 "state, user_context, pool_id "
420 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 "
429 "INSERT INTO lease4(address, hwaddr, client_id, "
430 "valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "
431 "state, user_context, relay_id, remote_id, pool_id) "
432 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" },
440 "INSERT INTO lease6(address, duid, valid_lifetime, "
441 "expire, subnet_id, pref_lifetime, "
442 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
443 "hwaddr, hwtype, hwaddr_source, "
444 "state, user_context, pool_id) "
445 "VALUES (cast($1 as inet), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)" },
452 "UPDATE lease4 SET address = $1, hwaddr = $2, "
453 "client_id = $3, valid_lifetime = $4, expire = $5, "
454 "subnet_id = $6, fqdn_fwd = $7, fqdn_rev = $8, hostname = $9, "
455 "state = $10, user_context = $11, relay_id = $12, remote_id = $13, pool_id = $14 "
456 "WHERE address = $15 AND expire = $16" },
464 "UPDATE lease6 SET address = cast($1 as inet), duid = $2, "
465 "valid_lifetime = $3, expire = $4, subnet_id = $5, "
466 "pref_lifetime = $6, lease_type = $7, iaid = $8, "
467 "prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, "
468 "hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
469 "state = $16, user_context = $17, pool_id = $18 "
470 "WHERE address = cast($19 as inet) AND expire = $20" },
475 "SELECT subnet_id, state, leases as state_count"
476 " FROM lease4_stat ORDER BY subnet_id, state" },
480 "subnet_lease4_stats",
481 "SELECT subnet_id, state, leases as state_count"
483 " WHERE subnet_id = $1 "
488 "subnet_range_lease4_stats",
489 "SELECT subnet_id, state, leases as state_count"
491 " WHERE subnet_id >= $1 and subnet_id <= $2 "
492 " ORDER BY subnet_id, state" },
496 "all_pool_lease4_stats",
497 "SELECT subnet_id, pool_id, state, leases as state_count"
498 " FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state" },
503 "SELECT subnet_id, lease_type, state, leases as state_count"
504 " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
508 "subnet_lease6_stats",
509 "SELECT subnet_id, lease_type, state, leases as state_count"
511 " WHERE subnet_id = $1 "
512 " ORDER BY lease_type, state" },
516 "subnet_range_lease6_stats",
517 "SELECT subnet_id, lease_type, state, leases as state_count"
519 " WHERE subnet_id >= $1 and subnet_id <= $2 "
520 " ORDER BY subnet_id, lease_type, state" },
524 "all_pool_lease6_stats",
525 "SELECT subnet_id, pool_id, lease_type, state, leases as state_count"
526 " FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state" },
530 "check_lease4_limits",
531 "SELECT checkLease4Limits($1)" },
535 "check_lease6_limits",
536 "SELECT checkLease6Limits($1)" },
541 "SELECT isJsonSupported()" },
545 "get_lease4_count_by_class",
547 "FROM lease4_stat_by_client_class "
548 "WHERE client_class = $1" },
552 "get_lease6_count_by_class",
554 "FROM lease6_stat_by_client_class "
555 "WHERE client_class = $1 AND lease_type = $2" },
560 "DELETE FROM lease6_relay_id" },
565 "DELETE FROM lease6_remote_id" },
570 "DELETE FROM lease6_relay_id WHERE lease_addr = cast($1 as inet)" },
575 "DELETE FROM lease6_remote_id WHERE lease_addr = cast($1 as inet)" },
580 "INSERT INTO lease6_relay_id(relay_id, lease_addr) "
581 "VALUES ($1, cast($2 as inet))" },
586 "INSERT INTO lease6_remote_id(remote_id, lease_addr) "
587 "VALUES ($1, cast($2 as inet))" },
592 "SELECT DISTINCT ON(l.address) "
593 "host(l.address), l.duid, l.valid_lifetime, "
594 "extract(epoch from l.expire)::bigint, l.subnet_id, l.pref_lifetime, "
595 "l.lease_type, l.iaid, l.prefix_len, l.fqdn_fwd, l.fqdn_rev, "
596 "l.hostname, l.hwaddr, l.hwtype, l.hwaddr_source, "
597 "l.state, l.user_context, l.pool_id "
599 "INNER JOIN lease6_relay_id AS r "
600 " ON l.address = r.lease_addr "
601 " WHERE r.relay_id = $1 AND r.lease_addr > cast($2 as inet) "
602 "ORDER BY l.address "
608 "SELECT DISTINCT ON(l.address) "
609 "host(l.address), l.duid, l.valid_lifetime, "
610 "extract(epoch from l.expire)::bigint, l.subnet_id, l.pref_lifetime, "
611 "l.lease_type, l.iaid, l.prefix_len, l.fqdn_fwd, l.fqdn_rev, "
612 "l.hostname, l.hwaddr, l.hwtype, l.hwaddr_source, "
613 "l.state, l.user_context, l.pool_id "
615 "INNER JOIN lease6_remote_id AS r "
616 " ON l.address = r.lease_addr "
617 " WHERE r.remote_id = $1 AND r.lease_addr > cast($2 as inet) "
618 "ORDER BY l.address "
624 "SELECT COUNT(*) FROM lease6_relay_id" },
629 "SELECT COUNT(*) FROM lease6_remote_id" },
693 static const size_t ADDRESS_COL = 0;
694 static const size_t HWADDR_COL = 1;
695 static const size_t CLIENT_ID_COL = 2;
696 static const size_t VALID_LIFETIME_COL = 3;
697 static const size_t EXPIRE_COL = 4;
698 static const size_t SUBNET_ID_COL = 5;
699 static const size_t FQDN_FWD_COL = 6;
700 static const size_t FQDN_REV_COL = 7;
701 static const size_t HOSTNAME_COL = 8;
702 static const size_t STATE_COL = 9;
703 static const size_t USER_CONTEXT_COL = 10;
704 static const size_t RELAY_ID_COL = 11;
705 static const size_t REMOTE_ID_COL = 12;
706 static const size_t POOL_ID_COL = 13;
709 static const size_t LEASE_COLUMNS = 14;
715 : lease_(), addr4_(0), client_id_length_(0),
716 relay_id_length_(0), remote_id_length_(0) {
718 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
721 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
722 memset(relay_id_buffer_, 0,
sizeof(relay_id_buffer_));
723 memset(remote_id_buffer_, 0,
sizeof(remote_id_buffer_));
729 columns_.push_back(
"valid_lifetime");
763 addr_str_ = boost::lexical_cast<std::string>(lease->addr_.toUint32());
766 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
771 << lease_->hwaddr_->hwaddr_.size()
772 <<
" exceeds maximum allowed of: "
775 bind_array.
add(lease->hwaddr_->hwaddr_);
780 if (lease->client_id_) {
781 bind_array.
add(lease->client_id_->getClientId());
803 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
806 bind_array.
add(lease->fqdn_fwd_);
808 bind_array.
add(lease->fqdn_rev_);
810 bind_array.
add(lease->hostname_);
812 state_str_ = boost::lexical_cast<std::string>(lease->state_);
823 if (!lease->relay_id_.empty()) {
824 bind_array.
add(lease->relay_id_);
829 if (!lease->remote_id_.empty()) {
830 bind_array.
add(lease->remote_id_);
835 pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
837 }
catch (
const std::exception& ex) {
839 "Could not create bind array from Lease4: "
840 << lease_->addr_.toText() <<
", reason: " << ex.what());
860 sizeof(client_id_buffer_), client_id_length_);
894 <<
"' is not a JSON map");
899 sizeof(relay_id_buffer_), relay_id_length_);
902 sizeof(remote_id_buffer_), remote_id_length_);
906 Lease4Ptr result(boost::make_shared<Lease4>(addr4_, hwaddr,
913 result->state_ = state;
916 result->setContext(ctx);
919 if (relay_id_length_) {
920 result->relay_id_.assign(relay_id_buffer_,
921 relay_id_buffer_ + relay_id_length_);
924 if (remote_id_length_) {
925 result->remote_id_.assign(remote_id_buffer_,
926 remote_id_buffer_ + remote_id_length_);
932 }
catch (
const std::exception& ex) {
934 "Could not convert data to Lease4, reason: "
948 size_t client_id_length_;
950 size_t relay_id_length_;
952 size_t remote_id_length_;
965 static const size_t ADDRESS_COL = 0;
966 static const size_t DUID_COL = 1;
967 static const size_t VALID_LIFETIME_COL = 2;
968 static const size_t EXPIRE_COL = 3;
969 static const size_t SUBNET_ID_COL = 4;
970 static const size_t PREF_LIFETIME_COL = 5;
971 static const size_t LEASE_TYPE_COL = 6;
972 static const size_t IAID_COL = 7;
973 static const size_t PREFIX_LEN_COL = 8;
974 static const size_t FQDN_FWD_COL = 9;
975 static const size_t FQDN_REV_COL = 10;
976 static const size_t HOSTNAME_COL = 11;
977 static const size_t HWADDR_COL = 12;
978 static const size_t HWTYPE_COL = 13;
979 static const size_t HWADDR_SOURCE_COL = 14;
980 static const size_t STATE_COL = 15;
981 static const size_t USER_CONTEXT_COL = 16;
982 static const size_t POOL_ID_COL = 17;
985 static const size_t LEASE_COLUMNS = 18;
1006 return (boost::lexical_cast<std::string>(
ival_));
1014 : lease_(), duid_length_(0), duid_(duid_length_), iaid_u_(0),
1015 iaid_str_(
""), lease_type_(
Lease6::TYPE_NA), lease_type_str_(
""),
1016 prefix_len_(0), prefix_len_str_(
""), pref_lifetime_(0),
1017 preferred_lifetime_str_(
""), hwtype_(0), hwtype_str_(
""),
1018 hwaddr_source_(0), hwaddr_source_str_(
"") {
1020 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1022 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
1027 columns_.push_back(
"valid_lifetime");
1030 columns_.push_back(
"pref_lifetime");
1039 columns_.push_back(
"hwaddr_source");
1041 columns_.push_back(
"user_context");
1068 if (lease_->duid_) {
1069 bind_array.
add(lease_->duid_->getDuid());
1087 lease_->valid_lft_);
1091 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
1094 preferred_lifetime_str_ = boost::lexical_cast<std::string>(lease_->preferred_lft_);
1095 bind_array.
add(preferred_lifetime_str_);
1097 lease_type_str_ = boost::lexical_cast<std::string>(lease_->type_);
1098 bind_array.
add(lease_type_str_);
1103 iaid_u_.
uval_ = lease_->iaid_;
1105 bind_array.
add(iaid_str_);
1107 prefix_len_str_ = boost::lexical_cast<std::string>
1108 (
static_cast<unsigned int>(lease_->prefixlen_));
1109 bind_array.
add(prefix_len_str_);
1111 bind_array.
add(lease->fqdn_fwd_);
1113 bind_array.
add(lease->fqdn_rev_);
1115 bind_array.
add(lease->hostname_);
1117 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
1122 << lease_->hwaddr_->hwaddr_.size()
1123 <<
" exceeds maximum allowed of: "
1126 bind_array.
add(lease->hwaddr_->hwaddr_);
1131 if (lease->hwaddr_) {
1132 hwtype_str_ = boost::lexical_cast<std::string>
1133 (
static_cast<unsigned int>(lease_->hwaddr_->htype_));
1134 hwaddr_source_str_ = boost::lexical_cast<std::string>
1135 (
static_cast<unsigned int>(lease_->hwaddr_->source_));
1137 hwtype_str_ = boost::lexical_cast<std::string>
1139 hwaddr_source_str_ = boost::lexical_cast<std::string>
1143 bind_array.
add(hwtype_str_);
1145 bind_array.
add(hwaddr_source_str_);
1147 state_str_ = boost::lexical_cast<std::string>(lease->state_);
1158 pool_id_str_ = boost::lexical_cast<std::string>(lease->pool_id_);
1160 }
catch (
const std::exception& ex) {
1162 "Could not create bind array from Lease6: "
1163 << lease_->addr_.toText() <<
", reason: " << ex.what());
1188 convertFromBytea(r, row, DUID_COL, duid_buffer_,
sizeof(duid_buffer_), duid_length_);
1189 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1232 hwaddr->source_ = hwaddr_source_;
1244 <<
"' is not a JSON map");
1254 Lease6Ptr result(boost::make_shared<Lease6>(lease_type_, addr,
1261 hwaddr, prefix_len_));
1263 result->cltt_ =
cltt_;
1264 result->current_cltt_ =
cltt_;
1266 result->state_ = state;
1269 result->setContext(ctx);
1275 }
catch (
const std::exception& ex) {
1277 "Could not convert data to Lease6, reason: "
1296 uint32_t raw_value = 0;
1298 switch (raw_value) {
1319 size_t duid_length_;
1320 std::vector<uint8_t> duid_;
1322 union Uiaid iaid_u_;
1323 std::string iaid_str_;
1325 std::string lease_type_str_;
1326 uint8_t prefix_len_;
1327 std::string prefix_len_str_;
1328 uint32_t pref_lifetime_;
1329 std::string preferred_lifetime_str_;
1331 std::string hwtype_str_;
1332 uint32_t hwaddr_source_;
1333 std::string hwaddr_source_str_;
1355 const bool fetch_type,
const bool fetch_pool =
false)
1369 const bool fetch_type,
const SubnetID& subnet_id)
1385 const bool fetch_type,
const SubnetID& first_subnet_id,
1467 uint32_t lease_type;
1531 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1536PgSqlLeaseMgr::PgSqlLeaseContextAlloc::PgSqlLeaseContextAlloc(
1543 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1544 if (!mgr_.pool_->pool_.empty()) {
1545 ctx_ = mgr_.pool_->pool_.back();
1546 mgr_.pool_->pool_.pop_back();
1550 ctx_ = mgr_.createContext();
1554 if (mgr_.pool_->pool_.empty()) {
1557 ctx_ = mgr_.pool_->pool_.back();
1561PgSqlLeaseMgr::PgSqlLeaseContextAlloc::~PgSqlLeaseContextAlloc() {
1564 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1565 mgr_.pool_->pool_.push_back(ctx_);
1572PgSqlLeaseMgr::PgSqlLeaseTrackingContextAlloc::PgSqlLeaseTrackingContextAlloc(
1579 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1580 if (mgr_.hasCallbacks() && !mgr_.tryLock(lease)) {
1583 if (!mgr_.pool_->pool_.empty()) {
1584 ctx_ = mgr_.pool_->pool_.back();
1585 mgr_.pool_->pool_.pop_back();
1589 ctx_ = mgr_.createContext();
1593 if (mgr_.pool_->pool_.empty()) {
1596 ctx_ = mgr_.pool_->pool_.back();
1600PgSqlLeaseMgr::PgSqlLeaseTrackingContextAlloc::~PgSqlLeaseTrackingContextAlloc() {
1603 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1604 if (mgr_.hasCallbacks()) {
1605 mgr_.unlock(lease_);
1607 mgr_.pool_->pool_.push_back(ctx_);
1622 tls += parameters.count(
"trust-anchor");
1623 tls += parameters.count(
"cert-file");
1624 tls += parameters.count(
"key-file");
1625 tls += parameters.count(
"cipher-list");
1626#ifdef HAVE_PGSQL_SSL
1638 <<
"backend (built with this feature disabled)");
1643 timer_name_ =
"PgSqlLeaseMgr[";
1644 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1645 timer_name_ +=
"]DbReconnectTimer";
1667 bool reopened =
false;
1669 const std::string timer_name = db_reconnect_ctl->timerName();
1676 }
catch (
const std::exception& ex) {
1692 if (!db_reconnect_ctl->checkRetries()) {
1695 .arg(db_reconnect_ctl->maxRetries());
1708 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1709 .arg(db_reconnect_ctl->maxRetries())
1710 .arg(db_reconnect_ctl->retryInterval());
1716 db_reconnect_ctl->retryInterval(),
1734 ctx->conn_.makeReconnectCtl(timer_name_);
1737 ctx->conn_.openDatabase();
1741 for (; tagged_statements[i].text != NULL; ++i) {
1742 ctx->conn_.prepareStatement(tagged_statements[i]);
1761 std::stringstream tmp;
1764 tmp <<
", library " << PQlibVersion();
1770 StatementIndex stindex,
1772 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
1773 tagged_statements[stindex].nbparams,
1778 int s = PQresultStatus(r);
1780 if (s != PGRES_COMMAND_OK) {
1787 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1796 .arg(lease->addr_.toText());
1799 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
1803 ctx->exchange4_->createBindForSend(lease, bind_array);
1804 auto result = addLeaseCommon(ctx,
INSERT_LEASE4, bind_array);
1808 lease->updateCurrentExpirationTime();
1821 .arg(lease->addr_.toText())
1827 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
1831 ctx->exchange6_->createBindForSend(lease, bind_array);
1833 auto result = addLeaseCommon(ctx,
INSERT_LEASE6, bind_array);
1837 lease->updateCurrentExpirationTime();
1851template <
typename Exchange,
typename LeaseCollection>
1854 StatementIndex stindex,
1857 LeaseCollection& result,
1858 bool single)
const {
1859 const int n = tagged_statements[stindex].nbparams;
1861 tagged_statements[stindex].name, n,
1862 n > 0 ? &bind_array.
values_[0] : NULL,
1863 n > 0 ? &bind_array.
lengths_[0] : NULL,
1864 n > 0 ? &bind_array.
formats_[0] : NULL, 0));
1866 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1868 int rows = PQntuples(r);
1869 if (single && rows > 1) {
1871 "database where only one was expected for query "
1872 << tagged_statements[stindex].name);
1875 for(
int i = 0; i < rows; ++i) {
1876 result.push_back(exchange->convertFromDatabase(r, i));
1890 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange4_,
1894 if (collection.empty()) {
1897 result = *collection.begin();
1911 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange6_,
1915 if (collection.empty()) {
1918 result = *collection.begin();
1931 std::string addr_str = boost::lexical_cast<std::string>(addr.
toUint32());
1932 bind_array.
add(addr_str);
1938 PgSqlLeaseContextAlloc get_context(*
this);
1955 if (!hwaddr.
hwaddr_.empty()) {
1965 PgSqlLeaseContextAlloc get_context(*
this);
1983 if (!hwaddr.
hwaddr_.empty()) {
1990 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1991 bind_array.
add(subnet_id_str);
1997 PgSqlLeaseContextAlloc get_context(*
this);
2020 PgSqlLeaseContextAlloc get_context(*
this);
2041 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2042 bind_array.
add(subnet_id_str);
2048 PgSqlLeaseContextAlloc get_context(*
this);
2065 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2066 bind_array.
add(subnet_id_str);
2072 PgSqlLeaseContextAlloc get_context(*
this);
2089 bind_array.
add(hostname);
2095 PgSqlLeaseContextAlloc get_context(*
this);
2113 PgSqlLeaseContextAlloc get_context(*
this);
2116 getLeaseCollection(ctx,
GET_LEASE4, bind_array, result);
2125 if (!lower_bound_address.
isV4()) {
2127 "retrieving leases from the lease database, got "
2128 << lower_bound_address);
2133 .arg(lower_bound_address.
toText());
2139 std::string lb_address_data = boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
2140 bind_array.
add(lb_address_data);
2143 std::string page_size_data = boost::lexical_cast<std::string>(page_size.
page_size_);
2144 bind_array.
add(page_size_data);
2150 PgSqlLeaseContextAlloc get_context(*
this);
2169 std::string addr_str = addr.
toText();
2170 bind_array.
add(addr_str);
2173 std::string type_str_ = boost::lexical_cast<std::string>(lease_type);
2174 bind_array.
add(type_str_);
2180 PgSqlLeaseContextAlloc get_context(*
this);
2190 uint32_t iaid)
const {
2204 bind_array.
add(iaid_str);
2207 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
2208 bind_array.
add(lease_type_str);
2214 PgSqlLeaseContextAlloc get_context(*
this);
2224 uint32_t iaid,
SubnetID subnet_id)
const {
2235 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
2236 bind_array.
add(lease_type_str);
2243 bind_array.
add(iaid_str);
2246 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2247 bind_array.
add(subnet_id_str);
2253 PgSqlLeaseContextAlloc get_context(*
this);
2270 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2271 bind_array.
add(subnet_id_str);
2277 PgSqlLeaseContextAlloc get_context(*
this);
2292 .arg(lower_bound_address.
toText())
2296 if (!lower_bound_address.
isV6()) {
2298 "retrieving leases from the lease database, got "
2299 << lower_bound_address);
2307 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
2308 bind_array.
add(subnet_id_str);
2311 std::string lb_address_str = lower_bound_address.
toText();
2312 bind_array.
add(lb_address_str);
2315 std::string page_size_data =
2316 boost::lexical_cast<std::string>(page_size.
page_size_);
2317 bind_array.
add(page_size_data);
2320 PgSqlLeaseContextAlloc get_context(*
this);
2342 PgSqlLeaseContextAlloc get_context(*
this);
2360 bind_array.
add(hostname);
2366 PgSqlLeaseContextAlloc get_context(*
this);
2384 PgSqlLeaseContextAlloc get_context(*
this);
2387 getLeaseCollection(ctx,
GET_LEASE6, bind_array, result);
2396 if (!lower_bound_address.
isV6()) {
2398 "retrieving leases from the lease database, got "
2399 << lower_bound_address);
2404 .arg(lower_bound_address.
toText());
2410 std::string lb_address_data = lower_bound_address.
toText();
2411 bind_array.
add(lb_address_data);
2414 std::string page_size_data =
2415 boost::lexical_cast<std::string>(page_size.
page_size_);
2416 bind_array.
add(page_size_data);
2422 PgSqlLeaseContextAlloc get_context(*
this);
2432 const size_t max_leases)
const {
2440 const size_t max_leases)
const {
2446template<
typename LeaseCollection>
2448PgSqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2449 const size_t max_leases,
2450 StatementIndex statement_index)
const {
2455 bind_array.
add(state_str);
2459 bind_array.
add(timestamp_str);
2463 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2464 std::numeric_limits<uint32_t>::max();
2465 std::string limit_str = boost::lexical_cast<std::string>(limit);
2466 bind_array.
add(limit_str);
2469 PgSqlLeaseContextAlloc get_context(*
this);
2473 getLeaseCollection(ctx, statement_index, bind_array, expired_leases);
2476template<
typename LeasePtr>
2479 StatementIndex stindex,
2482 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2483 tagged_statements[stindex].nbparams,
2488 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2490 int affected_rows = boost::lexical_cast<int>(PQcmdTuples(r));
2493 if (affected_rows == 1) {
2498 if (affected_rows == 0) {
2500 lease->addr_.toText() <<
" as it does not exist");
2506 "that had the address " << lease->addr_.toText());
2514 .arg(lease->addr_.toText());
2517 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2522 ctx->exchange4_->createBindForSend(lease, bind_array);
2525 std::string addr4_str = boost::lexical_cast<std::string>(lease->addr_.toUint32());
2526 bind_array.
add(addr4_str);
2528 std::string expire_str;
2534 lease->current_valid_lft_);
2536 bind_array.
add(expire_str);
2539 updateLeaseCommon(ctx, stindex, bind_array, lease);
2542 lease->updateCurrentExpirationTime();
2555 .arg(lease->addr_.toText())
2563 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2568 ctx->exchange6_->createBindForSend(lease, bind_array);
2571 std::string addr_str = lease->addr_.
toText();
2572 bind_array.
add(addr_str);
2574 std::string expire_str;
2580 lease->current_valid_lft_);
2582 bind_array.
add(expire_str);
2585 updateLeaseCommon(ctx, stindex, bind_array, lease);
2588 lease->updateCurrentExpirationTime();
2592 switch (recorded_action) {
2615 StatementIndex stindex,
2617 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2618 tagged_statements[stindex].nbparams,
2623 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2624 int affected_rows = boost::lexical_cast<int>(PQcmdTuples(r));
2626 return (affected_rows);
2638 std::string addr4_str = boost::lexical_cast<std::string>(addr.
toUint32());
2639 bind_array.
add(addr4_str);
2641 std::string expire_str;
2647 lease->current_valid_lft_);
2649 bind_array.
add(expire_str);
2652 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2655 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE4, bind_array);
2658 if (affected_rows == 1) {
2666 if (affected_rows == 0) {
2673 "that had the address " << lease->addr_.toText());
2688 std::string addr6_str = addr.
toText();
2689 bind_array.
add(addr6_str);
2691 std::string expire_str;
2697 lease->current_valid_lft_);
2699 bind_array.
add(expire_str);
2702 PgSqlLeaseTrackingContextAlloc get_context(*
this, lease);
2705 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE6, bind_array);
2708 if (affected_rows == 1) {
2720 if (affected_rows == 0) {
2727 "that had the address " << lease->addr_.toText());
2745PgSqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
2746 StatementIndex statement_index) {
2751 bind_array.
add(state_str);
2755 static_cast<time_t
>(secs));
2756 bind_array.
add(expiration_str);
2759 PgSqlLeaseContextAlloc get_context(*
this);
2763 return (deleteLeaseCommon(ctx, statement_index, bind_array));
2767PgSqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
2769 if (!user_context) {
2774 PgSqlLeaseContextAlloc get_context(*
this);
2779 std::string
const user_context_str(user_context->str());
2780 bind_array.
add(user_context_str);
2784 tagged_statements[stindex].name,
2785 tagged_statements[stindex].nbparams,
2789 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2809 PgSqlLeaseContextAlloc get_context(*
this);
2814 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2816 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2818 bool json_supported;
2820 return json_supported;
2827 PgSqlLeaseContextAlloc get_context(*
this);
2832 bind_array.
add(client_class);
2834 bind_array.
add(ltype);
2841 tagged_statements[stindex].name,
2842 tagged_statements[stindex].nbparams,
2846 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2848 int rows = PQntuples(r);
2887 PgSqlLeaseContextAlloc get_context(*
this);
2900 PgSqlLeaseContextAlloc get_context(*
this);
2913 PgSqlLeaseContextAlloc get_context(*
this);
2928 PgSqlLeaseContextAlloc get_context(*
this);
2943 PgSqlLeaseContextAlloc get_context(*
this);
2956 PgSqlLeaseContextAlloc get_context(*
this);
2969 PgSqlLeaseContextAlloc get_context(*
this);
2984 PgSqlLeaseContextAlloc get_context(*
this);
3009 PgSqlLeaseContextAlloc get_context(*
this);
3012 std::string name =
"";
3014 name = ctx->conn_.getParameter(
"name");
3023 return (std::string(
"PostgreSQL Database"));
3026std::pair<uint32_t, uint32_t>
3048 deleteRelayId6(addr);
3049 deleteRemoteId6(addr);
3053PgSqlLeaseMgr::deleteRelayId6(
const IOAddress& addr) {
3057 std::string addr_data = addr.
toText();
3058 bind_array.
add(addr_data);
3061 PgSqlLeaseContextAlloc get_context(*
this);
3067 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3068 tagged_statements[stindex].nbparams,
3073 int s = PQresultStatus(r);
3075 if (s != PGRES_COMMAND_OK) {
3076 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3081PgSqlLeaseMgr::deleteRemoteId6(
const IOAddress& addr) {
3085 std::string addr_data = addr.
toText();
3086 bind_array.
add(addr_data);
3089 PgSqlLeaseContextAlloc get_context(*
this);
3095 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3096 tagged_statements[stindex].nbparams,
3101 int s = PQresultStatus(r);
3103 if (s != PGRES_COMMAND_OK) {
3104 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3110 const vector<uint8_t>& relay_id) {
3115 if (relay_id.empty()) {
3118 bind_array.
add(relay_id);
3121 std::string lease_addr_data = lease_addr.
toText();
3122 bind_array.
add(lease_addr_data);
3125 PgSqlLeaseContextAlloc get_context(*
this);
3131 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3132 tagged_statements[stindex].nbparams,
3137 int s = PQresultStatus(r);
3139 if (s != PGRES_COMMAND_OK) {
3140 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3146 const vector<uint8_t>& remote_id) {
3151 if (remote_id.empty()) {
3154 bind_array.
add(remote_id);
3157 std::string lease_addr_data = lease_addr.
toText();
3158 bind_array.
add(lease_addr_data);
3161 PgSqlLeaseContextAlloc get_context(*
this);
3167 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3168 tagged_statements[stindex].nbparams,
3173 int s = PQresultStatus(r);
3175 if (s != PGRES_COMMAND_OK) {
3176 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3184 std::stringstream tmp;
3187 for (
auto const& it :
id) {
3191 tmp << std::setw(2) << std::setfill(
'0')
3192 <<
static_cast<unsigned int>(it);
3204 const time_t& qry_start_time ,
3205 const time_t& qry_end_time ) {
3207 if (!lower_bound_address.
isV4()) {
3209 "retrieving leases from the lease database, got "
3210 << lower_bound_address);
3214 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3218 bool have_qst = (qry_start_time > 0);
3219 bool have_qet = (qry_end_time > 0);
3222 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
3229 .arg(lower_bound_address.
toText())
3230 .arg(idToText(relay_id))
3231 .arg(qry_start_time)
3238 if (!relay_id.empty()) {
3239 bind_array.
add(relay_id);
3245 std::string lb_address_data =
3246 boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
3247 bind_array.
add(lb_address_data);
3250 std::string start_time_str;
3252 start_time_str = boost::lexical_cast<std::string>(qry_start_time);
3253 bind_array.
add(start_time_str);
3257 std::string end_time_str;
3259 end_time_str = boost::lexical_cast<std::string>(qry_end_time);
3260 bind_array.
add(end_time_str);
3264 std::string page_size_data =
3265 boost::lexical_cast<std::string>(page_size.
page_size_);
3266 bind_array.
add(page_size_data);
3269 if (have_qst && !have_qet) {
3271 }
else if (have_qst && have_qet) {
3273 }
else if (!have_qst && have_qet) {
3281 PgSqlLeaseContextAlloc get_context(*
this);
3284 getLeaseCollection(ctx, stindex, bind_array, result);
3293 const time_t& qry_start_time ,
3294 const time_t& qry_end_time ) {
3296 if (!lower_bound_address.
isV4()) {
3298 "retrieving leases from the lease database, got "
3299 << lower_bound_address);
3303 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3307 bool have_qst = (qry_start_time > 0);
3308 bool have_qet = (qry_end_time > 0);
3311 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
3318 .arg(lower_bound_address.
toText())
3319 .arg(idToText(remote_id))
3320 .arg(qry_start_time)
3327 if (!remote_id.empty()) {
3328 bind_array.
add(remote_id);
3334 std::string lb_address_data =
3335 boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
3336 bind_array.
add(lb_address_data);
3339 std::string start_time_str;
3341 start_time_str = boost::lexical_cast<std::string>(qry_start_time);
3342 bind_array.
add(start_time_str);
3346 std::string end_time_str;
3348 end_time_str = boost::lexical_cast<std::string>(qry_end_time);
3349 bind_array.
add(end_time_str);
3353 std::string page_size_data =
3354 boost::lexical_cast<std::string>(page_size.
page_size_);
3355 bind_array.
add(page_size_data);
3358 if (have_qst && !have_qet) {
3360 }
else if (have_qst && have_qet) {
3362 }
else if (!have_qst && have_qet) {
3370 PgSqlLeaseContextAlloc get_context(*
this);
3373 getLeaseCollection(ctx, stindex, bind_array, result);
3381 getConsistency()->getExtendedInfoSanityCheck();
3390 .arg(start_addr.
toText())
3397 uint32_t start_addr_data = start_addr.
toUint32();
3398 bind_array.
add(start_addr_data);
3401 std::string page_size_data =
3402 boost::lexical_cast<std::string>(page_size.
page_size_);
3403 bind_array.
add(page_size_data);
3409 PgSqlLeaseContextAlloc get_context(*
this);
3415 if (leases.empty()) {
3421 start_addr = leases.back()->addr_;
3422 for (
auto const& lease : leases) {
3424 vector<uint8_t> previous_relay_id = lease->relay_id_;
3425 vector<uint8_t> previous_remote_id = lease->remote_id_;
3426 if (!previous_user_context &&
3427 previous_relay_id.empty() &&
3428 previous_remote_id.empty()) {
3433 lease->relay_id_.clear();
3434 lease->remote_id_.clear();
3437 (previous_relay_id != lease->relay_id_) ||
3438 (previous_remote_id != lease->remote_id_)) {
3446 }
catch (
const std::exception& ex) {
3450 .arg(lease->addr_.toText())
3470 .arg(lower_bound_address.
toText())
3474 if (!lower_bound_address.
isV6()) {
3476 "retrieving leases from the lease database, got "
3477 << lower_bound_address);
3480 std::vector<uint8_t> relay_id_data = relay_id.
getDuid();
3481 if (relay_id_data.size() == 0) {
3489 bind_array.
add(relay_id_data);
3492 std::string lb_addr_data = lower_bound_address.
toText();
3493 bind_array.
add(lb_addr_data);
3496 std::string page_size_data =
3497 boost::lexical_cast<std::string>(page_size.
page_size_);
3498 bind_array.
add(page_size_data);
3501 PgSqlLeaseContextAlloc get_context(*
this);
3516 .arg(lower_bound_address.
toText())
3517 .arg(idToText(remote_id));
3520 if (!lower_bound_address.
isV6()) {
3522 "retrieving leases from the lease database, got "
3523 << lower_bound_address);
3526 if (remote_id.size() == 0) {
3534 bind_array.
add(remote_id);
3537 std::string lb_addr_data = lower_bound_address.
toText();
3538 bind_array.
add(lb_addr_data);
3541 std::string page_size_data =
3542 boost::lexical_cast<std::string>(page_size.
page_size_);
3543 bind_array.
add(page_size_data);
3546 PgSqlLeaseContextAlloc get_context(*
this);
3557 getConsistency()->getExtendedInfoSanityCheck();
3571 .arg(start_addr.
toText())
3578 std::string start_addr_str = start_addr.
toText();
3579 bind_array.
add(start_addr_str);
3582 std::string page_size_data =
3583 boost::lexical_cast<std::string>(page_size.
page_size_);
3584 bind_array.
add(page_size_data);
3590 PgSqlLeaseContextAlloc get_context(*
this);
3596 if (leases.empty()) {
3602 start_addr = leases.back()->addr_;
3603 for (
auto const& lease : leases) {
3611 if (modified || added) {
3618 }
catch (
const std::exception& ex) {
3622 .arg(lease->addr_.toText())
3638 PgSqlLeaseContextAlloc get_context(*
this);
3643 PgSqlResult r1(PQexecPrepared(ctx->conn_, tagged_statements[stindex1].name,
3645 ctx->conn_.checkStatementError(r1, tagged_statements[stindex1]);
3649 PgSqlResult r2(PQexecPrepared(ctx->conn_, tagged_statements[stindex2].name,
3651 ctx->conn_.checkStatementError(r2, tagged_statements[stindex2]);
3657 PgSqlLeaseContextAlloc get_context(*
this);
3662 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3664 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3667 return (
static_cast<size_t>(count));
3673 PgSqlLeaseContextAlloc get_context(*
this);
3678 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
3680 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
3683 return (
static_cast<size_t>(count));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown when an unexpected error condition occurs.
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())
Get the schema version.
void checkStatementError(const PgSqlResult &r, PgSqlTaggedStatement &statement)
Checks result of the r object.
Base class for marshalling data to and from PostgreSQL.
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.
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.
Base class for fulfilling a statistical lease data query.
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...
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.
Base class for marshalling leases to and from PostgreSQL.
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.
Introduces callbacks into the LeaseMgr.
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.
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.
const char * name
Short name of the query.
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.