21#include <boost/array.hpp>
22#include <boost/make_shared.hpp>
23#include <boost/static_assert.hpp>
24#include <mysqld_error.h>
101const size_t LIMITS_TEXT_MAX_LEN = 512;
103boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
104tagged_statements = { {
106 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
108 "DELETE FROM lease4 "
109 "WHERE state = ? AND expire < ?"},
111 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
113 "DELETE FROM lease6 "
114 "WHERE state = ? AND expire < ?"},
116 "SELECT address, hwaddr, client_id, "
117 "valid_lifetime, expire, subnet_id, "
118 "fqdn_fwd, fqdn_rev, hostname, "
119 "state, user_context, relay_id, remote_id, pool_id "
122 "SELECT address, hwaddr, client_id, "
123 "valid_lifetime, expire, subnet_id, "
124 "fqdn_fwd, fqdn_rev, hostname, "
125 "state, user_context, relay_id, remote_id, pool_id "
127 "WHERE address = ?"},
129 "SELECT address, hwaddr, client_id, "
130 "valid_lifetime, expire, subnet_id, "
131 "fqdn_fwd, fqdn_rev, hostname, "
132 "state, user_context, relay_id, remote_id, pool_id "
134 "WHERE client_id = ?"},
136 "SELECT address, hwaddr, client_id, "
137 "valid_lifetime, expire, subnet_id, "
138 "fqdn_fwd, fqdn_rev, hostname, "
139 "state, user_context, relay_id, remote_id, pool_id "
141 "WHERE client_id = ? AND subnet_id = ?"},
143 "SELECT address, hwaddr, client_id, "
144 "valid_lifetime, expire, subnet_id, "
145 "fqdn_fwd, fqdn_rev, hostname, "
146 "state, user_context, relay_id, remote_id, pool_id "
150 "SELECT address, hwaddr, client_id, "
151 "valid_lifetime, expire, subnet_id, "
152 "fqdn_fwd, fqdn_rev, hostname, "
153 "state, user_context, relay_id, remote_id, pool_id "
155 "WHERE hwaddr = ? AND subnet_id = ?"},
157 "SELECT address, hwaddr, client_id, "
158 "valid_lifetime, expire, subnet_id, "
159 "fqdn_fwd, fqdn_rev, hostname, "
160 "state, user_context, relay_id, remote_id, pool_id "
166 "SELECT address, hwaddr, client_id, "
167 "valid_lifetime, expire, subnet_id, "
168 "fqdn_fwd, fqdn_rev, hostname, "
169 "state, user_context, relay_id, remote_id, pool_id "
171 "WHERE address > ? AND user_context IS NOT NULL "
175 "SELECT address, hwaddr, client_id, "
176 "valid_lifetime, expire, subnet_id, "
177 "fqdn_fwd, fqdn_rev, hostname, "
178 "state, user_context, relay_id, remote_id, pool_id "
180 "WHERE subnet_id = ?"},
182 "SELECT address, hwaddr, client_id, "
183 "valid_lifetime, expire, subnet_id, "
184 "fqdn_fwd, fqdn_rev, hostname, "
185 "state, user_context, relay_id, remote_id, pool_id "
187 "WHERE hostname = ?"},
189 "SELECT address, hwaddr, client_id, "
190 "valid_lifetime, expire, subnet_id, "
191 "fqdn_fwd, fqdn_rev, hostname, "
192 "state, user_context, relay_id, remote_id, pool_id "
195 "AND valid_lifetime != 4294967295 "
197 "ORDER BY expire ASC "
200 "SELECT address, hwaddr, client_id, "
201 "valid_lifetime, expire, subnet_id, "
202 "fqdn_fwd, fqdn_rev, hostname, "
203 "state, user_context, relay_id, remote_id, pool_id "
205 "WHERE relay_id = ? and address > ? "
209 "SELECT address, hwaddr, client_id, "
210 "valid_lifetime, expire, subnet_id, "
211 "fqdn_fwd, fqdn_rev, hostname, "
212 "state, user_context, relay_id, remote_id, pool_id "
214 "WHERE relay_id = ? and address > ? "
215 " and UNIX_TIMESTAMP(expire) - IF"
216 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
221 "SELECT address, hwaddr, client_id, "
222 "valid_lifetime, expire, subnet_id, "
223 "fqdn_fwd, fqdn_rev, hostname, "
224 "state, user_context, relay_id, remote_id, pool_id "
226 "WHERE relay_id = ? and address > ? "
227 " and UNIX_TIMESTAMP(expire) - IF"
228 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
230 " and UNIX_TIMESTAMP(expire) - IF"
231 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
236 "SELECT address, hwaddr, client_id, "
237 "valid_lifetime, expire, subnet_id, "
238 "fqdn_fwd, fqdn_rev, hostname, "
239 "state, user_context, relay_id, remote_id, pool_id "
241 "WHERE relay_id = ? and address > ? "
242 " and UNIX_TIMESTAMP(expire) - IF"
243 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
248 "SELECT address, hwaddr, client_id, "
249 "valid_lifetime, expire, subnet_id, "
250 "fqdn_fwd, fqdn_rev, hostname, "
251 "state, user_context, relay_id, remote_id, pool_id "
253 "WHERE remote_id = ? and address > ? "
257 "SELECT address, hwaddr, client_id, "
258 "valid_lifetime, expire, subnet_id, "
259 "fqdn_fwd, fqdn_rev, hostname, "
260 "state, user_context, relay_id, remote_id, pool_id "
262 "WHERE remote_id = ? and address > ? "
263 " and UNIX_TIMESTAMP(expire) - IF"
264 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
269 "SELECT address, hwaddr, client_id, "
270 "valid_lifetime, expire, subnet_id, "
271 "fqdn_fwd, fqdn_rev, hostname, "
272 "state, user_context, relay_id, remote_id, pool_id "
274 "WHERE remote_id = ? and address > ? "
275 " and UNIX_TIMESTAMP(expire) - IF"
276 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
278 " and UNIX_TIMESTAMP(expire) - IF"
279 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
284 "SELECT address, hwaddr, client_id, "
285 "valid_lifetime, expire, subnet_id, "
286 "fqdn_fwd, fqdn_rev, hostname, "
287 "state, user_context, relay_id, remote_id, pool_id "
289 "WHERE remote_id = ? and address > ? "
290 " and UNIX_TIMESTAMP(expire) - IF"
291 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
296 "SELECT address, duid, valid_lifetime, "
297 "expire, subnet_id, pref_lifetime, "
298 "lease_type, iaid, prefix_len, "
299 "fqdn_fwd, fqdn_rev, hostname, "
300 "hwaddr, hwtype, hwaddr_source, "
301 "state, user_context, pool_id "
304 "SELECT address, duid, valid_lifetime, "
305 "expire, subnet_id, pref_lifetime, "
306 "lease_type, iaid, prefix_len, "
307 "fqdn_fwd, fqdn_rev, hostname, "
308 "hwaddr, hwtype, hwaddr_source, "
309 "state, user_context, pool_id "
311 "WHERE address = ? AND lease_type = ?"},
313 "SELECT address, duid, valid_lifetime, "
314 "expire, subnet_id, pref_lifetime, "
315 "lease_type, iaid, prefix_len, "
316 "fqdn_fwd, fqdn_rev, hostname, "
317 "hwaddr, hwtype, hwaddr_source, "
318 "state, user_context, pool_id "
320 "WHERE duid = ? AND iaid = ? AND lease_type = ?"},
322 "SELECT address, duid, valid_lifetime, "
323 "expire, subnet_id, pref_lifetime, "
324 "lease_type, iaid, prefix_len, "
325 "fqdn_fwd, fqdn_rev, hostname, "
326 "hwaddr, hwtype, hwaddr_source, "
327 "state, user_context, pool_id "
329 "WHERE duid = ? AND iaid = ? AND subnet_id = ? "
330 "AND lease_type = ?"},
332 "SELECT address, duid, valid_lifetime, "
333 "expire, subnet_id, pref_lifetime, "
334 "lease_type, iaid, prefix_len, "
335 "fqdn_fwd, fqdn_rev, hostname, "
336 "hwaddr, hwtype, hwaddr_source, "
337 "state, user_context, pool_id "
343 "SELECT address, duid, valid_lifetime, "
344 "expire, subnet_id, pref_lifetime, "
345 "lease_type, iaid, prefix_len, "
346 "fqdn_fwd, fqdn_rev, hostname, "
347 "hwaddr, hwtype, hwaddr_source, "
348 "state, user_context, pool_id "
350 "WHERE address > ? AND user_context IS NOT NULL "
354 "SELECT address, duid, valid_lifetime, "
355 "expire, subnet_id, pref_lifetime, "
356 "lease_type, iaid, prefix_len, "
357 "fqdn_fwd, fqdn_rev, hostname, "
358 "hwaddr, hwtype, hwaddr_source, "
359 "state, user_context, pool_id "
361 "WHERE subnet_id = ?"},
363 "SELECT address, duid, valid_lifetime, "
364 "expire, subnet_id, pref_lifetime, "
365 "lease_type, iaid, prefix_len, "
366 "fqdn_fwd, fqdn_rev, hostname, "
367 "hwaddr, hwtype, hwaddr_source, "
368 "state, user_context, pool_id "
370 "WHERE subnet_id = ? AND address > ? "
374 "SELECT address, duid, valid_lifetime, "
375 "expire, subnet_id, pref_lifetime, "
376 "lease_type, iaid, prefix_len, "
377 "fqdn_fwd, fqdn_rev, hostname, "
378 "hwaddr, hwtype, hwaddr_source, "
379 "state, user_context, pool_id "
383 "SELECT address, duid, valid_lifetime, "
384 "expire, subnet_id, pref_lifetime, "
385 "lease_type, iaid, prefix_len, "
386 "fqdn_fwd, fqdn_rev, hostname, "
387 "hwaddr, hwtype, hwaddr_source, "
388 "state, user_context, pool_id "
390 "WHERE hostname = ?"},
392 "SELECT address, duid, valid_lifetime, "
393 "expire, subnet_id, pref_lifetime, "
394 "lease_type, iaid, prefix_len, "
395 "fqdn_fwd, fqdn_rev, hostname, "
396 "hwaddr, hwtype, hwaddr_source, "
397 "state, user_context, pool_id "
400 "AND valid_lifetime != 4294967295 "
402 "ORDER BY expire ASC "
405 "INSERT INTO lease4(address, hwaddr, client_id, "
406 "valid_lifetime, expire, subnet_id, "
407 "fqdn_fwd, fqdn_rev, hostname, "
408 "state, user_context, relay_id, remote_id, pool_id) "
409 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
411 "INSERT INTO lease6(address, duid, valid_lifetime, "
412 "expire, subnet_id, pref_lifetime, "
413 "lease_type, iaid, prefix_len, "
414 "fqdn_fwd, fqdn_rev, hostname, "
415 "hwaddr, hwtype, hwaddr_source, "
416 "state, user_context, pool_id) "
417 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
419 "UPDATE lease4 SET address = ?, hwaddr = ?, "
420 "client_id = ?, valid_lifetime = ?, expire = ?, "
421 "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, "
423 "state = ?, user_context = ?, "
424 "relay_id = ?, remote_id = ?, pool_id = ? "
425 "WHERE address = ? AND expire = ?"},
427 "UPDATE lease6 SET address = ?, duid = ?, "
428 "valid_lifetime = ?, expire = ?, subnet_id = ?, "
429 "pref_lifetime = ?, lease_type = ?, iaid = ?, "
430 "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
431 "hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
432 "state = ?, user_context = ?, pool_id = ? "
433 "WHERE address = ? AND expire = ?"},
435 "SELECT subnet_id, state, leases as state_count "
436 "FROM lease4_stat ORDER BY subnet_id, state"},
438 "SELECT subnet_id, state, leases as state_count "
440 "WHERE subnet_id = ? "
443 "SELECT subnet_id, state, leases as state_count "
445 "WHERE subnet_id >= ? and subnet_id <= ? "
446 "ORDER BY subnet_id, state"},
448 "SELECT subnet_id, pool_id, state, leases as state_count "
449 "FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state"},
451 "SELECT subnet_id, lease_type, state, leases as state_count "
452 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
454 "SELECT subnet_id, lease_type, state, leases as state_count "
456 "WHERE subnet_id = ? "
457 "ORDER BY lease_type, state"},
459 "SELECT subnet_id, lease_type, state, leases as state_count "
461 "WHERE subnet_id >= ? and subnet_id <= ? "
462 "ORDER BY subnet_id, lease_type, state"},
464 "SELECT subnet_id, pool_id, lease_type, state, leases as state_count "
465 "FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state"},
467 "SELECT checkLease4Limits(?)"},
469 "SELECT checkLease6Limits(?)"},
471 "SELECT isJsonSupported()"},
474 "FROM lease4_stat_by_client_class "
475 "WHERE client_class = ?"},
478 "FROM lease6_stat_by_client_class "
479 "WHERE client_class = ? AND lease_type = ?"},
481 "DELETE FROM lease6_relay_id"},
483 "DELETE FROM lease6_remote_id"},
485 "DELETE FROM lease6_relay_id WHERE lease_addr = ?"},
487 "DELETE FROM lease6_remote_id WHERE lease_addr = ?"},
489 "INSERT INTO lease6_relay_id(relay_id, lease_addr) "
492 "INSERT INTO lease6_remote_id(remote_id, lease_addr) "
495 "SELECT l.address, l.duid, l.valid_lifetime, "
496 "l.expire, l.subnet_id, l.pref_lifetime, "
497 "l.lease_type, l.iaid, l.prefix_len, "
498 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
499 "l.hwaddr, l.hwtype, l.hwaddr_source, "
500 "l.state, l.user_context, l.pool_id "
502 "INNER JOIN lease6_relay_id AS r "
503 " ON l.address = r.lease_addr "
504 " WHERE r.relay_id = ? AND r.lease_addr > ? "
505 "GROUP BY l.address "
506 "ORDER BY l.address "
509 "SELECT l.address, l.duid, l.valid_lifetime, "
510 "l.expire, l.subnet_id, l.pref_lifetime, "
511 "l.lease_type, l.iaid, l.prefix_len, "
512 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
513 "l.hwaddr, l.hwtype, l.hwaddr_source, "
514 "l.state, l.user_context, l.pool_id "
516 "INNER JOIN lease6_remote_id AS r "
517 " ON l.address = r.lease_addr "
518 " WHERE r.remote_id = ? AND r.lease_addr > ? "
519 "GROUP BY l.address "
520 "ORDER BY l.address "
523 "SELECT COUNT(*) FROM lease6_relay_id"},
525 "SELECT COUNT(*) FROM lease6_remote_id"},
556 for (
size_t i = 0; i < count; ++i) {
577 std::string result =
"";
580 for (
size_t i = 0; i < count; ++i) {
582 if (!result.empty()) {
589 if (result.empty()) {
615 static const size_t ADDRESS_COL = 0;
616 static const size_t HWADDR_COL = 1;
617 static const size_t CLIENT_ID_COL = 2;
618 static const size_t VALID_LIFETIME_COL = 3;
619 static const size_t EXPIRE_COL = 4;
620 static const size_t SUBNET_ID_COL = 5;
621 static const size_t FQDN_FWD_COL = 6;
622 static const size_t FQDN_REV_COL = 7;
623 static const size_t HOSTNAME_COL = 8;
624 static const size_t STATE_COL = 9;
625 static const size_t USER_CONTEXT_COL = 10;
626 static const size_t RELAY_ID_COL = 11;
627 static const size_t REMOTE_ID_COL = 12;
628 static const size_t POOL_ID_COL = 13;
631 static const size_t LEASE_COLUMNS = 14;
640 client_id_length_(0), client_id_null_(
MLM_FALSE),
641 subnet_id_(0), pool_id_(0), valid_lifetime_(0),
642 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
643 state_(0), user_context_length_(0),
644 user_context_null_(
MLM_FALSE), relay_id_length_(0),
645 relay_id_null_(
MLM_FALSE), remote_id_length_(0),
647 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
648 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
649 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
650 memset(user_context_, 0,
sizeof(user_context_));
651 memset(relay_id_buffer_, 0,
sizeof(relay_id_buffer_));
652 memset(remote_id_buffer_, 0,
sizeof(remote_id_buffer_));
653 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
656 columns_[ADDRESS_COL] =
"address";
657 columns_[HWADDR_COL] =
"hwaddr";
658 columns_[CLIENT_ID_COL] =
"client_id";
659 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
660 columns_[EXPIRE_COL] =
"expire";
661 columns_[SUBNET_ID_COL] =
"subnet_id";
662 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
663 columns_[FQDN_REV_COL] =
"fqdn_rev";
664 columns_[HOSTNAME_COL] =
"hostname";
665 columns_[STATE_COL] =
"state";
666 columns_[USER_CONTEXT_COL] =
"user_context";
667 columns_[RELAY_ID_COL] =
"relay_id";
668 columns_[REMOTE_ID_COL] =
"remote_id";
669 columns_[POOL_ID_COL] =
"pool_id";
670 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
692 memset(bind_, 0,
sizeof(bind_));
701 addr4_ = lease_->addr_.toUint32();
702 bind_[0].buffer_type = MYSQL_TYPE_LONG;
703 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
711 hwaddr_ = hwaddr->hwaddr_;
712 hwaddr_length_ = hwaddr->hwaddr_.size();
719 if (hwaddr_.empty()) {
723 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
724 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
725 bind_[1].buffer_length = hwaddr_length_;
726 bind_[1].length = &hwaddr_length_;
728 bind_[1].buffer_type = MYSQL_TYPE_NULL;
735 bind_[1].buffer = NULL;
736 bind_[1].is_null = &hwaddr_null_;
740 if (lease_->client_id_) {
741 client_id_ = lease_->client_id_->getClientId();
742 client_id_length_ = client_id_.size();
749 if (client_id_.empty()) {
750 client_id_.resize(1);
753 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
754 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
755 bind_[2].buffer_length = client_id_length_;
756 bind_[2].length = &client_id_length_;
760 bind_[2].buffer_type = MYSQL_TYPE_NULL;
767 bind_[2].buffer = NULL;
768 bind_[2].is_null = &client_id_null_;
772 bind_[3].buffer_type = MYSQL_TYPE_LONG;
773 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
786 uint32_t valid_lft = lease_->valid_lft_;
792 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
793 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
794 bind_[4].buffer_length =
sizeof(expire_);
800 bind_[5].buffer_type = MYSQL_TYPE_LONG;
801 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
807 bind_[6].buffer_type = MYSQL_TYPE_TINY;
808 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
814 bind_[7].buffer_type = MYSQL_TYPE_TINY;
815 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
824 bind_[8].buffer_type = MYSQL_TYPE_STRING;
825 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
826 bind_[8].buffer_length = lease_->hostname_.length();
831 bind_[9].buffer_type = MYSQL_TYPE_LONG;
832 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
840 bind_[10].buffer_type = MYSQL_TYPE_STRING;
841 std::string ctx_txt = ctx->str();
843 bind_[10].buffer = user_context_;
844 bind_[10].buffer_length = ctx_txt.length();
848 bind_[10].buffer_type = MYSQL_TYPE_NULL;
852 relay_id_ = lease_->relay_id_;
853 if (!relay_id_.empty()) {
854 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
855 bind_[11].buffer =
reinterpret_cast<char*
>(&relay_id_[0]);
856 relay_id_length_ = relay_id_.size();
857 bind_[11].buffer_length = relay_id_length_;
858 bind_[11].length = &relay_id_length_;
860 bind_[11].buffer_type = MYSQL_TYPE_NULL;
862 bind_[11].buffer = NULL;
863 bind_[11].is_null = &relay_id_null_;
867 remote_id_ = lease_->remote_id_;
868 if (!remote_id_.empty()) {
869 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
870 bind_[12].buffer =
reinterpret_cast<char*
>(&remote_id_[0]);
871 remote_id_length_ = remote_id_.size();
872 bind_[12].buffer_length = remote_id_length_;
873 bind_[12].length = &remote_id_length_;
875 bind_[12].buffer_type = MYSQL_TYPE_NULL;
877 bind_[12].buffer = NULL;
878 bind_[12].is_null = &remote_id_null_;
883 bind_[13].buffer_type = MYSQL_TYPE_LONG;
884 bind_[13].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
893 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
895 }
catch (
const std::exception& ex) {
897 "Could not create bind array from Lease4: "
898 << lease_->addr_.toText() <<
", reason: " << ex.what());
903 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
918 memset(bind_, 0,
sizeof(bind_));
921 bind_[0].buffer_type = MYSQL_TYPE_LONG;
922 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
929 hwaddr_length_ =
sizeof(hwaddr_buffer_);
930 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
931 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
932 bind_[1].buffer_length = hwaddr_length_;
933 bind_[1].length = &hwaddr_length_;
934 bind_[1].is_null = &hwaddr_null_;
937 client_id_length_ =
sizeof(client_id_buffer_);
938 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
939 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
940 bind_[2].buffer_length = client_id_length_;
941 bind_[2].length = &client_id_length_;
942 bind_[2].is_null = &client_id_null_;
947 bind_[3].buffer_type = MYSQL_TYPE_LONG;
948 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
954 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
955 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
956 bind_[4].buffer_length =
sizeof(expire_);
961 bind_[5].buffer_type = MYSQL_TYPE_LONG;
962 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
968 bind_[6].buffer_type = MYSQL_TYPE_TINY;
969 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
975 bind_[7].buffer_type = MYSQL_TYPE_TINY;
976 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
985 hostname_length_ =
sizeof(hostname_buffer_);
986 bind_[8].buffer_type = MYSQL_TYPE_STRING;
987 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
988 bind_[8].buffer_length = hostname_length_;
989 bind_[8].length = &hostname_length_;
994 bind_[9].buffer_type = MYSQL_TYPE_LONG;
995 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
1002 user_context_length_ =
sizeof(user_context_);
1003 bind_[10].buffer_type = MYSQL_TYPE_STRING;
1004 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
1005 bind_[10].buffer_length = user_context_length_;
1006 bind_[10].length = &user_context_length_;
1007 bind_[10].is_null = &user_context_null_;
1010 relay_id_length_ =
sizeof(relay_id_buffer_);
1011 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
1012 bind_[11].buffer =
reinterpret_cast<char*
>(relay_id_buffer_);
1013 bind_[11].buffer_length = relay_id_length_;
1014 bind_[11].length = &relay_id_length_;
1015 bind_[11].is_null = &relay_id_null_;
1018 remote_id_length_ =
sizeof(remote_id_buffer_);
1019 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1020 bind_[12].buffer =
reinterpret_cast<char*
>(remote_id_buffer_);
1021 bind_[12].buffer_length = remote_id_length_;
1022 bind_[12].length = &remote_id_length_;
1023 bind_[12].is_null = &remote_id_null_;
1026 bind_[13].buffer_type = MYSQL_TYPE_LONG;
1027 bind_[13].buffer =
reinterpret_cast<char*
>(&pool_id_);
1036 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
1040 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1057 uint32_t valid_lft = valid_lifetime_;
1065 client_id_length_ = 0;
1070 std::string hostname(hostname_buffer_,
1071 hostname_buffer_ + hostname_length_);
1080 std::string user_context;
1082 user_context_[user_context_length_] =
'\0';
1083 user_context.assign(user_context_);
1088 if (!user_context.empty()) {
1092 <<
"' is not a JSON map");
1096 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
1099 valid_lifetime_, cltt,
1100 subnet_id_, fqdn_fwd_,
1101 fqdn_rev_, hostname));
1104 lease->state_ = state_;
1107 lease->setContext(ctx);
1112 lease->relay_id_.assign(relay_id_buffer_,
1113 relay_id_buffer_ + relay_id_length_);
1118 lease->remote_id_.assign(remote_id_buffer_,
1119 remote_id_buffer_ + remote_id_length_);
1123 lease->pool_id_ = pool_id_;
1148 MYSQL_BIND bind_[LEASE_COLUMNS];
1149 std::string columns_[LEASE_COLUMNS];
1150 my_bool error_[LEASE_COLUMNS];
1152 std::vector<uint8_t> hwaddr_;
1154 unsigned long hwaddr_length_;
1156 std::vector<uint8_t> client_id_;
1158 unsigned long client_id_length_;
1161 uint32_t subnet_id_;
1163 uint32_t valid_lifetime_;
1167 unsigned long hostname_length_;
1170 unsigned long user_context_length_;
1172 std::vector<uint8_t> relay_id_;
1174 unsigned long relay_id_length_;
1176 std::vector<uint8_t> remote_id_;
1178 unsigned long remote_id_length_;
1201 static const size_t ADDRESS_COL = 0;
1202 static const size_t DUID_COL = 1;
1203 static const size_t VALID_LIFETIME_COL = 2;
1204 static const size_t EXPIRE_COL = 3;
1205 static const size_t SUBNET_ID_COL = 4;
1206 static const size_t PREF_LIFETIME_COL = 5;
1207 static const size_t LEASE_TYPE_COL = 6;
1208 static const size_t IAID_COL = 7;
1209 static const size_t PREFIX_LEN_COL = 8;
1210 static const size_t FQDN_FWD_COL = 9;
1211 static const size_t FQDN_REV_COL = 10;
1212 static const size_t HOSTNAME_COL = 11;
1213 static const size_t HWADDR_COL = 12;
1214 static const size_t HWTYPE_COL = 13;
1215 static const size_t HWADDR_SOURCE_COL = 14;
1216 static const size_t STATE_COL = 15;
1217 static const size_t USER_CONTEXT_COL = 16;
1218 static const size_t POOL_ID_COL = 17;
1221 static const size_t LEASE_COLUMNS = 18;
1230 hwaddr_null_(
MLM_FALSE), duid_length_(0),
1231 iaid_(0), lease_type_(0), prefix_len_(0),
1232 pref_lifetime_(0), subnet_id_(0), pool_id_(0),
1233 valid_lifetime_(0), fqdn_fwd_(false), fqdn_rev_(false),
1234 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
1235 state_(0), user_context_length_(0),
1237 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
1238 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
1239 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
1240 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
1241 memset(user_context_, 0,
sizeof(user_context_));
1242 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
1245 columns_[ADDRESS_COL] =
"address";
1246 columns_[DUID_COL] =
"duid";
1247 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
1248 columns_[EXPIRE_COL] =
"expire";
1249 columns_[SUBNET_ID_COL] =
"subnet_id";
1250 columns_[PREF_LIFETIME_COL] =
"pref_lifetime";
1251 columns_[LEASE_TYPE_COL] =
"lease_type";
1252 columns_[IAID_COL] =
"iaid";
1253 columns_[PREFIX_LEN_COL] =
"prefix_len";
1254 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
1255 columns_[FQDN_REV_COL] =
"fqdn_rev";
1256 columns_[HOSTNAME_COL] =
"hostname";
1257 columns_[HWADDR_COL] =
"hwaddr";
1258 columns_[HWTYPE_COL] =
"hwtype";
1259 columns_[HWADDR_SOURCE_COL] =
"hwaddr_source";
1260 columns_[STATE_COL] =
"state";
1261 columns_[USER_CONTEXT_COL] =
"user_context";
1262 columns_[POOL_ID_COL] =
"pool_id";
1263 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1284 memset(bind_, 0,
sizeof(bind_));
1288 addr6_ = lease->addr_.toBytes();
1289 if (addr6_.size() != 16) {
1294 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1295 bind_[0].buffer =
reinterpret_cast<char*
>(&addr6_[0]);
1296 bind_[0].buffer_length = 16;
1297 bind_[0].length = &addr6_length_;
1302 if (!lease_->duid_) {
1304 <<
" is missing mandatory client-id.");
1306 duid_ = lease_->duid_->getDuid();
1307 duid_length_ = duid_.size();
1309 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1310 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
1311 bind_[1].buffer_length = duid_length_;
1312 bind_[1].length = &duid_length_;
1317 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1318 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1331 uint32_t valid_lft = lease_->valid_lft_;
1337 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1338 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1339 bind_[3].buffer_length =
sizeof(expire_);
1345 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1346 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1353 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1354 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1361 lease_type_ = lease_->type_;
1362 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1363 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1370 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1371 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1378 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1379 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1385 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1386 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1392 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1393 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1399 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1400 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1401 bind_[11].buffer_length = lease_->hostname_.length();
1408 hwaddr_ = hwaddr->hwaddr_;
1409 hwaddr_length_ = hwaddr->hwaddr_.size();
1416 if (hwaddr_.empty()) {
1420 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1421 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1422 bind_[12].buffer_length = hwaddr_length_;
1423 bind_[12].length = &hwaddr_length_;
1425 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1432 bind_[12].buffer = NULL;
1433 bind_[12].is_null = &hwaddr_null_;
1438 hwtype_ = lease->hwaddr_->htype_;
1439 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1440 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1444 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1451 bind_[13].buffer = NULL;
1452 bind_[13].is_null = &hwaddr_null_;
1457 hwaddr_source_ = lease->hwaddr_->source_;
1458 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1459 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1463 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1470 bind_[14].buffer = NULL;
1471 bind_[14].is_null = &hwaddr_null_;
1475 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1476 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1484 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1485 std::string ctx_txt = ctx->str();
1487 bind_[16].buffer = user_context_;
1488 bind_[16].buffer_length = ctx_txt.length();
1492 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1497 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1498 bind_[17].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
1507 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1509 }
catch (
const std::exception& ex) {
1511 "Could not create bind array from Lease6: "
1512 << lease_->addr_.toText() <<
", reason: " << ex.what());
1517 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1535 memset(bind_, 0,
sizeof(bind_));
1539 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1540 bind_[0].buffer =
reinterpret_cast<char*
>(addr6_buffer_);
1541 bind_[0].buffer_length = addr6_length_;
1542 bind_[0].length = &addr6_length_;
1547 duid_length_ =
sizeof(duid_buffer_);
1548 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1549 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1550 bind_[1].buffer_length = duid_length_;
1551 bind_[1].length = &duid_length_;
1556 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1557 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1563 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1564 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1565 bind_[3].buffer_length =
sizeof(expire_);
1570 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1571 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1577 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1578 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1584 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1585 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1591 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1592 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1598 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1599 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1605 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1606 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1612 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1613 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1619 hostname_length_ =
sizeof(hostname_buffer_);
1620 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1621 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1622 bind_[11].buffer_length = hostname_length_;
1623 bind_[11].length = &hostname_length_;
1629 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1630 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1631 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1632 bind_[12].buffer_length = hwaddr_length_;
1633 bind_[12].length = &hwaddr_length_;
1634 bind_[12].is_null = &hwaddr_null_;
1637 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1638 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1642 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1643 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1647 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1648 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1655 user_context_length_ =
sizeof(user_context_);
1656 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1657 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1658 bind_[16].buffer_length = user_context_length_;
1659 bind_[16].length = &user_context_length_;
1660 bind_[16].is_null = &user_context_null_;
1663 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1664 bind_[17].buffer =
reinterpret_cast<char*
>(&pool_id_);
1673 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1677 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1693 std::string address = addr.
toText();
1698 switch (lease_type_) {
1713 static_cast<int>(lease_type_) <<
") for lease with "
1714 <<
"address " << address <<
". Only 0, 1, or 2 are "
1723 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1727 std::string hostname(hostname_buffer_,
1728 hostname_buffer_ + hostname_length_);
1733 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1734 hwaddr->source_ = hwaddr_source_;
1738 std::string user_context;
1740 user_context_[user_context_length_] =
'\0';
1741 user_context.assign(user_context_);
1746 if (!user_context.empty()) {
1750 <<
"' is not a JSON map");
1756 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1758 valid_lifetime_, subnet_id_,
1759 fqdn_fwd_, fqdn_rev_,
1764 uint32_t valid_lft = valid_lifetime_;
1770 result->cltt_ = cltt;
1771 result->current_cltt_ = cltt;
1774 result->state_ = state_;
1777 result->setContext(ctx);
1781 result->pool_id_ = pool_id_;
1805 std::vector<uint8_t> addr6_;
1806 uint8_t addr6_buffer_[16];
1807 unsigned long addr6_length_;
1808 MYSQL_BIND bind_[LEASE_COLUMNS];
1809 std::string columns_[LEASE_COLUMNS];
1810 my_bool error_[LEASE_COLUMNS];
1812 std::vector<uint8_t> hwaddr_;
1814 unsigned long hwaddr_length_;
1816 std::vector<uint8_t> duid_;
1818 unsigned long duid_length_;
1821 uint8_t lease_type_;
1822 uint8_t prefix_len_;
1823 uint32_t pref_lifetime_;
1824 uint32_t subnet_id_;
1826 uint32_t valid_lifetime_;
1830 unsigned long hostname_length_;
1832 uint32_t hwaddr_source_;
1835 unsigned long user_context_length_;
1859 const bool fetch_type,
const bool fetch_pool =
false)
1860 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1861 fetch_type_(fetch_type), fetch_pool_(fetch_pool),
1864 bind_(fetch_type_ ? (fetch_pool_ ? 5 : 4) : (fetch_pool_ ? 4 : 3)),
1865 subnet_id_(0), pool_id_(0), lease_type_(
Lease::TYPE_NA),
1866 state_(
Lease::STATE_DEFAULT), state_count_(0) {
1867 validateStatement();
1880 const bool fetch_type,
const SubnetID& subnet_id)
1881 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1882 statement_(NULL), fetch_type_(fetch_type), fetch_pool_(false),
1885 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1886 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1888 validateStatement();
1904 const bool fetch_type,
const SubnetID& first_subnet_id,
1907 statement_index_(statement_index), statement_(NULL),
1908 fetch_type_(fetch_type), fetch_pool_(false),
1911 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1912 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1914 validateStatement();
1919 (void) mysql_stmt_free_result(statement_);
1932 MYSQL_BIND inbind[2];
1933 memset(inbind, 0,
sizeof(inbind));
1936 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1942 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1948 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1949 conn_.
checkError(status, statement_index_,
"unable to bind parameters");
1954 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1955 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1962 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1963 bind_[col].buffer =
reinterpret_cast<char*
>(&pool_id_);
1971 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1972 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1980 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1981 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1986 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1987 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1992 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1993 conn_.
checkError(status, statement_index_,
"outbound binding failed");
1997 conn_.
checkError(status, statement_index_,
"unable to execute");
2001 status = mysql_stmt_store_result(statement_);
2002 conn_.
checkError(status, statement_index_,
"results storage failed");
2021 bool have_row =
false;
2022 int status = mysql_stmt_fetch(statement_);
2028 if (state_count_ >= 0) {
2032 if (!negative_count_) {
2033 negative_count_ =
true;
2038 }
else if (status != MYSQL_NO_DATA) {
2039 conn_.
checkError(status, statement_index_,
"getNextRow failed");
2050 void validateStatement() {
2053 " - invalid statement index" << statement_index_);
2063 size_t statement_index_;
2066 MYSQL_STMT *statement_;
2075 std::vector<MYSQL_BIND> bind_;
2078 uint32_t subnet_id_;
2084 uint32_t lease_type_;
2090 int64_t state_count_;
2093 static bool negative_count_;
2097bool MySqlLeaseStatsQuery::negative_count_ =
false;
2104 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
2109MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
2116 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2117 if (!mgr_.pool_->pool_.empty()) {
2118 ctx_ = mgr_.pool_->pool_.back();
2119 mgr_.pool_->pool_.pop_back();
2123 ctx_ = mgr_.createContext();
2127 if (mgr_.pool_->pool_.empty()) {
2130 ctx_ = mgr_.pool_->pool_.back();
2134MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
2137 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2138 mgr_.pool_->pool_.push_back(ctx_);
2145MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::MySqlLeaseTrackingContextAlloc(
2152 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2153 if (mgr_.hasCallbacks() && !mgr_.tryLock(lease)) {
2156 if (!mgr_.pool_->pool_.empty()) {
2157 ctx_ = mgr_.pool_->pool_.back();
2158 mgr_.pool_->pool_.pop_back();
2162 ctx_ = mgr_.createContext();
2166 if (mgr_.pool_->pool_.empty()) {
2169 ctx_ = mgr_.pool_->pool_.back();
2173MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::~MySqlLeaseTrackingContextAlloc() {
2176 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2177 if (mgr_.hasCallbacks()) {
2178 mgr_.unlock(lease_);
2180 mgr_.pool_->pool_.push_back(ctx_);
2194 timer_name_ =
"MySqlLeaseMgr[";
2195 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
2196 timer_name_ +=
"]DbReconnectTimer";
2218 bool reopened =
false;
2220 const std::string timer_name = db_reconnect_ctl->timerName();
2227 }
catch (
const std::exception& ex) {
2243 if (!db_reconnect_ctl->checkRetries()) {
2246 .arg(db_reconnect_ctl->maxRetries());
2259 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
2260 .arg(db_reconnect_ctl->maxRetries())
2261 .arg(db_reconnect_ctl->retryInterval());
2267 db_reconnect_ctl->retryInterval(),
2285 ctx->conn_.makeReconnectCtl(timer_name_);
2288 ctx->conn_.openDatabase();
2291 if (ctx->conn_.getTls()) {
2292 std::string cipher = ctx->conn_.getTlsCipher();
2293 if (cipher.empty()) {
2303 ctx->conn_.prepareStatements(tagged_statements.begin(),
2304 tagged_statements.end());
2316 std::stringstream tmp;
2319 tmp <<
", library " << mysql_get_client_info();
2329 StatementIndex stindex,
2330 std::vector<MYSQL_BIND>& bind) {
2332 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), &bind[0]);
2333 checkError(ctx, status, stindex,
"unable to bind parameters");
2342 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
2345 checkError(ctx, status, stindex,
"unable to execute");
2355 .arg(lease->addr_.toText());
2358 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2362 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2369 lease->updateCurrentExpirationTime();
2382 .arg(lease->addr_.toText())
2388 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2392 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2399 lease->updateCurrentExpirationTime();
2438template <
typename Exchange,
typename LeaseCollection>
2441 StatementIndex stindex,
2444 LeaseCollection& result,
2445 bool single)
const {
2450 status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
2451 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2456 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2457 status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &outbind[0]);
2458 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2462 checkError(ctx, status, stindex,
"unable to execute");
2466 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
2467 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2474 while ((status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex))) == 0) {
2476 result.push_back(exchange->getLeaseData());
2481 ctx->conn_.text_statements_[stindex] <<
">");
2484 if (single && (++count > 1)) {
2486 "database where only one was expected for query "
2487 << ctx->conn_.text_statements_[stindex]);
2494 checkError(ctx, status, stindex,
"unable to fetch results");
2495 }
else if (status == MYSQL_DATA_TRUNCATED) {
2498 <<
" returned truncated data: columns affected are "
2499 << exchange->getErrorColumns());
2505 StatementIndex stindex, MYSQL_BIND* bind,
2513 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2516 if (collection.empty()) {
2519 result = *collection.begin();
2525 StatementIndex stindex, MYSQL_BIND* bind,
2533 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2536 if (collection.empty()) {
2539 result = *collection.begin();
2552 MYSQL_BIND inbind[1];
2553 memset(inbind, 0,
sizeof(inbind));
2556 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2557 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2564 MySqlLeaseContextAlloc get_context(*
this);
2578 MYSQL_BIND inbind[1];
2579 memset(inbind, 0,
sizeof(inbind));
2581 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2583 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2587 uint8_t single_byte_data = 0;
2594 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2595 : &single_byte_data;
2597 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2598 inbind[0].buffer_length = hwaddr_length;
2599 inbind[0].length = &hwaddr_length;
2605 MySqlLeaseContextAlloc get_context(*
this);
2620 MYSQL_BIND inbind[2];
2621 memset(inbind, 0,
sizeof(inbind));
2623 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2625 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2629 std::vector<uint8_t> single_byte_vec(1);
2636 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2637 : &single_byte_vec[0];
2639 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2640 inbind[0].buffer_length = hwaddr_length;
2641 inbind[0].length = &hwaddr_length;
2643 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2644 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2651 MySqlLeaseContextAlloc get_context(*
this);
2665 MYSQL_BIND inbind[1];
2666 memset(inbind, 0,
sizeof(inbind));
2668 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2670 std::vector<uint8_t> client_data = clientid.
getClientId();
2671 unsigned long client_data_length = client_data.size();
2675 if (client_data.empty()) {
2676 client_data.resize(1);
2679 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2680 inbind[0].buffer_length = client_data_length;
2681 inbind[0].length = &client_data_length;
2687 MySqlLeaseContextAlloc get_context(*
this);
2702 MYSQL_BIND inbind[2];
2703 memset(inbind, 0,
sizeof(inbind));
2705 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2707 std::vector<uint8_t> client_data = clientid.
getClientId();
2708 unsigned long client_data_length = client_data.size();
2712 if (client_data.empty()) {
2713 client_data.resize(1);
2716 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2717 inbind[0].buffer_length = client_data_length;
2718 inbind[0].length = &client_data_length;
2720 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2721 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2728 MySqlLeaseContextAlloc get_context(*
this);
2742 MYSQL_BIND inbind[1];
2743 memset(inbind, 0,
sizeof(inbind));
2746 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2747 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2754 MySqlLeaseContextAlloc get_context(*
this);
2768 MYSQL_BIND inbind[1];
2769 memset(inbind, 0,
sizeof(inbind));
2772 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2773 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2774 inbind[0].buffer_length = hostname.length();
2780 MySqlLeaseContextAlloc get_context(*
this);
2795 MySqlLeaseContextAlloc get_context(*
this);
2798 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2807 if (!lower_bound_address.
isV4()) {
2809 "retrieving leases from the lease database, got "
2810 << lower_bound_address);
2815 .arg(lower_bound_address.
toText());
2818 MYSQL_BIND inbind[2];
2819 memset(inbind, 0,
sizeof(inbind));
2822 uint32_t lb_address_data = lower_bound_address.
toUint32();
2823 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2824 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2828 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
2829 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2830 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
2837 MySqlLeaseContextAlloc get_context(*
this);
2853 MYSQL_BIND inbind[2];
2854 memset(inbind, 0,
sizeof(inbind));
2857 std::vector<uint8_t>addr6 = addr.
toBytes();
2858 if (addr6.size() != 16) {
2862 unsigned long addr6_length = 16;
2863 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2864 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
2865 inbind[0].buffer_length = 16;
2866 inbind[0].length = &addr6_length;
2869 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2870 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2876 MySqlLeaseContextAlloc get_context(*
this);
2886 uint32_t iaid)
const {
2893 MYSQL_BIND inbind[3];
2894 memset(inbind, 0,
sizeof(inbind));
2908 const vector<uint8_t>& duid_vector = duid.
getDuid();
2909 unsigned long duid_length = duid_vector.size();
2916 uint8_t single_byte_data = 0;
2917 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2918 : &single_byte_data;
2920 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2921 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2922 inbind[0].buffer_length = duid_length;
2923 inbind[0].length = &duid_length;
2926 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2927 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2931 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2932 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2939 MySqlLeaseContextAlloc get_context(*
this);
2949 uint32_t iaid,
SubnetID subnet_id)
const {
2957 MYSQL_BIND inbind[4];
2958 memset(inbind, 0,
sizeof(inbind));
2962 const vector<uint8_t>& duid_vector = duid.
getDuid();
2963 unsigned long duid_length = duid_vector.size();
2964 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2965 inbind[0].buffer =
reinterpret_cast<char*
>(
2966 const_cast<uint8_t*
>(&duid_vector[0]));
2967 inbind[0].buffer_length = duid_length;
2968 inbind[0].length = &duid_length;
2971 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2972 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2976 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2977 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2981 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2982 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2989 MySqlLeaseContextAlloc get_context(*
this);
3003 MYSQL_BIND inbind[1];
3004 memset(inbind, 0,
sizeof(inbind));
3007 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3008 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
3015 MySqlLeaseContextAlloc get_context(*
this);
3030 .arg(lower_bound_address.
toText())
3034 if (!lower_bound_address.
isV6()) {
3036 "retrieving leases from the lease database, got "
3037 << lower_bound_address);
3042 MYSQL_BIND inbind[3];
3043 memset(inbind, 0,
sizeof(inbind));
3046 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3047 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
3051 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
3052 unsigned long lb_addr_size = lb_addr_data.size();
3053 if (lb_addr_size != 16) {
3056 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
3057 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
3058 inbind[1].buffer_length = lb_addr_size;
3059 inbind[1].length = &lb_addr_size;
3062 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
3063 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3064 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
3068 MySqlLeaseContextAlloc get_context(*
this);
3084 MySqlLeaseContextAlloc get_context(*
this);
3087 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
3098 MYSQL_BIND inbind[1];
3099 memset(inbind, 0,
sizeof(inbind));
3101 const vector<uint8_t>& duid_vector = duid.
getDuid();
3102 unsigned long duid_length = duid_vector.size();
3104 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3105 inbind[0].buffer =
reinterpret_cast<char*
>(
3106 const_cast<uint8_t*
>(&duid_vector[0]));
3107 inbind[0].buffer_length = duid_length;
3108 inbind[0].length = &duid_length;
3113 MySqlLeaseContextAlloc get_context(*
this);
3127 MYSQL_BIND inbind[1];
3128 memset(inbind, 0,
sizeof(inbind));
3131 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3132 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
3133 inbind[0].buffer_length = hostname.length();
3139 MySqlLeaseContextAlloc get_context(*
this);
3151 if (!lower_bound_address.
isV6()) {
3153 "retrieving leases from the lease database, got "
3154 << lower_bound_address);
3159 .arg(lower_bound_address.
toText());
3162 MYSQL_BIND inbind[2];
3163 memset(inbind, 0,
sizeof(inbind));
3166 std::vector<uint8_t>lb_addr = lower_bound_address.
toBytes();
3167 if (lb_addr.size() != 16) {
3171 unsigned long lb_addr_length = 16;
3172 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3173 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_addr[0]);
3174 inbind[0].buffer_length = 16;
3175 inbind[0].length = &lb_addr_length;
3178 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
3179 inbind[1].buffer_type = MYSQL_TYPE_LONG;
3180 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
3187 MySqlLeaseContextAlloc get_context(*
this);
3197 const size_t max_leases)
const {
3205 const size_t max_leases)
const {
3211template<
typename LeaseCollection>
3213MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
3214 const size_t max_leases,
3215 StatementIndex statement_index)
const {
3217 MYSQL_BIND inbind[3];
3218 memset(inbind, 0,
sizeof(inbind));
3222 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3223 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3227 MYSQL_TIME expire_time;
3229 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3230 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3231 inbind[1].buffer_length =
sizeof(expire_time);
3235 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
3236 std::numeric_limits<uint32_t>::max();
3237 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3238 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
3242 MySqlLeaseContextAlloc get_context(*
this);
3246 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
3253template <
typename LeasePtr>
3256 StatementIndex stindex,
3261 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3262 checkError(ctx, status, stindex,
"unable to bind parameters");
3266 checkError(ctx, status, stindex,
"unable to execute");
3270 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex));
3273 if (affected_rows == 1) {
3278 if (affected_rows == 0) {
3280 lease->addr_.toText() <<
" as it does not exist");
3286 "that had the address " << lease->addr_.toText());
3294 .arg(lease->addr_.toText());
3297 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3301 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
3304 MYSQL_BIND inbind[2];
3305 memset(inbind, 0,
sizeof(inbind));
3307 uint32_t addr4 = lease->addr_.toUint32();
3308 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3309 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3312 bind.push_back(inbind[0]);
3317 uint32_t valid_lft = lease->current_valid_lft_;
3323 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3324 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3325 inbind[1].buffer_length =
sizeof(expire);
3327 bind.push_back(inbind[1]);
3330 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3333 lease->updateCurrentExpirationTime();
3346 .arg(lease->addr_.toText())
3354 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3358 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
3361 MYSQL_BIND inbind[2];
3362 memset(inbind, 0,
sizeof(inbind));
3365 std::vector<uint8_t>addr6 = lease->addr_.toBytes();
3366 if (addr6.size() != 16) {
3370 unsigned long addr6_length = 16;
3371 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3372 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3373 inbind[0].buffer_length = 16;
3374 inbind[0].length = &addr6_length;
3376 bind.push_back(inbind[0]);
3381 uint32_t valid_lft = lease->current_valid_lft_;
3387 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3388 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3389 inbind[1].buffer_length =
sizeof(expire);
3391 bind.push_back(inbind[1]);
3394 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3397 lease->updateCurrentExpirationTime();
3401 switch (recorded_action) {
3429 StatementIndex stindex,
3432 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3433 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3437 checkError(ctx, status, stindex,
"unable to execute");
3441 return (
static_cast<uint64_t
>(mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex))));
3451 MYSQL_BIND inbind[2];
3452 memset(inbind, 0,
sizeof(inbind));
3456 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3457 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3463 uint32_t valid_lft = lease->current_valid_lft_;
3469 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3470 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3471 inbind[1].buffer_length =
sizeof(expire);
3474 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3477 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE4, inbind);
3480 if (affected_rows == 1) {
3488 if (affected_rows == 0) {
3495 "that had the address " << lease->addr_.toText());
3508 MYSQL_BIND inbind[2];
3509 memset(inbind, 0,
sizeof(inbind));
3512 std::vector<uint8_t>addr6 = addr.
toBytes();
3513 if (addr6.size() != 16) {
3517 unsigned long addr6_length = 16;
3518 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3519 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3520 inbind[0].buffer_length = 16;
3521 inbind[0].length = &addr6_length;
3526 uint32_t valid_lft = lease->current_valid_lft_;
3532 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3533 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3534 inbind[1].buffer_length =
sizeof(expire);
3537 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3540 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE6, inbind);
3543 if (affected_rows == 1) {
3555 if (affected_rows == 0) {
3562 "that had the address " << lease->addr_.toText());
3580MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3581 StatementIndex statement_index) {
3583 MYSQL_BIND inbind[2];
3584 memset(inbind, 0,
sizeof(inbind));
3588 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3589 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3593 MYSQL_TIME expire_time;
3595 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3596 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3597 inbind[1].buffer_length =
sizeof(expire_time);
3600 MySqlLeaseContextAlloc get_context(*
this);
3604 uint64_t deleted_leases = deleteLeaseCommon(ctx, statement_index, inbind);
3606 .arg(deleted_leases);
3608 return (deleted_leases);
3612MySqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
3614 if (!user_context) {
3619 MySqlLeaseContextAlloc get_context(*
this);
3631 std::string limit_text;
3632 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3634 limit_text = result[0]->getString();
3641MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3646MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3651MySqlLeaseMgr::isJsonSupported()
const {
3653 MySqlLeaseContextAlloc get_context(*
this);
3663 bool json_supported(
false);
3666 json_supported = result[0]->getBool();
3669 return json_supported;
3673MySqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
3676 MySqlLeaseContextAlloc get_context(*
this);
3684 in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(ltype));
3687 MySqlBinding::createInteger<int64_t>()
3694 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3696 count = result[0]->getInteger<int64_t>();
3703MySqlLeaseMgr::recountClassLeases4() {
3708MySqlLeaseMgr::recountClassLeases6() {
3713MySqlLeaseMgr::clearClassLeaseCounts() {
3718MySqlLeaseMgr::writeLeases4(
const std::string&) {
3723MySqlLeaseMgr::writeLeases6(
const std::string&) {
3730 MySqlLeaseContextAlloc get_context(*
this);
3743 MySqlLeaseContextAlloc get_context(*
this);
3756 MySqlLeaseContextAlloc get_context(*
this);
3771 MySqlLeaseContextAlloc get_context(*
this);
3786 MySqlLeaseContextAlloc get_context(*
this);
3799 MySqlLeaseContextAlloc get_context(*
this);
3812 MySqlLeaseContextAlloc get_context(*
this);
3827 MySqlLeaseContextAlloc get_context(*
this);
3854 MySqlLeaseContextAlloc get_context(*
this);
3857 std::string name =
"";
3859 name = ctx->conn_.getParameter(
"name");
3868 return (std::string(
"MySQL Database"));
3871std::pair<uint32_t, uint32_t>
3893 int status, StatementIndex index,
3894 const char* what)
const {
3895 ctx->conn_.checkError(status, index, what);
3900 deleteRelayId6(addr);
3901 deleteRemoteId6(addr);
3905MySqlLeaseMgr::deleteRelayId6(
const IOAddress& addr) {
3907 MySqlLeaseContextAlloc get_context(*
this);
3912 memset(bind, 0,
sizeof(bind));
3914 std::vector<uint8_t> addr_data = addr.
toBytes();
3916 unsigned long addr_size = addr_data.size();
3917 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3918 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3919 bind[0].buffer_length = addr_size;
3920 bind[0].length = &addr_size;
3926 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3927 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3931 checkError(ctx, status, stindex,
"unable to execute");
3935MySqlLeaseMgr::deleteRemoteId6(
const IOAddress& addr) {
3937 MySqlLeaseContextAlloc get_context(*
this);
3942 memset(bind, 0,
sizeof(bind));
3944 std::vector<uint8_t> addr_data = addr.
toBytes();
3946 unsigned long addr_size = addr_data.size();
3947 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3948 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3949 bind[0].buffer_length = addr_size;
3950 bind[0].length = &addr_size;
3956 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3957 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3961 checkError(ctx, status, stindex,
"unable to execute");
3966 const vector<uint8_t>& relay_id) {
3968 MySqlLeaseContextAlloc get_context(*
this);
3973 memset(bind, 0,
sizeof(bind));
3975 unsigned long relay_id_size = relay_id.size();
3976 if (relay_id_size == 0) {
3979 std::vector<uint8_t> relay_id_data = relay_id;
3980 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3981 bind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
3982 bind[0].buffer_length = relay_id_size;
3983 bind[0].length = &relay_id_size;
3986 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
3987 unsigned long lease_addr_length = lease_addr_data.size();
3988 if (lease_addr_length != 16) {
3991 bind[1].buffer_type = MYSQL_TYPE_BLOB;
3992 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
3993 bind[1].buffer_length = lease_addr_length;
3994 bind[1].length = &lease_addr_length;
4000 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
4001 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
4005 checkError(ctx, status, stindex,
"unable to execute");
4010 const vector<uint8_t>& remote_id) {
4012 MySqlLeaseContextAlloc get_context(*
this);
4017 memset(bind, 0,
sizeof(bind));
4019 unsigned long remote_id_size = remote_id.size();
4020 if (remote_id_size == 0) {
4023 std::vector<uint8_t> remote_id_data = remote_id;
4024 bind[0].buffer_type = MYSQL_TYPE_BLOB;
4025 bind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4026 bind[0].buffer_length = remote_id_size;
4027 bind[0].length = &remote_id_size;
4030 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
4031 unsigned long lease_addr_length = lease_addr_data.size();
4032 if (lease_addr_length != 16) {
4035 bind[1].buffer_type = MYSQL_TYPE_BLOB;
4036 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
4037 bind[1].buffer_length = lease_addr_length;
4038 bind[1].length = &lease_addr_length;
4044 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
4045 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
4049 checkError(ctx, status, stindex,
"unable to execute");
4056 std::stringstream tmp;
4059 for (
auto const& it :
id) {
4063 tmp << std::setw(2) << std::setfill(
'0')
4064 <<
static_cast<unsigned int>(it);
4076 const time_t& qry_start_time ,
4077 const time_t& qry_end_time ) {
4081 .arg(lower_bound_address.
toText())
4082 .arg(idToText(relay_id))
4083 .arg(qry_start_time)
4087 if (!lower_bound_address.
isV4()) {
4089 "retrieving leases from the lease database, got "
4090 << lower_bound_address);
4094 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4098 bool have_qst = (qry_start_time > 0);
4099 bool have_qet = (qry_end_time > 0);
4102 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4107 size_t bindings = 3;
4114 MYSQL_BIND inbind[bindings];
4115 memset(inbind, 0,
sizeof(inbind));
4117 std::vector<uint8_t> relay_id_data = relay_id;
4118 unsigned long relay_id_length = relay_id.size();
4122 if (relay_id_data.empty()) {
4123 relay_id_data.resize(1);
4127 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4128 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4129 inbind[0].buffer_length = relay_id_length;
4130 inbind[0].length = &relay_id_length;
4133 uint32_t lb_address_data = lower_bound_address.
toUint32();
4134 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4135 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4140 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4142 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4143 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4144 inbind[index].is_unsigned =
MLM_TRUE;
4149 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4151 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4152 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4153 inbind[index].is_unsigned =
MLM_TRUE;
4158 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4159 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4160 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4161 inbind[index].is_unsigned =
MLM_TRUE;
4164 if (have_qst && !have_qet) {
4166 }
else if (have_qst && have_qet) {
4168 }
else if (!have_qst && have_qet) {
4176 MySqlLeaseContextAlloc get_context(*
this);
4179 getLeaseCollection(ctx, stindex, inbind, result);
4188 const time_t& qry_start_time ,
4189 const time_t& qry_end_time ) {
4193 .arg(lower_bound_address.
toText())
4194 .arg(idToText(remote_id))
4195 .arg(qry_start_time)
4199 if (!lower_bound_address.
isV4()) {
4201 "retrieving leases from the lease database, got "
4202 << lower_bound_address);
4206 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4210 bool have_qst = (qry_start_time > 0);
4211 bool have_qet = (qry_end_time > 0);
4214 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4219 size_t bindings = 3;
4226 MYSQL_BIND inbind[bindings];
4227 memset(inbind, 0,
sizeof(inbind));
4229 std::vector<uint8_t> remote_id_data = remote_id;
4230 unsigned long remote_id_length = remote_id.size();
4234 if (remote_id_data.empty()) {
4235 remote_id_data.resize(1);
4239 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4240 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4241 inbind[0].buffer_length = remote_id_length;
4242 inbind[0].length = &remote_id_length;
4245 uint32_t lb_address_data = lower_bound_address.
toUint32();
4246 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4247 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4252 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4254 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4255 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4256 inbind[index].is_unsigned =
MLM_TRUE;
4261 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4263 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4264 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4265 inbind[index].is_unsigned =
MLM_TRUE;
4270 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4271 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4272 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4273 inbind[index].is_unsigned =
MLM_TRUE;
4276 if (have_qst && !have_qet) {
4278 }
else if (have_qst && have_qet) {
4280 }
else if (!have_qst && have_qet) {
4288 MySqlLeaseContextAlloc get_context(*
this);
4291 getLeaseCollection(ctx, stindex, inbind, result);
4299 getConsistency()->getExtendedInfoSanityCheck();
4308 .arg(start_addr.
toText())
4312 MYSQL_BIND inbind[2];
4313 memset(inbind, 0,
sizeof(inbind));
4316 uint32_t start_addr_data = start_addr.
toUint32();
4317 inbind[0].buffer_type = MYSQL_TYPE_LONG;
4318 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_data);
4322 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4323 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4324 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4331 MySqlLeaseContextAlloc get_context(*
this);
4337 if (leases.empty()) {
4343 start_addr = leases.back()->addr_;
4344 for (
auto const& lease : leases) {
4346 vector<uint8_t> previous_relay_id = lease->relay_id_;
4347 vector<uint8_t> previous_remote_id = lease->remote_id_;
4348 if (!previous_user_context &&
4349 previous_relay_id.empty() &&
4350 previous_remote_id.empty()) {
4355 lease->relay_id_.clear();
4356 lease->remote_id_.clear();
4359 (previous_relay_id != lease->relay_id_) ||
4360 (previous_remote_id != lease->remote_id_)) {
4368 }
catch (
const std::exception& ex) {
4372 .arg(lease->addr_.toText())
4392 .arg(lower_bound_address.
toText())
4396 if (!lower_bound_address.
isV6()) {
4398 "retrieving leases from the lease database, got "
4399 << lower_bound_address);
4402 std::vector<uint8_t> relay_id_data = relay_id.
getDuid();
4403 unsigned long relay_id_size = relay_id_data.size();
4404 if (relay_id_size == 0) {
4409 MYSQL_BIND inbind[3];
4410 memset(inbind, 0,
sizeof(inbind));
4412 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4413 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4414 inbind[0].buffer_length = relay_id_size;
4415 inbind[0].length = &relay_id_size;
4418 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4419 unsigned long lb_addr_size = lb_addr_data.size();
4420 if (lb_addr_size != 16) {
4423 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4424 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4425 inbind[1].buffer_length = lb_addr_size;
4426 inbind[1].length = &lb_addr_size;
4429 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4430 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4431 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4435 MySqlLeaseContextAlloc get_context(*
this);
4450 .arg(lower_bound_address.
toText())
4451 .arg(idToText(remote_id));
4454 if (!lower_bound_address.
isV6()) {
4456 "retrieving leases from the lease database, got "
4457 << lower_bound_address);
4460 std::vector<uint8_t> remote_id_data = remote_id;
4461 unsigned long remote_id_size = remote_id_data.size();
4462 if (remote_id_size == 0) {
4467 MYSQL_BIND inbind[3];
4468 memset(inbind, 0,
sizeof(inbind));
4470 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4471 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4472 inbind[0].buffer_length = remote_id_size;
4473 inbind[0].length = &remote_id_size;
4476 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4477 unsigned long lb_addr_size = lb_addr_data.size();
4478 if (lb_addr_size != 16) {
4481 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4482 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4483 inbind[1].buffer_length = lb_addr_size;
4484 inbind[1].length = &lb_addr_size;
4487 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4488 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4489 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4493 MySqlLeaseContextAlloc get_context(*
this);
4505 getConsistency()->getExtendedInfoSanityCheck();
4519 .arg(start_addr.
toText())
4523 MYSQL_BIND inbind[2];
4524 memset(inbind, 0,
sizeof(inbind));
4527 std::vector<uint8_t>start_addr_bytes = start_addr.
toBytes();
4528 if (start_addr_bytes.size() != 16) {
4532 unsigned long start_addr_size = 16;
4533 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4534 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_bytes[0]);
4535 inbind[0].buffer_length = 16;
4536 inbind[0].length = &start_addr_size;
4539 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4540 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4541 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4548 MySqlLeaseContextAlloc get_context(*
this);
4554 if (leases.empty()) {
4560 start_addr = leases.back()->addr_;
4561 for (
auto const& lease : leases) {
4569 if (modified || added) {
4576 }
catch (
const std::exception& ex) {
4580 .arg(lease->addr_.toText())
4596 MySqlLeaseContextAlloc get_context(*
this);
4602 checkError(ctx, status, stindex,
"unable to execute");
4608 checkError(ctx, status, stindex,
"unable to execute");
4615 MySqlLeaseContextAlloc get_context(*
this);
4622 memset(bind, 0,
sizeof(bind));
4625 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4626 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4628 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4629 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4634 checkError(ctx, status, stindex,
"unable to execute");
4637 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4638 checkError(ctx, status, stindex,
"unable to store result");
4643 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4645 checkError(ctx, status, stindex,
"unable to fetch results");
4647 return (
static_cast<size_t>(count));
4653 MySqlLeaseContextAlloc get_context(*
this);
4660 memset(bind, 0,
sizeof(bind));
4663 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4664 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4666 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4667 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4672 checkError(ctx, status, stindex,
"unable to execute");
4675 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4676 checkError(ctx, status, stindex,
"unable to store result");
4681 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4683 checkError(ctx, status, stindex,
"unable to fetch results");
4685 return (
static_cast<size_t>(count));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to execute a database function.
Invalid address family used as input to Lease Manager.
Multiple lease records found where one expected.
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
static MySqlBindingPtr createBool()
Creates binding having a bool type for receiving data.
Common MySQL Connector Pool.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Convert time_t value to database time.
static std::pair< uint32_t, uint32_t > getVersion(const ParameterMap ¶meters, const IOServiceAccessorPtr &ac=IOServiceAccessorPtr(), const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string())
Get the schema version.
static void convertFromDatabaseTime(const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
Convert Database Time to Lease Times.
void checkError(const int status, const StatementIndex &index, const char *what)
Check Error and Throw Exception.
MYSQL_STMT * getStatement(StatementIndex index) const
Returns a prepared statement by an index.
static void ensureSchemaVersion(const ParameterMap ¶meters, const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string())
Retrieve schema version, validate it against the hardcoded version, and attempt to initialize the sch...
Fetch and Release MySQL Results.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds Client identifier or client IPv4 address.
static constexpr size_t MAX_CLIENT_ID_LEN
Maximum size of a client ID.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Holds DUID (DHCPv6 Unique Identifier)
static constexpr size_t MAX_DUID_LEN
maximum duid size
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
std::string toText() const
Returns textual representation of the identifier (e.g.
static void recreate(const std::string &dbaccess, bool preserve_callbacks=true)
Recreate an instance of a lease manager with optionally preserving registered callbacks.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
static bool upgradeLease6ExtendedInfo(const Lease6Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
Upgrade a V6 lease user context to the new extended info entry.
bool getExtendedInfoTablesEnabled() const
Returns the setting indicating if lease6 extended info tables are enabled.
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
static bool upgradeLease4ExtendedInfo(const Lease4Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
The following queries are used to fulfill Bulk Lease Query queries.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
Base class for fulfilling a statistical lease data query.
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
Exchange MySQL and Lease4 Data.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
MySqlLease4Exchange()
Constructor.
std::vector< MYSQL_BIND > createBindForSend(const Lease4Ptr &lease)
Create MYSQL_BIND objects for Lease4 Pointer.
std::string getErrorColumns()
Return columns in error.
Lease4Ptr getLeaseData()
Copy Received Data into Lease4 Object.
Exchange MySQL and Lease6 Data.
std::vector< MYSQL_BIND > createBindForSend(const Lease6Ptr &lease)
Create MYSQL_BIND objects for Lease6 Pointer.
std::string getErrorColumns()
Return columns in error.
Lease6Ptr getLeaseData()
Copy Received Data into Lease6 Object.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
MySqlLease6Exchange()
Constructor.
MySQL Lease Context Pool.
MySqlLeaseContext(const db::DatabaseConnection::ParameterMap ¶meters, db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback)
Constructor.
Common MySQL and Lease Data Methods.
static std::string getColumnsInError(my_bool *error, std::string *names, size_t count)
Return columns in error.
static void setErrorIndicators(MYSQL_BIND *bind, my_bool *error, size_t count)
Set error indicators.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual std::string getDescription() const override
Returns description of the backend.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
virtual size_t byRemoteId6size() const override
Return the by-remote-id table size.
static std::string getDBVersion()
Local version of getDBVersion() class method.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual Lease4Collection getLeases4ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
Returns existing IPv4 leases with a given remote-id.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual Lease4Collection getLeases4ByRelayId(const OptionBuffer &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
The following queries are used to fulfill Bulk Lease Query queries.
virtual void rollback() override
Rollback Transactions.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual void wipeExtendedInfoTables6() override
Wipe by-relay-id table (v6).
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
virtual std::pair< uint32_t, uint32_t > getVersion(const std::string &timer_name=std::string()) const override
Returns backend version.
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id) override
Add lease6 extended info into by-remote-id table.
virtual void commit() override
Commit Transactions.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
MySqlLeaseContextPtr createContext() const
Create a new context.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Extended information / Bulk Lease Query shared interface.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query for all subnets and pools.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
MySqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query for all subnets and pools.
virtual std::string getName() const override
Returns backend name.
StatementIndex
Statement Tags.
@ SUBNET_RANGE_LEASE6_STATS
@ GET_LEASE6_DUID_IAID_SUBID
@ SUBNET_RANGE_LEASE4_STATS
@ GET_LEASE4_REMOTEID_QST
@ GET_LEASE6_COUNT_BY_CLASS
@ GET_LEASE4_HWADDR_SUBID
@ GET_LEASE4_REMOTEID_QSET
@ GET_LEASE4_COUNT_BY_CLASS
@ DELETE_LEASE4_STATE_EXPIRED
@ GET_LEASE4_RELAYID_QSET
@ GET_LEASE4_CLIENTID_SUBID
@ DELETE_LEASE6_STATE_EXPIRED
@ GET_LEASE4_REMOTEID_QET
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns an IPv4 lease for specified IPv4 address.
virtual size_t upgradeExtendedInfo4(const LeasePageSize &page_size) override
Upgrade extended info (v4).
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual ~MySqlLeaseMgr()
Destructor (closes database)
virtual size_t upgradeExtendedInfo6(const LeasePageSize &page_size) override
Upgrade extended info (v6).
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id) override
Add lease6 extended info into by-relay-id table.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
virtual size_t byRelayId6size() const override
Return the by-relay-id table size.
MySql derivation of the statistical lease data query.
void start()
Creates the IPv4 lease statistical data result set.
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.
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 ~MySqlLeaseStatsQuery()
Destructor.
bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
MySqlLeaseStatsQuery(MySqlConnection &conn, const size_t statement_index, const bool fetch_type, const bool fetch_pool=false)
Constructor to query for all subnets' stats.
Attempt to update lease that was not there.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Introduces callbacks into the LeaseMgr.
void trackAddLease(const LeasePtr &lease)
Invokes the callbacks when a new lease is added.
void trackUpdateLease(const LeasePtr &lease)
Invokes the callbacks when a lease is updated.
void trackDeleteLease(const LeasePtr &lease)
Invokes the callbacks when a lease is deleted.
bool hasCallbacks() const
Checks if any callbacks have been registered.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< const Element > ConstElementPtr
const my_bool MLM_FALSE
MySQL false value.
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
const uint32_t MYSQL_SCHEMA_VERSION_MINOR
const my_bool MLM_TRUE
MySQL true value.
bool my_bool
my_bool type in MySQL 8.x.
std::vector< MySqlBindingPtr > MySqlBindingCollection
Collection of bindings.
const int MLM_MYSQL_FETCH_SUCCESS
check for bool size
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
std::function< isc::asiolink::IOServicePtr()> IOServiceAccessor
Function which returns the IOService that can be used to recover the connection.
int MysqlExecuteStatement(MYSQL_STMT *stmt)
Execute a prepared statement.
const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME4
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR4
std::string ClientClass
Defines a single class name.
const isc::log::MessageID DHCPSRV_MYSQL_COMMIT
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MYSQL_NEGATIVE_LEASES_STAT
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_PAGE6
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO6
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_DUID
const isc::log::MessageID DHCPSRV_MYSQL_GET_PAGE4
const isc::log::MessageID DHCPSRV_MYSQL_GET_CLIENTID
const isc::log::MessageID DHCPSRV_MYSQL_NO_TLS
const isc::log::MessageID DHCPSRV_MYSQL_GET4
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
boost::shared_ptr< DUID > DuidPtr
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_ADDR
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO6_ERROR
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED
const isc::log::MessageID DHCPSRV_MYSQL_GET_REMOTEID6
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE
const isc::log::MessageID DHCPSRV_MYSQL_GET_ADDR4
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID
const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR6
const isc::log::MessageID DHCPSRV_MYSQL_GET_REMOTEID4
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID6
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4
const isc::log::MessageID DHCPSRV_MYSQL_GET_PAGE6
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED4
const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_MYSQL_GET_HWADDR
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
const size_t ADDRESS6_TEXT_MAX_LEN
Maximum size of an IPv6 address represented as a text string.
const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR6
const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME6
const isc::log::MessageID DHCPSRV_MYSQL_GET_VERSION
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_SCHEDULE
const size_t HOSTNAME_MAX_LEN
Maximum length of the hostname stored in DNS.
const isc::log::MessageID DHCPSRV_MYSQL_GET_RELAYID4
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID4
const isc::log::MessageID DHCPSRV_MYSQL_GET6
const size_t USER_CONTEXT_MAX_LEN
Maximum length of user context.
const isc::log::MessageID DHCPSRV_MYSQL_LEASE_DB_RECONNECT_FAILED
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
const isc::log::MessageID DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO6_PAGE
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_CLIENTID
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const isc::log::MessageID DHCPSRV_MYSQL_ROLLBACK
@ HTYPE_ETHER
Ethernet 10Mbps.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
boost::shared_ptr< MySqlLeaseContext > MySqlLeaseContextPtr
Type of pointers to contexts.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
const isc::log::MessageID DHCPSRV_MYSQL_GET_ADDR6
const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_HWADDR
const isc::log::MessageID DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED
const isc::log::MessageID DHCPSRV_MYSQL_GET_RELAYID6
const isc::log::MessageID DHCPSRV_MYSQL_GET_DUID
const isc::log::MessageID DHCPSRV_MYSQL_TLS_CIPHER
PerfMonMgrPtr mgr
PerfMonMgr singleton.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
static const size_t MAX_HWADDR_LEN
Maximum size of a hardware address.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
ExtendedInfoAction
Action on extended info tables.
@ ACTION_UPDATE
update extended info tables.
@ ACTION_DELETE
delete reference to the lease
@ ACTION_IGNORE
ignore extended info,
Contains a single row of lease statistical data.
uint32_t pool_id_
The pool ID to which this data applies.
int64_t state_count_
state_count The count of leases in the lease state
uint32_t lease_state_
The lease_state to which the count applies.
SubnetID subnet_id_
The subnet ID to which this data applies.
Lease::Type lease_type_
The lease_type to which the count applies.
a common structure for IPv4 and IPv6 leases
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address