22#include <boost/array.hpp>
23#include <boost/make_shared.hpp>
24#include <boost/static_assert.hpp>
25#include <mysqld_error.h>
88const size_t LIMITS_TEXT_MAX_LEN = 512;
90boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
91tagged_statements = { {
93 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
96 "WHERE state = ? AND expire < ?"},
98 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
100 "DELETE FROM lease6 "
101 "WHERE state = ? AND expire < ?"},
103 "SELECT address, hwaddr, client_id, "
104 "valid_lifetime, expire, subnet_id, "
105 "fqdn_fwd, fqdn_rev, hostname, "
106 "state, user_context, relay_id, remote_id, pool_id "
109 "SELECT address, hwaddr, client_id, "
110 "valid_lifetime, expire, subnet_id, "
111 "fqdn_fwd, fqdn_rev, hostname, "
112 "state, user_context, relay_id, remote_id, pool_id "
114 "WHERE address = ?"},
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 "
121 "WHERE client_id = ?"},
123 "SELECT address, hwaddr, client_id, "
124 "valid_lifetime, expire, subnet_id, "
125 "fqdn_fwd, fqdn_rev, hostname, "
126 "state, user_context, relay_id, remote_id, pool_id "
128 "WHERE client_id = ? AND subnet_id = ?"},
130 "SELECT address, hwaddr, client_id, "
131 "valid_lifetime, expire, subnet_id, "
132 "fqdn_fwd, fqdn_rev, hostname, "
133 "state, user_context, relay_id, remote_id, pool_id "
137 "SELECT address, hwaddr, client_id, "
138 "valid_lifetime, expire, subnet_id, "
139 "fqdn_fwd, fqdn_rev, hostname, "
140 "state, user_context, relay_id, remote_id, pool_id "
142 "WHERE hwaddr = ? AND subnet_id = ?"},
144 "SELECT address, hwaddr, client_id, "
145 "valid_lifetime, expire, subnet_id, "
146 "fqdn_fwd, fqdn_rev, hostname, "
147 "state, user_context, relay_id, remote_id, pool_id "
153 "SELECT address, hwaddr, client_id, "
154 "valid_lifetime, expire, subnet_id, "
155 "fqdn_fwd, fqdn_rev, hostname, "
156 "state, user_context, relay_id, remote_id, pool_id "
158 "WHERE address > ? AND user_context IS NOT NULL "
162 "SELECT address, hwaddr, client_id, "
163 "valid_lifetime, expire, subnet_id, "
164 "fqdn_fwd, fqdn_rev, hostname, "
165 "state, user_context, relay_id, remote_id, pool_id "
167 "WHERE subnet_id = ?"},
169 "SELECT address, hwaddr, client_id, "
170 "valid_lifetime, expire, subnet_id, "
171 "fqdn_fwd, fqdn_rev, hostname, "
172 "state, user_context, relay_id, remote_id, pool_id "
174 "WHERE hostname = ?"},
176 "SELECT address, hwaddr, client_id, "
177 "valid_lifetime, expire, subnet_id, "
178 "fqdn_fwd, fqdn_rev, hostname, "
179 "state, user_context, relay_id, remote_id, pool_id "
182 "AND valid_lifetime != 4294967295 "
184 "ORDER BY expire ASC "
187 "SELECT address, hwaddr, client_id, "
188 "valid_lifetime, expire, subnet_id, "
189 "fqdn_fwd, fqdn_rev, hostname, "
190 "state, user_context, relay_id, remote_id, pool_id "
192 "WHERE relay_id = ? and address > ? "
196 "SELECT address, hwaddr, client_id, "
197 "valid_lifetime, expire, subnet_id, "
198 "fqdn_fwd, fqdn_rev, hostname, "
199 "state, user_context, relay_id, remote_id, pool_id "
201 "WHERE relay_id = ? and address > ? "
202 " and UNIX_TIMESTAMP(expire) - IF"
203 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
208 "SELECT address, hwaddr, client_id, "
209 "valid_lifetime, expire, subnet_id, "
210 "fqdn_fwd, fqdn_rev, hostname, "
211 "state, user_context, relay_id, remote_id, pool_id "
213 "WHERE relay_id = ? and address > ? "
214 " and UNIX_TIMESTAMP(expire) - IF"
215 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
217 " and UNIX_TIMESTAMP(expire) - IF"
218 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
223 "SELECT address, hwaddr, client_id, "
224 "valid_lifetime, expire, subnet_id, "
225 "fqdn_fwd, fqdn_rev, hostname, "
226 "state, user_context, relay_id, remote_id, pool_id "
228 "WHERE relay_id = ? and address > ? "
229 " and UNIX_TIMESTAMP(expire) - IF"
230 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
235 "SELECT address, hwaddr, client_id, "
236 "valid_lifetime, expire, subnet_id, "
237 "fqdn_fwd, fqdn_rev, hostname, "
238 "state, user_context, relay_id, remote_id, pool_id "
240 "WHERE remote_id = ? and address > ? "
244 "SELECT address, hwaddr, client_id, "
245 "valid_lifetime, expire, subnet_id, "
246 "fqdn_fwd, fqdn_rev, hostname, "
247 "state, user_context, relay_id, remote_id, pool_id "
249 "WHERE remote_id = ? and address > ? "
250 " and UNIX_TIMESTAMP(expire) - IF"
251 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
256 "SELECT address, hwaddr, client_id, "
257 "valid_lifetime, expire, subnet_id, "
258 "fqdn_fwd, fqdn_rev, hostname, "
259 "state, user_context, relay_id, remote_id, pool_id "
261 "WHERE remote_id = ? and address > ? "
262 " and UNIX_TIMESTAMP(expire) - IF"
263 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
265 " and UNIX_TIMESTAMP(expire) - IF"
266 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
271 "SELECT address, hwaddr, client_id, "
272 "valid_lifetime, expire, subnet_id, "
273 "fqdn_fwd, fqdn_rev, hostname, "
274 "state, user_context, relay_id, remote_id, pool_id "
276 "WHERE remote_id = ? and address > ? "
277 " and UNIX_TIMESTAMP(expire) - IF"
278 "(valid_lifetime = 4294967295, 0, valid_lifetime)"
283 "SELECT address, duid, valid_lifetime, "
284 "expire, subnet_id, pref_lifetime, "
285 "lease_type, iaid, prefix_len, "
286 "fqdn_fwd, fqdn_rev, hostname, "
287 "hwaddr, hwtype, hwaddr_source, "
288 "state, user_context, pool_id "
291 "SELECT address, duid, valid_lifetime, "
292 "expire, subnet_id, pref_lifetime, "
293 "lease_type, iaid, prefix_len, "
294 "fqdn_fwd, fqdn_rev, hostname, "
295 "hwaddr, hwtype, hwaddr_source, "
296 "state, user_context, pool_id "
298 "WHERE address = ? AND lease_type = ?"},
300 "SELECT address, duid, valid_lifetime, "
301 "expire, subnet_id, pref_lifetime, "
302 "lease_type, iaid, prefix_len, "
303 "fqdn_fwd, fqdn_rev, hostname, "
304 "hwaddr, hwtype, hwaddr_source, "
305 "state, user_context, pool_id "
307 "WHERE duid = ? AND iaid = ? AND lease_type = ?"},
309 "SELECT address, duid, valid_lifetime, "
310 "expire, subnet_id, pref_lifetime, "
311 "lease_type, iaid, prefix_len, "
312 "fqdn_fwd, fqdn_rev, hostname, "
313 "hwaddr, hwtype, hwaddr_source, "
314 "state, user_context, pool_id "
316 "WHERE duid = ? AND iaid = ? AND subnet_id = ? "
317 "AND lease_type = ?"},
319 "SELECT address, duid, valid_lifetime, "
320 "expire, subnet_id, pref_lifetime, "
321 "lease_type, iaid, prefix_len, "
322 "fqdn_fwd, fqdn_rev, hostname, "
323 "hwaddr, hwtype, hwaddr_source, "
324 "state, user_context, pool_id "
330 "SELECT address, duid, valid_lifetime, "
331 "expire, subnet_id, pref_lifetime, "
332 "lease_type, iaid, prefix_len, "
333 "fqdn_fwd, fqdn_rev, hostname, "
334 "hwaddr, hwtype, hwaddr_source, "
335 "state, user_context, pool_id "
337 "WHERE address > ? AND user_context IS NOT NULL "
341 "SELECT address, duid, valid_lifetime, "
342 "expire, subnet_id, pref_lifetime, "
343 "lease_type, iaid, prefix_len, "
344 "fqdn_fwd, fqdn_rev, hostname, "
345 "hwaddr, hwtype, hwaddr_source, "
346 "state, user_context, pool_id "
348 "WHERE subnet_id = ?"},
350 "SELECT address, duid, valid_lifetime, "
351 "expire, subnet_id, pref_lifetime, "
352 "lease_type, iaid, prefix_len, "
353 "fqdn_fwd, fqdn_rev, hostname, "
354 "hwaddr, hwtype, hwaddr_source, "
355 "state, user_context, pool_id "
357 "WHERE subnet_id = ? AND address > ? "
361 "SELECT address, duid, valid_lifetime, "
362 "expire, subnet_id, pref_lifetime, "
363 "lease_type, iaid, prefix_len, "
364 "fqdn_fwd, fqdn_rev, hostname, "
365 "hwaddr, hwtype, hwaddr_source, "
366 "state, user_context, pool_id "
370 "SELECT address, duid, valid_lifetime, "
371 "expire, subnet_id, pref_lifetime, "
372 "lease_type, iaid, prefix_len, "
373 "fqdn_fwd, fqdn_rev, hostname, "
374 "hwaddr, hwtype, hwaddr_source, "
375 "state, user_context, pool_id "
377 "WHERE hostname = ?"},
379 "SELECT address, duid, valid_lifetime, "
380 "expire, subnet_id, pref_lifetime, "
381 "lease_type, iaid, prefix_len, "
382 "fqdn_fwd, fqdn_rev, hostname, "
383 "hwaddr, hwtype, hwaddr_source, "
384 "state, user_context, pool_id "
387 "AND valid_lifetime != 4294967295 "
389 "ORDER BY expire ASC "
392 "INSERT INTO lease4(address, hwaddr, client_id, "
393 "valid_lifetime, expire, subnet_id, "
394 "fqdn_fwd, fqdn_rev, hostname, "
395 "state, user_context, relay_id, remote_id, pool_id) "
396 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
398 "INSERT INTO lease6(address, duid, valid_lifetime, "
399 "expire, subnet_id, pref_lifetime, "
400 "lease_type, iaid, prefix_len, "
401 "fqdn_fwd, fqdn_rev, hostname, "
402 "hwaddr, hwtype, hwaddr_source, "
403 "state, user_context, pool_id) "
404 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
406 "UPDATE lease4 SET address = ?, hwaddr = ?, "
407 "client_id = ?, valid_lifetime = ?, expire = ?, "
408 "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, "
410 "state = ?, user_context = ?, "
411 "relay_id = ?, remote_id = ?, pool_id = ? "
412 "WHERE address = ? AND expire = ?"},
414 "UPDATE lease6 SET address = ?, duid = ?, "
415 "valid_lifetime = ?, expire = ?, subnet_id = ?, "
416 "pref_lifetime = ?, lease_type = ?, iaid = ?, "
417 "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
418 "hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
419 "state = ?, user_context = ?, pool_id = ? "
420 "WHERE address = ? AND expire = ?"},
422 "SELECT subnet_id, state, leases as state_count "
423 "FROM lease4_stat ORDER BY subnet_id, state"},
425 "SELECT subnet_id, state, leases as state_count "
427 "WHERE subnet_id = ? "
430 "SELECT subnet_id, state, leases as state_count "
432 "WHERE subnet_id >= ? and subnet_id <= ? "
433 "ORDER BY subnet_id, state"},
435 "SELECT subnet_id, pool_id, state, leases as state_count "
436 "FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state"},
438 "SELECT subnet_id, lease_type, state, leases as state_count "
439 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
441 "SELECT subnet_id, lease_type, state, leases as state_count "
443 "WHERE subnet_id = ? "
444 "ORDER BY lease_type, state"},
446 "SELECT subnet_id, lease_type, state, leases as state_count "
448 "WHERE subnet_id >= ? and subnet_id <= ? "
449 "ORDER BY subnet_id, lease_type, state"},
451 "SELECT subnet_id, pool_id, lease_type, state, leases as state_count "
452 "FROM lease6_pool_stat ORDER BY subnet_id, pool_id, lease_type, state"},
454 "SELECT checkLease4Limits(?)"},
456 "SELECT checkLease6Limits(?)"},
458 "SELECT isJsonSupported()"},
461 "FROM lease4_stat_by_client_class "
462 "WHERE client_class = ?"},
465 "FROM lease6_stat_by_client_class "
466 "WHERE client_class = ? AND lease_type = ?"},
468 "DELETE FROM lease6_relay_id"},
470 "DELETE FROM lease6_remote_id"},
472 "DELETE FROM lease6_relay_id WHERE lease_addr = ?"},
474 "DELETE FROM lease6_remote_id WHERE lease_addr = ?"},
476 "INSERT INTO lease6_relay_id(relay_id, lease_addr) "
479 "INSERT INTO lease6_remote_id(remote_id, lease_addr) "
482 "SELECT l.address, l.duid, l.valid_lifetime, "
483 "l.expire, l.subnet_id, l.pref_lifetime, "
484 "l.lease_type, l.iaid, l.prefix_len, "
485 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
486 "l.hwaddr, l.hwtype, l.hwaddr_source, "
487 "l.state, l.user_context, l.pool_id "
489 "INNER JOIN lease6_relay_id AS r "
490 " ON l.address = r.lease_addr "
491 " WHERE r.relay_id = ? AND r.lease_addr > ? "
492 "GROUP BY l.address "
493 "ORDER BY l.address "
496 "SELECT l.address, l.duid, l.valid_lifetime, "
497 "l.expire, l.subnet_id, l.pref_lifetime, "
498 "l.lease_type, l.iaid, l.prefix_len, "
499 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
500 "l.hwaddr, l.hwtype, l.hwaddr_source, "
501 "l.state, l.user_context, l.pool_id "
503 "INNER JOIN lease6_remote_id AS r "
504 " ON l.address = r.lease_addr "
505 " WHERE r.remote_id = ? AND r.lease_addr > ? "
506 "GROUP BY l.address "
507 "ORDER BY l.address "
510 "SELECT COUNT(*) FROM lease6_relay_id"},
512 "SELECT COUNT(*) FROM lease6_remote_id"},
543 for (
size_t i = 0; i < count; ++i) {
545 bind[i].error = &
error[i];
567 for (
size_t i = 0; i < count; ++i) {
602 static const size_t ADDRESS_COL = 0;
603 static const size_t HWADDR_COL = 1;
604 static const size_t CLIENT_ID_COL = 2;
605 static const size_t VALID_LIFETIME_COL = 3;
606 static const size_t EXPIRE_COL = 4;
607 static const size_t SUBNET_ID_COL = 5;
608 static const size_t FQDN_FWD_COL = 6;
609 static const size_t FQDN_REV_COL = 7;
610 static const size_t HOSTNAME_COL = 8;
611 static const size_t STATE_COL = 9;
612 static const size_t USER_CONTEXT_COL = 10;
613 static const size_t RELAY_ID_COL = 11;
614 static const size_t REMOTE_ID_COL = 12;
615 static const size_t POOL_ID_COL = 13;
618 static const size_t LEASE_COLUMNS = 14;
627 client_id_length_(0), client_id_null_(
MLM_FALSE),
628 subnet_id_(0), pool_id_(0), valid_lifetime_(0),
629 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
630 state_(0), user_context_length_(0),
631 user_context_null_(
MLM_FALSE), relay_id_length_(0),
632 relay_id_null_(
MLM_FALSE), remote_id_length_(0),
634 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
635 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
636 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
637 memset(user_context_, 0,
sizeof(user_context_));
638 memset(relay_id_buffer_, 0,
sizeof(relay_id_buffer_));
639 memset(remote_id_buffer_, 0,
sizeof(remote_id_buffer_));
640 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
643 columns_[ADDRESS_COL] =
"address";
644 columns_[HWADDR_COL] =
"hwaddr";
645 columns_[CLIENT_ID_COL] =
"client_id";
646 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
647 columns_[EXPIRE_COL] =
"expire";
648 columns_[SUBNET_ID_COL] =
"subnet_id";
649 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
650 columns_[FQDN_REV_COL] =
"fqdn_rev";
651 columns_[HOSTNAME_COL] =
"hostname";
652 columns_[STATE_COL] =
"state";
653 columns_[USER_CONTEXT_COL] =
"user_context";
654 columns_[RELAY_ID_COL] =
"relay_id";
655 columns_[REMOTE_ID_COL] =
"remote_id";
656 columns_[POOL_ID_COL] =
"pool_id";
657 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
679 memset(bind_, 0,
sizeof(bind_));
688 addr4_ = lease_->addr_.toUint32();
689 bind_[0].buffer_type = MYSQL_TYPE_LONG;
690 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
698 hwaddr_ = hwaddr->hwaddr_;
699 hwaddr_length_ = hwaddr->hwaddr_.size();
706 if (hwaddr_.empty()) {
710 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
711 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
712 bind_[1].buffer_length = hwaddr_length_;
713 bind_[1].length = &hwaddr_length_;
715 bind_[1].buffer_type = MYSQL_TYPE_NULL;
722 bind_[1].buffer = NULL;
723 bind_[1].is_null = &hwaddr_null_;
727 if (lease_->client_id_) {
728 client_id_ = lease_->client_id_->getClientId();
729 client_id_length_ = client_id_.size();
736 if (client_id_.empty()) {
737 client_id_.resize(1);
740 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
741 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
742 bind_[2].buffer_length = client_id_length_;
743 bind_[2].length = &client_id_length_;
747 bind_[2].buffer_type = MYSQL_TYPE_NULL;
754 bind_[2].buffer = NULL;
755 bind_[2].is_null = &client_id_null_;
759 bind_[3].buffer_type = MYSQL_TYPE_LONG;
760 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
773 uint32_t valid_lft = lease_->valid_lft_;
779 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
780 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
781 bind_[4].buffer_length =
sizeof(expire_);
787 bind_[5].buffer_type = MYSQL_TYPE_LONG;
788 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
794 bind_[6].buffer_type = MYSQL_TYPE_TINY;
795 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
801 bind_[7].buffer_type = MYSQL_TYPE_TINY;
802 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
811 bind_[8].buffer_type = MYSQL_TYPE_STRING;
812 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
813 bind_[8].buffer_length = lease_->hostname_.length();
818 bind_[9].buffer_type = MYSQL_TYPE_LONG;
819 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
827 bind_[10].buffer_type = MYSQL_TYPE_STRING;
828 std::string ctx_txt = ctx->str();
830 bind_[10].buffer = user_context_;
831 bind_[10].buffer_length = ctx_txt.length();
835 bind_[10].buffer_type = MYSQL_TYPE_NULL;
839 relay_id_ = lease_->relay_id_;
840 if (!relay_id_.empty()) {
841 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
842 bind_[11].buffer =
reinterpret_cast<char*
>(&relay_id_[0]);
843 relay_id_length_ = relay_id_.size();
844 bind_[11].buffer_length = relay_id_length_;
845 bind_[11].length = &relay_id_length_;
847 bind_[11].buffer_type = MYSQL_TYPE_NULL;
849 bind_[11].buffer = NULL;
850 bind_[11].is_null = &relay_id_null_;
854 remote_id_ = lease_->remote_id_;
855 if (!remote_id_.empty()) {
856 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
857 bind_[12].buffer =
reinterpret_cast<char*
>(&remote_id_[0]);
858 remote_id_length_ = remote_id_.size();
859 bind_[12].buffer_length = remote_id_length_;
860 bind_[12].length = &remote_id_length_;
862 bind_[12].buffer_type = MYSQL_TYPE_NULL;
864 bind_[12].buffer = NULL;
865 bind_[12].is_null = &remote_id_null_;
870 bind_[13].buffer_type = MYSQL_TYPE_LONG;
871 bind_[13].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
880 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
882 }
catch (
const std::exception& ex) {
884 "Could not create bind array from Lease4: "
885 << lease_->addr_.toText() <<
", reason: " << ex.what());
890 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
905 memset(bind_, 0,
sizeof(bind_));
908 bind_[0].buffer_type = MYSQL_TYPE_LONG;
909 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
916 hwaddr_length_ =
sizeof(hwaddr_buffer_);
917 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
918 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
919 bind_[1].buffer_length = hwaddr_length_;
920 bind_[1].length = &hwaddr_length_;
921 bind_[1].is_null = &hwaddr_null_;
924 client_id_length_ =
sizeof(client_id_buffer_);
925 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
926 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
927 bind_[2].buffer_length = client_id_length_;
928 bind_[2].length = &client_id_length_;
929 bind_[2].is_null = &client_id_null_;
934 bind_[3].buffer_type = MYSQL_TYPE_LONG;
935 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
941 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
942 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
943 bind_[4].buffer_length =
sizeof(expire_);
948 bind_[5].buffer_type = MYSQL_TYPE_LONG;
949 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
955 bind_[6].buffer_type = MYSQL_TYPE_TINY;
956 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
962 bind_[7].buffer_type = MYSQL_TYPE_TINY;
963 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
972 hostname_length_ =
sizeof(hostname_buffer_);
973 bind_[8].buffer_type = MYSQL_TYPE_STRING;
974 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
975 bind_[8].buffer_length = hostname_length_;
976 bind_[8].length = &hostname_length_;
981 bind_[9].buffer_type = MYSQL_TYPE_LONG;
982 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
989 user_context_length_ =
sizeof(user_context_);
990 bind_[10].buffer_type = MYSQL_TYPE_STRING;
991 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
992 bind_[10].buffer_length = user_context_length_;
993 bind_[10].length = &user_context_length_;
994 bind_[10].is_null = &user_context_null_;
997 relay_id_length_ =
sizeof(relay_id_buffer_);
998 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
999 bind_[11].buffer =
reinterpret_cast<char*
>(relay_id_buffer_);
1000 bind_[11].buffer_length = relay_id_length_;
1001 bind_[11].length = &relay_id_length_;
1002 bind_[11].is_null = &relay_id_null_;
1005 remote_id_length_ =
sizeof(remote_id_buffer_);
1006 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1007 bind_[12].buffer =
reinterpret_cast<char*
>(remote_id_buffer_);
1008 bind_[12].buffer_length = remote_id_length_;
1009 bind_[12].length = &remote_id_length_;
1010 bind_[12].is_null = &remote_id_null_;
1013 bind_[13].buffer_type = MYSQL_TYPE_LONG;
1014 bind_[13].buffer =
reinterpret_cast<char*
>(&pool_id_);
1023 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
1027 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1044 uint32_t valid_lft = valid_lifetime_;
1052 client_id_length_ = 0;
1057 std::string hostname(hostname_buffer_,
1058 hostname_buffer_ + hostname_length_);
1067 std::string user_context;
1069 user_context_[user_context_length_] =
'\0';
1070 user_context.assign(user_context_);
1075 if (!user_context.empty()) {
1079 <<
"' is not a JSON map");
1083 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
1086 valid_lifetime_, cltt,
1087 subnet_id_, fqdn_fwd_,
1088 fqdn_rev_, hostname));
1091 lease->state_ = state_;
1094 lease->setContext(ctx);
1099 lease->relay_id_.assign(relay_id_buffer_,
1100 relay_id_buffer_ + relay_id_length_);
1105 lease->remote_id_.assign(remote_id_buffer_,
1106 remote_id_buffer_ + remote_id_length_);
1110 lease->pool_id_ = pool_id_;
1135 MYSQL_BIND bind_[LEASE_COLUMNS];
1136 std::string columns_[LEASE_COLUMNS];
1137 my_bool error_[LEASE_COLUMNS];
1139 std::vector<uint8_t> hwaddr_;
1141 unsigned long hwaddr_length_;
1143 std::vector<uint8_t> client_id_;
1145 unsigned long client_id_length_;
1148 uint32_t subnet_id_;
1150 uint32_t valid_lifetime_;
1154 unsigned long hostname_length_;
1157 unsigned long user_context_length_;
1159 std::vector<uint8_t> relay_id_;
1161 unsigned long relay_id_length_;
1163 std::vector<uint8_t> remote_id_;
1165 unsigned long remote_id_length_;
1188 static const size_t ADDRESS_COL = 0;
1189 static const size_t DUID_COL = 1;
1190 static const size_t VALID_LIFETIME_COL = 2;
1191 static const size_t EXPIRE_COL = 3;
1192 static const size_t SUBNET_ID_COL = 4;
1193 static const size_t PREF_LIFETIME_COL = 5;
1194 static const size_t LEASE_TYPE_COL = 6;
1195 static const size_t IAID_COL = 7;
1196 static const size_t PREFIX_LEN_COL = 8;
1197 static const size_t FQDN_FWD_COL = 9;
1198 static const size_t FQDN_REV_COL = 10;
1199 static const size_t HOSTNAME_COL = 11;
1200 static const size_t HWADDR_COL = 12;
1201 static const size_t HWTYPE_COL = 13;
1202 static const size_t HWADDR_SOURCE_COL = 14;
1203 static const size_t STATE_COL = 15;
1204 static const size_t USER_CONTEXT_COL = 16;
1205 static const size_t POOL_ID_COL = 17;
1208 static const size_t LEASE_COLUMNS = 18;
1217 hwaddr_null_(
MLM_FALSE), duid_length_(0),
1218 iaid_(0), lease_type_(0), prefix_len_(0),
1219 pref_lifetime_(0), subnet_id_(0), pool_id_(0),
1220 valid_lifetime_(0), fqdn_fwd_(false), fqdn_rev_(false),
1221 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
1222 state_(0), user_context_length_(0),
1224 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
1225 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
1226 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
1227 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
1228 memset(user_context_, 0,
sizeof(user_context_));
1229 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
1232 columns_[ADDRESS_COL] =
"address";
1233 columns_[DUID_COL] =
"duid";
1234 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
1235 columns_[EXPIRE_COL] =
"expire";
1236 columns_[SUBNET_ID_COL] =
"subnet_id";
1237 columns_[PREF_LIFETIME_COL] =
"pref_lifetime";
1238 columns_[LEASE_TYPE_COL] =
"lease_type";
1239 columns_[IAID_COL] =
"iaid";
1240 columns_[PREFIX_LEN_COL] =
"prefix_len";
1241 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
1242 columns_[FQDN_REV_COL] =
"fqdn_rev";
1243 columns_[HOSTNAME_COL] =
"hostname";
1244 columns_[HWADDR_COL] =
"hwaddr";
1245 columns_[HWTYPE_COL] =
"hwtype";
1246 columns_[HWADDR_SOURCE_COL] =
"hwaddr_source";
1247 columns_[STATE_COL] =
"state";
1248 columns_[USER_CONTEXT_COL] =
"user_context";
1249 columns_[POOL_ID_COL] =
"pool_id";
1250 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1271 memset(bind_, 0,
sizeof(bind_));
1275 addr6_ = lease->addr_.toBytes();
1276 if (addr6_.size() != 16) {
1281 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1282 bind_[0].buffer =
reinterpret_cast<char*
>(&addr6_[0]);
1283 bind_[0].buffer_length = 16;
1284 bind_[0].length = &addr6_length_;
1289 if (!lease_->duid_) {
1291 <<
" is missing mandatory client-id.");
1293 duid_ = lease_->duid_->getDuid();
1294 duid_length_ = duid_.size();
1296 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1297 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
1298 bind_[1].buffer_length = duid_length_;
1299 bind_[1].length = &duid_length_;
1304 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1305 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1318 uint32_t valid_lft = lease_->valid_lft_;
1324 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1325 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1326 bind_[3].buffer_length =
sizeof(expire_);
1332 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1333 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1340 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1341 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1348 lease_type_ = lease_->type_;
1349 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1350 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1357 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1358 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1365 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1366 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1372 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1373 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1379 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1380 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1386 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1387 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1388 bind_[11].buffer_length = lease_->hostname_.length();
1395 hwaddr_ = hwaddr->hwaddr_;
1396 hwaddr_length_ = hwaddr->hwaddr_.size();
1403 if (hwaddr_.empty()) {
1407 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1408 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1409 bind_[12].buffer_length = hwaddr_length_;
1410 bind_[12].length = &hwaddr_length_;
1412 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1419 bind_[12].buffer = NULL;
1420 bind_[12].is_null = &hwaddr_null_;
1425 hwtype_ = lease->hwaddr_->htype_;
1426 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1427 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1431 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1438 bind_[13].buffer = NULL;
1439 bind_[13].is_null = &hwaddr_null_;
1444 hwaddr_source_ = lease->hwaddr_->source_;
1445 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1446 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1450 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1457 bind_[14].buffer = NULL;
1458 bind_[14].is_null = &hwaddr_null_;
1462 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1463 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1471 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1472 std::string ctx_txt = ctx->str();
1474 bind_[16].buffer = user_context_;
1475 bind_[16].buffer_length = ctx_txt.length();
1479 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1484 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1485 bind_[17].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
1494 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1496 }
catch (
const std::exception& ex) {
1498 "Could not create bind array from Lease6: "
1499 << lease_->addr_.toText() <<
", reason: " << ex.what());
1504 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1522 memset(bind_, 0,
sizeof(bind_));
1526 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1527 bind_[0].buffer =
reinterpret_cast<char*
>(addr6_buffer_);
1528 bind_[0].buffer_length = addr6_length_;
1529 bind_[0].length = &addr6_length_;
1534 duid_length_ =
sizeof(duid_buffer_);
1535 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1536 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1537 bind_[1].buffer_length = duid_length_;
1538 bind_[1].length = &duid_length_;
1543 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1544 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1550 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1551 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1552 bind_[3].buffer_length =
sizeof(expire_);
1557 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1558 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1564 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1565 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1571 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1572 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1578 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1579 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1585 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1586 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1592 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1593 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1599 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1600 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1606 hostname_length_ =
sizeof(hostname_buffer_);
1607 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1608 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1609 bind_[11].buffer_length = hostname_length_;
1610 bind_[11].length = &hostname_length_;
1616 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1617 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1618 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1619 bind_[12].buffer_length = hwaddr_length_;
1620 bind_[12].length = &hwaddr_length_;
1621 bind_[12].is_null = &hwaddr_null_;
1624 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1625 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1629 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1630 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1634 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1635 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1642 user_context_length_ =
sizeof(user_context_);
1643 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1644 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1645 bind_[16].buffer_length = user_context_length_;
1646 bind_[16].length = &user_context_length_;
1647 bind_[16].is_null = &user_context_null_;
1650 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1651 bind_[17].buffer =
reinterpret_cast<char*
>(&pool_id_);
1660 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1664 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1680 std::string address = addr.
toText();
1685 switch (lease_type_) {
1700 static_cast<int>(lease_type_) <<
") for lease with "
1701 <<
"address " << address <<
". Only 0, 1, or 2 are "
1710 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1714 std::string hostname(hostname_buffer_,
1715 hostname_buffer_ + hostname_length_);
1720 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1721 hwaddr->source_ = hwaddr_source_;
1725 std::string user_context;
1727 user_context_[user_context_length_] =
'\0';
1728 user_context.assign(user_context_);
1733 if (!user_context.empty()) {
1737 <<
"' is not a JSON map");
1743 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1745 valid_lifetime_, subnet_id_,
1746 fqdn_fwd_, fqdn_rev_,
1751 uint32_t valid_lft = valid_lifetime_;
1758 result->current_cltt_ = cltt;
1768 result->pool_id_ = pool_id_;
1792 std::vector<uint8_t> addr6_;
1793 uint8_t addr6_buffer_[16];
1794 unsigned long addr6_length_;
1795 MYSQL_BIND bind_[LEASE_COLUMNS];
1796 std::string columns_[LEASE_COLUMNS];
1797 my_bool error_[LEASE_COLUMNS];
1799 std::vector<uint8_t> hwaddr_;
1801 unsigned long hwaddr_length_;
1803 std::vector<uint8_t> duid_;
1805 unsigned long duid_length_;
1808 uint8_t lease_type_;
1809 uint8_t prefix_len_;
1810 uint32_t pref_lifetime_;
1811 uint32_t subnet_id_;
1813 uint32_t valid_lifetime_;
1817 unsigned long hostname_length_;
1819 uint32_t hwaddr_source_;
1822 unsigned long user_context_length_;
1846 const bool fetch_type,
const bool fetch_pool =
false)
1847 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1848 fetch_type_(fetch_type), fetch_pool_(fetch_pool),
1851 bind_(fetch_type_ ? (fetch_pool_ ? 5 : 4) : (fetch_pool_ ? 4 : 3)),
1852 subnet_id_(0), pool_id_(0), lease_type_(
Lease::TYPE_NA),
1853 state_(
Lease::STATE_DEFAULT), state_count_(0) {
1854 validateStatement();
1867 const bool fetch_type,
const SubnetID& subnet_id)
1868 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1869 statement_(NULL), fetch_type_(fetch_type), fetch_pool_(false),
1872 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1873 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1875 validateStatement();
1891 const bool fetch_type,
const SubnetID& first_subnet_id,
1894 statement_index_(statement_index), statement_(NULL),
1895 fetch_type_(fetch_type), fetch_pool_(false),
1898 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1899 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1901 validateStatement();
1906 (void) mysql_stmt_free_result(statement_);
1919 MYSQL_BIND inbind[2];
1920 memset(inbind, 0,
sizeof(inbind));
1923 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1929 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1935 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1936 conn_.checkError(status, statement_index_,
"unable to bind parameters");
1941 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1942 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1949 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1950 bind_[col].buffer =
reinterpret_cast<char*
>(&pool_id_);
1958 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1959 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1967 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1968 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1973 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1974 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1979 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1980 conn_.checkError(status, statement_index_,
"outbound binding failed");
1984 conn_.checkError(status, statement_index_,
"unable to execute");
1988 status = mysql_stmt_store_result(statement_);
1989 conn_.checkError(status, statement_index_,
"results storage failed");
2008 bool have_row =
false;
2009 int status = mysql_stmt_fetch(statement_);
2015 if (state_count_ >= 0) {
2019 if (!negative_count_) {
2020 negative_count_ =
true;
2025 }
else if (status != MYSQL_NO_DATA) {
2026 conn_.checkError(status, statement_index_,
"getNextRow failed");
2037 void validateStatement() {
2040 " - invalid statement index" << statement_index_);
2050 size_t statement_index_;
2053 MYSQL_STMT *statement_;
2062 std::vector<MYSQL_BIND> bind_;
2065 uint32_t subnet_id_;
2071 uint32_t lease_type_;
2077 int64_t state_count_;
2080 static bool negative_count_;
2084bool MySqlLeaseStatsQuery::negative_count_ =
false;
2091 :
conn_(parameters, io_service_accessor, db_reconnect_callback) {
2096MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
2103 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2104 if (!mgr_.pool_->pool_.empty()) {
2105 ctx_ = mgr_.pool_->pool_.back();
2106 mgr_.pool_->pool_.pop_back();
2110 ctx_ = mgr_.createContext();
2114 if (mgr_.pool_->pool_.empty()) {
2115 isc_throw(Unexpected,
"No available MySQL lease context?!");
2117 ctx_ = mgr_.pool_->pool_.back();
2121MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
2124 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2125 mgr_.pool_->pool_.push_back(ctx_);
2132MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::MySqlLeaseTrackingContextAlloc(
2139 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2140 if (mgr_.hasCallbacks() && !mgr_.tryLock(lease)) {
2141 isc_throw(DbOperationError,
"unable to lock the lease " << lease->addr_);
2143 if (!mgr_.pool_->pool_.empty()) {
2144 ctx_ = mgr_.pool_->pool_.back();
2145 mgr_.pool_->pool_.pop_back();
2149 ctx_ = mgr_.createContext();
2153 if (mgr_.pool_->pool_.empty()) {
2154 isc_throw(Unexpected,
"No available MySQL lease context?!");
2156 ctx_ = mgr_.pool_->pool_.back();
2160MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::~MySqlLeaseTrackingContextAlloc() {
2163 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2164 if (mgr_.hasCallbacks()) {
2165 mgr_.unlock(lease_);
2167 mgr_.pool_->pool_.push_back(ctx_);
2181 timer_name_ =
"MySqlLeaseMgr[";
2182 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
2183 timer_name_ +=
"]DbReconnectTimer";
2205 bool reopened =
false;
2207 const std::string timer_name = db_reconnect_ctl->timerName();
2208 bool check = db_reconnect_ctl->checkRetries();
2215 }
catch (
const std::exception& ex) {
2234 .arg(db_reconnect_ctl->maxRetries());
2247 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
2248 .arg(db_reconnect_ctl->maxRetries())
2249 .arg(db_reconnect_ctl->retryInterval());
2255 db_reconnect_ctl->retryInterval(),
2276 ctx->conn_.openDatabase();
2279 if (ctx->conn_.getTls()) {
2280 std::string cipher = ctx->conn_.getTlsCipher();
2281 if (cipher.empty()) {
2291 ctx->conn_.prepareStatements(tagged_statements.begin(),
2292 tagged_statements.end());
2304 std::stringstream tmp;
2307 tmp <<
", library " << mysql_get_client_info();
2317 StatementIndex stindex,
2318 std::vector<MYSQL_BIND>& bind) {
2320 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), &bind[0]);
2321 checkError(ctx, status, stindex,
"unable to bind parameters");
2330 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
2333 checkError(ctx, status, stindex,
"unable to execute");
2343 .arg(lease->addr_.toText());
2346 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2350 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2357 lease->updateCurrentExpirationTime();
2370 .arg(lease->addr_.toText())
2376 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2380 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2387 lease->updateCurrentExpirationTime();
2426template <
typename Exchange,
typename LeaseCollection>
2429 StatementIndex stindex,
2433 bool single)
const {
2438 status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
2439 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2444 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2445 status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &outbind[0]);
2446 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2450 checkError(ctx, status, stindex,
"unable to execute");
2454 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
2455 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2462 while ((status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex))) == 0) {
2464 result.push_back(exchange->getLeaseData());
2469 ctx->conn_.text_statements_[stindex] <<
">");
2472 if (single && (++count > 1)) {
2473 isc_throw(MultipleRecords,
"multiple records were found in the "
2474 "database where only one was expected for query "
2475 << ctx->conn_.text_statements_[stindex]);
2482 checkError(ctx, status, stindex,
"unable to fetch results");
2483 }
else if (status == MYSQL_DATA_TRUNCATED) {
2485 isc_throw(DataTruncated, ctx->conn_.text_statements_[stindex]
2486 <<
" returned truncated data: columns affected are "
2487 << exchange->getErrorColumns());
2493 StatementIndex stindex, MYSQL_BIND* bind,
2501 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2504 if (collection.empty()) {
2507 result = *collection.begin();
2513 StatementIndex stindex, MYSQL_BIND* bind,
2521 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2524 if (collection.empty()) {
2527 result = *collection.begin();
2540 MYSQL_BIND inbind[1];
2541 memset(inbind, 0,
sizeof(inbind));
2544 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2545 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2552 MySqlLeaseContextAlloc get_context(*
this);
2566 MYSQL_BIND inbind[1];
2567 memset(inbind, 0,
sizeof(inbind));
2569 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2571 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2575 uint8_t single_byte_data = 0;
2583 : &single_byte_data;
2585 inbind[0].buffer =
reinterpret_cast<char*
>(
data);
2586 inbind[0].buffer_length = hwaddr_length;
2587 inbind[0].length = &hwaddr_length;
2593 MySqlLeaseContextAlloc get_context(*
this);
2608 MYSQL_BIND inbind[2];
2609 memset(inbind, 0,
sizeof(inbind));
2611 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2613 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2617 std::vector<uint8_t> single_byte_vec(1);
2625 : &single_byte_vec[0];
2627 inbind[0].buffer =
reinterpret_cast<char*
>(
data);
2628 inbind[0].buffer_length = hwaddr_length;
2629 inbind[0].length = &hwaddr_length;
2631 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2632 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2639 MySqlLeaseContextAlloc get_context(*
this);
2653 MYSQL_BIND inbind[1];
2654 memset(inbind, 0,
sizeof(inbind));
2656 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2658 std::vector<uint8_t> client_data = clientid.
getClientId();
2659 unsigned long client_data_length = client_data.size();
2663 if (client_data.empty()) {
2664 client_data.resize(1);
2667 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2668 inbind[0].buffer_length = client_data_length;
2669 inbind[0].length = &client_data_length;
2675 MySqlLeaseContextAlloc get_context(*
this);
2690 MYSQL_BIND inbind[2];
2691 memset(inbind, 0,
sizeof(inbind));
2693 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2695 std::vector<uint8_t> client_data = clientid.
getClientId();
2696 unsigned long client_data_length = client_data.size();
2700 if (client_data.empty()) {
2701 client_data.resize(1);
2704 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2705 inbind[0].buffer_length = client_data_length;
2706 inbind[0].length = &client_data_length;
2708 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2709 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2716 MySqlLeaseContextAlloc get_context(*
this);
2730 MYSQL_BIND inbind[1];
2731 memset(inbind, 0,
sizeof(inbind));
2734 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2735 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2742 MySqlLeaseContextAlloc get_context(*
this);
2756 MYSQL_BIND inbind[1];
2757 memset(inbind, 0,
sizeof(inbind));
2760 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2761 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2762 inbind[0].buffer_length = hostname.length();
2768 MySqlLeaseContextAlloc get_context(*
this);
2783 MySqlLeaseContextAlloc get_context(*
this);
2795 if (!lower_bound_address.
isV4()) {
2797 "retrieving leases from the lease database, got "
2798 << lower_bound_address);
2803 .arg(lower_bound_address.
toText());
2806 MYSQL_BIND inbind[2];
2807 memset(inbind, 0,
sizeof(inbind));
2810 uint32_t lb_address_data = lower_bound_address.
toUint32();
2811 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2812 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2816 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
2817 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2818 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
2825 MySqlLeaseContextAlloc get_context(*
this);
2841 MYSQL_BIND inbind[2];
2842 memset(inbind, 0,
sizeof(inbind));
2845 std::vector<uint8_t>addr6 = addr.
toBytes();
2846 if (addr6.size() != 16) {
2850 unsigned long addr6_length = 16;
2851 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2852 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
2853 inbind[0].buffer_length = 16;
2854 inbind[0].length = &addr6_length;
2857 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2858 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2864 MySqlLeaseContextAlloc get_context(*
this);
2874 uint32_t iaid)
const {
2881 MYSQL_BIND inbind[3];
2882 memset(inbind, 0,
sizeof(inbind));
2896 const vector<uint8_t>& duid_vector = duid.
getDuid();
2897 unsigned long duid_length = duid_vector.size();
2904 uint8_t single_byte_data = 0;
2905 uint8_t*
data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2906 : &single_byte_data;
2908 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2909 inbind[0].buffer =
reinterpret_cast<char*
>(
data);
2910 inbind[0].buffer_length = duid_length;
2911 inbind[0].length = &duid_length;
2914 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2915 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2919 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2920 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2927 MySqlLeaseContextAlloc get_context(*
this);
2937 uint32_t iaid,
SubnetID subnet_id)
const {
2945 MYSQL_BIND inbind[4];
2946 memset(inbind, 0,
sizeof(inbind));
2950 const vector<uint8_t>& duid_vector = duid.
getDuid();
2951 unsigned long duid_length = duid_vector.size();
2952 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2953 inbind[0].buffer =
reinterpret_cast<char*
>(
2954 const_cast<uint8_t*
>(&duid_vector[0]));
2955 inbind[0].buffer_length = duid_length;
2956 inbind[0].length = &duid_length;
2959 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2960 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2964 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2965 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2969 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2970 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2977 MySqlLeaseContextAlloc get_context(*
this);
2991 MYSQL_BIND inbind[1];
2992 memset(inbind, 0,
sizeof(inbind));
2995 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2996 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
3003 MySqlLeaseContextAlloc get_context(*
this);
3018 .arg(lower_bound_address.
toText())
3022 if (!lower_bound_address.
isV6()) {
3024 "retrieving leases from the lease database, got "
3025 << lower_bound_address);
3030 MYSQL_BIND inbind[3];
3031 memset(inbind, 0,
sizeof(inbind));
3034 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3035 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
3039 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
3040 unsigned long lb_addr_size = lb_addr_data.size();
3041 if (lb_addr_size != 16) {
3044 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
3045 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
3046 inbind[1].buffer_length = lb_addr_size;
3047 inbind[1].length = &lb_addr_size;
3050 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
3051 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3052 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
3056 MySqlLeaseContextAlloc get_context(*
this);
3072 MySqlLeaseContextAlloc get_context(*
this);
3086 MYSQL_BIND inbind[1];
3087 memset(inbind, 0,
sizeof(inbind));
3089 const vector<uint8_t>& duid_vector = duid.
getDuid();
3090 unsigned long duid_length = duid_vector.size();
3092 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3093 inbind[0].buffer =
reinterpret_cast<char*
>(
3094 const_cast<uint8_t*
>(&duid_vector[0]));
3095 inbind[0].buffer_length = duid_length;
3096 inbind[0].length = &duid_length;
3101 MySqlLeaseContextAlloc get_context(*
this);
3115 MYSQL_BIND inbind[1];
3116 memset(inbind, 0,
sizeof(inbind));
3119 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3120 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
3121 inbind[0].buffer_length = hostname.length();
3127 MySqlLeaseContextAlloc get_context(*
this);
3139 if (!lower_bound_address.
isV6()) {
3141 "retrieving leases from the lease database, got "
3142 << lower_bound_address);
3147 .arg(lower_bound_address.
toText());
3150 MYSQL_BIND inbind[2];
3151 memset(inbind, 0,
sizeof(inbind));
3154 std::vector<uint8_t>lb_addr = lower_bound_address.
toBytes();
3155 if (lb_addr.size() != 16) {
3159 unsigned long lb_addr_length = 16;
3160 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3161 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_addr[0]);
3162 inbind[0].buffer_length = 16;
3163 inbind[0].length = &lb_addr_length;
3166 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
3167 inbind[1].buffer_type = MYSQL_TYPE_LONG;
3168 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
3175 MySqlLeaseContextAlloc get_context(*
this);
3185 const size_t max_leases)
const {
3193 const size_t max_leases)
const {
3199template<
typename LeaseCollection>
3201MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
3202 const size_t max_leases,
3203 StatementIndex statement_index)
const {
3205 MYSQL_BIND inbind[3];
3206 memset(inbind, 0,
sizeof(inbind));
3210 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3211 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3215 MYSQL_TIME expire_time;
3217 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3218 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3219 inbind[1].buffer_length =
sizeof(expire_time);
3223 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
3224 std::numeric_limits<uint32_t>::max();
3225 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3226 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
3230 MySqlLeaseContextAlloc get_context(*
this);
3234 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
3241template <
typename LeasePtr>
3244 StatementIndex stindex,
3249 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3250 checkError(ctx, status, stindex,
"unable to bind parameters");
3254 checkError(ctx, status, stindex,
"unable to execute");
3258 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex));
3261 if (affected_rows == 1) {
3266 if (affected_rows == 0) {
3268 lease->addr_.toText() <<
" either because the lease does not exist, "
3269 "it has been deleted or it has changed in the database.");
3274 isc_throw(DbOperationError,
"apparently updated more than one lease "
3275 "that had the address " << lease->addr_.toText());
3283 .arg(lease->addr_.toText());
3286 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3290 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
3293 MYSQL_BIND inbind[2];
3294 memset(inbind, 0,
sizeof(inbind));
3296 uint32_t addr4 = lease->addr_.toUint32();
3297 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3298 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3301 bind.push_back(inbind[0]);
3306 uint32_t valid_lft = lease->current_valid_lft_;
3312 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3313 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3314 inbind[1].buffer_length =
sizeof(expire);
3316 bind.push_back(inbind[1]);
3319 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3322 lease->updateCurrentExpirationTime();
3335 .arg(lease->addr_.toText())
3343 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3347 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
3350 MYSQL_BIND inbind[2];
3351 memset(inbind, 0,
sizeof(inbind));
3354 std::vector<uint8_t>addr6 = lease->addr_.toBytes();
3355 if (addr6.size() != 16) {
3359 unsigned long addr6_length = 16;
3360 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3361 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3362 inbind[0].buffer_length = 16;
3363 inbind[0].length = &addr6_length;
3365 bind.push_back(inbind[0]);
3370 uint32_t valid_lft = lease->current_valid_lft_;
3376 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3377 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3378 inbind[1].buffer_length =
sizeof(expire);
3380 bind.push_back(inbind[1]);
3383 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3386 lease->updateCurrentExpirationTime();
3390 switch (recorded_action) {
3418 StatementIndex stindex,
3421 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3422 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3426 checkError(ctx, status, stindex,
"unable to execute");
3430 return (mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex)));
3440 MYSQL_BIND inbind[2];
3441 memset(inbind, 0,
sizeof(inbind));
3445 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3446 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3452 uint32_t valid_lft = lease->current_valid_lft_;
3458 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3459 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3460 inbind[1].buffer_length =
sizeof(expire);
3463 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3466 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE4, inbind);
3469 if (affected_rows == 1) {
3477 if (affected_rows == 0) {
3484 "that had the address " << lease->addr_.toText());
3497 MYSQL_BIND inbind[2];
3498 memset(inbind, 0,
sizeof(inbind));
3501 std::vector<uint8_t>addr6 = addr.
toBytes();
3502 if (addr6.size() != 16) {
3506 unsigned long addr6_length = 16;
3507 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3508 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3509 inbind[0].buffer_length = 16;
3510 inbind[0].length = &addr6_length;
3515 uint32_t valid_lft = lease->current_valid_lft_;
3521 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3522 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3523 inbind[1].buffer_length =
sizeof(expire);
3526 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3529 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE6, inbind);
3532 if (affected_rows == 1) {
3544 if (affected_rows == 0) {
3551 "that had the address " << lease->addr_.toText());
3569MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3570 StatementIndex statement_index) {
3572 MYSQL_BIND inbind[2];
3573 memset(inbind, 0,
sizeof(inbind));
3577 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3578 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3582 MYSQL_TIME expire_time;
3584 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3585 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3586 inbind[1].buffer_length =
sizeof(expire_time);
3589 MySqlLeaseContextAlloc get_context(*
this);
3593 uint64_t deleted_leases = deleteLeaseCommon(ctx, statement_index, inbind);
3595 .arg(deleted_leases);
3597 return (deleted_leases);
3601MySqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
3603 if (!user_context) {
3608 MySqlLeaseContextAlloc get_context(*
this);
3620 std::string limit_text;
3621 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3623 limit_text =
result[0]->getString();
3630MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3635MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3640MySqlLeaseMgr::isJsonSupported()
const {
3642 MySqlLeaseContextAlloc get_context(*
this);
3652 bool json_supported(
false);
3655 json_supported =
result[0]->getBool();
3658 return json_supported;
3662MySqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
3665 MySqlLeaseContextAlloc get_context(*
this);
3683 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3685 count =
result[0]->getInteger<int64_t>();
3692MySqlLeaseMgr::recountClassLeases4() {
3693 isc_throw(NotImplemented,
"MySqlLeaseMgr::recountClassLeases4() not implemented");
3697MySqlLeaseMgr::recountClassLeases6() {
3698 isc_throw(NotImplemented,
"MySqlLeaseMgr::recountClassLeases6() not implemented");
3702MySqlLeaseMgr::clearClassLeaseCounts() {
3703 isc_throw(NotImplemented,
"MySqlLeaseMgr::clearClassLeaseCounts() not implemented");
3707MySqlLeaseMgr::writeLeases4(
const std::string&) {
3708 isc_throw(NotImplemented,
"MySqlLeaseMgr::writeLeases4() not implemented");
3712MySqlLeaseMgr::writeLeases6(
const std::string&) {
3713 isc_throw(NotImplemented,
"MySqlLeaseMgr::writeLeases6() not implemented");
3719 MySqlLeaseContextAlloc get_context(*
this);
3732 MySqlLeaseContextAlloc get_context(*
this);
3745 MySqlLeaseContextAlloc get_context(*
this);
3760 MySqlLeaseContextAlloc get_context(*
this);
3775 MySqlLeaseContextAlloc get_context(*
this);
3788 MySqlLeaseContextAlloc get_context(*
this);
3801 MySqlLeaseContextAlloc get_context(*
this);
3816 MySqlLeaseContextAlloc get_context(*
this);
3843 MySqlLeaseContextAlloc get_context(*
this);
3846 std::string name =
"";
3848 name = ctx->conn_.getParameter(
"name");
3857 return (std::string(
"MySQL Database"));
3860std::pair<uint32_t, uint32_t>
3882 int status, StatementIndex index,
3883 const char* what)
const {
3884 ctx->conn_.checkError(status, index, what);
3889 deleteRelayId6(addr);
3890 deleteRemoteId6(addr);
3894MySqlLeaseMgr::deleteRelayId6(
const IOAddress& addr) {
3896 MySqlLeaseContextAlloc get_context(*
this);
3901 memset(bind, 0,
sizeof(bind));
3903 std::vector<uint8_t> addr_data = addr.
toBytes();
3905 unsigned long addr_size = addr_data.size();
3906 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3907 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3908 bind[0].buffer_length = addr_size;
3909 bind[0].length = &addr_size;
3915 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3916 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3920 checkError(ctx, status, stindex,
"unable to execute");
3924MySqlLeaseMgr::deleteRemoteId6(
const IOAddress& addr) {
3926 MySqlLeaseContextAlloc get_context(*
this);
3931 memset(bind, 0,
sizeof(bind));
3933 std::vector<uint8_t> addr_data = addr.
toBytes();
3935 unsigned long addr_size = addr_data.size();
3936 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3937 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3938 bind[0].buffer_length = addr_size;
3939 bind[0].length = &addr_size;
3945 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3946 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3950 checkError(ctx, status, stindex,
"unable to execute");
3955 const vector<uint8_t>& relay_id) {
3957 MySqlLeaseContextAlloc get_context(*
this);
3962 memset(bind, 0,
sizeof(bind));
3964 unsigned long relay_id_size = relay_id.size();
3965 if (relay_id_size == 0) {
3968 std::vector<uint8_t> relay_id_data = relay_id;
3969 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3970 bind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
3971 bind[0].buffer_length = relay_id_size;
3972 bind[0].length = &relay_id_size;
3975 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
3976 unsigned long lease_addr_length = lease_addr_data.size();
3977 if (lease_addr_length != 16) {
3980 bind[1].buffer_type = MYSQL_TYPE_BLOB;
3981 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
3982 bind[1].buffer_length = lease_addr_length;
3983 bind[1].length = &lease_addr_length;
3989 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3990 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3994 checkError(ctx, status, stindex,
"unable to execute");
3999 const vector<uint8_t>& remote_id) {
4001 MySqlLeaseContextAlloc get_context(*
this);
4006 memset(bind, 0,
sizeof(bind));
4008 unsigned long remote_id_size = remote_id.size();
4009 if (remote_id_size == 0) {
4012 std::vector<uint8_t> remote_id_data = remote_id;
4013 bind[0].buffer_type = MYSQL_TYPE_BLOB;
4014 bind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4015 bind[0].buffer_length = remote_id_size;
4016 bind[0].length = &remote_id_size;
4019 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
4020 unsigned long lease_addr_length = lease_addr_data.size();
4021 if (lease_addr_length != 16) {
4024 bind[1].buffer_type = MYSQL_TYPE_BLOB;
4025 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
4026 bind[1].buffer_length = lease_addr_length;
4027 bind[1].length = &lease_addr_length;
4033 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
4034 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
4038 checkError(ctx, status, stindex,
"unable to execute");
4045 std::stringstream tmp;
4048 for (
auto const& it :
id) {
4052 tmp << std::setw(2) << std::setfill(
'0')
4053 <<
static_cast<unsigned int>(it);
4065 const time_t& qry_start_time ,
4066 const time_t& qry_end_time ) {
4070 .arg(lower_bound_address.
toText())
4071 .arg(idToText(relay_id))
4072 .arg(qry_start_time)
4076 if (!lower_bound_address.
isV4()) {
4078 "retrieving leases from the lease database, got "
4079 << lower_bound_address);
4083 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4087 bool have_qst = (qry_start_time > 0);
4088 bool have_qet = (qry_end_time > 0);
4091 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4096 size_t bindings = 3;
4103 MYSQL_BIND zeroed_out;
4104 memset(&zeroed_out, 0,
sizeof(zeroed_out));
4105 vector<MYSQL_BIND> inbind(bindings, zeroed_out);
4107 std::vector<uint8_t> relay_id_data = relay_id;
4108 unsigned long relay_id_length = relay_id.size();
4112 if (relay_id_data.empty()) {
4113 relay_id_data.resize(1);
4117 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4118 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4119 inbind[0].buffer_length = relay_id_length;
4120 inbind[0].length = &relay_id_length;
4123 uint32_t lb_address_data = lower_bound_address.
toUint32();
4124 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4125 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4130 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4132 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4133 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4134 inbind[index].is_unsigned =
MLM_TRUE;
4139 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4141 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4142 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4143 inbind[index].is_unsigned =
MLM_TRUE;
4148 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4149 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4150 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4151 inbind[index].is_unsigned =
MLM_TRUE;
4154 if (have_qst && !have_qet) {
4156 }
else if (have_qst && have_qet) {
4158 }
else if (!have_qst && have_qet) {
4166 MySqlLeaseContextAlloc get_context(*
this);
4169 getLeaseCollection(ctx, stindex, inbind.data(),
result);
4178 const time_t& qry_start_time ,
4179 const time_t& qry_end_time ) {
4183 .arg(lower_bound_address.
toText())
4184 .arg(idToText(remote_id))
4185 .arg(qry_start_time)
4189 if (!lower_bound_address.
isV4()) {
4191 "retrieving leases from the lease database, got "
4192 << lower_bound_address);
4196 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4200 bool have_qst = (qry_start_time > 0);
4201 bool have_qet = (qry_end_time > 0);
4204 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4209 size_t bindings = 3;
4216 MYSQL_BIND zeroed_out;
4217 memset(&zeroed_out, 0,
sizeof(zeroed_out));
4218 vector<MYSQL_BIND> inbind(bindings, zeroed_out);
4220 std::vector<uint8_t> remote_id_data = remote_id;
4221 unsigned long remote_id_length = remote_id.size();
4225 if (remote_id_data.empty()) {
4226 remote_id_data.resize(1);
4230 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4231 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4232 inbind[0].buffer_length = remote_id_length;
4233 inbind[0].length = &remote_id_length;
4236 uint32_t lb_address_data = lower_bound_address.
toUint32();
4237 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4238 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4243 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4245 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4246 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4247 inbind[index].is_unsigned =
MLM_TRUE;
4252 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4254 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4255 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4256 inbind[index].is_unsigned =
MLM_TRUE;
4261 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4262 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4263 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4264 inbind[index].is_unsigned =
MLM_TRUE;
4267 if (have_qst && !have_qet) {
4269 }
else if (have_qst && have_qet) {
4271 }
else if (!have_qst && have_qet) {
4279 MySqlLeaseContextAlloc get_context(*
this);
4282 getLeaseCollection(ctx, stindex, inbind.data(),
result);
4290 getConsistency()->getExtendedInfoSanityCheck();
4299 .arg(start_addr.
toText())
4303 MYSQL_BIND inbind[2];
4304 memset(inbind, 0,
sizeof(inbind));
4307 uint32_t start_addr_data = start_addr.
toUint32();
4308 inbind[0].buffer_type = MYSQL_TYPE_LONG;
4309 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_data);
4313 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4314 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4315 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4322 MySqlLeaseContextAlloc get_context(*
this);
4328 if (leases.empty()) {
4334 start_addr = leases.back()->addr_;
4335 for (
auto const& lease : leases) {
4337 vector<uint8_t> previous_relay_id = lease->relay_id_;
4338 vector<uint8_t> previous_remote_id = lease->remote_id_;
4339 if (!previous_user_context &&
4340 previous_relay_id.empty() &&
4341 previous_remote_id.empty()) {
4346 lease->relay_id_.clear();
4347 lease->remote_id_.clear();
4350 (previous_relay_id != lease->relay_id_) ||
4351 (previous_remote_id != lease->remote_id_)) {
4359 }
catch (
const std::exception& ex) {
4363 .arg(lease->addr_.toText())
4383 .arg(lower_bound_address.
toText())
4387 if (!lower_bound_address.
isV6()) {
4389 "retrieving leases from the lease database, got "
4390 << lower_bound_address);
4393 std::vector<uint8_t> relay_id_data = relay_id.
getDuid();
4394 unsigned long relay_id_size = relay_id_data.size();
4395 if (relay_id_size == 0) {
4400 MYSQL_BIND inbind[3];
4401 memset(inbind, 0,
sizeof(inbind));
4403 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4404 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4405 inbind[0].buffer_length = relay_id_size;
4406 inbind[0].length = &relay_id_size;
4409 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4410 unsigned long lb_addr_size = lb_addr_data.size();
4411 if (lb_addr_size != 16) {
4414 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4415 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4416 inbind[1].buffer_length = lb_addr_size;
4417 inbind[1].length = &lb_addr_size;
4420 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4421 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4422 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4426 MySqlLeaseContextAlloc get_context(*
this);
4441 .arg(lower_bound_address.
toText())
4442 .arg(idToText(remote_id));
4445 if (!lower_bound_address.
isV6()) {
4447 "retrieving leases from the lease database, got "
4448 << lower_bound_address);
4451 std::vector<uint8_t> remote_id_data = remote_id;
4452 unsigned long remote_id_size = remote_id_data.size();
4453 if (remote_id_size == 0) {
4458 MYSQL_BIND inbind[3];
4459 memset(inbind, 0,
sizeof(inbind));
4461 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4462 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4463 inbind[0].buffer_length = remote_id_size;
4464 inbind[0].length = &remote_id_size;
4467 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4468 unsigned long lb_addr_size = lb_addr_data.size();
4469 if (lb_addr_size != 16) {
4472 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4473 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4474 inbind[1].buffer_length = lb_addr_size;
4475 inbind[1].length = &lb_addr_size;
4478 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4479 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4480 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4484 MySqlLeaseContextAlloc get_context(*
this);
4496 getConsistency()->getExtendedInfoSanityCheck();
4510 .arg(start_addr.
toText())
4514 MYSQL_BIND inbind[2];
4515 memset(inbind, 0,
sizeof(inbind));
4518 std::vector<uint8_t>start_addr_bytes = start_addr.
toBytes();
4519 if (start_addr_bytes.size() != 16) {
4523 unsigned long start_addr_size = 16;
4524 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4525 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_bytes[0]);
4526 inbind[0].buffer_length = 16;
4527 inbind[0].length = &start_addr_size;
4530 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4531 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4532 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4539 MySqlLeaseContextAlloc get_context(*
this);
4545 if (leases.empty()) {
4551 start_addr = leases.back()->addr_;
4552 for (
auto const& lease : leases) {
4560 if (modified || added) {
4567 }
catch (
const std::exception& ex) {
4571 .arg(lease->addr_.toText())
4587 MySqlLeaseContextAlloc get_context(*
this);
4593 checkError(ctx, status, stindex,
"unable to execute");
4599 checkError(ctx, status, stindex,
"unable to execute");
4606 MySqlLeaseContextAlloc get_context(*
this);
4613 memset(bind, 0,
sizeof(bind));
4616 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4617 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4619 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4620 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4625 checkError(ctx, status, stindex,
"unable to execute");
4628 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4629 checkError(ctx, status, stindex,
"unable to store result");
4634 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4636 checkError(ctx, status, stindex,
"unable to fetch results");
4638 return (
static_cast<size_t>(count));
4644 MySqlLeaseContextAlloc get_context(*
this);
4651 memset(bind, 0,
sizeof(bind));
4654 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4655 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4657 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4658 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4663 checkError(ctx, status, stindex,
"unable to execute");
4666 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4667 checkError(ctx, status, stindex,
"unable to store result");
4672 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4674 checkError(ctx, status, stindex,
"unable to fetch results");
4676 return (
static_cast<size_t>(count));
when the call the UDPServer carries on at the same position As a result
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.
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.
static MySqlBindingPtr createString(const unsigned long length)
Creates binding of text type for receiving data.
static MySqlBindingPtr createInteger()
Creates binding of numeric type for receiving data.
static MySqlBindingPtr createBool()
Creates binding having a bool type for receiving data.
Common MySQL Connector Pool.
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(), unsigned int id=0)
Get the schema version.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Convert time_t value to database time.
static void convertFromDatabaseTime(const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
Convert Database Time to Lease Times.
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.
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
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.
db::MySqlConnection conn_
MySQL connection.
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() override
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) override
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.
static const unsigned int DB_CONNECTION
The network state is being altered by the DB connection recovery mechanics.
Attempt to update lease that was not there.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
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.
TrackingLeaseMgr()
Constructor.
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 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