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 = $1 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 " 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 " 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 " 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 " 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 " 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 " 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 " 133 "WHERE address > $1 " 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 " 145 "WHERE subnet_id = $1"},
149 "get_lease4_hostname",
150 "SELECT address, hwaddr, client_id, " 151 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, " 152 "fqdn_fwd, fqdn_rev, hostname, " 153 "state, user_context " 155 "WHERE lower(hostname) = $1"},
160 "SELECT address, hwaddr, client_id, " 161 "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, " 162 "fqdn_fwd, fqdn_rev, hostname, " 163 "state, user_context " 165 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 " 172 "SELECT address, duid, valid_lifetime, " 173 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 174 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 175 "hwaddr, hwtype, hwaddr_source, " 176 "state, user_context " 182 "SELECT address, duid, valid_lifetime, " 183 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 184 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 185 "hwaddr, hwtype, hwaddr_source, " 186 "state, user_context " 188 "WHERE address = $1 AND lease_type = $2"},
192 "get_lease6_duid_iaid",
193 "SELECT address, duid, valid_lifetime, " 194 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 195 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 196 "hwaddr, hwtype, hwaddr_source, " 197 "state, user_context " 199 "WHERE duid = $1 AND iaid = $2 AND lease_type = $3"},
203 "get_lease6_duid_iaid_subid",
204 "SELECT address, duid, valid_lifetime, " 205 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 206 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 207 "hwaddr, hwtype, hwaddr_source, " 208 "state, user_context " 210 "WHERE lease_type = $1 " 211 "AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
216 "SELECT address, duid, valid_lifetime, " 217 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 218 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 219 "hwaddr, hwtype, hwaddr_source, " 220 "state, user_context " 222 "WHERE address > $1 " 229 "SELECT address, duid, valid_lifetime, " 230 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 231 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 232 "hwaddr, hwtype, hwaddr_source, " 233 "state, user_context " 235 "WHERE subnet_id = $1"},
240 "SELECT address, duid, valid_lifetime, " 241 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 242 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 243 "hwaddr, hwtype, hwaddr_source, " 244 "state, user_context " 250 "get_lease6_hostname",
251 "SELECT address, duid, valid_lifetime, " 252 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 253 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 254 "hwaddr, hwtype, hwaddr_source, " 255 "state, user_context " 257 "WHERE lower(hostname) = $1"},
262 "SELECT address, duid, valid_lifetime, " 263 "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, " 264 "lease_type, iaid, prefix_len, " 265 "fqdn_fwd, fqdn_rev, hostname, " 266 "hwaddr, hwtype, hwaddr_source, " 267 "state, user_context " 269 "WHERE state != $1 AND valid_lifetime != 4294967295 AND expire < $2 " 277 "INSERT INTO lease4(address, hwaddr, client_id, " 278 "valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, " 279 "state, user_context) " 280 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)"},
287 "INSERT INTO lease6(address, duid, valid_lifetime, " 288 "expire, subnet_id, pref_lifetime, " 289 "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " 290 "hwaddr, hwtype, hwaddr_source, " 291 "state, user_context) " 292 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)"},
298 "UPDATE lease4 SET address = $1, hwaddr = $2, " 299 "client_id = $3, valid_lifetime = $4, expire = $5, " 300 "subnet_id = $6, fqdn_fwd = $7, fqdn_rev = $8, hostname = $9, " 301 "state = $10, user_context = $11 " 302 "WHERE address = $12 AND expire = $13"},
310 "UPDATE lease6 SET address = $1, duid = $2, " 311 "valid_lifetime = $3, expire = $4, subnet_id = $5, " 312 "pref_lifetime = $6, lease_type = $7, iaid = $8, " 313 "prefix_len = $9, fqdn_fwd = $10, fqdn_rev = $11, hostname = $12, " 314 "hwaddr = $13, hwtype = $14, hwaddr_source = $15, " 315 "state = $16, user_context = $17 " 316 "WHERE address = $18 AND expire = $19"},
321 "SELECT subnet_id, state, leases as state_count" 322 " FROM lease4_stat ORDER BY subnet_id, state"},
326 "subnet_lease4_stats",
327 "SELECT subnet_id, state, leases as state_count" 329 " WHERE subnet_id = $1 " 334 "subnet_range_lease4_stats",
335 "SELECT subnet_id, state, leases as state_count" 337 " WHERE subnet_id >= $1 and subnet_id <= $2 " 338 " ORDER BY subnet_id, state"},
343 "SELECT subnet_id, lease_type, state, leases as state_count" 344 " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
348 "subnet_lease6_stats",
349 "SELECT subnet_id, lease_type, state, leases as state_count" 351 " WHERE subnet_id = $1 " 352 " ORDER BY lease_type, state" },
356 "subnet_range_lease6_stats",
357 "SELECT subnet_id, lease_type, state, leases as state_count" 359 " WHERE subnet_id >= $1 and subnet_id <= $2 " 360 " ORDER BY subnet_id, lease_type, state" },
364 "check_lease4_limits",
365 "SELECT checkLease4Limits($1)" },
369 "check_lease6_limits",
370 "SELECT checkLease6Limits($1)" },
375 "SELECT isJsonSupported()" },
379 "get_lease4_count_by_class",
381 "FROM lease4_stat_by_client_class " 382 "WHERE client_class = $1"},
386 "get_lease6_count_by_class",
388 "FROM lease6_stat_by_client_class " 389 "WHERE client_class = $1 AND lease_type = $2"},
392 { 0, { 0 }, NULL, NULL}
409 : addr_str_(
""), hwaddr_length_(0), hwaddr_(hwaddr_length_),
410 valid_lifetime_(0), valid_lifetime_str_(
""), expire_(0),
411 expire_str_(
""), subnet_id_(0), subnet_id_str_(
""), cltt_(0),
412 fqdn_fwd_(false), fqdn_rev_(false), hostname_(
""), state_str_(
""),
425 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
449 static const size_t ADDRESS_COL = 0;
450 static const size_t HWADDR_COL = 1;
451 static const size_t CLIENT_ID_COL = 2;
452 static const size_t VALID_LIFETIME_COL = 3;
453 static const size_t EXPIRE_COL = 4;
454 static const size_t SUBNET_ID_COL = 5;
455 static const size_t FQDN_FWD_COL = 6;
456 static const size_t FQDN_REV_COL = 7;
457 static const size_t HOSTNAME_COL = 8;
458 static const size_t STATE_COL = 9;
459 static const size_t USER_CONTEXT_COL = 10;
461 static const size_t LEASE_COLUMNS = 11;
467 : lease_(), addr4_(0), client_id_length_(0) {
469 BOOST_STATIC_ASSERT(9 < LEASE_COLUMNS);
471 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
472 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
475 columns_.push_back(
"address");
476 columns_.push_back(
"hwaddr");
477 columns_.push_back(
"client_id");
478 columns_.push_back(
"valid_lifetime");
479 columns_.push_back(
"expire");
480 columns_.push_back(
"subnet_id");
481 columns_.push_back(
"fqdn_fwd");
482 columns_.push_back(
"fqdn_rev");
483 columns_.push_back(
"hostname");
484 columns_.push_back(
"state");
485 columns_.push_back(
"user_context");
509 addr_str_ = boost::lexical_cast<std::string>(lease->addr_.toUint32());
510 bind_array.
add(addr_str_);
512 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
515 if (lease->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
517 << lease_->hwaddr_->hwaddr_.size()
518 <<
" exceeds maximum allowed of: " 519 << HWAddr::MAX_HWADDR_LEN);
521 bind_array.
add(lease->hwaddr_->hwaddr_);
526 if (lease->client_id_) {
527 bind_array.
add(lease->client_id_->getClientId());
532 valid_lifetime_str_ = boost::lexical_cast<std::string>(lease->valid_lft_);
533 bind_array.
add(valid_lifetime_str_);
541 if (lease_->valid_lft_ == Lease::INFINITY_LFT) {
542 expire_str_ = convertToDatabaseTime(lease->cltt_, 0);
544 expire_str_ = convertToDatabaseTime(lease->cltt_,
547 bind_array.
add(expire_str_);
549 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
550 bind_array.
add(subnet_id_str_);
552 bind_array.
add(lease->fqdn_fwd_);
554 bind_array.
add(lease->fqdn_rev_);
556 bind_array.
add(lease->hostname_);
558 state_str_ = boost::lexical_cast<std::string>(lease->state_);
559 bind_array.
add(state_str_);
563 user_context_ = ctx->str();
567 bind_array.
add(user_context_);
568 }
catch (
const std::exception& ex) {
570 "Could not create bind array from Lease4: " 571 << lease_->addr_.toText() <<
", reason: " << ex.
what());
585 getColumnValue(r, row, ADDRESS_COL, addr4_);
587 convertFromBytea(r, row, HWADDR_COL, hwaddr_buffer_,
588 sizeof(hwaddr_buffer_), hwaddr_length_);
590 convertFromBytea(r, row, CLIENT_ID_COL, client_id_buffer_,
591 sizeof(client_id_buffer_), client_id_length_);
593 getColumnValue(r, row, VALID_LIFETIME_COL, valid_lifetime_);
595 expire_ = convertFromDatabaseTime(getRawColumnValue(r, row,
598 getColumnValue(r, row , SUBNET_ID_COL, subnet_id_);
601 if (valid_lifetime_ == Lease::INFINITY_LFT) {
604 cltt_ = expire_ - valid_lifetime_;
607 getColumnValue(r, row, FQDN_FWD_COL, fqdn_fwd_);
609 getColumnValue(r, row, FQDN_REV_COL, fqdn_rev_);
611 hostname_ = getRawColumnValue(r, row, HOSTNAME_COL);
614 getColumnValue(r, row , STATE_COL, state);
619 user_context_ = getRawColumnValue(r, row, USER_CONTEXT_COL);
621 if (!user_context_.empty()) {
622 ctx = Element::fromJSON(user_context_);
623 if (!ctx || (ctx->getType() != Element::map)) {
625 <<
"' is not a JSON map");
629 Lease4Ptr result(boost::make_shared<Lease4>(addr4_, hwaddr,
632 valid_lifetime_, cltt_,
633 subnet_id_, fqdn_fwd_,
634 fqdn_rev_, hostname_));
636 result->state_ = state;
639 result->setContext(ctx);
643 }
catch (
const std::exception& ex) {
645 "Could not convert data to Lease4, reason: " 659 size_t client_id_length_;
660 uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
672 static const int ADDRESS_COL = 0;
673 static const int DUID_COL = 1;
674 static const int VALID_LIFETIME_COL = 2;
675 static const int EXPIRE_COL = 3;
676 static const int SUBNET_ID_COL = 4;
677 static const int PREF_LIFETIME_COL = 5;
678 static const int LEASE_TYPE_COL = 6;
679 static const int IAID_COL = 7;
680 static const int PREFIX_LEN_COL = 8;
681 static const int FQDN_FWD_COL = 9;
682 static const int FQDN_REV_COL = 10;
683 static const int HOSTNAME_COL = 11;
684 static const int HWADDR_COL = 12;
685 static const int HWTYPE_COL = 13;
686 static const int HWADDR_SOURCE_COL = 14;
687 static const int STATE_COL = 15;
688 static const size_t USER_CONTEXT_COL = 16;
690 static const size_t LEASE_COLUMNS = 17;
712 return (boost::lexical_cast<std::string>(ival_));
720 : lease_(), duid_length_(0), duid_(duid_length_), iaid_u_(0),
721 iaid_str_(
""), lease_type_(
Lease6::TYPE_NA), lease_type_str_(
""),
722 prefix_len_(0), prefix_len_str_(
""), pref_lifetime_(0),
723 preferred_lifetime_str_(
""), hwtype_(0), hwtype_str_(
""),
724 hwaddr_source_(0), hwaddr_source_str_(
"") {
726 BOOST_STATIC_ASSERT(15 < LEASE_COLUMNS);
728 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
731 columns_.push_back(
"address");
732 columns_.push_back(
"duid");
733 columns_.push_back(
"valid_lifetime");
734 columns_.push_back(
"expire");
735 columns_.push_back(
"subnet_id");
736 columns_.push_back(
"pref_lifetime");
737 columns_.push_back(
"lease_type");
738 columns_.push_back(
"iaid");
739 columns_.push_back(
"prefix_len");
740 columns_.push_back(
"fqdn_fwd");
741 columns_.push_back(
"fqdn_rev");
742 columns_.push_back(
"hostname");
743 columns_.push_back(
"hwaddr");
744 columns_.push_back(
"hwtype");
745 columns_.push_back(
"hwaddr_source");
746 columns_.push_back(
"state");
747 columns_.push_back(
"user_context");
770 addr_str_ = lease_->addr_.toText();
771 bind_array.
add(addr_str_);
774 bind_array.
add(lease_->duid_->getDuid());
779 valid_lifetime_str_ = boost::lexical_cast<std::string>(lease->valid_lft_);
780 bind_array.
add(valid_lifetime_str_);
788 if (lease_->valid_lft_ == Lease::INFINITY_LFT) {
789 expire_str_ = convertToDatabaseTime(lease->cltt_, 0);
791 expire_str_ = convertToDatabaseTime(lease->cltt_,
794 bind_array.
add(expire_str_);
796 subnet_id_str_ = boost::lexical_cast<std::string>(lease->subnet_id_);
797 bind_array.
add(subnet_id_str_);
799 preferred_lifetime_str_ = boost::lexical_cast<std::string>(lease_->preferred_lft_);
800 bind_array.
add(preferred_lifetime_str_);
802 lease_type_str_ = boost::lexical_cast<std::string>(lease_->type_);
803 bind_array.
add(lease_type_str_);
808 iaid_u_.uval_ = lease_->iaid_;
809 iaid_str_ = iaid_u_.dbInputString();
810 bind_array.
add(iaid_str_);
812 prefix_len_str_ = boost::lexical_cast<std::string>
813 (
static_cast<unsigned int>(lease_->prefixlen_));
814 bind_array.
add(prefix_len_str_);
816 bind_array.
add(lease->fqdn_fwd_);
818 bind_array.
add(lease->fqdn_rev_);
820 bind_array.
add(lease->hostname_);
822 if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
825 if (lease->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
827 << lease_->hwaddr_->hwaddr_.size()
828 <<
" exceeds maximum allowed of: " 829 << HWAddr::MAX_HWADDR_LEN);
831 bind_array.
add(lease->hwaddr_->hwaddr_);
836 if (lease->hwaddr_) {
837 hwtype_str_ = boost::lexical_cast<std::string>
838 (
static_cast<unsigned int>(lease_->hwaddr_->htype_));
839 hwaddr_source_str_ = boost::lexical_cast<std::string>
840 (
static_cast<unsigned int>(lease_->hwaddr_->source_));
842 hwtype_str_ = boost::lexical_cast<std::string>
844 hwaddr_source_str_ = boost::lexical_cast<std::string>
845 (
static_cast<unsigned int>(HWAddr::HWADDR_SOURCE_UNKNOWN));
848 bind_array.
add(hwtype_str_);
850 bind_array.
add(hwaddr_source_str_);
852 state_str_ = boost::lexical_cast<std::string>(lease->state_);
853 bind_array.
add(state_str_);
857 user_context_ = ctx->str();
861 bind_array.
add(user_context_);
862 }
catch (
const std::exception& ex) {
864 "Could not create bind array from Lease6: " 865 << lease_->addr_.toText() <<
", reason: " << ex.
what());
888 IOAddress addr(getIPv6Value(r, row, ADDRESS_COL));
890 convertFromBytea(r, row, DUID_COL, duid_buffer_,
sizeof(duid_buffer_), duid_length_);
891 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
893 getColumnValue(r, row, VALID_LIFETIME_COL, valid_lifetime_);
895 expire_ = convertFromDatabaseTime(getRawColumnValue(r, row,
899 if (valid_lifetime_ == Lease::INFINITY_LFT) {
902 cltt_ = expire_ - valid_lifetime_;
905 getColumnValue(r, row , SUBNET_ID_COL, subnet_id_);
907 getColumnValue(r, row , PREF_LIFETIME_COL, pref_lifetime_);
909 getLeaseTypeColumnValue(r, row, LEASE_TYPE_COL, lease_type_);
911 getColumnValue(r, row , IAID_COL, iaid_u_.ival_);
913 getColumnValue(r, row , PREFIX_LEN_COL, prefix_len_);
915 getColumnValue(r, row, FQDN_FWD_COL, fqdn_fwd_);
917 getColumnValue(r, row, FQDN_REV_COL, fqdn_rev_);
919 hostname_ = getRawColumnValue(r, row, HOSTNAME_COL);
921 convertFromBytea(r, row, HWADDR_COL, hwaddr_buffer_,
922 sizeof(hwaddr_buffer_), hwaddr_length_);
924 getColumnValue(r, row , HWTYPE_COL, hwtype_);
926 getColumnValue(r, row , HWADDR_SOURCE_COL, hwaddr_source_);
930 if (hwaddr_length_) {
931 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_,
934 hwaddr->source_ = hwaddr_source_;
938 getColumnValue(r, row , STATE_COL, state);
940 user_context_ = getRawColumnValue(r, row, USER_CONTEXT_COL);
942 if (!user_context_.empty()) {
943 ctx = Element::fromJSON(user_context_);
944 if (!ctx || (ctx->getType() != Element::map)) {
946 <<
"' is not a JSON map");
950 Lease6Ptr result(boost::make_shared<Lease6>(lease_type_, addr,
955 subnet_id_, fqdn_fwd_,
956 fqdn_rev_, hostname_,
957 hwaddr, prefix_len_));
959 result->cltt_ = cltt_;
960 result->current_cltt_ = cltt_;
962 result->state_ = state;
965 result->setContext(ctx);
969 }
catch (
const std::exception& ex) {
971 "Could not convert data to Lease6, reason: " 990 uint32_t raw_value = 0;
991 getColumnValue(r, row , col, raw_value);
993 case Lease6::TYPE_NA:
994 case Lease6::TYPE_TA:
995 case Lease6::TYPE_PD:
1001 <<
" for: " << getColumnLabel(r, col) <<
" row:" << row);
1013 size_t duid_length_;
1014 std::vector<uint8_t> duid_;
1015 uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
1016 union Uiaid iaid_u_;
1017 std::string iaid_str_;
1019 std::string lease_type_str_;
1020 uint8_t prefix_len_;
1021 std::string prefix_len_str_;
1022 uint32_t pref_lifetime_;
1023 std::string preferred_lifetime_str_;
1025 std::string hwtype_str_;
1026 uint32_t hwaddr_source_;
1027 std::string hwaddr_source_str_;
1048 const bool fetch_type)
1049 : conn_(conn), statement_(statement), result_set_(), next_row_(0),
1050 fetch_type_(fetch_type) {
1062 const bool fetch_type,
const SubnetID& subnet_id)
1063 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_(statement), result_set_(),
1064 next_row_(0), fetch_type_(fetch_type) {
1078 const bool fetch_type,
const SubnetID& first_subnet_id,
1080 :
LeaseStatsQuery(first_subnet_id, last_subnet_id), conn_(conn), statement_(statement),
1081 result_set_(), next_row_(0), fetch_type_(fetch_type) {
1098 if (getSelectMode() == ALL_SUBNETS) {
1100 result_set_.reset(
new PgSqlResult(PQexecPrepared(conn_, statement_.name,
1107 parms.
addTempString(boost::lexical_cast<std::string>(getFirstSubnetID()));
1110 if (getSelectMode() == SUBNET_RANGE) {
1112 parms.
addTempString(boost::lexical_cast<std::string>(getLastSubnetID()));
1116 result_set_.reset(
new PgSqlResult(PQexecPrepared(conn_, statement_.name,
1121 conn_.checkStatementError(*result_set_, statement_);
1140 if (next_row_ >= result_set_->getRows()) {
1147 PgSqlExchange::getColumnValue(*result_set_, next_row_, col, subnet_id);
1153 uint32_t lease_type;
1154 PgSqlExchange::getColumnValue(*result_set_, next_row_ , col,
1163 PgSqlExchange::getColumnValue(*result_set_, next_row_ , col,
1168 PgSqlExchange::getColumnValue(*result_set_, next_row_, col,
1174 if (!negative_count_) {
1175 negative_count_ =
true;
1207 bool PgSqlLeaseStatsQuery::negative_count_ =
false;
1214 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1219 PgSqlLeaseMgr::PgSqlLeaseContextAlloc::PgSqlLeaseContextAlloc(
1222 if (MultiThreadingMgr::instance().getMode()) {
1226 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1227 if (!mgr_.pool_->pool_.empty()) {
1228 ctx_ = mgr_.pool_->pool_.back();
1229 mgr_.pool_->pool_.pop_back();
1233 ctx_ = mgr_.createContext();
1237 if (mgr_.pool_->pool_.empty()) {
1240 ctx_ = mgr_.pool_->pool_.back();
1244 PgSqlLeaseMgr::PgSqlLeaseContextAlloc::~PgSqlLeaseContextAlloc() {
1245 if (MultiThreadingMgr::instance().getMode()) {
1247 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1248 mgr_.pool_->pool_.push_back(ctx_);
1261 : parameters_(parameters), timer_name_(
"") {
1267 timer_name_ =
"PgSqlLeaseMgr[";
1268 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1269 timer_name_ +=
"]DbReconnectTimer";
1273 tls += parameters.count(
"trust-anchor");
1274 tls += parameters.count(
"cert-file");
1275 tls += parameters.count(
"key-file");
1276 tls += parameters.count(
"cipher-list");
1277 #ifdef HAVE_PGSQL_SSL 1289 <<
"backend (built with this feature disabled)");
1296 std::pair<uint32_t, uint32_t> db_version =
getVersion();
1297 if (code_version != db_version) {
1299 "PostgreSQL schema version mismatch: need version: " 1300 << code_version.first <<
"." << code_version.second
1301 <<
" found version: " << db_version.first <<
"." 1302 << db_version.second);
1322 bool reopened =
false;
1324 const std::string timer_name = db_reconnect_ctl->timerName();
1332 }
catch (
const std::exception& ex) {
1348 if (!db_reconnect_ctl->checkRetries()) {
1351 .arg(db_reconnect_ctl->maxRetries());
1364 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1365 .arg(db_reconnect_ctl->maxRetries())
1366 .arg(db_reconnect_ctl->retryInterval());
1372 db_reconnect_ctl->retryInterval(),
1390 ctx->conn_.openDatabase();
1394 for (; tagged_statements[i].text != NULL; ++i) {
1395 ctx->conn_.prepareStatement(tagged_statements[i]);
1410 ctx->conn_.makeReconnectCtl(timer_name_);
1417 std::stringstream tmp;
1420 tmp <<
", library " << PQlibVersion();
1428 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
1429 tagged_statements[stindex].nbparams,
1434 int s = PQresultStatus(r);
1436 if (s != PGRES_COMMAND_OK) {
1443 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1452 .arg(lease->addr_.toText());
1455 PgSqlLeaseContextAlloc get_context(*
this);
1459 ctx->exchange4_->createBindForSend(lease, bind_array);
1460 auto result = addLeaseCommon(ctx,
INSERT_LEASE4, bind_array);
1464 lease->updateCurrentExpirationTime();
1472 .arg(lease->addr_.toText())
1476 PgSqlLeaseContextAlloc get_context(*
this);
1480 ctx->exchange6_->createBindForSend(lease, bind_array);
1482 auto result = addLeaseCommon(ctx,
INSERT_LEASE6, bind_array);
1486 lease->updateCurrentExpirationTime();
1491 template <
typename Exchange,
typename LeaseCollection>
1497 LeaseCollection& result,
1498 bool single)
const {
1499 const int n = tagged_statements[stindex].nbparams;
1501 tagged_statements[stindex].name, n,
1502 n > 0 ? &bind_array.
values_[0] : NULL,
1503 n > 0 ? &bind_array.
lengths_[0] : NULL,
1504 n > 0 ? &bind_array.
formats_[0] : NULL, 0));
1506 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
1508 int rows = PQntuples(r);
1509 if (single && rows > 1) {
1511 "database where only one was expected for query " 1512 << tagged_statements[stindex].name);
1515 for(
int i = 0; i < rows; ++ i) {
1516 result.push_back(exchange->convertFromDatabase(r, i));
1530 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange4_,
1534 if (collection.empty()) {
1537 result = *collection.begin();
1551 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange6_,
1555 if (collection.empty()) {
1558 result = *collection.begin();
1571 std::string addr_str = boost::lexical_cast<std::string>(addr.
toUint32());
1572 bind_array.
add(addr_str);
1578 PgSqlLeaseContextAlloc get_context(*
this);
1595 if (!hwaddr.
hwaddr_.empty()) {
1605 PgSqlLeaseContextAlloc get_context(*
this);
1623 if (!hwaddr.
hwaddr_.empty()) {
1630 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1631 bind_array.
add(subnet_id_str);
1637 PgSqlLeaseContextAlloc get_context(*
this);
1660 PgSqlLeaseContextAlloc get_context(*
this);
1681 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1682 bind_array.
add(subnet_id_str);
1688 PgSqlLeaseContextAlloc get_context(*
this);
1705 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1706 bind_array.
add(subnet_id_str);
1712 PgSqlLeaseContextAlloc get_context(*
this);
1729 bind_array.
add(hostname);
1735 PgSqlLeaseContextAlloc get_context(*
this);
1753 PgSqlLeaseContextAlloc get_context(*
this);
1756 getLeaseCollection(ctx,
GET_LEASE4, bind_array, result);
1765 if (!lower_bound_address.
isV4()) {
1767 "retrieving leases from the lease database, got " 1768 << lower_bound_address);
1773 .arg(lower_bound_address.
toText());
1779 std::string lb_address_data = boost::lexical_cast<std::string>(lower_bound_address.
toUint32());
1780 bind_array.
add(lb_address_data);
1783 std::string page_size_data = boost::lexical_cast<std::string>(page_size.
page_size_);
1784 bind_array.
add(page_size_data);
1790 PgSqlLeaseContextAlloc get_context(*
this);
1809 std::string addr_str = addr.
toText();
1810 bind_array.
add(addr_str);
1813 std::string type_str_ = boost::lexical_cast<std::string>(lease_type);
1814 bind_array.
add(type_str_);
1820 PgSqlLeaseContextAlloc get_context(*
this);
1830 uint32_t iaid)
const {
1844 bind_array.
add(iaid_str);
1847 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
1848 bind_array.
add(lease_type_str);
1854 PgSqlLeaseContextAlloc get_context(*
this);
1864 uint32_t iaid,
SubnetID subnet_id)
const {
1875 std::string lease_type_str = boost::lexical_cast<std::string>(lease_type);
1876 bind_array.
add(lease_type_str);
1883 bind_array.
add(iaid_str);
1886 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1887 bind_array.
add(subnet_id_str);
1893 PgSqlLeaseContextAlloc get_context(*
this);
1910 std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
1911 bind_array.
add(subnet_id_str);
1917 PgSqlLeaseContextAlloc get_context(*
this);
1938 PgSqlLeaseContextAlloc get_context(*
this);
1956 bind_array.
add(hostname);
1962 PgSqlLeaseContextAlloc get_context(*
this);
1980 PgSqlLeaseContextAlloc get_context(*
this);
1983 getLeaseCollection(ctx,
GET_LEASE6, bind_array, result);
1992 if (!lower_bound_address.
isV6()) {
1994 "retrieving leases from the lease database, got " 1995 << lower_bound_address);
2000 .arg(lower_bound_address.
toText());
2008 std::string lb_address_data =
"0";
2009 if (!lower_bound_address.
isV6Zero()) {
2010 lb_address_data = lower_bound_address.
toText();
2014 bind_array.
add(lb_address_data);
2017 std::string page_size_data = boost::lexical_cast<std::string>(page_size.
page_size_);
2018 bind_array.
add(page_size_data);
2024 PgSqlLeaseContextAlloc get_context(*
this);
2034 const size_t max_leases)
const {
2042 const size_t max_leases)
const {
2048 template<
typename LeaseCollection>
2050 PgSqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2051 const size_t max_leases,
2057 bind_array.
add(state_str);
2061 bind_array.
add(timestamp_str);
2065 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2066 std::numeric_limits<uint32_t>::max();
2067 std::string limit_str = boost::lexical_cast<std::string>(limit);
2068 bind_array.
add(limit_str);
2071 PgSqlLeaseContextAlloc get_context(*
this);
2075 getLeaseCollection(ctx, statement_index, bind_array, expired_leases);
2078 template<
typename LeasePtr>
2084 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2085 tagged_statements[stindex].nbparams,
2090 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2092 int affected_rows = boost::lexical_cast<
int>(PQcmdTuples(r));
2095 if (affected_rows == 1) {
2100 if (affected_rows == 0) {
2102 lease->addr_.toText() <<
" as it does not exist");
2108 "that had the address " << lease->addr_.toText());
2116 .arg(lease->addr_.toText());
2119 PgSqlLeaseContextAlloc get_context(*
this);
2124 ctx->exchange4_->createBindForSend(lease, bind_array);
2127 std::string addr4_str = boost::lexical_cast<std::string>(lease->addr_.toUint32());
2128 bind_array.
add(addr4_str);
2130 std::string expire_str;
2136 lease->current_valid_lft_);
2138 bind_array.
add(expire_str);
2141 updateLeaseCommon(ctx, stindex, bind_array, lease);
2144 lease->updateCurrentExpirationTime();
2152 .arg(lease->addr_.toText())
2156 PgSqlLeaseContextAlloc get_context(*
this);
2161 ctx->exchange6_->createBindForSend(lease, bind_array);
2164 std::string addr_str = lease->addr_.
toText();
2165 bind_array.
add(addr_str);
2167 std::string expire_str;
2173 lease->current_valid_lft_);
2175 bind_array.
add(expire_str);
2178 updateLeaseCommon(ctx, stindex, bind_array, lease);
2181 lease->updateCurrentExpirationTime();
2188 PgSqlLeaseContextAlloc get_context(*
this);
2191 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2192 tagged_statements[stindex].nbparams,
2197 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2198 int affected_rows = boost::lexical_cast<
int>(PQcmdTuples(r));
2200 return (affected_rows);
2212 std::string addr4_str = boost::lexical_cast<std::string>(addr.
toUint32());
2213 bind_array.
add(addr4_str);
2215 std::string expire_str;
2221 lease->current_valid_lft_);
2223 bind_array.
add(expire_str);
2225 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE4, bind_array);
2228 if (affected_rows == 1) {
2233 if (affected_rows == 0) {
2240 "that had the address " << lease->addr_.toText());
2253 std::string addr6_str = addr.
toText();
2254 bind_array.
add(addr6_str);
2256 std::string expire_str;
2262 lease->current_valid_lft_);
2264 bind_array.
add(expire_str);
2266 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE6, bind_array);
2269 if (affected_rows == 1) {
2274 if (affected_rows == 0) {
2281 "that had the address " << lease->addr_.toText());
2299 PgSqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
2305 bind_array.
add(state_str);
2309 static_cast<time_t>(secs));
2310 bind_array.
add(expiration_str);
2313 return (deleteLeaseCommon(statement_index, bind_array));
2319 if (!user_context) {
2324 PgSqlLeaseContextAlloc get_context(*
this);
2329 std::string
const user_context_str(user_context->str());
2330 bind_array.
add(user_context_str);
2334 tagged_statements[stindex].name,
2335 tagged_statements[stindex].nbparams,
2339 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2347 PgSqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
2352 PgSqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
2357 PgSqlLeaseMgr::isJsonSupported()
const {
2359 PgSqlLeaseContextAlloc get_context(*
this);
2364 PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
2366 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2368 bool json_supported;
2370 return json_supported;
2374 PgSqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
2377 PgSqlLeaseContextAlloc get_context(*
this);
2382 bind_array.
add(client_class);
2384 bind_array.
add(ltype);
2391 tagged_statements[stindex].name,
2392 tagged_statements[stindex].nbparams,
2396 ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
2398 int rows = PQntuples(r);
2410 PgSqlLeaseMgr::recountClassLeases4() {
2415 PgSqlLeaseMgr::recountClassLeases6() {
2420 PgSqlLeaseMgr::clearClassLeaseCounts() {
2425 PgSqlLeaseMgr::writeLeases4(
const std::string&) {
2430 PgSqlLeaseMgr::writeLeases6(
const std::string&) {
2437 PgSqlLeaseContextAlloc get_context(*
this);
2450 PgSqlLeaseContextAlloc get_context(*
this);
2465 PgSqlLeaseContextAlloc get_context(*
this);
2480 PgSqlLeaseContextAlloc get_context(*
this);
2493 PgSqlLeaseContextAlloc get_context(*
this);
2508 PgSqlLeaseContextAlloc get_context(*
this);
2533 PgSqlLeaseContextAlloc get_context(*
this);
2536 std::string name =
"";
2538 name = ctx->conn_.getParameter(
"name");
2547 return (std::string(
"PostgreSQL Database"));
2550 std::pair<uint32_t, uint32_t>
2574 const vector<uint8_t>& ) {
2580 const vector<uint8_t>& ) {
2585 PgSqlLeaseMgr::getLeases4ByRelayId(
const OptionBuffer& ,
2594 PgSqlLeaseMgr::getLeases4ByRemoteId(
const OptionBuffer& ,
2603 PgSqlLeaseMgr::getLeases6ByRelayId(
const DUID& ,
2612 PgSqlLeaseMgr::getLeases6ByRemoteId(
const OptionBuffer& ,
2621 PgSqlLeaseMgr::getLeases6ByLink(
const IOAddress& ,
2629 PgSqlLeaseMgr::buildExtendedInfoTables6(
bool ,
bool ) {
2631 "PgSqlLeaseMgr::buildExtendedInfoTables6 not implemented");
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID6
virtual ~PgSqlLeaseMgr()
Destructor (closes database)
PgSqlLeaseStatsQuery(PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type, const SubnetID &subnet_id)
Constructor to query for a single subnet's stats.
RAII class creating a critical section.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
boost::shared_ptr< DUID > DuidPtr
std::string toText() const
Dumps the contents of the array to a string.
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_FAILED
RAII wrapper for PostgreSQL Result sets.
const isc::log::MessageID DHCPSRV_PGSQL_ROLLBACK
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
void createBindForSend(const Lease6Ptr &lease, PsqlBindArray &bind_array)
Creates the bind array for sending Lease6 data to the database.
PostgreSQL Lease Context.
virtual void rollback() override
Rollback Transactions.
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID4
A generic exception that is thrown when a function is not implemented.
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
static bool negative_count_
Received negative state count showing a problem.
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.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
static std::string convertToDatabaseTime(const time_t input_time)
Converts UTC time_t value to a text representation in local time.
virtual void setExtendedInfoTablesEnabled(const bool enabled)
Extended information / Bulk Lease Query shared interface.
virtual void setExtendedInfoTablesEnabled(const bool enabled) override
Extended information / Bulk Lease Query shared interface.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Delete lease6 extended info from tables.
std::string valid_lifetime_str_
const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME4
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Uiaid(uint32_t val)
Constructor.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
std::vector< int > formats_
Vector of "format" for each value.
boost::shared_ptr< PgSqlResult > result_set_
The result set returned by Postgres.
PostgreSQL Lease Manager.
uint32_t next_row_
Index of the next row to fetch.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_SCHEDULE
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
static void destroy()
Destroy lease manager.
const isc::log::MessageID DHCPSRV_PGSQL_NO_TLS_SUPPORT
bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
Base class for marshalling leases to and from PostgreSQL.
const isc::log::MessageID DHCPSRV_PGSQL_GET_ADDR4
const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED4
static CfgMgr & instance()
returns a single instance of Configuration Manager
std::vector< int > lengths_
Vector of data lengths for each value.
virtual std::string getDescription() const override
Returns description of the backend.
std::string user_context_
Attempt to update lease that was not there.
Union for marshalling IAID into and out of the database IAID is defined in the RFC as 4 octets...
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const isc::log::MessageID DHCPSRV_PGSQL_GET_VERSION
static const char DUPLICATE_KEY[]
Define the PgSql error state for a duplicate key error.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
std::vector< uint8_t > hwaddr_
Base class for fulfilling a statistical lease data query.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
Base class for marshalling data to and from PostgreSQL.
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6
PgSqlLease4Exchange()
Constructor.
void createBindForSend(const Lease4Ptr &lease, PsqlBindArray &bind_array)
Creates the bind array for sending Lease4 data to the database.
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_HWADDR
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
std::vector< uint8_t > hwaddr_
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Holds DUID (DHCPv6 Unique Identifier)
const isc::log::MessageID DHCPSRV_PGSQL_GET_EXPIRED6
Exception thrown on failure to open database.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
const isc::log::MessageID DHCPSRV_PGSQL_GET_HOSTNAME6
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
not specified or undefined
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
std::vector< const char * > values_
Vector of pointers to the data values.
Multiple lease records found where one expected.
Lease6Ptr convertFromDatabase(const PgSqlResult &r, int row)
Creates a Lease6 object from a given row in a result set.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void addTempString(const std::string &str)
Binds the given string to the bind array.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
PostgreSQL Lease Context Pool.
void add(const char *value)
Adds a char array to bind array based.
const size_t page_size_
Holds page size.
PgSqlLeaseContextPtr createContext() const
Create a new context.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
const isc::log::MessageID DHCPSRV_PGSQL_GET4
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
const isc::log::MessageID DHCPSRV_PGSQL_GET_ADDR6
std::string subnet_id_str_
static bool warned_about_tls
Emit the TLS support warning only once.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
const isc::log::MessageID DHCPSRV_PGSQL_GET_CLIENTID
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
const isc::log::MessageID DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
SubnetID subnet_id_
The subnet ID to which this data applies.
static std::string getDBVersion()
Local version of getDBVersion() class method.
A generic exception that is thrown when an unexpected error condition occurs.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_SUBID_DUID
boost::shared_ptr< const Element > ConstElementPtr
Structure that holds a lease for IPv6 address and/or prefix.
const isc::log::MessageID DHCPSRV_PGSQL_GET_PAGE6
PgSqlTaggedStatement & statement_
The query's prepared statement.
const isc::log::MessageID DHCPSRV_PGSQL_COMMIT
static void getColumnValue(const PgSqlResult &r, const int row, const size_t col, std::string &value)
Fetches text column value as a string.
const isc::log::MessageID DHCPSRV_PGSQL_GET_HWADDR
std::string addr_str_
Common Instance members used for binding and conversion.
Common PgSql Connector Pool.
virtual ~PgSqlLeaseExchange()
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
bool isV6() const
Convenience function to check for an IPv6 address.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual void commit() override
Commit Transactions.
bool isV4() const
Convenience function to check for an IPv4 address.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
Invalid address family used as input to Lease Manager.
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.
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID DHCPSRV_PGSQL_GET6
Lease4Ptr convertFromDatabase(const PgSqlResult &r, int row)
Creates a Lease4 object from a given row in a result set.
Define a PostgreSQL statement.
void start()
Creates the lease statistical data result set.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
size_t size() const
Fetches the number of entries in the array.
std::string toText() const
Convert the address to a string.
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_ADDR
const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR6
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns an IPv4 lease for specified IPv4 address.
PgSqlConnection & conn_
Database connection to use to execute the query.
boost::shared_ptr< PgSqlLeaseContext > PgSqlLeaseContextPtr
Type of pointers to contexts.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4
const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR6
const isc::log::MessageID DHCPSRV_PGSQL_GET_PAGE4
uint32_t lease_state_
The lease_state to which the count applies.
Type
Type of lease or pool.
Holds Client identifier or client IPv4 address.
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const isc::log::MessageID DHCPSRV_PGSQL_GET_DUID
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
Uiaid(int32_t val)
Constructor.
StatementIndex
Statement Tags.
Hardware type that represents information from DHCPv4 packet.
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.
int64_t state_count_
state_count The count of leases in the lease state
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Contains a single row of lease statistical data.
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR
Define the PostgreSQL backend version.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
Wraps value holding size of the page with leases.
static std::pair< uint32_t, uint32_t > getVersion(const ParameterMap ¶meters)
Get the schema version.
const size_t OID_NONE
Constants for PostgreSQL data types These are defined by PostgreSQL in <catalog/pg_type.h>, but including this file is extraordinarily convoluted, so we'll use these to fill-in.
Lease::Type lease_type_
The lease_type to which the count applies.
std::string ClientClass
Defines a single class name.
std::function< isc::asiolink::IOServicePtr()> IOServiceAccessor
Function which returns the IOService that can be used to recover the connection.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
The IOAddress class represents an IP addresses (version agnostic)
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
const isc::log::MessageID DHCPSRV_PGSQL_UPDATE_ADDR4
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual ~PgSqlLeaseStatsQuery()
Destructor.
Base PgSql derivation of the statistical lease data query.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
std::string dbInputString()
Return a string representing the signed 32-bit value.
PgSqlLeaseStatsQuery(PgSqlConnection &conn, PgSqlTaggedStatement &statement, const bool fetch_type)
Constructor to query for all subnets' stats.
const size_t OID_TIMESTAMP
const isc::log::MessageID DHCPSRV_PGSQL_TLS_SUPPORT
Supports exchanging IPv6 leases with PostgreSQL.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
Exception thrown on failure to execute a database function.
Supports exchanging IPv4 leases with PostgreSQL.
const isc::log::MessageID DHCPSRV_PGSQL_NEGATIVE_LEASES_STAT
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
const isc::log::MessageID DHCPSRV_PGSQL_GET_IAID_DUID
const uint32_t PGSQL_SCHEMA_VERSION_MINOR
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR4
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
bool fetch_type_
Indicates if query supplies lease type.
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 std::string getName() const override
Returns backend name.
const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_CLIENTID
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
PgSqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
virtual std::pair< uint32_t, uint32_t > getVersion() const override
Returns backend version.
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.