21 #include <boost/array.hpp> 22 #include <boost/make_shared.hpp> 23 #include <boost/static_assert.hpp> 24 #include <mysqld_error.h> 101 const size_t LIMITS_TEXT_MAX_LEN = 512;
103 boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
104 tagged_statements = { {
105 {MySqlLeaseMgr::DELETE_LEASE4,
106 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
107 {MySqlLeaseMgr::DELETE_LEASE4_STATE_EXPIRED,
108 "DELETE FROM lease4 " 109 "WHERE state = ? AND expire < ?"},
110 {MySqlLeaseMgr::DELETE_LEASE6,
111 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
112 {MySqlLeaseMgr::DELETE_LEASE6_STATE_EXPIRED,
113 "DELETE FROM lease6 " 114 "WHERE state = ? AND expire < ?"},
115 {MySqlLeaseMgr::GET_LEASE4,
116 "SELECT address, hwaddr, client_id, " 117 "valid_lifetime, expire, subnet_id, " 118 "fqdn_fwd, fqdn_rev, hostname, " 119 "state, user_context " 121 {MySqlLeaseMgr::GET_LEASE4_ADDR,
122 "SELECT address, hwaddr, client_id, " 123 "valid_lifetime, expire, subnet_id, " 124 "fqdn_fwd, fqdn_rev, hostname, " 125 "state, user_context " 127 "WHERE address = ?"},
128 {MySqlLeaseMgr::GET_LEASE4_CLIENTID,
129 "SELECT address, hwaddr, client_id, " 130 "valid_lifetime, expire, subnet_id, " 131 "fqdn_fwd, fqdn_rev, hostname, " 132 "state, user_context " 134 "WHERE client_id = ?"},
135 {MySqlLeaseMgr::GET_LEASE4_CLIENTID_SUBID,
136 "SELECT address, hwaddr, client_id, " 137 "valid_lifetime, expire, subnet_id, " 138 "fqdn_fwd, fqdn_rev, hostname, " 139 "state, user_context " 141 "WHERE client_id = ? AND subnet_id = ?"},
142 {MySqlLeaseMgr::GET_LEASE4_HWADDR,
143 "SELECT address, hwaddr, client_id, " 144 "valid_lifetime, expire, subnet_id, " 145 "fqdn_fwd, fqdn_rev, hostname, " 146 "state, user_context " 149 {MySqlLeaseMgr::GET_LEASE4_HWADDR_SUBID,
150 "SELECT address, hwaddr, client_id, " 151 "valid_lifetime, expire, subnet_id, " 152 "fqdn_fwd, fqdn_rev, hostname, " 153 "state, user_context " 155 "WHERE hwaddr = ? AND subnet_id = ?"},
156 {MySqlLeaseMgr::GET_LEASE4_PAGE,
157 "SELECT address, hwaddr, client_id, " 158 "valid_lifetime, expire, subnet_id, " 159 "fqdn_fwd, fqdn_rev, hostname, " 160 "state, user_context " 165 {MySqlLeaseMgr::GET_LEASE4_SUBID,
166 "SELECT address, hwaddr, client_id, " 167 "valid_lifetime, expire, subnet_id, " 168 "fqdn_fwd, fqdn_rev, hostname, " 169 "state, user_context " 171 "WHERE subnet_id = ?"},
172 {MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
173 "SELECT address, hwaddr, client_id, " 174 "valid_lifetime, expire, subnet_id, " 175 "fqdn_fwd, fqdn_rev, hostname, " 176 "state, user_context " 178 "WHERE hostname = ?"},
179 {MySqlLeaseMgr::GET_LEASE4_EXPIRE,
180 "SELECT address, hwaddr, client_id, " 181 "valid_lifetime, expire, subnet_id, " 182 "fqdn_fwd, fqdn_rev, hostname, " 183 "state, user_context " 186 "AND valid_lifetime != 4294967295 " 188 "ORDER BY expire ASC " 190 {MySqlLeaseMgr::GET_LEASE6,
191 "SELECT address, duid, valid_lifetime, " 192 "expire, subnet_id, pref_lifetime, " 193 "lease_type, iaid, prefix_len, " 194 "fqdn_fwd, fqdn_rev, hostname, " 195 "hwaddr, hwtype, hwaddr_source, " 196 "state, user_context " 198 {MySqlLeaseMgr::GET_LEASE6_ADDR,
199 "SELECT address, duid, valid_lifetime, " 200 "expire, subnet_id, pref_lifetime, " 201 "lease_type, iaid, prefix_len, " 202 "fqdn_fwd, fqdn_rev, hostname, " 203 "hwaddr, hwtype, hwaddr_source, " 204 "state, user_context " 206 "WHERE address = ? AND lease_type = ?"},
207 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
208 "SELECT address, duid, valid_lifetime, " 209 "expire, subnet_id, pref_lifetime, " 210 "lease_type, iaid, prefix_len, " 211 "fqdn_fwd, fqdn_rev, hostname, " 212 "hwaddr, hwtype, hwaddr_source, " 213 "state, user_context " 215 "WHERE duid = ? AND iaid = ? AND lease_type = ?"},
216 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID_SUBID,
217 "SELECT address, duid, valid_lifetime, " 218 "expire, subnet_id, pref_lifetime, " 219 "lease_type, iaid, prefix_len, " 220 "fqdn_fwd, fqdn_rev, hostname, " 221 "hwaddr, hwtype, hwaddr_source, " 222 "state, user_context " 224 "WHERE duid = ? AND iaid = ? AND subnet_id = ? " 225 "AND lease_type = ?"},
226 {MySqlLeaseMgr::GET_LEASE6_PAGE,
227 "SELECT address, duid, valid_lifetime, " 228 "expire, subnet_id, pref_lifetime, " 229 "lease_type, iaid, prefix_len, " 230 "fqdn_fwd, fqdn_rev, hostname, " 231 "hwaddr, hwtype, hwaddr_source, " 232 "state, user_context " 237 {MySqlLeaseMgr::GET_LEASE6_SUBID,
238 "SELECT address, duid, valid_lifetime, " 239 "expire, subnet_id, pref_lifetime, " 240 "lease_type, iaid, prefix_len, " 241 "fqdn_fwd, fqdn_rev, hostname, " 242 "hwaddr, hwtype, hwaddr_source, " 243 "state, user_context " 245 "WHERE subnet_id = ?"},
246 {MySqlLeaseMgr::GET_LEASE6_DUID,
247 "SELECT address, duid, valid_lifetime, " 248 "expire, subnet_id, pref_lifetime, " 249 "lease_type, iaid, prefix_len, " 250 "fqdn_fwd, fqdn_rev, hostname, " 251 "hwaddr, hwtype, hwaddr_source, " 252 "state, user_context " 255 {MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
256 "SELECT address, duid, valid_lifetime, " 257 "expire, subnet_id, pref_lifetime, " 258 "lease_type, iaid, prefix_len, " 259 "fqdn_fwd, fqdn_rev, hostname, " 260 "hwaddr, hwtype, hwaddr_source, " 261 "state, user_context " 263 "WHERE hostname = ?"},
264 {MySqlLeaseMgr::GET_LEASE6_EXPIRE,
265 "SELECT address, duid, valid_lifetime, " 266 "expire, subnet_id, pref_lifetime, " 267 "lease_type, iaid, prefix_len, " 268 "fqdn_fwd, fqdn_rev, hostname, " 269 "hwaddr, hwtype, hwaddr_source, " 270 "state, user_context " 273 "AND valid_lifetime != 4294967295 " 275 "ORDER BY expire ASC " 277 {MySqlLeaseMgr::INSERT_LEASE4,
278 "INSERT INTO lease4(address, hwaddr, client_id, " 279 "valid_lifetime, expire, subnet_id, " 280 "fqdn_fwd, fqdn_rev, hostname, " 281 "state, user_context) " 282 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
283 {MySqlLeaseMgr::INSERT_LEASE6,
284 "INSERT INTO lease6(address, duid, valid_lifetime, " 285 "expire, subnet_id, pref_lifetime, " 286 "lease_type, iaid, prefix_len, " 287 "fqdn_fwd, fqdn_rev, hostname, " 288 "hwaddr, hwtype, hwaddr_source, " 289 "state, user_context) " 290 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
291 {MySqlLeaseMgr::UPDATE_LEASE4,
292 "UPDATE lease4 SET address = ?, hwaddr = ?, " 293 "client_id = ?, valid_lifetime = ?, expire = ?, " 294 "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, " 296 "state = ?, user_context = ? " 297 "WHERE address = ? AND expire = ?"},
298 {MySqlLeaseMgr::UPDATE_LEASE6,
299 "UPDATE lease6 SET address = ?, duid = ?, " 300 "valid_lifetime = ?, expire = ?, subnet_id = ?, " 301 "pref_lifetime = ?, lease_type = ?, iaid = ?, " 302 "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, " 303 "hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, " 304 "state = ?, user_context = ? " 305 "WHERE address = ? AND expire = ?"},
306 {MySqlLeaseMgr::ALL_LEASE4_STATS,
307 "SELECT subnet_id, state, leases as state_count " 308 "FROM lease4_stat ORDER BY subnet_id, state"},
309 {MySqlLeaseMgr::SUBNET_LEASE4_STATS,
310 "SELECT subnet_id, state, leases as state_count " 312 "WHERE subnet_id = ? " 314 {MySqlLeaseMgr::SUBNET_RANGE_LEASE4_STATS,
315 "SELECT subnet_id, state, leases as state_count " 317 "WHERE subnet_id >= ? and subnet_id <= ? " 318 "ORDER BY subnet_id, state"},
319 {MySqlLeaseMgr::ALL_LEASE6_STATS,
320 "SELECT subnet_id, lease_type, state, leases as state_count " 321 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
322 {MySqlLeaseMgr::SUBNET_LEASE6_STATS,
323 "SELECT subnet_id, lease_type, state, leases as state_count " 325 "WHERE subnet_id = ? " 326 "ORDER BY lease_type, state"},
327 {MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
328 "SELECT subnet_id, lease_type, state, leases as state_count " 330 "WHERE subnet_id >= ? and subnet_id <= ? " 331 "ORDER BY subnet_id, lease_type, state"},
332 {MySqlLeaseMgr::CHECK_LEASE4_LIMITS,
"SELECT checkLease4Limits(?)"},
333 {MySqlLeaseMgr::CHECK_LEASE6_LIMITS,
"SELECT checkLease6Limits(?)"},
334 {MySqlLeaseMgr::IS_JSON_SUPPORTED,
"SELECT isJsonSupported()"},
365 for (
size_t i = 0; i < count; ++i) {
367 bind[i].error =
reinterpret_cast<my_bool*
>(&error[i]);
386 std::string result =
"";
389 for (
size_t i = 0; i < count; ++i) {
391 if (!result.empty()) {
398 if (result.empty()) {
421 static const size_t LEASE_COLUMNS = 11;
430 client_id_length_(0), client_id_null_(
MLM_FALSE),
431 subnet_id_(0), valid_lifetime_(0),
432 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
433 state_(0), user_context_length_(0),
435 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
436 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
437 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
438 memset(user_context_, 0,
sizeof(user_context_));
439 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
442 columns_[0] =
"address";
443 columns_[1] =
"hwaddr";
444 columns_[2] =
"client_id";
445 columns_[3] =
"valid_lifetime";
446 columns_[4] =
"expire";
447 columns_[5] =
"subnet_id";
448 columns_[6] =
"fqdn_fwd";
449 columns_[7] =
"fqdn_rev";
450 columns_[8] =
"hostname";
451 columns_[9] =
"state";
452 columns_[10] =
"user_context";
453 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
475 memset(bind_, 0,
sizeof(bind_));
484 addr4_ = lease_->addr_.toUint32();
485 bind_[0].buffer_type = MYSQL_TYPE_LONG;
486 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
494 hwaddr_ = hwaddr->hwaddr_;
495 hwaddr_length_ = hwaddr->hwaddr_.size();
502 if (hwaddr_.empty()) {
506 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
507 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
508 bind_[1].buffer_length = hwaddr_length_;
509 bind_[1].length = &hwaddr_length_;
511 bind_[1].buffer_type = MYSQL_TYPE_NULL;
518 bind_[1].buffer = NULL;
519 bind_[1].is_null = &hwaddr_null_;
523 if (lease_->client_id_) {
524 client_id_ = lease_->client_id_->getClientId();
525 client_id_length_ = client_id_.size();
532 if (client_id_.empty()) {
533 client_id_.resize(1);
536 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
537 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
538 bind_[2].buffer_length = client_id_length_;
539 bind_[2].length = &client_id_length_;
543 bind_[2].buffer_type = MYSQL_TYPE_NULL;
550 bind_[2].buffer = NULL;
551 bind_[2].is_null = &client_id_null_;
555 bind_[3].buffer_type = MYSQL_TYPE_LONG;
556 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
569 uint32_t valid_lft = lease_->valid_lft_;
570 if (valid_lft == Lease::INFINITY_LFT) {
573 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
575 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
576 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
577 bind_[4].buffer_length =
sizeof(expire_);
583 bind_[5].buffer_type = MYSQL_TYPE_LONG;
584 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
590 bind_[6].buffer_type = MYSQL_TYPE_TINY;
591 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
597 bind_[7].buffer_type = MYSQL_TYPE_TINY;
598 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
607 bind_[8].buffer_type = MYSQL_TYPE_STRING;
608 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
609 bind_[8].buffer_length = lease_->hostname_.length();
614 bind_[9].buffer_type = MYSQL_TYPE_LONG;
615 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
623 bind_[10].buffer_type = MYSQL_TYPE_STRING;
624 std::string ctx_txt = ctx->str();
626 bind_[10].buffer = user_context_;
627 bind_[10].buffer_length = ctx_txt.length();
631 bind_[10].buffer_type = MYSQL_TYPE_NULL;
635 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
638 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
640 }
catch (
const std::exception& ex) {
642 "Could not create bind array from Lease4: " 643 << lease_->addr_.toText() <<
", reason: " << ex.
what());
648 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
663 memset(bind_, 0,
sizeof(bind_));
666 bind_[0].buffer_type = MYSQL_TYPE_LONG;
667 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
673 hwaddr_length_ =
sizeof(hwaddr_buffer_);
674 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
675 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
676 bind_[1].buffer_length = hwaddr_length_;
677 bind_[1].length = &hwaddr_length_;
682 client_id_length_ =
sizeof(client_id_buffer_);
683 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
684 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
685 bind_[2].buffer_length = client_id_length_;
686 bind_[2].length = &client_id_length_;
687 bind_[2].is_null = &client_id_null_;
692 bind_[3].buffer_type = MYSQL_TYPE_LONG;
693 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
699 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
700 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
701 bind_[4].buffer_length =
sizeof(expire_);
706 bind_[5].buffer_type = MYSQL_TYPE_LONG;
707 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
713 bind_[6].buffer_type = MYSQL_TYPE_TINY;
714 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
720 bind_[7].buffer_type = MYSQL_TYPE_TINY;
721 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
730 hostname_length_ =
sizeof(hostname_buffer_);
731 bind_[8].buffer_type = MYSQL_TYPE_STRING;
732 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
733 bind_[8].buffer_length = hostname_length_;
734 bind_[8].length = &hostname_length_;
739 bind_[9].buffer_type = MYSQL_TYPE_LONG;
740 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
747 user_context_length_ =
sizeof(user_context_);
748 bind_[10].buffer_type = MYSQL_TYPE_STRING;
749 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
750 bind_[10].buffer_length = user_context_length_;
751 bind_[10].length = &user_context_length_;
752 bind_[10].is_null = &user_context_null_;
755 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
758 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
762 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
779 uint32_t valid_lft = valid_lifetime_;
780 if (valid_lft == Lease::INFINITY_LFT) {
783 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
787 client_id_length_ = 0;
792 std::string hostname(hostname_buffer_,
793 hostname_buffer_ + hostname_length_);
802 std::string user_context;
804 user_context_[user_context_length_] =
'\0';
805 user_context.assign(user_context_);
810 if (!user_context.empty()) {
811 ctx = Element::fromJSON(user_context);
812 if (!ctx || (ctx->getType() != Element::map)) {
814 <<
"' is not a JSON map");
818 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
821 valid_lifetime_, cltt,
822 subnet_id_, fqdn_fwd_,
823 fqdn_rev_, hostname));
826 lease->state_ = state_;
829 lease->setContext(ctx);
846 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
855 MYSQL_BIND bind_[LEASE_COLUMNS];
856 std::string columns_[LEASE_COLUMNS];
859 std::vector<uint8_t> hwaddr_;
860 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
861 unsigned long hwaddr_length_;
863 std::vector<uint8_t> client_id_;
864 uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
865 unsigned long client_id_length_;
869 uint32_t valid_lifetime_;
873 unsigned long hostname_length_;
876 unsigned long user_context_length_;
895 static const size_t LEASE_COLUMNS = 17;
904 hwaddr_null_(
MLM_FALSE), duid_length_(0),
905 iaid_(0), lease_type_(0), prefix_len_(0),
906 pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
907 fqdn_fwd_(false), fqdn_rev_(false),
908 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
909 state_(0), user_context_length_(0),
911 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
912 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
913 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
914 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
915 memset(user_context_, 0,
sizeof(user_context_));
916 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
919 columns_[0] =
"address";
920 columns_[1] =
"duid";
921 columns_[2] =
"valid_lifetime";
922 columns_[3] =
"expire";
923 columns_[4] =
"subnet_id";
924 columns_[5] =
"pref_lifetime";
925 columns_[6] =
"lease_type";
926 columns_[7] =
"iaid";
927 columns_[8] =
"prefix_len";
928 columns_[9] =
"fqdn_fwd";
929 columns_[10] =
"fqdn_rev";
930 columns_[11] =
"hostname";
931 columns_[12] =
"hwaddr";
932 columns_[13] =
"hwtype";
933 columns_[14] =
"hwaddr_source";
934 columns_[15] =
"state";
935 columns_[16] =
"user_context";
936 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
957 memset(bind_, 0,
sizeof(bind_));
961 addr6_ = lease_->addr_.toText();
962 addr6_length_ = addr6_.size();
978 bind_[0].buffer_type = MYSQL_TYPE_STRING;
979 bind_[0].buffer =
const_cast<char*
>(addr6_.c_str());
980 bind_[0].buffer_length = addr6_length_;
981 bind_[0].length = &addr6_length_;
986 if (!lease_->duid_) {
988 <<
" is missing mandatory client-id.");
990 duid_ = lease_->duid_->getDuid();
991 duid_length_ = duid_.size();
993 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
994 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
995 bind_[1].buffer_length = duid_length_;
996 bind_[1].length = &duid_length_;
1001 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1002 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1015 uint32_t valid_lft = lease_->valid_lft_;
1016 if (valid_lft == Lease::INFINITY_LFT) {
1019 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
1021 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1022 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1023 bind_[3].buffer_length =
sizeof(expire_);
1029 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1030 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1037 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1038 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1045 lease_type_ = lease_->type_;
1046 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1047 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1054 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1055 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1062 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1063 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1069 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1070 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1076 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1077 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1083 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1084 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1085 bind_[11].buffer_length = lease_->hostname_.length();
1092 hwaddr_ = hwaddr->hwaddr_;
1093 hwaddr_length_ = hwaddr->hwaddr_.size();
1100 if (hwaddr_.empty()) {
1104 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1105 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1106 bind_[12].buffer_length = hwaddr_length_;
1107 bind_[12].length = &hwaddr_length_;
1109 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1116 bind_[12].buffer = NULL;
1117 bind_[12].is_null = &hwaddr_null_;
1122 hwtype_ = lease->hwaddr_->htype_;
1123 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1124 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1128 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1135 bind_[13].buffer = NULL;
1136 bind_[13].is_null = &hwaddr_null_;
1141 hwaddr_source_ = lease->hwaddr_->source_;
1142 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1143 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1147 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1154 bind_[14].buffer = NULL;
1155 bind_[14].is_null = &hwaddr_null_;
1159 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1160 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1168 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1169 std::string ctx_txt = ctx->str();
1171 bind_[16].buffer = user_context_;
1172 bind_[16].buffer_length = ctx_txt.length();
1176 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1180 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1183 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1185 }
catch (
const std::exception& ex) {
1187 "Could not create bind array from Lease6: " 1188 << lease_->addr_.toText() <<
", reason: " << ex.
what());
1193 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1211 memset(bind_, 0,
sizeof(bind_));
1217 addr6_length_ =
sizeof(addr6_buffer_) - 1;
1218 bind_[0].buffer_type = MYSQL_TYPE_STRING;
1219 bind_[0].buffer = addr6_buffer_;
1220 bind_[0].buffer_length = addr6_length_;
1221 bind_[0].length = &addr6_length_;
1226 duid_length_ =
sizeof(duid_buffer_);
1227 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1228 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1229 bind_[1].buffer_length = duid_length_;
1230 bind_[1].length = &duid_length_;
1235 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1236 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1242 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1243 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1244 bind_[3].buffer_length =
sizeof(expire_);
1249 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1250 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1256 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1257 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1263 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1264 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1270 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1271 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1277 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1278 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1284 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1285 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1291 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1292 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1298 hostname_length_ =
sizeof(hostname_buffer_);
1299 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1300 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1301 bind_[11].buffer_length = hostname_length_;
1302 bind_[11].length = &hostname_length_;
1308 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1309 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1310 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1311 bind_[12].buffer_length = hwaddr_length_;
1312 bind_[12].length = &hwaddr_length_;
1313 bind_[12].is_null = &hwaddr_null_;
1316 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1317 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1321 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1322 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1326 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1327 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1334 user_context_length_ =
sizeof(user_context_);
1335 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1336 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1337 bind_[16].buffer_length = user_context_length_;
1338 bind_[16].length = &user_context_length_;
1339 bind_[16].is_null = &user_context_null_;
1342 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1345 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1349 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1366 addr6_buffer_[addr6_length_] =
'\0';
1367 std::string address = addr6_buffer_;
1373 switch (lease_type_) {
1374 case Lease::TYPE_NA:
1375 type = Lease::TYPE_NA;
1378 case Lease::TYPE_TA:
1379 type = Lease::TYPE_TA;
1382 case Lease::TYPE_PD:
1383 type = Lease::TYPE_PD;
1388 static_cast<int>(lease_type_) <<
") for lease with " 1389 <<
"address " << address <<
". Only 0, 1, or 2 are " 1394 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1398 std::string hostname(hostname_buffer_,
1399 hostname_buffer_ + hostname_length_);
1404 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1405 hwaddr->source_ = hwaddr_source_;
1409 std::string user_context;
1411 user_context_[user_context_length_] =
'\0';
1412 user_context.assign(user_context_);
1417 if (!user_context.empty()) {
1418 ctx = Element::fromJSON(user_context);
1419 if (!ctx || (ctx->getType() != Element::map)) {
1421 <<
"' is not a JSON map");
1427 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1429 valid_lifetime_, subnet_id_,
1430 fqdn_fwd_, fqdn_rev_,
1435 uint32_t valid_lft = valid_lifetime_;
1436 if (valid_lft == Lease::INFINITY_LFT) {
1439 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
1441 result->cltt_ = cltt;
1442 result->current_cltt_ = cltt;
1445 result->state_ = state_;
1448 result->setContext(ctx);
1465 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
1475 unsigned long addr6_length_;
1476 MYSQL_BIND bind_[LEASE_COLUMNS];
1477 std::string columns_[LEASE_COLUMNS];
1478 my_bool error_[LEASE_COLUMNS];
1480 std::vector<uint8_t> hwaddr_;
1481 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
1482 unsigned long hwaddr_length_;
1484 std::vector<uint8_t> duid_;
1485 uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
1486 unsigned long duid_length_;
1489 uint8_t lease_type_;
1490 uint8_t prefix_len_;
1491 uint32_t pref_lifetime_;
1492 uint32_t subnet_id_;
1493 uint32_t valid_lifetime_;
1497 unsigned long hostname_length_;
1499 uint32_t hwaddr_source_;
1502 unsigned long user_context_length_;
1525 const bool fetch_type)
1526 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1527 fetch_type_(fetch_type),
1530 bind_(fetch_type_ ? 4 : 3),
1531 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1532 validateStatement();
1545 const bool fetch_type,
const SubnetID& subnet_id)
1546 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1547 statement_(NULL), fetch_type_(fetch_type),
1550 bind_(fetch_type_ ? 4 : 3),
1551 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1552 validateStatement();
1568 const bool fetch_type,
const SubnetID& first_subnet_id,
1571 statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
1574 bind_(fetch_type_ ? 4 : 3),
1575 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1576 validateStatement();
1581 (void) mysql_stmt_free_result(statement_);
1593 if (getSelectMode() != ALL_SUBNETS) {
1594 MYSQL_BIND inbind[2];
1595 memset(inbind, 0,
sizeof(inbind));
1598 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1599 inbind[0].buffer =
reinterpret_cast<char*
>(&first_subnet_id_);
1603 if (getSelectMode() == SUBNET_RANGE) {
1604 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1605 inbind[1].buffer =
reinterpret_cast<char*
>(&last_subnet_id_);
1610 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1611 conn_.checkError(status, statement_index_,
"unable to bind parameters");
1616 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1617 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1624 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1625 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1629 fetch_type_ = Lease::TYPE_NA;
1633 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1634 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1639 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1640 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1645 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1646 conn_.checkError(status, statement_index_,
"outbound binding failed");
1650 conn_.checkError(status, statement_index_,
"unable to execute");
1654 status = mysql_stmt_store_result(statement_);
1655 conn_.checkError(status, statement_index_,
"results storage failed");
1674 bool have_row =
false;
1675 int status = mysql_stmt_fetch(statement_);
1680 if (state_count_ >= 0) {
1684 if (!negative_count_) {
1685 negative_count_ =
true;
1690 }
else if (status != MYSQL_NO_DATA) {
1691 conn_.checkError(status, statement_index_,
"getNextRow failed");
1702 void validateStatement() {
1703 if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
1705 " - invalid statement index" << statement_index_);
1708 statement_ = conn_.statements_[statement_index_];
1715 size_t statement_index_;
1718 MYSQL_STMT *statement_;
1724 std::vector<MYSQL_BIND> bind_;
1727 uint32_t subnet_id_;
1730 uint32_t lease_type_;
1736 int64_t state_count_;
1739 static bool negative_count_;
1743 bool MySqlLeaseStatsQuery::negative_count_ =
false;
1750 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1755 MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
1758 if (MultiThreadingMgr::instance().getMode()) {
1762 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1763 if (!mgr_.pool_->pool_.empty()) {
1764 ctx_ = mgr_.pool_->pool_.back();
1765 mgr_.pool_->pool_.pop_back();
1769 ctx_ = mgr_.createContext();
1773 if (mgr_.pool_->pool_.empty()) {
1776 ctx_ = mgr_.pool_->pool_.back();
1780 MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
1781 if (MultiThreadingMgr::instance().getMode()) {
1783 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1784 mgr_.pool_->pool_.push_back(ctx_);
1792 : parameters_(parameters), timer_name_(
"") {
1795 timer_name_ =
"MySqlLeaseMgr[";
1796 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1797 timer_name_ +=
"]DbReconnectTimer";
1802 std::pair<uint32_t, uint32_t> db_version =
getVersion();
1803 if (code_version != db_version) {
1805 "MySQL schema version mismatch: need version: " 1806 << code_version.first <<
"." << code_version.second
1807 <<
" found version: " << db_version.first <<
"." 1808 << db_version.second);
1828 bool reopened =
false;
1830 const std::string timer_name = db_reconnect_ctl->timerName();
1838 }
catch (
const std::exception& ex) {
1854 if (!db_reconnect_ctl->checkRetries()) {
1857 .arg(db_reconnect_ctl->maxRetries());
1870 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1871 .arg(db_reconnect_ctl->maxRetries())
1872 .arg(db_reconnect_ctl->retryInterval());
1878 db_reconnect_ctl->retryInterval(),
1896 ctx->conn_.openDatabase();
1899 if (ctx->conn_.getTls()) {
1900 std::string cipher = ctx->conn_.getTlsCipher();
1901 if (cipher.empty()) {
1911 ctx->conn_.prepareStatements(tagged_statements.begin(),
1912 tagged_statements.end());
1920 ctx->conn_.makeReconnectCtl(timer_name_);
1927 std::stringstream tmp;
1930 tmp <<
", library " << mysql_get_client_info();
1941 std::vector<MYSQL_BIND>& bind) {
1944 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], &bind[0]);
1945 checkError(ctx, status, stindex,
"unable to bind parameters");
1954 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
1957 checkError(ctx, status, stindex,
"unable to execute");
1967 .arg(lease->addr_.toText());
1970 MySqlLeaseContextAlloc get_context(*
this);
1974 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
1981 lease->updateCurrentExpirationTime();
1989 .arg(lease->addr_.toText())
1993 MySqlLeaseContextAlloc get_context(*
this);
1997 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2004 lease->updateCurrentExpirationTime();
2034 template <
typename Exchange,
typename LeaseCollection>
2040 LeaseCollection& result,
2041 bool single)
const {
2046 status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2047 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2052 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2053 status = mysql_stmt_bind_result(ctx->conn_.statements_[stindex], &outbind[0]);
2054 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2058 checkError(ctx, status, stindex,
"unable to execute");
2062 status = mysql_stmt_store_result(ctx->conn_.statements_[stindex]);
2063 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2070 while ((status = mysql_stmt_fetch(ctx->conn_.statements_[stindex])) == 0) {
2072 result.push_back(exchange->getLeaseData());
2077 ctx->conn_.text_statements_[stindex] <<
">");
2080 if (single && (++count > 1)) {
2082 "database where only one was expected for query " 2083 << ctx->conn_.text_statements_[stindex]);
2090 checkError(ctx, status, stindex,
"unable to fetch results");
2091 }
else if (status == MYSQL_DATA_TRUNCATED) {
2094 <<
" returned truncated data: columns affected are " 2095 << exchange->getErrorColumns());
2109 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2112 if (collection.empty()) {
2115 result = *collection.begin();
2129 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2132 if (collection.empty()) {
2135 result = *collection.begin();
2148 MYSQL_BIND inbind[1];
2149 memset(inbind, 0,
sizeof(inbind));
2152 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2153 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2160 MySqlLeaseContextAlloc get_context(*
this);
2174 MYSQL_BIND inbind[1];
2175 memset(inbind, 0,
sizeof(inbind));
2177 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2179 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2183 uint8_t single_byte_data = 0;
2190 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2191 : &single_byte_data;
2193 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2194 inbind[0].buffer_length = hwaddr_length;
2195 inbind[0].length = &hwaddr_length;
2201 MySqlLeaseContextAlloc get_context(*
this);
2216 MYSQL_BIND inbind[2];
2217 memset(inbind, 0,
sizeof(inbind));
2219 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2221 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2225 std::vector<uint8_t> single_byte_vec(1);
2232 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2233 : &single_byte_vec[0];
2235 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2236 inbind[0].buffer_length = hwaddr_length;
2237 inbind[0].length = &hwaddr_length;
2239 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2240 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2247 MySqlLeaseContextAlloc get_context(*
this);
2261 MYSQL_BIND inbind[1];
2262 memset(inbind, 0,
sizeof(inbind));
2264 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2266 std::vector<uint8_t> client_data = clientid.
getClientId();
2267 unsigned long client_data_length = client_data.size();
2271 if (client_data.empty()) {
2272 client_data.resize(1);
2275 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2276 inbind[0].buffer_length = client_data_length;
2277 inbind[0].length = &client_data_length;
2283 MySqlLeaseContextAlloc get_context(*
this);
2298 MYSQL_BIND inbind[2];
2299 memset(inbind, 0,
sizeof(inbind));
2301 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2303 std::vector<uint8_t> client_data = clientid.
getClientId();
2304 unsigned long client_data_length = client_data.size();
2308 if (client_data.empty()) {
2309 client_data.resize(1);
2312 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2313 inbind[0].buffer_length = client_data_length;
2314 inbind[0].length = &client_data_length;
2316 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2317 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2324 MySqlLeaseContextAlloc get_context(*
this);
2338 MYSQL_BIND inbind[1];
2339 memset(inbind, 0,
sizeof(inbind));
2342 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2343 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2350 MySqlLeaseContextAlloc get_context(*
this);
2364 MYSQL_BIND inbind[1];
2365 memset(inbind, 0,
sizeof(inbind));
2368 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2369 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2370 inbind[0].buffer_length = hostname.length();
2376 MySqlLeaseContextAlloc get_context(*
this);
2391 MySqlLeaseContextAlloc get_context(*
this);
2394 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2403 if (!lower_bound_address.
isV4()) {
2405 "retrieving leases from the lease database, got " 2406 << lower_bound_address);
2411 .arg(lower_bound_address.
toText());
2414 MYSQL_BIND inbind[2];
2415 memset(inbind, 0,
sizeof(inbind));
2418 uint32_t lb_address_data = lower_bound_address.
toUint32();
2419 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2420 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2424 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2425 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2426 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2433 MySqlLeaseContextAlloc get_context(*
this);
2449 MYSQL_BIND inbind[2];
2450 memset(inbind, 0,
sizeof(inbind));
2452 std::string addr6 = addr.
toText();
2453 unsigned long addr6_length = addr6.size();
2457 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2458 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2459 inbind[0].buffer_length = addr6_length;
2460 inbind[0].length = &addr6_length;
2463 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2464 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2470 MySqlLeaseContextAlloc get_context(*
this);
2480 uint32_t iaid)
const {
2487 MYSQL_BIND inbind[3];
2488 memset(inbind, 0,
sizeof(inbind));
2502 const vector<uint8_t>& duid_vector = duid.
getDuid();
2503 unsigned long duid_length = duid_vector.size();
2510 uint8_t single_byte_data = 0;
2511 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2512 : &single_byte_data;
2514 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2515 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2516 inbind[0].buffer_length = duid_length;
2517 inbind[0].length = &duid_length;
2520 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2521 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2525 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2526 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2533 MySqlLeaseContextAlloc get_context(*
this);
2543 uint32_t iaid,
SubnetID subnet_id)
const {
2551 MYSQL_BIND inbind[4];
2552 memset(inbind, 0,
sizeof(inbind));
2556 const vector<uint8_t>& duid_vector = duid.
getDuid();
2557 unsigned long duid_length = duid_vector.size();
2558 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2559 inbind[0].buffer =
reinterpret_cast<char*
>(
2560 const_cast<uint8_t*
>(&duid_vector[0]));
2561 inbind[0].buffer_length = duid_length;
2562 inbind[0].length = &duid_length;
2565 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2566 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2570 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2571 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2575 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2576 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2583 MySqlLeaseContextAlloc get_context(*
this);
2597 MYSQL_BIND inbind[1];
2598 memset(inbind, 0,
sizeof(inbind));
2601 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2602 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2609 MySqlLeaseContextAlloc get_context(*
this);
2624 MySqlLeaseContextAlloc get_context(*
this);
2627 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
2638 MYSQL_BIND inbind[1];
2639 memset(inbind, 0,
sizeof(inbind));
2641 const vector<uint8_t>& duid_vector = duid.
getDuid();
2642 unsigned long duid_length = duid_vector.size();
2644 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2645 inbind[0].buffer =
reinterpret_cast<char*
>(
2646 const_cast<uint8_t*
>(&duid_vector[0]));
2647 inbind[0].buffer_length = duid_length;
2648 inbind[0].length = &duid_length;
2653 MySqlLeaseContextAlloc get_context(*
this);
2667 MYSQL_BIND inbind[1];
2668 memset(inbind, 0,
sizeof(inbind));
2671 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2672 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2673 inbind[0].buffer_length = hostname.length();
2679 MySqlLeaseContextAlloc get_context(*
this);
2691 if (!lower_bound_address.
isV6()) {
2693 "retrieving leases from the lease database, got " 2694 << lower_bound_address);
2699 .arg(lower_bound_address.
toText());
2702 MYSQL_BIND inbind[2];
2703 memset(inbind, 0,
sizeof(inbind));
2708 std::string lb_address_data =
"0";
2709 if (!lower_bound_address.
isV6Zero()) {
2710 lb_address_data = lower_bound_address.
toText();
2714 unsigned long lb_address_data_size = lb_address_data.size();
2715 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2716 inbind[0].buffer =
const_cast<char*
>(lb_address_data.c_str());
2717 inbind[0].buffer_length = lb_address_data_size;
2718 inbind[0].length = &lb_address_data_size;
2721 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2722 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2723 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2730 MySqlLeaseContextAlloc get_context(*
this);
2740 const size_t max_leases)
const {
2748 const size_t max_leases)
const {
2754 template<
typename LeaseCollection>
2756 MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2757 const size_t max_leases,
2760 MYSQL_BIND inbind[3];
2761 memset(inbind, 0,
sizeof(inbind));
2765 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2766 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
2770 MYSQL_TIME expire_time;
2772 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2773 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
2774 inbind[1].buffer_length =
sizeof(expire_time);
2778 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2779 std::numeric_limits<uint32_t>::max();
2780 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2781 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
2785 MySqlLeaseContextAlloc get_context(*
this);
2789 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
2796 template <
typename LeasePtr>
2804 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2805 checkError(ctx, status, stindex,
"unable to bind parameters");
2809 checkError(ctx, status, stindex,
"unable to execute");
2813 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.statements_[stindex]);
2816 if (affected_rows == 1) {
2821 if (affected_rows == 0) {
2823 lease->addr_.toText() <<
" as it does not exist");
2829 "that had the address " << lease->addr_.toText());
2837 .arg(lease->addr_.toText());
2840 MySqlLeaseContextAlloc get_context(*
this);
2844 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2847 MYSQL_BIND inbind[2];
2848 memset(inbind, 0,
sizeof(inbind));
2850 uint32_t addr4 = lease->addr_.toUint32();
2851 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2852 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2855 bind.push_back(inbind[0]);
2860 uint32_t valid_lft = lease->current_valid_lft_;
2866 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2867 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2868 inbind[1].buffer_length =
sizeof(expire);
2870 bind.push_back(inbind[1]);
2873 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2876 lease->updateCurrentExpirationTime();
2884 .arg(lease->addr_.toText())
2888 MySqlLeaseContextAlloc get_context(*
this);
2892 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2895 MYSQL_BIND inbind[2];
2896 memset(inbind, 0,
sizeof(inbind));
2898 std::string addr6 = lease->addr_.toText();
2899 unsigned long addr6_length = addr6.size();
2903 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2904 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2905 inbind[0].buffer_length = addr6_length;
2906 inbind[0].length = &addr6_length;
2908 bind.push_back(inbind[0]);
2913 uint32_t valid_lft = lease->current_valid_lft_;
2919 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2920 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2921 inbind[1].buffer_length =
sizeof(expire);
2923 bind.push_back(inbind[1]);
2926 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2929 lease->updateCurrentExpirationTime();
2942 MySqlLeaseContextAlloc get_context(*
this);
2946 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2947 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2951 checkError(ctx, status, stindex,
"unable to execute");
2955 return (static_cast<uint64_t>(mysql_stmt_affected_rows(ctx->conn_.statements_[stindex])));
2965 MYSQL_BIND inbind[2];
2966 memset(inbind, 0,
sizeof(inbind));
2970 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2971 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2977 uint32_t valid_lft = lease->current_valid_lft_;
2983 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2984 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2985 inbind[1].buffer_length =
sizeof(expire);
2987 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE4, inbind);
2990 if (affected_rows == 1) {
2995 if (affected_rows == 0) {
3002 "that had the address " << lease->addr_.toText());
3013 MYSQL_BIND inbind[2];
3014 memset(inbind, 0,
sizeof(inbind));
3016 std::string addr6 = addr.
toText();
3017 unsigned long addr6_length = addr6.size();
3021 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3022 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
3023 inbind[0].buffer_length = addr6_length;
3024 inbind[0].length = &addr6_length;
3029 uint32_t valid_lft = lease->current_valid_lft_;
3035 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3036 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3037 inbind[1].buffer_length =
sizeof(expire);
3039 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE6, inbind);
3042 if (affected_rows == 1) {
3047 if (affected_rows == 0) {
3054 "that had the address " << lease->addr_.toText());
3072 MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3075 MYSQL_BIND inbind[2];
3076 memset(inbind, 0,
sizeof(inbind));
3080 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3081 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3085 MYSQL_TIME expire_time;
3087 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3088 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3089 inbind[1].buffer_length =
sizeof(expire_time);
3092 uint64_t deleted_leases = deleteLeaseCommon(statement_index, inbind);
3094 .arg(deleted_leases);
3096 return (deleted_leases);
3102 if (!user_context) {
3107 MySqlLeaseContextAlloc get_context(*
this);
3119 std::string limit_text;
3120 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3122 limit_text = result[0]->getString();
3129 MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3134 MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3141 MySqlLeaseContextAlloc get_context(*
this);
3154 MySqlLeaseContextAlloc get_context(*
this);
3169 MySqlLeaseContextAlloc get_context(*
this);
3184 MySqlLeaseContextAlloc get_context(*
this);
3197 MySqlLeaseContextAlloc get_context(*
this);
3212 MySqlLeaseContextAlloc get_context(*
this);
3237 MySqlLeaseContextAlloc get_context(*
this);
3247 bool json_supported(
false);
3250 json_supported = result[0]->getBool();
3253 return json_supported;
3261 MySqlLeaseContextAlloc get_context(*
this);
3264 std::string name =
"";
3266 name = ctx->conn_.getParameter(
"name");
3275 return (std::string(
"MySQL Database"));
3278 std::pair<uint32_t, uint32_t>
3298 const char* what)
const {
3299 ctx->conn_.checkError(status, index, what);
RAII class creating a critical section.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED4
const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR4
void start()
Creates the IPv4 lease statistical data result set.
#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
const size_t ADDRESS6_TEXT_MAX_LEN
Maximum size of an IPv6 address represented as a text string.
bool my_bool
my_bool type in MySQL 8.x.
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
virtual std::pair< uint32_t, uint32_t > getVersion() const
Returns backend version.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID
Fetch and Release MySQL Results.
A generic exception that is thrown when a function is not implemented.
const size_t USER_CONTEXT_MAX_LEN
Maximum length of user context.
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
static std::string getDBVersion()
Local version of getDBVersion() class method.
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_ADDR
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Convert time_t value to database time.
const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME6
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs)
Deletes all expired-reclaimed DHCPv6 leases.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const
Returns an IPv4 lease for specified IPv4 address.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const isc::log::MessageID DHCPSRV_MYSQL_GET4
static std::pair< uint32_t, uint32_t > getVersion(const ParameterMap ¶meters)
Get the schema version.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
static void setErrorIndicators(MYSQL_BIND *bind, my_bool *error, size_t count)
Set error indicators.
MySQL Lease Context Pool.
const isc::log::MessageID DHCPSRV_MYSQL_GET_PAGE6
static void destroy()
Destroy lease manager.
const isc::log::MessageID DHCPSRV_MYSQL_NEGATIVE_LEASES_STAT
MySqlLeaseStatsQuery(MySqlConnection &conn, const size_t statement_index, const bool fetch_type, const SubnetID &subnet_id)
Constructor to query for a single subnet's stats.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv4 leases.
virtual size_t wipeLeases6(const SubnetID &subnet_id)
Removed specified IPv6 leases.
static CfgMgr & instance()
returns a single instance of Configuration Manager
std::string getErrorColumns()
Return columns in error.
Attempt to update lease that was not there.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR
const isc::log::MessageID DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const
Returns existing IPv6 lease for a given IPv6 address.
virtual void updateLease6(const Lease6Ptr &lease6)
Updates IPv6 lease.
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID4
#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.
const uint32_t MYSQL_SCHEMA_VERSION_MINOR
const isc::log::MessageID DHCPSRV_MYSQL_GET_HWADDR
const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR4
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query.
virtual size_t wipeLeases4(const SubnetID &subnet_id)
Removes specified IPv4 leases.
const isc::log::MessageID DHCPSRV_MYSQL_GET_DUID
virtual Lease6Collection getLeases6() const
Returns all IPv6 leases.
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.
static MySqlBindingPtr createBool()
Creates binding having a bool type for receiving data.
Holds DUID (DHCPv6 Unique Identifier)
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs)
Deletes all expired-reclaimed DHCPv4 leases.
Exception thrown on failure to open database.
const isc::log::MessageID DHCPSRV_MYSQL_GET_PAGE4
const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME4
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
const size_t HOSTNAME_MAX_LEN
Maximum length of the hostname stored in DNS.
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
virtual void rollback()
Rollback Transactions.
virtual bool addLease(const Lease4Ptr &lease)
Adds an IPv4 lease.
int MysqlExecuteStatement(MYSQL_STMT *stmt)
Execute a prepared statement.
Multiple lease records found where one expected.
#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...
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
MySqlLease6Exchange()
Constructor.
const my_bool MLM_FALSE
MySQL false value.
std::vector< MYSQL_BIND > createBindForSend(const Lease4Ptr &lease)
Create MYSQL_BIND objects for Lease4 Pointer.
const size_t page_size_
Holds page size.
StatementIndex
Statement Tags.
boost::shared_ptr< MySqlLeaseContext > MySqlLeaseContextPtr
Type of pointers to contexts.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
virtual std::string getDescription() const
Returns description of the backend.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
virtual Lease4Collection getLeases4() const
Returns all IPv4 leases.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
SubnetID subnet_id_
The subnet ID to which this data applies.
const isc::log::MessageID DHCPSRV_MYSQL_GET_ADDR6
A generic exception that is thrown when an unexpected error condition occurs.
virtual ~MySqlLeaseMgr()
Destructor (closes database)
boost::shared_ptr< const Element > ConstElementPtr
std::vector< MYSQL_BIND > createBindForSend(const Lease6Ptr &lease)
Create MYSQL_BIND objects for Lease6 Pointer.
const isc::log::MessageID DHCPSRV_MYSQL_GET_ADDR4
MySqlLease4Exchange()
Constructor.
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.
virtual void updateLease4(const Lease4Ptr &lease4)
Updates IPv4 lease.
bool isV6() const
Convenience function to check for an IPv6 address.
MySql derivation of the statistical lease data query.
const isc::log::MessageID DHCPSRV_MYSQL_ROLLBACK
bool isV4() const
Convenience function to check for an IPv4 address.
const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR6
const isc::log::MessageID DHCPSRV_MYSQL_GET_VERSION
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_CLIENTID
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
const int MLM_MYSQL_FETCH_SUCCESS
check for bool size
Lease6Ptr getLeaseData()
Copy Received Data into Lease6 Object.
MySqlLeaseStatsQuery(MySqlConnection &conn, const size_t statement_index, const bool fetch_type)
Constructor to query for all subnets' stats.
virtual bool deleteLease(const Lease4Ptr &lease)
Deletes an IPv4 lease.
const isc::log::MessageID DHCPSRV_MYSQL_NO_TLS
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
Invalid address family used as input to Lease Manager.
const isc::log::MessageID DHCPSRV_MYSQL_COMMIT
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED6
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
std::string toText() const
Convert the address to a string.
Common MySQL and Lease Data Methods.
Lease4Ptr getLeaseData()
Copy Received Data into Lease4 Object.
Exchange MySQL and Lease6 Data.
Exchange MySQL and Lease4 Data.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
uint32_t lease_state_
The lease_state to which the count applies.
Type
Type of lease or pool.
bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
Holds Client identifier or client IPv4 address.
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_FAILED
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID6
MySqlLeaseStatsQuery(MySqlConnection &conn, const size_t statement_index, 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.
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_DUID
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Hardware type that represents information from DHCPv4 packet.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
const isc::log::MessageID DHCPSRV_MYSQL_GET_CLIENTID
std::vector< MySqlBindingPtr > MySqlBindingCollection
Collection of bindings.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
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.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query.
Wraps value holding size of the page with leases.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6
virtual std::string getName() const
Returns backend name.
const isc::log::MessageID DHCPSRV_MYSQL_TLS_CIPHER
Lease::Type lease_type_
The lease_type to which the count applies.
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.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv6 leases.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_SCHEDULE
virtual ~MySqlLeaseStatsQuery()
Destructor.
const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR6
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
virtual void commit()
Commit Transactions.
MySqlLeaseContextPtr createContext() const
Create a new context.
MySqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
static std::string getColumnsInError(my_bool *error, std::string *names, size_t count)
Return columns in error.
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_HWADDR
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.
const isc::log::MessageID DHCPSRV_MYSQL_GET6
const my_bool MLM_TRUE
MySQL true value.
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Common MySQL Connector Pool.
std::string getErrorColumns()
Return columns in error.