21 #include <boost/array.hpp>
22 #include <boost/make_shared.hpp>
23 #include <boost/static_assert.hpp>
24 #include <mysqld_error.h>
89 const size_t HOSTNAME_MAX_LEN = 255;
95 const size_t ADDRESS6_TEXT_MAX_LEN = 39;
100 boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
101 tagged_statements = { {
102 {MySqlLeaseMgr::DELETE_LEASE4,
103 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
104 {MySqlLeaseMgr::DELETE_LEASE4_STATE_EXPIRED,
105 "DELETE FROM lease4 "
106 "WHERE state = ? AND expire < ?"},
107 {MySqlLeaseMgr::DELETE_LEASE6,
108 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
109 {MySqlLeaseMgr::DELETE_LEASE6_STATE_EXPIRED,
110 "DELETE FROM lease6 "
111 "WHERE state = ? AND expire < ?"},
112 {MySqlLeaseMgr::GET_LEASE4,
113 "SELECT address, hwaddr, client_id, "
114 "valid_lifetime, expire, subnet_id, "
115 "fqdn_fwd, fqdn_rev, hostname, "
116 "state, user_context "
118 {MySqlLeaseMgr::GET_LEASE4_ADDR,
119 "SELECT address, hwaddr, client_id, "
120 "valid_lifetime, expire, subnet_id, "
121 "fqdn_fwd, fqdn_rev, hostname, "
122 "state, user_context "
124 "WHERE address = ?"},
125 {MySqlLeaseMgr::GET_LEASE4_CLIENTID,
126 "SELECT address, hwaddr, client_id, "
127 "valid_lifetime, expire, subnet_id, "
128 "fqdn_fwd, fqdn_rev, hostname, "
129 "state, user_context "
131 "WHERE client_id = ?"},
132 {MySqlLeaseMgr::GET_LEASE4_CLIENTID_SUBID,
133 "SELECT address, hwaddr, client_id, "
134 "valid_lifetime, expire, subnet_id, "
135 "fqdn_fwd, fqdn_rev, hostname, "
136 "state, user_context "
138 "WHERE client_id = ? AND subnet_id = ?"},
139 {MySqlLeaseMgr::GET_LEASE4_HWADDR,
140 "SELECT address, hwaddr, client_id, "
141 "valid_lifetime, expire, subnet_id, "
142 "fqdn_fwd, fqdn_rev, hostname, "
143 "state, user_context "
146 {MySqlLeaseMgr::GET_LEASE4_HWADDR_SUBID,
147 "SELECT address, hwaddr, client_id, "
148 "valid_lifetime, expire, subnet_id, "
149 "fqdn_fwd, fqdn_rev, hostname, "
150 "state, user_context "
152 "WHERE hwaddr = ? AND subnet_id = ?"},
153 {MySqlLeaseMgr::GET_LEASE4_PAGE,
154 "SELECT address, hwaddr, client_id, "
155 "valid_lifetime, expire, subnet_id, "
156 "fqdn_fwd, fqdn_rev, hostname, "
157 "state, user_context "
162 {MySqlLeaseMgr::GET_LEASE4_SUBID,
163 "SELECT address, hwaddr, client_id, "
164 "valid_lifetime, expire, subnet_id, "
165 "fqdn_fwd, fqdn_rev, hostname, "
166 "state, user_context "
168 "WHERE subnet_id = ?"},
169 {MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
170 "SELECT address, hwaddr, client_id, "
171 "valid_lifetime, expire, subnet_id, "
172 "fqdn_fwd, fqdn_rev, hostname, "
173 "state, user_context "
175 "WHERE hostname = ?"},
176 {MySqlLeaseMgr::GET_LEASE4_EXPIRE,
177 "SELECT address, hwaddr, client_id, "
178 "valid_lifetime, expire, subnet_id, "
179 "fqdn_fwd, fqdn_rev, hostname, "
180 "state, user_context "
183 "AND valid_lifetime != 4294967295 "
185 "ORDER BY expire ASC "
187 {MySqlLeaseMgr::GET_LEASE6,
188 "SELECT address, duid, valid_lifetime, "
189 "expire, subnet_id, pref_lifetime, "
190 "lease_type, iaid, prefix_len, "
191 "fqdn_fwd, fqdn_rev, hostname, "
192 "hwaddr, hwtype, hwaddr_source, "
193 "state, user_context "
195 {MySqlLeaseMgr::GET_LEASE6_ADDR,
196 "SELECT address, duid, valid_lifetime, "
197 "expire, subnet_id, pref_lifetime, "
198 "lease_type, iaid, prefix_len, "
199 "fqdn_fwd, fqdn_rev, hostname, "
200 "hwaddr, hwtype, hwaddr_source, "
201 "state, user_context "
203 "WHERE address = ? AND lease_type = ?"},
204 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
205 "SELECT address, duid, valid_lifetime, "
206 "expire, subnet_id, pref_lifetime, "
207 "lease_type, iaid, prefix_len, "
208 "fqdn_fwd, fqdn_rev, hostname, "
209 "hwaddr, hwtype, hwaddr_source, "
210 "state, user_context "
212 "WHERE duid = ? AND iaid = ? AND lease_type = ?"},
213 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID_SUBID,
214 "SELECT address, duid, valid_lifetime, "
215 "expire, subnet_id, pref_lifetime, "
216 "lease_type, iaid, prefix_len, "
217 "fqdn_fwd, fqdn_rev, hostname, "
218 "hwaddr, hwtype, hwaddr_source, "
219 "state, user_context "
221 "WHERE duid = ? AND iaid = ? AND subnet_id = ? "
222 "AND lease_type = ?"},
223 {MySqlLeaseMgr::GET_LEASE6_PAGE,
224 "SELECT address, duid, valid_lifetime, "
225 "expire, subnet_id, pref_lifetime, "
226 "lease_type, iaid, prefix_len, "
227 "fqdn_fwd, fqdn_rev, hostname, "
228 "hwaddr, hwtype, hwaddr_source, "
229 "state, user_context "
234 {MySqlLeaseMgr::GET_LEASE6_SUBID,
235 "SELECT address, duid, valid_lifetime, "
236 "expire, subnet_id, pref_lifetime, "
237 "lease_type, iaid, prefix_len, "
238 "fqdn_fwd, fqdn_rev, hostname, "
239 "hwaddr, hwtype, hwaddr_source, "
240 "state, user_context "
242 "WHERE subnet_id = ?"},
243 {MySqlLeaseMgr::GET_LEASE6_DUID,
244 "SELECT address, duid, valid_lifetime, "
245 "expire, subnet_id, pref_lifetime, "
246 "lease_type, iaid, prefix_len, "
247 "fqdn_fwd, fqdn_rev, hostname, "
248 "hwaddr, hwtype, hwaddr_source, "
249 "state, user_context "
252 {MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
253 "SELECT address, duid, valid_lifetime, "
254 "expire, subnet_id, pref_lifetime, "
255 "lease_type, iaid, prefix_len, "
256 "fqdn_fwd, fqdn_rev, hostname, "
257 "hwaddr, hwtype, hwaddr_source, "
258 "state, user_context "
260 "WHERE hostname = ?"},
261 {MySqlLeaseMgr::GET_LEASE6_EXPIRE,
262 "SELECT address, duid, valid_lifetime, "
263 "expire, subnet_id, pref_lifetime, "
264 "lease_type, iaid, prefix_len, "
265 "fqdn_fwd, fqdn_rev, hostname, "
266 "hwaddr, hwtype, hwaddr_source, "
267 "state, user_context "
270 "AND valid_lifetime != 4294967295 "
272 "ORDER BY expire ASC "
274 {MySqlLeaseMgr::INSERT_LEASE4,
275 "INSERT INTO lease4(address, hwaddr, client_id, "
276 "valid_lifetime, expire, subnet_id, "
277 "fqdn_fwd, fqdn_rev, hostname, "
278 "state, user_context) "
279 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
280 {MySqlLeaseMgr::INSERT_LEASE6,
281 "INSERT INTO lease6(address, duid, valid_lifetime, "
282 "expire, subnet_id, pref_lifetime, "
283 "lease_type, iaid, prefix_len, "
284 "fqdn_fwd, fqdn_rev, hostname, "
285 "hwaddr, hwtype, hwaddr_source, "
286 "state, user_context) "
287 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
288 {MySqlLeaseMgr::UPDATE_LEASE4,
289 "UPDATE lease4 SET address = ?, hwaddr = ?, "
290 "client_id = ?, valid_lifetime = ?, expire = ?, "
291 "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, "
293 "state = ?, user_context = ? "
294 "WHERE address = ? AND expire = ?"},
295 {MySqlLeaseMgr::UPDATE_LEASE6,
296 "UPDATE lease6 SET address = ?, duid = ?, "
297 "valid_lifetime = ?, expire = ?, subnet_id = ?, "
298 "pref_lifetime = ?, lease_type = ?, iaid = ?, "
299 "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
300 "hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
301 "state = ?, user_context = ? "
302 "WHERE address = ? AND expire = ?"},
303 {MySqlLeaseMgr::ALL_LEASE4_STATS,
304 "SELECT subnet_id, state, leases as state_count "
305 "FROM lease4_stat ORDER BY subnet_id, state"},
306 {MySqlLeaseMgr::SUBNET_LEASE4_STATS,
307 "SELECT subnet_id, state, leases as state_count "
309 "WHERE subnet_id = ? "
311 {MySqlLeaseMgr::SUBNET_RANGE_LEASE4_STATS,
312 "SELECT subnet_id, state, leases as state_count "
314 "WHERE subnet_id >= ? and subnet_id <= ? "
315 "ORDER BY subnet_id, state"},
316 {MySqlLeaseMgr::ALL_LEASE6_STATS,
317 "SELECT subnet_id, lease_type, state, leases as state_count "
318 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
319 {MySqlLeaseMgr::SUBNET_LEASE6_STATS,
320 "SELECT subnet_id, lease_type, state, leases as state_count "
322 "WHERE subnet_id = ? "
323 "ORDER BY lease_type, state"},
324 {MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
325 "SELECT subnet_id, lease_type, state, leases as state_count "
327 "WHERE subnet_id >= ? and subnet_id <= ? "
328 "ORDER BY subnet_id, lease_type, state"}
360 for (
size_t i = 0; i < count; ++i) {
362 bind[i].error =
reinterpret_cast<my_bool*
>(&error[i]);
381 std::string result =
"";
384 for (
size_t i = 0; i < count; ++i) {
386 if (!result.empty()) {
393 if (result.empty()) {
416 static const size_t LEASE_COLUMNS = 11;
425 client_id_length_(0), client_id_null_(
MLM_FALSE),
426 subnet_id_(0), valid_lifetime_(0),
427 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
428 state_(0), user_context_length_(0),
430 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
431 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
432 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
433 memset(user_context_, 0,
sizeof(user_context_));
434 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
437 columns_[0] =
"address";
438 columns_[1] =
"hwaddr";
439 columns_[2] =
"client_id";
440 columns_[3] =
"valid_lifetime";
441 columns_[4] =
"expire";
442 columns_[5] =
"subnet_id";
443 columns_[6] =
"fqdn_fwd";
444 columns_[7] =
"fqdn_rev";
445 columns_[8] =
"hostname";
446 columns_[9] =
"state";
447 columns_[10] =
"user_context";
448 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
470 memset(bind_, 0,
sizeof(bind_));
479 addr4_ = lease_->addr_.toUint32();
480 bind_[0].buffer_type = MYSQL_TYPE_LONG;
481 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
489 hwaddr_ = hwaddr->hwaddr_;
490 hwaddr_length_ = hwaddr->hwaddr_.size();
497 if (hwaddr_.empty()) {
501 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
502 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
503 bind_[1].buffer_length = hwaddr_length_;
504 bind_[1].length = &hwaddr_length_;
506 bind_[1].buffer_type = MYSQL_TYPE_NULL;
513 bind_[1].buffer = NULL;
514 bind_[1].is_null = &hwaddr_null_;
518 if (lease_->client_id_) {
519 client_id_ = lease_->client_id_->getClientId();
520 client_id_length_ = client_id_.size();
527 if (client_id_.empty()) {
528 client_id_.resize(1);
531 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
532 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
533 bind_[2].buffer_length = client_id_length_;
534 bind_[2].length = &client_id_length_;
538 bind_[2].buffer_type = MYSQL_TYPE_NULL;
545 bind_[2].buffer = NULL;
546 bind_[2].is_null = &client_id_null_;
550 bind_[3].buffer_type = MYSQL_TYPE_LONG;
551 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
563 uint32_t valid_lft = lease_->valid_lft_;
564 if (valid_lft == Lease::INFINITY_LFT) {
567 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
569 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
570 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
571 bind_[4].buffer_length =
sizeof(expire_);
577 bind_[5].buffer_type = MYSQL_TYPE_LONG;
578 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
584 bind_[6].buffer_type = MYSQL_TYPE_TINY;
585 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
591 bind_[7].buffer_type = MYSQL_TYPE_TINY;
592 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
601 bind_[8].buffer_type = MYSQL_TYPE_STRING;
602 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
603 bind_[8].buffer_length = lease_->hostname_.length();
608 bind_[9].buffer_type = MYSQL_TYPE_LONG;
609 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
617 bind_[10].buffer_type = MYSQL_TYPE_STRING;
618 std::string ctx_txt = ctx->str();
620 bind_[10].buffer = user_context_;
621 bind_[10].buffer_length = ctx_txt.length();
625 bind_[10].buffer_type = MYSQL_TYPE_NULL;
629 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
632 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
634 }
catch (
const std::exception& ex) {
636 "Could not create bind array from Lease4: "
637 << lease_->addr_.toText() <<
", reason: " << ex.
what());
642 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
657 memset(bind_, 0,
sizeof(bind_));
660 bind_[0].buffer_type = MYSQL_TYPE_LONG;
661 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
667 hwaddr_length_ =
sizeof(hwaddr_buffer_);
668 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
669 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
670 bind_[1].buffer_length = hwaddr_length_;
671 bind_[1].length = &hwaddr_length_;
676 client_id_length_ =
sizeof(client_id_buffer_);
677 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
678 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
679 bind_[2].buffer_length = client_id_length_;
680 bind_[2].length = &client_id_length_;
681 bind_[2].is_null = &client_id_null_;
686 bind_[3].buffer_type = MYSQL_TYPE_LONG;
687 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
693 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
694 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
695 bind_[4].buffer_length =
sizeof(expire_);
700 bind_[5].buffer_type = MYSQL_TYPE_LONG;
701 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
707 bind_[6].buffer_type = MYSQL_TYPE_TINY;
708 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
714 bind_[7].buffer_type = MYSQL_TYPE_TINY;
715 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
724 hostname_length_ =
sizeof(hostname_buffer_);
725 bind_[8].buffer_type = MYSQL_TYPE_STRING;
726 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
727 bind_[8].buffer_length = hostname_length_;
728 bind_[8].length = &hostname_length_;
733 bind_[9].buffer_type = MYSQL_TYPE_LONG;
734 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
741 user_context_length_ =
sizeof(user_context_);
742 bind_[10].buffer_type = MYSQL_TYPE_STRING;
743 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
744 bind_[10].buffer_length = user_context_length_;
745 bind_[10].length = &user_context_length_;
746 bind_[10].is_null = &user_context_null_;
749 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
752 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
756 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
772 uint32_t valid_lft = valid_lifetime_;
773 if (valid_lft == Lease::INFINITY_LFT) {
776 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
780 client_id_length_ = 0;
785 std::string hostname(hostname_buffer_,
786 hostname_buffer_ + hostname_length_);
795 std::string user_context;
797 user_context_[user_context_length_] =
'\0';
798 user_context.assign(user_context_);
803 if (!user_context.empty()) {
804 ctx = Element::fromJSON(user_context);
805 if (!ctx || (ctx->getType() != Element::map)) {
807 <<
"' is not a JSON map");
811 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
814 valid_lifetime_, cltt,
815 subnet_id_, fqdn_fwd_,
816 fqdn_rev_, hostname));
819 lease->state_ = state_;
822 lease->setContext(ctx);
839 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
848 MYSQL_BIND bind_[LEASE_COLUMNS];
849 std::string columns_[LEASE_COLUMNS];
852 std::vector<uint8_t> hwaddr_;
853 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
854 unsigned long hwaddr_length_;
856 std::vector<uint8_t> client_id_;
857 uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
858 unsigned long client_id_length_;
862 uint32_t valid_lifetime_;
865 char hostname_buffer_[HOSTNAME_MAX_LEN];
866 unsigned long hostname_length_;
869 unsigned long user_context_length_;
888 static const size_t LEASE_COLUMNS = 17;
897 hwaddr_null_(
MLM_FALSE), duid_length_(0),
898 iaid_(0), lease_type_(0), prefix_len_(0),
899 pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
900 fqdn_fwd_(false), fqdn_rev_(false),
901 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
902 state_(0), user_context_length_(0),
904 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
905 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
906 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
907 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
908 memset(user_context_, 0,
sizeof(user_context_));
909 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
912 columns_[0] =
"address";
913 columns_[1] =
"duid";
914 columns_[2] =
"valid_lifetime";
915 columns_[3] =
"expire";
916 columns_[4] =
"subnet_id";
917 columns_[5] =
"pref_lifetime";
918 columns_[6] =
"lease_type";
919 columns_[7] =
"iaid";
920 columns_[8] =
"prefix_len";
921 columns_[9] =
"fqdn_fwd";
922 columns_[10] =
"fqdn_rev";
923 columns_[11] =
"hostname";
924 columns_[12] =
"hwaddr";
925 columns_[13] =
"hwtype";
926 columns_[14] =
"hwaddr_source";
927 columns_[15] =
"state";
928 columns_[16] =
"user_context";
929 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
950 memset(bind_, 0,
sizeof(bind_));
954 addr6_ = lease_->addr_.toText();
955 addr6_length_ = addr6_.size();
971 bind_[0].buffer_type = MYSQL_TYPE_STRING;
972 bind_[0].buffer =
const_cast<char*
>(addr6_.c_str());
973 bind_[0].buffer_length = addr6_length_;
974 bind_[0].length = &addr6_length_;
979 if (!lease_->duid_) {
981 <<
" is missing mandatory client-id.");
983 duid_ = lease_->duid_->getDuid();
984 duid_length_ = duid_.size();
986 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
987 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
988 bind_[1].buffer_length = duid_length_;
989 bind_[1].length = &duid_length_;
994 bind_[2].buffer_type = MYSQL_TYPE_LONG;
995 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1007 uint32_t valid_lft = lease_->valid_lft_;
1008 if (valid_lft == Lease::INFINITY_LFT) {
1011 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
1013 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1014 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1015 bind_[3].buffer_length =
sizeof(expire_);
1021 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1022 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1029 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1030 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1037 lease_type_ = lease_->type_;
1038 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1039 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1046 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1047 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1054 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1055 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1061 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1062 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1068 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1069 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1075 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1076 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1077 bind_[11].buffer_length = lease_->hostname_.length();
1084 hwaddr_ = hwaddr->hwaddr_;
1085 hwaddr_length_ = hwaddr->hwaddr_.size();
1092 if (hwaddr_.empty()) {
1096 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1097 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1098 bind_[12].buffer_length = hwaddr_length_;
1099 bind_[12].length = &hwaddr_length_;
1101 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1108 bind_[12].buffer = NULL;
1109 bind_[12].is_null = &hwaddr_null_;
1114 hwtype_ = lease->hwaddr_->htype_;
1115 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1116 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1120 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1127 bind_[13].buffer = NULL;
1128 bind_[13].is_null = &hwaddr_null_;
1133 hwaddr_source_ = lease->hwaddr_->source_;
1134 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1135 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1139 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1146 bind_[14].buffer = NULL;
1147 bind_[14].is_null = &hwaddr_null_;
1151 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1152 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1160 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1161 std::string ctx_txt = ctx->str();
1163 bind_[16].buffer = user_context_;
1164 bind_[16].buffer_length = ctx_txt.length();
1168 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1172 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1175 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1177 }
catch (
const std::exception& ex) {
1179 "Could not create bind array from Lease6: "
1180 << lease_->addr_.toText() <<
", reason: " << ex.
what());
1185 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1203 memset(bind_, 0,
sizeof(bind_));
1209 addr6_length_ =
sizeof(addr6_buffer_) - 1;
1210 bind_[0].buffer_type = MYSQL_TYPE_STRING;
1211 bind_[0].buffer = addr6_buffer_;
1212 bind_[0].buffer_length = addr6_length_;
1213 bind_[0].length = &addr6_length_;
1218 duid_length_ =
sizeof(duid_buffer_);
1219 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1220 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1221 bind_[1].buffer_length = duid_length_;
1222 bind_[1].length = &duid_length_;
1227 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1228 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1234 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1235 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1236 bind_[3].buffer_length =
sizeof(expire_);
1241 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1242 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1248 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1249 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1255 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1256 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1262 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1263 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1269 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1270 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1276 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1277 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1283 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1284 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1290 hostname_length_ =
sizeof(hostname_buffer_);
1291 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1292 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1293 bind_[11].buffer_length = hostname_length_;
1294 bind_[11].length = &hostname_length_;
1300 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1301 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1302 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1303 bind_[12].buffer_length = hwaddr_length_;
1304 bind_[12].length = &hwaddr_length_;
1305 bind_[12].is_null = &hwaddr_null_;
1308 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1309 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1313 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1314 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1318 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1319 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1326 user_context_length_ =
sizeof(user_context_);
1327 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1328 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1329 bind_[16].buffer_length = user_context_length_;
1330 bind_[16].length = &user_context_length_;
1331 bind_[16].is_null = &user_context_null_;
1334 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1337 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1341 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1358 addr6_buffer_[addr6_length_] =
'\0';
1359 std::string address = addr6_buffer_;
1365 switch (lease_type_) {
1366 case Lease::TYPE_NA:
1367 type = Lease::TYPE_NA;
1370 case Lease::TYPE_TA:
1371 type = Lease::TYPE_TA;
1374 case Lease::TYPE_PD:
1375 type = Lease::TYPE_PD;
1380 static_cast<int>(lease_type_) <<
") for lease with "
1381 <<
"address " << address <<
". Only 0, 1, or 2 are "
1386 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1390 std::string hostname(hostname_buffer_,
1391 hostname_buffer_ + hostname_length_);
1396 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1397 hwaddr->source_ = hwaddr_source_;
1401 std::string user_context;
1403 user_context_[user_context_length_] =
'\0';
1404 user_context.assign(user_context_);
1409 if (!user_context.empty()) {
1410 ctx = Element::fromJSON(user_context);
1411 if (!ctx || (ctx->getType() != Element::map)) {
1413 <<
"' is not a JSON map");
1419 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1421 valid_lifetime_, subnet_id_,
1422 fqdn_fwd_, fqdn_rev_,
1427 uint32_t valid_lft = valid_lifetime_;
1428 if (valid_lft == Lease::INFINITY_LFT) {
1431 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
1433 result->cltt_ = cltt;
1434 result->current_cltt_ = cltt;
1437 result->state_ = state_;
1440 result->setContext(ctx);
1457 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
1466 char addr6_buffer_[ADDRESS6_TEXT_MAX_LEN + 1];
1467 unsigned long addr6_length_;
1468 MYSQL_BIND bind_[LEASE_COLUMNS];
1469 std::string columns_[LEASE_COLUMNS];
1470 my_bool error_[LEASE_COLUMNS];
1472 std::vector<uint8_t> hwaddr_;
1473 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
1474 unsigned long hwaddr_length_;
1476 std::vector<uint8_t> duid_;
1477 uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
1478 unsigned long duid_length_;
1481 uint8_t lease_type_;
1482 uint8_t prefix_len_;
1483 uint32_t pref_lifetime_;
1484 uint32_t subnet_id_;
1485 uint32_t valid_lifetime_;
1488 char hostname_buffer_[HOSTNAME_MAX_LEN];
1489 unsigned long hostname_length_;
1491 uint32_t hwaddr_source_;
1494 unsigned long user_context_length_;
1517 const bool fetch_type)
1518 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1519 fetch_type_(fetch_type),
1522 bind_(fetch_type_ ? 4 : 3),
1523 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1524 validateStatement();
1537 const bool fetch_type,
const SubnetID& subnet_id)
1538 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1539 statement_(NULL), fetch_type_(fetch_type),
1542 bind_(fetch_type_ ? 4 : 3),
1543 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1544 validateStatement();
1560 const bool fetch_type,
const SubnetID& first_subnet_id,
1563 statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
1566 bind_(fetch_type_ ? 4 : 3),
1567 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1568 validateStatement();
1573 (void) mysql_stmt_free_result(statement_);
1585 if (getSelectMode() != ALL_SUBNETS) {
1586 MYSQL_BIND inbind[2];
1587 memset(inbind, 0,
sizeof(inbind));
1590 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1591 inbind[0].buffer =
reinterpret_cast<char*
>(&first_subnet_id_);
1595 if (getSelectMode() == SUBNET_RANGE) {
1596 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1597 inbind[1].buffer =
reinterpret_cast<char*
>(&last_subnet_id_);
1602 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1603 conn_.checkError(status, statement_index_,
"unable to bind parameters");
1608 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1609 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1616 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1617 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1621 fetch_type_ = Lease::TYPE_NA;
1625 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1626 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1631 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1632 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1637 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1638 conn_.checkError(status, statement_index_,
"outbound binding failed");
1642 conn_.checkError(status, statement_index_,
"unable to execute");
1646 status = mysql_stmt_store_result(statement_);
1647 conn_.checkError(status, statement_index_,
"results storage failed");
1666 bool have_row =
false;
1667 int status = mysql_stmt_fetch(statement_);
1672 if (state_count_ >= 0) {
1676 if (!negative_count_) {
1677 negative_count_ =
true;
1682 }
else if (status != MYSQL_NO_DATA) {
1683 conn_.checkError(status, statement_index_,
"getNextRow failed");
1694 void validateStatement() {
1695 if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
1697 " - invalid statement index" << statement_index_);
1700 statement_ = conn_.statements_[statement_index_];
1707 size_t statement_index_;
1710 MYSQL_STMT *statement_;
1716 std::vector<MYSQL_BIND> bind_;
1719 uint32_t subnet_id_;
1722 uint32_t lease_type_;
1728 int64_t state_count_;
1731 static bool negative_count_;
1735 bool MySqlLeaseStatsQuery::negative_count_ =
false;
1742 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1747 MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
1750 if (MultiThreadingMgr::instance().getMode()) {
1754 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1755 if (!mgr_.pool_->pool_.empty()) {
1756 ctx_ = mgr_.pool_->pool_.back();
1757 mgr_.pool_->pool_.pop_back();
1761 ctx_ = mgr_.createContext();
1765 if (mgr_.pool_->pool_.empty()) {
1768 ctx_ = mgr_.pool_->pool_.back();
1772 MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
1773 if (MultiThreadingMgr::instance().getMode()) {
1775 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1776 mgr_.pool_->pool_.push_back(ctx_);
1784 : parameters_(parameters), timer_name_(
"") {
1787 timer_name_ =
"MySqlLeaseMgr[";
1788 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1789 timer_name_ +=
"]DbReconnectTimer";
1794 std::pair<uint32_t, uint32_t> db_version =
getVersion();
1795 if (code_version != db_version) {
1797 "MySQL schema version mismatch: need version: "
1798 << code_version.first <<
"." << code_version.second
1799 <<
" found version: " << db_version.first <<
"."
1800 << db_version.second);
1820 bool reopened =
false;
1822 const std::string timer_name = db_reconnect_ctl->timerName();
1830 }
catch (
const std::exception& ex) {
1846 if (!db_reconnect_ctl->checkRetries()) {
1849 .arg(db_reconnect_ctl->maxRetries());
1862 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1863 .arg(db_reconnect_ctl->maxRetries())
1864 .arg(db_reconnect_ctl->retryInterval());
1870 db_reconnect_ctl->retryInterval(),
1888 ctx->conn_.openDatabase();
1891 ctx->conn_.prepareStatements(tagged_statements.begin(),
1892 tagged_statements.end());
1900 ctx->conn_.makeReconnectCtl(timer_name_);
1907 std::stringstream tmp;
1910 tmp <<
", library " << mysql_get_client_info();
1920 StatementIndex stindex,
1921 std::vector<MYSQL_BIND>& bind) {
1924 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], &bind[0]);
1925 checkError(ctx, status, stindex,
"unable to bind parameters");
1934 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
1937 checkError(ctx, status, stindex,
"unable to execute");
1947 .arg(lease->addr_.toText());
1950 MySqlLeaseContextAlloc get_context(*
this);
1954 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
1961 lease->updateCurrentExpirationTime();
1969 .arg(lease->addr_.toText())
1973 MySqlLeaseContextAlloc get_context(*
this);
1977 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
1984 lease->updateCurrentExpirationTime();
2014 template <
typename Exchange,
typename LeaseCollection>
2017 StatementIndex stindex,
2020 LeaseCollection& result,
2021 bool single)
const {
2026 status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2027 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2032 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2033 status = mysql_stmt_bind_result(ctx->conn_.statements_[stindex], &outbind[0]);
2034 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2038 checkError(ctx, status, stindex,
"unable to execute");
2042 status = mysql_stmt_store_result(ctx->conn_.statements_[stindex]);
2043 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2050 while ((status = mysql_stmt_fetch(ctx->conn_.statements_[stindex])) == 0) {
2052 result.push_back(exchange->getLeaseData());
2057 ctx->conn_.text_statements_[stindex] <<
">");
2060 if (single && (++count > 1)) {
2062 "database where only one was expected for query "
2063 << ctx->conn_.text_statements_[stindex]);
2070 checkError(ctx, status, stindex,
"unable to fetch results");
2071 }
else if (status == MYSQL_DATA_TRUNCATED) {
2074 <<
" returned truncated data: columns affected are "
2075 << exchange->getErrorColumns());
2081 StatementIndex stindex, MYSQL_BIND* bind,
2089 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2092 if (collection.empty()) {
2095 result = *collection.begin();
2101 StatementIndex stindex, MYSQL_BIND* bind,
2109 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2112 if (collection.empty()) {
2115 result = *collection.begin();
2128 MYSQL_BIND inbind[1];
2129 memset(inbind, 0,
sizeof(inbind));
2132 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2133 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2140 MySqlLeaseContextAlloc get_context(*
this);
2154 MYSQL_BIND inbind[1];
2155 memset(inbind, 0,
sizeof(inbind));
2157 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2159 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2163 uint8_t single_byte_data = 0;
2170 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2171 : &single_byte_data;
2173 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2174 inbind[0].buffer_length = hwaddr_length;
2175 inbind[0].length = &hwaddr_length;
2181 MySqlLeaseContextAlloc get_context(*
this);
2196 MYSQL_BIND inbind[2];
2197 memset(inbind, 0,
sizeof(inbind));
2199 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2201 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2205 std::vector<uint8_t> single_byte_vec(1);
2212 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2213 : &single_byte_vec[0];
2215 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2216 inbind[0].buffer_length = hwaddr_length;
2217 inbind[0].length = &hwaddr_length;
2219 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2220 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2227 MySqlLeaseContextAlloc get_context(*
this);
2241 MYSQL_BIND inbind[1];
2242 memset(inbind, 0,
sizeof(inbind));
2244 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2246 std::vector<uint8_t> client_data = clientid.
getClientId();
2247 unsigned long client_data_length = client_data.size();
2251 if (client_data.empty()) {
2252 client_data.resize(1);
2255 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2256 inbind[0].buffer_length = client_data_length;
2257 inbind[0].length = &client_data_length;
2263 MySqlLeaseContextAlloc get_context(*
this);
2278 MYSQL_BIND inbind[2];
2279 memset(inbind, 0,
sizeof(inbind));
2281 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2283 std::vector<uint8_t> client_data = clientid.
getClientId();
2284 unsigned long client_data_length = client_data.size();
2288 if (client_data.empty()) {
2289 client_data.resize(1);
2292 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2293 inbind[0].buffer_length = client_data_length;
2294 inbind[0].length = &client_data_length;
2296 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2297 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2304 MySqlLeaseContextAlloc get_context(*
this);
2318 MYSQL_BIND inbind[1];
2319 memset(inbind, 0,
sizeof(inbind));
2322 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2323 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2330 MySqlLeaseContextAlloc get_context(*
this);
2344 MYSQL_BIND inbind[1];
2345 memset(inbind, 0,
sizeof(inbind));
2348 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2349 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2350 inbind[0].buffer_length = hostname.length();
2356 MySqlLeaseContextAlloc get_context(*
this);
2371 MySqlLeaseContextAlloc get_context(*
this);
2374 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2383 if (!lower_bound_address.
isV4()) {
2385 "retrieving leases from the lease database, got "
2386 << lower_bound_address);
2391 .arg(lower_bound_address.
toText());
2394 MYSQL_BIND inbind[2];
2395 memset(inbind, 0,
sizeof(inbind));
2398 uint32_t lb_address_data = lower_bound_address.
toUint32();
2399 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2400 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2404 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2405 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2406 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2413 MySqlLeaseContextAlloc get_context(*
this);
2429 MYSQL_BIND inbind[2];
2430 memset(inbind, 0,
sizeof(inbind));
2432 std::string addr6 = addr.
toText();
2433 unsigned long addr6_length = addr6.size();
2437 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2438 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2439 inbind[0].buffer_length = addr6_length;
2440 inbind[0].length = &addr6_length;
2443 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2444 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2450 MySqlLeaseContextAlloc get_context(*
this);
2460 uint32_t iaid)
const {
2467 MYSQL_BIND inbind[3];
2468 memset(inbind, 0,
sizeof(inbind));
2482 const vector<uint8_t>& duid_vector = duid.
getDuid();
2483 unsigned long duid_length = duid_vector.size();
2490 uint8_t single_byte_data = 0;
2491 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2492 : &single_byte_data;
2494 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2495 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2496 inbind[0].buffer_length = duid_length;
2497 inbind[0].length = &duid_length;
2500 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2501 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2505 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2506 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2513 MySqlLeaseContextAlloc get_context(*
this);
2523 uint32_t iaid,
SubnetID subnet_id)
const {
2531 MYSQL_BIND inbind[4];
2532 memset(inbind, 0,
sizeof(inbind));
2536 const vector<uint8_t>& duid_vector = duid.
getDuid();
2537 unsigned long duid_length = duid_vector.size();
2538 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2539 inbind[0].buffer =
reinterpret_cast<char*
>(
2540 const_cast<uint8_t*
>(&duid_vector[0]));
2541 inbind[0].buffer_length = duid_length;
2542 inbind[0].length = &duid_length;
2545 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2546 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2550 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2551 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2555 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2556 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2563 MySqlLeaseContextAlloc get_context(*
this);
2577 MYSQL_BIND inbind[1];
2578 memset(inbind, 0,
sizeof(inbind));
2581 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2582 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2589 MySqlLeaseContextAlloc get_context(*
this);
2604 MySqlLeaseContextAlloc get_context(*
this);
2607 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
2618 MYSQL_BIND inbind[1];
2619 memset(inbind, 0,
sizeof(inbind));
2621 const vector<uint8_t>& duid_vector = duid.
getDuid();
2622 unsigned long duid_length = duid_vector.size();
2624 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2625 inbind[0].buffer =
reinterpret_cast<char*
>(
2626 const_cast<uint8_t*
>(&duid_vector[0]));
2627 inbind[0].buffer_length = duid_length;
2628 inbind[0].length = &duid_length;
2633 MySqlLeaseContextAlloc get_context(*
this);
2647 MYSQL_BIND inbind[1];
2648 memset(inbind, 0,
sizeof(inbind));
2651 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2652 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2653 inbind[0].buffer_length = hostname.length();
2659 MySqlLeaseContextAlloc get_context(*
this);
2671 if (!lower_bound_address.
isV6()) {
2673 "retrieving leases from the lease database, got "
2674 << lower_bound_address);
2679 .arg(lower_bound_address.
toText());
2682 MYSQL_BIND inbind[2];
2683 memset(inbind, 0,
sizeof(inbind));
2688 std::string lb_address_data =
"0";
2689 if (!lower_bound_address.
isV6Zero()) {
2690 lb_address_data = lower_bound_address.
toText();
2694 unsigned long lb_address_data_size = lb_address_data.size();
2695 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2696 inbind[0].buffer =
const_cast<char*
>(lb_address_data.c_str());
2697 inbind[0].buffer_length = lb_address_data_size;
2698 inbind[0].length = &lb_address_data_size;
2701 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2702 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2703 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2710 MySqlLeaseContextAlloc get_context(*
this);
2720 const size_t max_leases)
const {
2728 const size_t max_leases)
const {
2734 template<
typename LeaseCollection>
2736 MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2737 const size_t max_leases,
2738 StatementIndex statement_index)
const {
2740 MYSQL_BIND inbind[3];
2741 memset(inbind, 0,
sizeof(inbind));
2745 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2746 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
2750 MYSQL_TIME expire_time;
2752 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2753 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
2754 inbind[1].buffer_length =
sizeof(expire_time);
2758 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2759 std::numeric_limits<uint32_t>::max();
2760 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2761 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
2765 MySqlLeaseContextAlloc get_context(*
this);
2769 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
2776 template <
typename LeasePtr>
2779 StatementIndex stindex,
2784 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2785 checkError(ctx, status, stindex,
"unable to bind parameters");
2789 checkError(ctx, status, stindex,
"unable to execute");
2793 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.statements_[stindex]);
2796 if (affected_rows == 1) {
2801 if (affected_rows == 0) {
2803 lease->addr_.toText() <<
" as it does not exist");
2809 "that had the address " << lease->addr_.toText());
2817 .arg(lease->addr_.toText());
2820 MySqlLeaseContextAlloc get_context(*
this);
2824 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2827 MYSQL_BIND inbind[2];
2828 memset(inbind, 0,
sizeof(inbind));
2830 uint32_t addr4 = lease->addr_.toUint32();
2831 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2832 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2835 bind.push_back(inbind[0]);
2839 lease->current_valid_lft_,
2841 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2842 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2843 inbind[1].buffer_length =
sizeof(expire);
2845 bind.push_back(inbind[1]);
2848 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2851 lease->updateCurrentExpirationTime();
2859 .arg(lease->addr_.toText())
2863 MySqlLeaseContextAlloc get_context(*
this);
2867 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2870 MYSQL_BIND inbind[2];
2871 memset(inbind, 0,
sizeof(inbind));
2873 std::string addr6 = lease->addr_.toText();
2874 unsigned long addr6_length = addr6.size();
2878 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2879 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2880 inbind[0].buffer_length = addr6_length;
2881 inbind[0].length = &addr6_length;
2883 bind.push_back(inbind[0]);
2887 lease->current_valid_lft_,
2889 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2890 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2891 inbind[1].buffer_length =
sizeof(expire);
2893 bind.push_back(inbind[1]);
2896 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2899 lease->updateCurrentExpirationTime();
2908 MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex,
2912 MySqlLeaseContextAlloc get_context(*
this);
2916 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2917 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2921 checkError(ctx, status, stindex,
"unable to execute");
2925 return (static_cast<uint64_t>(mysql_stmt_affected_rows(ctx->conn_.statements_[stindex])));
2935 MYSQL_BIND inbind[2];
2936 memset(inbind, 0,
sizeof(inbind));
2940 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2941 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2946 lease->current_valid_lft_,
2948 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2949 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2950 inbind[1].buffer_length =
sizeof(expire);
2952 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE4, inbind);
2955 if (affected_rows == 1) {
2960 if (affected_rows == 0) {
2967 "that had the address " << lease->addr_.toText());
2978 MYSQL_BIND inbind[2];
2979 memset(inbind, 0,
sizeof(inbind));
2981 std::string addr6 = addr.
toText();
2982 unsigned long addr6_length = addr6.size();
2986 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2987 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2988 inbind[0].buffer_length = addr6_length;
2989 inbind[0].length = &addr6_length;
2993 lease->current_valid_lft_,
2995 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2996 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2997 inbind[1].buffer_length =
sizeof(expire);
2999 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE6, inbind);
3002 if (affected_rows == 1) {
3007 if (affected_rows == 0) {
3014 "that had the address " << lease->addr_.toText());
3032 MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3033 StatementIndex statement_index) {
3035 MYSQL_BIND inbind[2];
3036 memset(inbind, 0,
sizeof(inbind));
3040 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3041 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3045 MYSQL_TIME expire_time;
3047 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3048 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3049 inbind[1].buffer_length =
sizeof(expire_time);
3052 uint64_t deleted_leases = deleteLeaseCommon(statement_index, inbind);
3054 .arg(deleted_leases);
3056 return (deleted_leases);
3062 MySqlLeaseContextAlloc get_context(*
this);
3075 MySqlLeaseContextAlloc get_context(*
this);
3090 MySqlLeaseContextAlloc get_context(*
this);
3105 MySqlLeaseContextAlloc get_context(*
this);
3118 MySqlLeaseContextAlloc get_context(*
this);
3133 MySqlLeaseContextAlloc get_context(*
this);
3160 MySqlLeaseContextAlloc get_context(*
this);
3163 std::string name =
"";
3165 name = ctx->conn_.getParameter(
"name");
3174 return (std::string(
"MySQL Database"));
3177 std::pair<uint32_t, uint32_t>
3196 int status, StatementIndex index,
3197 const char* what)
const {
3198 ctx->conn_.checkError(status, index, what);
static bool dbReconnect(db::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
RAII class creating a critical section.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED4
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
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.
boost::shared_ptr< DUID > DuidPtr
bool my_bool
my_bool type in MySQL 8.x.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
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.
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
virtual std::string getName() const
Returns backend name.
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.
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 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 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
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
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 std::string getDescription() const
Returns description of the backend.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
bool isV4() const
Convenience function to check for an IPv4 address.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const
Returns existing IPv6 lease for a given IPv6 address.
Holds DUID (DHCPv6 Unique Identifier)
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.
virtual Lease4Collection getLeases4() const
Returns all IPv4 leases.
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.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
virtual std::pair< uint32_t, uint32_t > getVersion() const
Returns backend version.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
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.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
virtual void updateLease4(const Lease4Ptr &lease4)
Updates IPv4 lease.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
MySql derivation of the statistical lease data query.
const isc::log::MessageID DHCPSRV_MYSQL_ROLLBACK
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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 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.
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
static bool invokeDbFailedCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED6
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv4 leases.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::function< bool(ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
Common MySQL and Lease Data Methods.
static bool invokeDbRecoveredCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
Lease4Ptr getLeaseData()
Copy Received Data into Lease4 Object.
Exchange MySQL and Lease6 Data.
Exchange MySQL and Lease4 Data.
virtual Lease6Collection getLeases6() const
Returns all IPv6 leases.
static bool invokeDbLostCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
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
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.
std::string toText() const
Convert the address to a string.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const
Returns an IPv4 lease for specified IPv4 address.
Hardware type that represents information from DHCPv4 packet.
const isc::log::MessageID DHCPSRV_MYSQL_GET_CLIENTID
MySqlLeaseContextPtr createContext() const
Create a new context.
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
bool isV6() const
Convenience function to check for an IPv6 address.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv6 leases.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Contains a single row of lease statistical data.
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
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)
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
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.
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
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.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Common MySQL Connector Pool.
std::string getErrorColumns()
Return columns in error.