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()"},
335 {MySqlLeaseMgr::GET_LEASE4_COUNT_BY_CLASS,
337 "FROM lease4_stat_by_client_class " 338 "WHERE client_class = ?"},
339 {MySqlLeaseMgr::GET_LEASE6_COUNT_BY_CLASS,
341 "FROM lease6_stat_by_client_class " 342 "WHERE client_class = ? AND lease_type = ?"},
373 for (
size_t i = 0; i < count; ++i) {
375 bind[i].error =
reinterpret_cast<my_bool*
>(&error[i]);
394 std::string result =
"";
397 for (
size_t i = 0; i < count; ++i) {
399 if (!result.empty()) {
406 if (result.empty()) {
429 static const size_t LEASE_COLUMNS = 11;
438 client_id_length_(0), client_id_null_(
MLM_FALSE),
439 subnet_id_(0), valid_lifetime_(0),
440 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
441 state_(0), user_context_length_(0),
443 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
444 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
445 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
446 memset(user_context_, 0,
sizeof(user_context_));
447 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
450 columns_[0] =
"address";
451 columns_[1] =
"hwaddr";
452 columns_[2] =
"client_id";
453 columns_[3] =
"valid_lifetime";
454 columns_[4] =
"expire";
455 columns_[5] =
"subnet_id";
456 columns_[6] =
"fqdn_fwd";
457 columns_[7] =
"fqdn_rev";
458 columns_[8] =
"hostname";
459 columns_[9] =
"state";
460 columns_[10] =
"user_context";
461 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
483 memset(bind_, 0,
sizeof(bind_));
492 addr4_ = lease_->addr_.toUint32();
493 bind_[0].buffer_type = MYSQL_TYPE_LONG;
494 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
502 hwaddr_ = hwaddr->hwaddr_;
503 hwaddr_length_ = hwaddr->hwaddr_.size();
510 if (hwaddr_.empty()) {
514 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
515 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
516 bind_[1].buffer_length = hwaddr_length_;
517 bind_[1].length = &hwaddr_length_;
519 bind_[1].buffer_type = MYSQL_TYPE_NULL;
526 bind_[1].buffer = NULL;
527 bind_[1].is_null = &hwaddr_null_;
531 if (lease_->client_id_) {
532 client_id_ = lease_->client_id_->getClientId();
533 client_id_length_ = client_id_.size();
540 if (client_id_.empty()) {
541 client_id_.resize(1);
544 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
545 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
546 bind_[2].buffer_length = client_id_length_;
547 bind_[2].length = &client_id_length_;
551 bind_[2].buffer_type = MYSQL_TYPE_NULL;
558 bind_[2].buffer = NULL;
559 bind_[2].is_null = &client_id_null_;
563 bind_[3].buffer_type = MYSQL_TYPE_LONG;
564 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
577 uint32_t valid_lft = lease_->valid_lft_;
578 if (valid_lft == Lease::INFINITY_LFT) {
581 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
583 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
584 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
585 bind_[4].buffer_length =
sizeof(expire_);
591 bind_[5].buffer_type = MYSQL_TYPE_LONG;
592 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
598 bind_[6].buffer_type = MYSQL_TYPE_TINY;
599 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
605 bind_[7].buffer_type = MYSQL_TYPE_TINY;
606 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
615 bind_[8].buffer_type = MYSQL_TYPE_STRING;
616 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
617 bind_[8].buffer_length = lease_->hostname_.length();
622 bind_[9].buffer_type = MYSQL_TYPE_LONG;
623 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
631 bind_[10].buffer_type = MYSQL_TYPE_STRING;
632 std::string ctx_txt = ctx->str();
634 bind_[10].buffer = user_context_;
635 bind_[10].buffer_length = ctx_txt.length();
639 bind_[10].buffer_type = MYSQL_TYPE_NULL;
643 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
646 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
648 }
catch (
const std::exception& ex) {
650 "Could not create bind array from Lease4: " 651 << lease_->addr_.toText() <<
", reason: " << ex.
what());
656 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
671 memset(bind_, 0,
sizeof(bind_));
674 bind_[0].buffer_type = MYSQL_TYPE_LONG;
675 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
681 hwaddr_length_ =
sizeof(hwaddr_buffer_);
682 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
683 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
684 bind_[1].buffer_length = hwaddr_length_;
685 bind_[1].length = &hwaddr_length_;
690 client_id_length_ =
sizeof(client_id_buffer_);
691 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
692 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
693 bind_[2].buffer_length = client_id_length_;
694 bind_[2].length = &client_id_length_;
695 bind_[2].is_null = &client_id_null_;
700 bind_[3].buffer_type = MYSQL_TYPE_LONG;
701 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
707 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
708 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
709 bind_[4].buffer_length =
sizeof(expire_);
714 bind_[5].buffer_type = MYSQL_TYPE_LONG;
715 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
721 bind_[6].buffer_type = MYSQL_TYPE_TINY;
722 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
728 bind_[7].buffer_type = MYSQL_TYPE_TINY;
729 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
738 hostname_length_ =
sizeof(hostname_buffer_);
739 bind_[8].buffer_type = MYSQL_TYPE_STRING;
740 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
741 bind_[8].buffer_length = hostname_length_;
742 bind_[8].length = &hostname_length_;
747 bind_[9].buffer_type = MYSQL_TYPE_LONG;
748 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
755 user_context_length_ =
sizeof(user_context_);
756 bind_[10].buffer_type = MYSQL_TYPE_STRING;
757 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
758 bind_[10].buffer_length = user_context_length_;
759 bind_[10].length = &user_context_length_;
760 bind_[10].is_null = &user_context_null_;
763 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
766 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
770 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
787 uint32_t valid_lft = valid_lifetime_;
788 if (valid_lft == Lease::INFINITY_LFT) {
791 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
795 client_id_length_ = 0;
800 std::string hostname(hostname_buffer_,
801 hostname_buffer_ + hostname_length_);
810 std::string user_context;
812 user_context_[user_context_length_] =
'\0';
813 user_context.assign(user_context_);
818 if (!user_context.empty()) {
819 ctx = Element::fromJSON(user_context);
820 if (!ctx || (ctx->getType() != Element::map)) {
822 <<
"' is not a JSON map");
826 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
829 valid_lifetime_, cltt,
830 subnet_id_, fqdn_fwd_,
831 fqdn_rev_, hostname));
834 lease->state_ = state_;
837 lease->setContext(ctx);
854 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
863 MYSQL_BIND bind_[LEASE_COLUMNS];
864 std::string columns_[LEASE_COLUMNS];
867 std::vector<uint8_t> hwaddr_;
868 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
869 unsigned long hwaddr_length_;
871 std::vector<uint8_t> client_id_;
872 uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
873 unsigned long client_id_length_;
877 uint32_t valid_lifetime_;
881 unsigned long hostname_length_;
884 unsigned long user_context_length_;
903 static const size_t LEASE_COLUMNS = 17;
912 hwaddr_null_(
MLM_FALSE), duid_length_(0),
913 iaid_(0), lease_type_(0), prefix_len_(0),
914 pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
915 fqdn_fwd_(false), fqdn_rev_(false),
916 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
917 state_(0), user_context_length_(0),
919 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
920 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
921 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
922 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
923 memset(user_context_, 0,
sizeof(user_context_));
924 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
927 columns_[0] =
"address";
928 columns_[1] =
"duid";
929 columns_[2] =
"valid_lifetime";
930 columns_[3] =
"expire";
931 columns_[4] =
"subnet_id";
932 columns_[5] =
"pref_lifetime";
933 columns_[6] =
"lease_type";
934 columns_[7] =
"iaid";
935 columns_[8] =
"prefix_len";
936 columns_[9] =
"fqdn_fwd";
937 columns_[10] =
"fqdn_rev";
938 columns_[11] =
"hostname";
939 columns_[12] =
"hwaddr";
940 columns_[13] =
"hwtype";
941 columns_[14] =
"hwaddr_source";
942 columns_[15] =
"state";
943 columns_[16] =
"user_context";
944 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
965 memset(bind_, 0,
sizeof(bind_));
969 addr6_ = lease_->addr_.toText();
970 addr6_length_ = addr6_.size();
986 bind_[0].buffer_type = MYSQL_TYPE_STRING;
987 bind_[0].buffer =
const_cast<char*
>(addr6_.c_str());
988 bind_[0].buffer_length = addr6_length_;
989 bind_[0].length = &addr6_length_;
994 if (!lease_->duid_) {
996 <<
" is missing mandatory client-id.");
998 duid_ = lease_->duid_->getDuid();
999 duid_length_ = duid_.size();
1001 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1002 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
1003 bind_[1].buffer_length = duid_length_;
1004 bind_[1].length = &duid_length_;
1009 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1010 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1023 uint32_t valid_lft = lease_->valid_lft_;
1024 if (valid_lft == Lease::INFINITY_LFT) {
1027 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
1029 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1030 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1031 bind_[3].buffer_length =
sizeof(expire_);
1037 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1038 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1045 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1046 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1053 lease_type_ = lease_->type_;
1054 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1055 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1062 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1063 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1070 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1071 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1077 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1078 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1084 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1085 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1091 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1092 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1093 bind_[11].buffer_length = lease_->hostname_.length();
1100 hwaddr_ = hwaddr->hwaddr_;
1101 hwaddr_length_ = hwaddr->hwaddr_.size();
1108 if (hwaddr_.empty()) {
1112 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1113 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1114 bind_[12].buffer_length = hwaddr_length_;
1115 bind_[12].length = &hwaddr_length_;
1117 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1124 bind_[12].buffer = NULL;
1125 bind_[12].is_null = &hwaddr_null_;
1130 hwtype_ = lease->hwaddr_->htype_;
1131 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1132 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1136 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1143 bind_[13].buffer = NULL;
1144 bind_[13].is_null = &hwaddr_null_;
1149 hwaddr_source_ = lease->hwaddr_->source_;
1150 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1151 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1155 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1162 bind_[14].buffer = NULL;
1163 bind_[14].is_null = &hwaddr_null_;
1167 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1168 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1176 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1177 std::string ctx_txt = ctx->str();
1179 bind_[16].buffer = user_context_;
1180 bind_[16].buffer_length = ctx_txt.length();
1184 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1188 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1191 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1193 }
catch (
const std::exception& ex) {
1195 "Could not create bind array from Lease6: " 1196 << lease_->addr_.toText() <<
", reason: " << ex.
what());
1201 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1219 memset(bind_, 0,
sizeof(bind_));
1225 addr6_length_ =
sizeof(addr6_buffer_) - 1;
1226 bind_[0].buffer_type = MYSQL_TYPE_STRING;
1227 bind_[0].buffer = addr6_buffer_;
1228 bind_[0].buffer_length = addr6_length_;
1229 bind_[0].length = &addr6_length_;
1234 duid_length_ =
sizeof(duid_buffer_);
1235 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1236 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1237 bind_[1].buffer_length = duid_length_;
1238 bind_[1].length = &duid_length_;
1243 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1244 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1250 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1251 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1252 bind_[3].buffer_length =
sizeof(expire_);
1257 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1258 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1264 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1265 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1271 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1272 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1278 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1279 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1285 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1286 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1292 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1293 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1299 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1300 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1306 hostname_length_ =
sizeof(hostname_buffer_);
1307 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1308 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1309 bind_[11].buffer_length = hostname_length_;
1310 bind_[11].length = &hostname_length_;
1316 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1317 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1318 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1319 bind_[12].buffer_length = hwaddr_length_;
1320 bind_[12].length = &hwaddr_length_;
1321 bind_[12].is_null = &hwaddr_null_;
1324 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1325 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1329 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1330 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1334 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1335 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1342 user_context_length_ =
sizeof(user_context_);
1343 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1344 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1345 bind_[16].buffer_length = user_context_length_;
1346 bind_[16].length = &user_context_length_;
1347 bind_[16].is_null = &user_context_null_;
1350 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1353 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1357 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1374 addr6_buffer_[addr6_length_] =
'\0';
1375 std::string address = addr6_buffer_;
1381 switch (lease_type_) {
1382 case Lease::TYPE_NA:
1383 type = Lease::TYPE_NA;
1386 case Lease::TYPE_TA:
1387 type = Lease::TYPE_TA;
1390 case Lease::TYPE_PD:
1391 type = Lease::TYPE_PD;
1396 static_cast<int>(lease_type_) <<
") for lease with " 1397 <<
"address " << address <<
". Only 0, 1, or 2 are " 1402 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1406 std::string hostname(hostname_buffer_,
1407 hostname_buffer_ + hostname_length_);
1412 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1413 hwaddr->source_ = hwaddr_source_;
1417 std::string user_context;
1419 user_context_[user_context_length_] =
'\0';
1420 user_context.assign(user_context_);
1425 if (!user_context.empty()) {
1426 ctx = Element::fromJSON(user_context);
1427 if (!ctx || (ctx->getType() != Element::map)) {
1429 <<
"' is not a JSON map");
1435 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1437 valid_lifetime_, subnet_id_,
1438 fqdn_fwd_, fqdn_rev_,
1443 uint32_t valid_lft = valid_lifetime_;
1444 if (valid_lft == Lease::INFINITY_LFT) {
1447 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
1449 result->cltt_ = cltt;
1450 result->current_cltt_ = cltt;
1453 result->state_ = state_;
1456 result->setContext(ctx);
1473 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
1483 unsigned long addr6_length_;
1484 MYSQL_BIND bind_[LEASE_COLUMNS];
1485 std::string columns_[LEASE_COLUMNS];
1486 my_bool error_[LEASE_COLUMNS];
1488 std::vector<uint8_t> hwaddr_;
1489 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
1490 unsigned long hwaddr_length_;
1492 std::vector<uint8_t> duid_;
1493 uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
1494 unsigned long duid_length_;
1497 uint8_t lease_type_;
1498 uint8_t prefix_len_;
1499 uint32_t pref_lifetime_;
1500 uint32_t subnet_id_;
1501 uint32_t valid_lifetime_;
1505 unsigned long hostname_length_;
1507 uint32_t hwaddr_source_;
1510 unsigned long user_context_length_;
1533 const bool fetch_type)
1534 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1535 fetch_type_(fetch_type),
1538 bind_(fetch_type_ ? 4 : 3),
1539 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1540 validateStatement();
1553 const bool fetch_type,
const SubnetID& subnet_id)
1554 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1555 statement_(NULL), fetch_type_(fetch_type),
1558 bind_(fetch_type_ ? 4 : 3),
1559 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1560 validateStatement();
1576 const bool fetch_type,
const SubnetID& first_subnet_id,
1579 statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
1582 bind_(fetch_type_ ? 4 : 3),
1583 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1584 validateStatement();
1589 (void) mysql_stmt_free_result(statement_);
1601 if (getSelectMode() != ALL_SUBNETS) {
1602 MYSQL_BIND inbind[2];
1603 memset(inbind, 0,
sizeof(inbind));
1606 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1607 inbind[0].buffer =
reinterpret_cast<char*
>(&first_subnet_id_);
1611 if (getSelectMode() == SUBNET_RANGE) {
1612 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1613 inbind[1].buffer =
reinterpret_cast<char*
>(&last_subnet_id_);
1618 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1619 conn_.checkError(status, statement_index_,
"unable to bind parameters");
1624 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1625 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1632 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1633 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1637 fetch_type_ = Lease::TYPE_NA;
1641 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1642 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1647 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1648 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1653 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1654 conn_.checkError(status, statement_index_,
"outbound binding failed");
1658 conn_.checkError(status, statement_index_,
"unable to execute");
1662 status = mysql_stmt_store_result(statement_);
1663 conn_.checkError(status, statement_index_,
"results storage failed");
1682 bool have_row =
false;
1683 int status = mysql_stmt_fetch(statement_);
1688 if (state_count_ >= 0) {
1692 if (!negative_count_) {
1693 negative_count_ =
true;
1698 }
else if (status != MYSQL_NO_DATA) {
1699 conn_.checkError(status, statement_index_,
"getNextRow failed");
1710 void validateStatement() {
1711 if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
1713 " - invalid statement index" << statement_index_);
1716 statement_ = conn_.statements_[statement_index_];
1723 size_t statement_index_;
1726 MYSQL_STMT *statement_;
1732 std::vector<MYSQL_BIND> bind_;
1735 uint32_t subnet_id_;
1738 uint32_t lease_type_;
1744 int64_t state_count_;
1747 static bool negative_count_;
1751 bool MySqlLeaseStatsQuery::negative_count_ =
false;
1758 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1763 MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
1766 if (MultiThreadingMgr::instance().getMode()) {
1770 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1771 if (!mgr_.pool_->pool_.empty()) {
1772 ctx_ = mgr_.pool_->pool_.back();
1773 mgr_.pool_->pool_.pop_back();
1777 ctx_ = mgr_.createContext();
1781 if (mgr_.pool_->pool_.empty()) {
1784 ctx_ = mgr_.pool_->pool_.back();
1788 MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
1789 if (MultiThreadingMgr::instance().getMode()) {
1791 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1792 mgr_.pool_->pool_.push_back(ctx_);
1805 : parameters_(parameters), timer_name_(
"") {
1811 timer_name_ =
"MySqlLeaseMgr[";
1812 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1813 timer_name_ +=
"]DbReconnectTimer";
1818 std::pair<uint32_t, uint32_t> db_version =
getVersion();
1819 if (code_version != db_version) {
1821 "MySQL schema version mismatch: need version: " 1822 << code_version.first <<
"." << code_version.second
1823 <<
" found version: " << db_version.first <<
"." 1824 << db_version.second);
1844 bool reopened =
false;
1846 const std::string timer_name = db_reconnect_ctl->timerName();
1854 }
catch (
const std::exception& ex) {
1870 if (!db_reconnect_ctl->checkRetries()) {
1873 .arg(db_reconnect_ctl->maxRetries());
1886 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1887 .arg(db_reconnect_ctl->maxRetries())
1888 .arg(db_reconnect_ctl->retryInterval());
1894 db_reconnect_ctl->retryInterval(),
1912 ctx->conn_.openDatabase();
1915 if (ctx->conn_.getTls()) {
1916 std::string cipher = ctx->conn_.getTlsCipher();
1917 if (cipher.empty()) {
1927 ctx->conn_.prepareStatements(tagged_statements.begin(),
1928 tagged_statements.end());
1936 ctx->conn_.makeReconnectCtl(timer_name_);
1943 std::stringstream tmp;
1946 tmp <<
", library " << mysql_get_client_info();
1957 std::vector<MYSQL_BIND>& bind) {
1960 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], &bind[0]);
1961 checkError(ctx, status, stindex,
"unable to bind parameters");
1970 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
1973 checkError(ctx, status, stindex,
"unable to execute");
1983 .arg(lease->addr_.toText());
1986 MySqlLeaseContextAlloc get_context(*
this);
1990 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
1997 lease->updateCurrentExpirationTime();
2005 .arg(lease->addr_.toText())
2009 MySqlLeaseContextAlloc get_context(*
this);
2013 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2020 lease->updateCurrentExpirationTime();
2050 template <
typename Exchange,
typename LeaseCollection>
2056 LeaseCollection& result,
2057 bool single)
const {
2062 status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2063 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2068 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2069 status = mysql_stmt_bind_result(ctx->conn_.statements_[stindex], &outbind[0]);
2070 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2074 checkError(ctx, status, stindex,
"unable to execute");
2078 status = mysql_stmt_store_result(ctx->conn_.statements_[stindex]);
2079 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2086 while ((status = mysql_stmt_fetch(ctx->conn_.statements_[stindex])) == 0) {
2088 result.push_back(exchange->getLeaseData());
2093 ctx->conn_.text_statements_[stindex] <<
">");
2096 if (single && (++count > 1)) {
2098 "database where only one was expected for query " 2099 << ctx->conn_.text_statements_[stindex]);
2106 checkError(ctx, status, stindex,
"unable to fetch results");
2107 }
else if (status == MYSQL_DATA_TRUNCATED) {
2110 <<
" returned truncated data: columns affected are " 2111 << exchange->getErrorColumns());
2125 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2128 if (collection.empty()) {
2131 result = *collection.begin();
2145 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2148 if (collection.empty()) {
2151 result = *collection.begin();
2164 MYSQL_BIND inbind[1];
2165 memset(inbind, 0,
sizeof(inbind));
2168 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2169 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2176 MySqlLeaseContextAlloc get_context(*
this);
2190 MYSQL_BIND inbind[1];
2191 memset(inbind, 0,
sizeof(inbind));
2193 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2195 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2199 uint8_t single_byte_data = 0;
2206 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2207 : &single_byte_data;
2209 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2210 inbind[0].buffer_length = hwaddr_length;
2211 inbind[0].length = &hwaddr_length;
2217 MySqlLeaseContextAlloc get_context(*
this);
2232 MYSQL_BIND inbind[2];
2233 memset(inbind, 0,
sizeof(inbind));
2235 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2237 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2241 std::vector<uint8_t> single_byte_vec(1);
2248 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2249 : &single_byte_vec[0];
2251 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2252 inbind[0].buffer_length = hwaddr_length;
2253 inbind[0].length = &hwaddr_length;
2255 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2256 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2263 MySqlLeaseContextAlloc get_context(*
this);
2277 MYSQL_BIND inbind[1];
2278 memset(inbind, 0,
sizeof(inbind));
2280 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2282 std::vector<uint8_t> client_data = clientid.
getClientId();
2283 unsigned long client_data_length = client_data.size();
2287 if (client_data.empty()) {
2288 client_data.resize(1);
2291 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2292 inbind[0].buffer_length = client_data_length;
2293 inbind[0].length = &client_data_length;
2299 MySqlLeaseContextAlloc get_context(*
this);
2314 MYSQL_BIND inbind[2];
2315 memset(inbind, 0,
sizeof(inbind));
2317 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2319 std::vector<uint8_t> client_data = clientid.
getClientId();
2320 unsigned long client_data_length = client_data.size();
2324 if (client_data.empty()) {
2325 client_data.resize(1);
2328 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2329 inbind[0].buffer_length = client_data_length;
2330 inbind[0].length = &client_data_length;
2332 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2333 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2340 MySqlLeaseContextAlloc get_context(*
this);
2354 MYSQL_BIND inbind[1];
2355 memset(inbind, 0,
sizeof(inbind));
2358 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2359 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2366 MySqlLeaseContextAlloc get_context(*
this);
2380 MYSQL_BIND inbind[1];
2381 memset(inbind, 0,
sizeof(inbind));
2384 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2385 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2386 inbind[0].buffer_length = hostname.length();
2392 MySqlLeaseContextAlloc get_context(*
this);
2407 MySqlLeaseContextAlloc get_context(*
this);
2410 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2419 if (!lower_bound_address.
isV4()) {
2421 "retrieving leases from the lease database, got " 2422 << lower_bound_address);
2427 .arg(lower_bound_address.
toText());
2430 MYSQL_BIND inbind[2];
2431 memset(inbind, 0,
sizeof(inbind));
2434 uint32_t lb_address_data = lower_bound_address.
toUint32();
2435 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2436 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2440 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2441 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2442 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2449 MySqlLeaseContextAlloc get_context(*
this);
2465 MYSQL_BIND inbind[2];
2466 memset(inbind, 0,
sizeof(inbind));
2468 std::string addr6 = addr.
toText();
2469 unsigned long addr6_length = addr6.size();
2473 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2474 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2475 inbind[0].buffer_length = addr6_length;
2476 inbind[0].length = &addr6_length;
2479 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2480 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2486 MySqlLeaseContextAlloc get_context(*
this);
2496 uint32_t iaid)
const {
2503 MYSQL_BIND inbind[3];
2504 memset(inbind, 0,
sizeof(inbind));
2518 const vector<uint8_t>& duid_vector = duid.
getDuid();
2519 unsigned long duid_length = duid_vector.size();
2526 uint8_t single_byte_data = 0;
2527 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2528 : &single_byte_data;
2530 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2531 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2532 inbind[0].buffer_length = duid_length;
2533 inbind[0].length = &duid_length;
2536 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2537 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2541 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2542 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2549 MySqlLeaseContextAlloc get_context(*
this);
2559 uint32_t iaid,
SubnetID subnet_id)
const {
2567 MYSQL_BIND inbind[4];
2568 memset(inbind, 0,
sizeof(inbind));
2572 const vector<uint8_t>& duid_vector = duid.
getDuid();
2573 unsigned long duid_length = duid_vector.size();
2574 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2575 inbind[0].buffer =
reinterpret_cast<char*
>(
2576 const_cast<uint8_t*
>(&duid_vector[0]));
2577 inbind[0].buffer_length = duid_length;
2578 inbind[0].length = &duid_length;
2581 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2582 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2586 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2587 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2591 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2592 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2599 MySqlLeaseContextAlloc get_context(*
this);
2613 MYSQL_BIND inbind[1];
2614 memset(inbind, 0,
sizeof(inbind));
2617 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2618 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2625 MySqlLeaseContextAlloc get_context(*
this);
2640 MySqlLeaseContextAlloc get_context(*
this);
2643 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
2654 MYSQL_BIND inbind[1];
2655 memset(inbind, 0,
sizeof(inbind));
2657 const vector<uint8_t>& duid_vector = duid.
getDuid();
2658 unsigned long duid_length = duid_vector.size();
2660 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2661 inbind[0].buffer =
reinterpret_cast<char*
>(
2662 const_cast<uint8_t*
>(&duid_vector[0]));
2663 inbind[0].buffer_length = duid_length;
2664 inbind[0].length = &duid_length;
2669 MySqlLeaseContextAlloc get_context(*
this);
2683 MYSQL_BIND inbind[1];
2684 memset(inbind, 0,
sizeof(inbind));
2687 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2688 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2689 inbind[0].buffer_length = hostname.length();
2695 MySqlLeaseContextAlloc get_context(*
this);
2707 if (!lower_bound_address.
isV6()) {
2709 "retrieving leases from the lease database, got " 2710 << lower_bound_address);
2715 .arg(lower_bound_address.
toText());
2718 MYSQL_BIND inbind[2];
2719 memset(inbind, 0,
sizeof(inbind));
2724 std::string lb_address_data =
"0";
2725 if (!lower_bound_address.
isV6Zero()) {
2726 lb_address_data = lower_bound_address.
toText();
2730 unsigned long lb_address_data_size = lb_address_data.size();
2731 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2732 inbind[0].buffer =
const_cast<char*
>(lb_address_data.c_str());
2733 inbind[0].buffer_length = lb_address_data_size;
2734 inbind[0].length = &lb_address_data_size;
2737 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2738 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2739 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2746 MySqlLeaseContextAlloc get_context(*
this);
2756 const size_t max_leases)
const {
2764 const size_t max_leases)
const {
2770 template<
typename LeaseCollection>
2772 MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2773 const size_t max_leases,
2776 MYSQL_BIND inbind[3];
2777 memset(inbind, 0,
sizeof(inbind));
2781 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2782 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
2786 MYSQL_TIME expire_time;
2788 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2789 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
2790 inbind[1].buffer_length =
sizeof(expire_time);
2794 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2795 std::numeric_limits<uint32_t>::max();
2796 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2797 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
2801 MySqlLeaseContextAlloc get_context(*
this);
2805 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
2812 template <
typename LeasePtr>
2820 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2821 checkError(ctx, status, stindex,
"unable to bind parameters");
2825 checkError(ctx, status, stindex,
"unable to execute");
2829 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.statements_[stindex]);
2832 if (affected_rows == 1) {
2837 if (affected_rows == 0) {
2839 lease->addr_.toText() <<
" as it does not exist");
2845 "that had the address " << lease->addr_.toText());
2853 .arg(lease->addr_.toText());
2856 MySqlLeaseContextAlloc get_context(*
this);
2860 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2863 MYSQL_BIND inbind[2];
2864 memset(inbind, 0,
sizeof(inbind));
2866 uint32_t addr4 = lease->addr_.toUint32();
2867 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2868 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2871 bind.push_back(inbind[0]);
2876 uint32_t valid_lft = lease->current_valid_lft_;
2882 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2883 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2884 inbind[1].buffer_length =
sizeof(expire);
2886 bind.push_back(inbind[1]);
2889 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2892 lease->updateCurrentExpirationTime();
2900 .arg(lease->addr_.toText())
2904 MySqlLeaseContextAlloc get_context(*
this);
2908 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2911 MYSQL_BIND inbind[2];
2912 memset(inbind, 0,
sizeof(inbind));
2914 std::string addr6 = lease->addr_.toText();
2915 unsigned long addr6_length = addr6.size();
2919 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2920 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2921 inbind[0].buffer_length = addr6_length;
2922 inbind[0].length = &addr6_length;
2924 bind.push_back(inbind[0]);
2929 uint32_t valid_lft = lease->current_valid_lft_;
2935 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2936 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2937 inbind[1].buffer_length =
sizeof(expire);
2939 bind.push_back(inbind[1]);
2942 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2945 lease->updateCurrentExpirationTime();
2958 MySqlLeaseContextAlloc get_context(*
this);
2962 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2963 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2967 checkError(ctx, status, stindex,
"unable to execute");
2971 return (static_cast<uint64_t>(mysql_stmt_affected_rows(ctx->conn_.statements_[stindex])));
2981 MYSQL_BIND inbind[2];
2982 memset(inbind, 0,
sizeof(inbind));
2986 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2987 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2993 uint32_t valid_lft = lease->current_valid_lft_;
2999 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3000 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3001 inbind[1].buffer_length =
sizeof(expire);
3003 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE4, inbind);
3006 if (affected_rows == 1) {
3011 if (affected_rows == 0) {
3018 "that had the address " << lease->addr_.toText());
3029 MYSQL_BIND inbind[2];
3030 memset(inbind, 0,
sizeof(inbind));
3032 std::string addr6 = addr.
toText();
3033 unsigned long addr6_length = addr6.size();
3037 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3038 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
3039 inbind[0].buffer_length = addr6_length;
3040 inbind[0].length = &addr6_length;
3045 uint32_t valid_lft = lease->current_valid_lft_;
3051 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3052 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3053 inbind[1].buffer_length =
sizeof(expire);
3055 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE6, inbind);
3058 if (affected_rows == 1) {
3063 if (affected_rows == 0) {
3070 "that had the address " << lease->addr_.toText());
3088 MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3091 MYSQL_BIND inbind[2];
3092 memset(inbind, 0,
sizeof(inbind));
3096 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3097 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3101 MYSQL_TIME expire_time;
3103 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3104 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3105 inbind[1].buffer_length =
sizeof(expire_time);
3108 uint64_t deleted_leases = deleteLeaseCommon(statement_index, inbind);
3110 .arg(deleted_leases);
3112 return (deleted_leases);
3118 if (!user_context) {
3123 MySqlLeaseContextAlloc get_context(*
this);
3135 std::string limit_text;
3136 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3138 limit_text = result[0]->getString();
3145 MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3150 MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3155 MySqlLeaseMgr::isJsonSupported()
const {
3157 MySqlLeaseContextAlloc get_context(*
this);
3167 bool json_supported(
false);
3170 json_supported = result[0]->getBool();
3173 return json_supported;
3177 MySqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
3180 MySqlLeaseContextAlloc get_context(*
this);
3188 in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(ltype));
3191 MySqlBinding::createInteger<int64_t>()
3198 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3200 count = result[0]->getInteger<int64_t>();
3207 MySqlLeaseMgr::recountClassLeases4() {
3212 MySqlLeaseMgr::recountClassLeases6() {
3217 MySqlLeaseMgr::clearClassLeaseCounts() {
3222 MySqlLeaseMgr::writeLeases4(
const std::string&) {
3227 MySqlLeaseMgr::writeLeases6(
const std::string&) {
3234 MySqlLeaseContextAlloc get_context(*
this);
3247 MySqlLeaseContextAlloc get_context(*
this);
3262 MySqlLeaseContextAlloc get_context(*
this);
3277 MySqlLeaseContextAlloc get_context(*
this);
3290 MySqlLeaseContextAlloc get_context(*
this);
3305 MySqlLeaseContextAlloc get_context(*
this);
3332 MySqlLeaseContextAlloc get_context(*
this);
3335 std::string name =
"";
3337 name = ctx->conn_.getParameter(
"name");
3346 return (std::string(
"MySQL Database"));
3349 std::pair<uint32_t, uint32_t>
3369 const char* what)
const {
3370 ctx->conn_.checkError(status, index, what);
3380 const vector<uint8_t>& ) {
3386 const vector<uint8_t>& ) {
3391 MySqlLeaseMgr::getLeases4ByRelayId(
const OptionBuffer& ,
3400 MySqlLeaseMgr::getLeases4ByRemoteId(
const OptionBuffer& ,
3409 MySqlLeaseMgr::getLeases6ByRelayId(
const DUID& ,
3418 MySqlLeaseMgr::getLeases6ByRemoteId(
const OptionBuffer& ,
3427 MySqlLeaseMgr::getLeases6ByLink(
const IOAddress& ,
3435 MySqlLeaseMgr::buildExtendedInfoTables6(
bool ,
bool ) {
3437 "MySqlLeaseMgr::buildExtendedInfoTables6 not implemented");
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.
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.
virtual void setExtendedInfoTablesEnabled(const bool enabled)
Extended information / Bulk Lease Query shared interface.
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
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
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.
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.
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.
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 LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
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
const isc::log::MessageID DHCPSRV_MYSQL_GET_DUID
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.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
Holds DUID (DHCPv6 Unique Identifier)
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
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.
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...
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.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns an IPv4 lease for specified IPv4 address.
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.
virtual void setExtendedInfoTablesEnabled(const bool enabled) override
Extended information / Bulk Lease Query shared interface.
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)
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
boost::shared_ptr< const Element > ConstElementPtr
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.
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.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
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 Lease4Collection getLeases4() const override
Returns all IPv4 leases.
bool isV6() const
Convenience function to check for an IPv6 address.
virtual std::pair< uint32_t, uint32_t > getVersion() const override
Returns backend version.
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
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
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
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 void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Delete lease6 extended info from tables.
const isc::log::MessageID DHCPSRV_MYSQL_NO_TLS
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
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual std::string getName() const override
Returns backend name.
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.
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.
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.
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
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.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
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
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
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)
Wraps value holding size of the page with leases.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_MYSQL_TLS_CIPHER
Lease::Type lease_type_
The lease_type to which the count applies.
std::string ClientClass
Defines a single class name.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
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 LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 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 updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
virtual std::string getDescription() const override
Returns description of the backend.
virtual void commit() override
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)
virtual void rollback() override
Rollback Transactions.
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.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
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.
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
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.
std::string getErrorColumns()
Return columns in error.