21 #include <boost/array.hpp>
22 #include <boost/make_shared.hpp>
23 #include <boost/static_assert.hpp>
24 #include <mysqld_error.h>
101 const size_t LIMITS_TEXT_MAX_LEN = 512;
103 boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
104 tagged_statements = { {
105 {MySqlLeaseMgr::DELETE_LEASE4,
106 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
107 {MySqlLeaseMgr::DELETE_LEASE4_STATE_EXPIRED,
108 "DELETE FROM lease4 "
109 "WHERE state = ? AND expire < ?"},
110 {MySqlLeaseMgr::DELETE_LEASE6,
111 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
112 {MySqlLeaseMgr::DELETE_LEASE6_STATE_EXPIRED,
113 "DELETE FROM lease6 "
114 "WHERE state = ? AND expire < ?"},
115 {MySqlLeaseMgr::GET_LEASE4,
116 "SELECT address, hwaddr, client_id, "
117 "valid_lifetime, expire, subnet_id, "
118 "fqdn_fwd, fqdn_rev, hostname, "
119 "state, user_context, relay_id, remote_id, pool_id "
121 {MySqlLeaseMgr::GET_LEASE4_ADDR,
122 "SELECT address, hwaddr, client_id, "
123 "valid_lifetime, expire, subnet_id, "
124 "fqdn_fwd, fqdn_rev, hostname, "
125 "state, user_context, relay_id, remote_id, pool_id "
127 "WHERE address = ?"},
128 {MySqlLeaseMgr::GET_LEASE4_CLIENTID,
129 "SELECT address, hwaddr, client_id, "
130 "valid_lifetime, expire, subnet_id, "
131 "fqdn_fwd, fqdn_rev, hostname, "
132 "state, user_context, relay_id, remote_id, pool_id "
134 "WHERE client_id = ?"},
135 {MySqlLeaseMgr::GET_LEASE4_CLIENTID_SUBID,
136 "SELECT address, hwaddr, client_id, "
137 "valid_lifetime, expire, subnet_id, "
138 "fqdn_fwd, fqdn_rev, hostname, "
139 "state, user_context, relay_id, remote_id, pool_id "
141 "WHERE client_id = ? AND subnet_id = ?"},
142 {MySqlLeaseMgr::GET_LEASE4_HWADDR,
143 "SELECT address, hwaddr, client_id, "
144 "valid_lifetime, expire, subnet_id, "
145 "fqdn_fwd, fqdn_rev, hostname, "
146 "state, user_context, relay_id, remote_id, pool_id "
149 {MySqlLeaseMgr::GET_LEASE4_HWADDR_SUBID,
150 "SELECT address, hwaddr, client_id, "
151 "valid_lifetime, expire, subnet_id, "
152 "fqdn_fwd, fqdn_rev, hostname, "
153 "state, user_context, relay_id, remote_id, pool_id "
155 "WHERE hwaddr = ? AND subnet_id = ?"},
156 {MySqlLeaseMgr::GET_LEASE4_PAGE,
157 "SELECT address, hwaddr, client_id, "
158 "valid_lifetime, expire, subnet_id, "
159 "fqdn_fwd, fqdn_rev, hostname, "
160 "state, user_context, relay_id, remote_id, pool_id "
165 {MySqlLeaseMgr::GET_LEASE4_UCTX_PAGE,
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 "
174 {MySqlLeaseMgr::GET_LEASE4_SUBID,
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 = ?"},
181 {MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
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 = ?"},
188 {MySqlLeaseMgr::GET_LEASE4_EXPIRE,
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 "
199 {MySqlLeaseMgr::GET_LEASE4_RELAYID,
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 > ? "
208 {MySqlLeaseMgr::GET_LEASE4_RELAYID_QST,
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)"
220 {MySqlLeaseMgr::GET_LEASE4_RELAYID_QSET,
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)"
235 {MySqlLeaseMgr::GET_LEASE4_RELAYID_QET,
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)"
247 {MySqlLeaseMgr::GET_LEASE4_REMOTEID,
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 > ? "
256 {MySqlLeaseMgr::GET_LEASE4_REMOTEID_QST,
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)"
268 {MySqlLeaseMgr::GET_LEASE4_REMOTEID_QSET,
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)"
283 {MySqlLeaseMgr::GET_LEASE4_REMOTEID_QET,
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)"
295 {MySqlLeaseMgr::GET_LEASE6,
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 "
303 {MySqlLeaseMgr::GET_LEASE6_ADDR,
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 = ?"},
312 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
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 = ?"},
321 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID_SUBID,
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 = ?"},
331 {MySqlLeaseMgr::GET_LEASE6_PAGE,
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 "
342 {MySqlLeaseMgr::GET_LEASE6_UCTX_PAGE,
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 "
353 {MySqlLeaseMgr::GET_LEASE6_SUBID,
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 = ?"},
362 {MySqlLeaseMgr::GET_LEASE6_DUID,
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 "
371 {MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
372 "SELECT address, duid, valid_lifetime, "
373 "expire, subnet_id, pref_lifetime, "
374 "lease_type, iaid, prefix_len, "
375 "fqdn_fwd, fqdn_rev, hostname, "
376 "hwaddr, hwtype, hwaddr_source, "
377 "state, user_context, pool_id "
379 "WHERE hostname = ?"},
380 {MySqlLeaseMgr::GET_LEASE6_EXPIRE,
381 "SELECT address, duid, valid_lifetime, "
382 "expire, subnet_id, pref_lifetime, "
383 "lease_type, iaid, prefix_len, "
384 "fqdn_fwd, fqdn_rev, hostname, "
385 "hwaddr, hwtype, hwaddr_source, "
386 "state, user_context, pool_id "
389 "AND valid_lifetime != 4294967295 "
391 "ORDER BY expire ASC "
393 {MySqlLeaseMgr::GET_LEASE6_LINK,
394 "SELECT address, duid, valid_lifetime, "
395 "expire, subnet_id, pref_lifetime, "
396 "lease_type, iaid, prefix_len, "
397 "fqdn_fwd, fqdn_rev, hostname, "
398 "hwaddr, hwtype, hwaddr_source, "
399 "state, user_context, pool_id "
401 "WHERE address BETWEEN ? AND ? "
404 {MySqlLeaseMgr::INSERT_LEASE4,
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
410 {MySqlLeaseMgr::INSERT_LEASE6,
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
418 {MySqlLeaseMgr::UPDATE_LEASE4,
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 = ?"},
426 {MySqlLeaseMgr::UPDATE_LEASE6,
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 = ?"},
434 {MySqlLeaseMgr::ALL_LEASE4_STATS,
435 "SELECT subnet_id, state, leases as state_count "
436 "FROM lease4_stat ORDER BY subnet_id, state"},
437 {MySqlLeaseMgr::SUBNET_LEASE4_STATS,
438 "SELECT subnet_id, state, leases as state_count "
440 "WHERE subnet_id = ? "
442 {MySqlLeaseMgr::SUBNET_RANGE_LEASE4_STATS,
443 "SELECT subnet_id, state, leases as state_count "
445 "WHERE subnet_id >= ? and subnet_id <= ? "
446 "ORDER BY subnet_id, state"},
447 {MySqlLeaseMgr::ALL_POOL_LEASE4_STATS,
448 "SELECT subnet_id, pool_id, state, leases as state_count "
449 "FROM lease4_pool_stat ORDER BY subnet_id, pool_id, state"},
450 {MySqlLeaseMgr::ALL_LEASE6_STATS,
451 "SELECT subnet_id, lease_type, state, leases as state_count "
452 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
453 {MySqlLeaseMgr::SUBNET_LEASE6_STATS,
454 "SELECT subnet_id, lease_type, state, leases as state_count "
456 "WHERE subnet_id = ? "
457 "ORDER BY lease_type, state"},
458 {MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
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"},
463 {MySqlLeaseMgr::ALL_POOL_LEASE6_STATS,
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"},
466 {MySqlLeaseMgr::CHECK_LEASE4_LIMITS,
467 "SELECT checkLease4Limits(?)"},
468 {MySqlLeaseMgr::CHECK_LEASE6_LIMITS,
469 "SELECT checkLease6Limits(?)"},
470 {MySqlLeaseMgr::IS_JSON_SUPPORTED,
471 "SELECT isJsonSupported()"},
472 {MySqlLeaseMgr::GET_LEASE4_COUNT_BY_CLASS,
474 "FROM lease4_stat_by_client_class "
475 "WHERE client_class = ?"},
476 {MySqlLeaseMgr::GET_LEASE6_COUNT_BY_CLASS,
478 "FROM lease6_stat_by_client_class "
479 "WHERE client_class = ? AND lease_type = ?"},
480 {MySqlLeaseMgr::WIPE_RELAY_ID6,
481 "DELETE FROM lease6_relay_id"},
482 {MySqlLeaseMgr::WIPE_REMOTE_ID6,
483 "DELETE FROM lease6_remote_id"},
484 {MySqlLeaseMgr::DELETE_RELAY_ID6,
485 "DELETE FROM lease6_relay_id WHERE lease_addr = ?"},
486 {MySqlLeaseMgr::DELETE_REMOTE_ID6,
487 "DELETE FROM lease6_remote_id WHERE lease_addr = ?"},
488 {MySqlLeaseMgr::ADD_RELAY_ID6,
489 "INSERT INTO lease6_relay_id(relay_id, lease_addr) "
491 {MySqlLeaseMgr::ADD_REMOTE_ID6,
492 "INSERT INTO lease6_remote_id(remote_id, lease_addr) "
494 {MySqlLeaseMgr::GET_RELAY_ID6,
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 "
508 {MySqlLeaseMgr::GET_REMOTE_ID6,
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 "
522 {MySqlLeaseMgr::GET_RELAY_ID6_LINK,
523 "SELECT l.address, l.duid, l.valid_lifetime, "
524 "l.expire, l.subnet_id, l.pref_lifetime, "
525 "l.lease_type, l.iaid, l.prefix_len, "
526 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
527 "l.hwaddr, l.hwtype, l.hwaddr_source, "
528 "l.state, l.user_context, l.pool_id "
530 "INNER JOIN lease6_relay_id AS r "
531 " ON l.address = r.lease_addr "
532 " WHERE r.relay_id = ? AND r.lease_addr BETWEEN ? AND ? "
533 "GROUP BY l.address "
534 "ORDER BY l.address "
536 {MySqlLeaseMgr::GET_REMOTE_ID6_LINK,
537 "SELECT l.address, l.duid, l.valid_lifetime, "
538 "l.expire, l.subnet_id, l.pref_lifetime, "
539 "l.lease_type, l.iaid, l.prefix_len, "
540 "l.fqdn_fwd, l.fqdn_rev, l.hostname, "
541 "l.hwaddr, l.hwtype, l.hwaddr_source, "
542 "l.state, l.user_context, l.pool_id "
544 "INNER JOIN lease6_remote_id AS r "
545 " ON l.address = r.lease_addr "
546 " WHERE r.remote_id = ? AND r.lease_addr BETWEEN ? AND ? "
547 "GROUP BY l.address "
548 "ORDER BY l.address "
550 {MySqlLeaseMgr::COUNT_RELAY_ID6,
551 "SELECT COUNT(*) FROM lease6_relay_id"},
552 {MySqlLeaseMgr::COUNT_REMOTE_ID6,
553 "SELECT COUNT(*) FROM lease6_remote_id"},
584 for (
size_t i = 0; i < count; ++i) {
605 std::string result =
"";
608 for (
size_t i = 0; i < count; ++i) {
610 if (!result.empty()) {
617 if (result.empty()) {
643 static const size_t ADDRESS_COL = 0;
644 static const size_t HWADDR_COL = 1;
645 static const size_t CLIENT_ID_COL = 2;
646 static const size_t VALID_LIFETIME_COL = 3;
647 static const size_t EXPIRE_COL = 4;
648 static const size_t SUBNET_ID_COL = 5;
649 static const size_t FQDN_FWD_COL = 6;
650 static const size_t FQDN_REV_COL = 7;
651 static const size_t HOSTNAME_COL = 8;
652 static const size_t STATE_COL = 9;
653 static const size_t USER_CONTEXT_COL = 10;
654 static const size_t RELAY_ID_COL = 11;
655 static const size_t REMOTE_ID_COL = 12;
656 static const size_t POOL_ID_COL = 13;
658 static const size_t LEASE_COLUMNS = 14;
668 client_id_length_(0), client_id_null_(
MLM_FALSE),
669 subnet_id_(0), pool_id_(0), valid_lifetime_(0),
670 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
671 state_(0), user_context_length_(0),
672 user_context_null_(
MLM_FALSE), relay_id_length_(0),
673 relay_id_null_(
MLM_FALSE), remote_id_length_(0),
675 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
676 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
677 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
678 memset(user_context_, 0,
sizeof(user_context_));
679 memset(relay_id_buffer_, 0,
sizeof(relay_id_buffer_));
680 memset(remote_id_buffer_, 0,
sizeof(remote_id_buffer_));
681 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
684 columns_[ADDRESS_COL] =
"address";
685 columns_[HWADDR_COL] =
"hwaddr";
686 columns_[CLIENT_ID_COL] =
"client_id";
687 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
688 columns_[EXPIRE_COL] =
"expire";
689 columns_[SUBNET_ID_COL] =
"subnet_id";
690 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
691 columns_[FQDN_REV_COL] =
"fqdn_rev";
692 columns_[HOSTNAME_COL] =
"hostname";
693 columns_[STATE_COL] =
"state";
694 columns_[USER_CONTEXT_COL] =
"user_context";
695 columns_[RELAY_ID_COL] =
"relay_id";
696 columns_[REMOTE_ID_COL] =
"remote_id";
697 columns_[POOL_ID_COL] =
"pool_id";
698 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
720 memset(bind_, 0,
sizeof(bind_));
729 addr4_ = lease_->addr_.toUint32();
730 bind_[0].buffer_type = MYSQL_TYPE_LONG;
731 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
739 hwaddr_ = hwaddr->hwaddr_;
740 hwaddr_length_ = hwaddr->hwaddr_.size();
747 if (hwaddr_.empty()) {
751 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
752 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
753 bind_[1].buffer_length = hwaddr_length_;
754 bind_[1].length = &hwaddr_length_;
756 bind_[1].buffer_type = MYSQL_TYPE_NULL;
763 bind_[1].buffer = NULL;
764 bind_[1].is_null = &hwaddr_null_;
768 if (lease_->client_id_) {
769 client_id_ = lease_->client_id_->getClientId();
770 client_id_length_ = client_id_.size();
777 if (client_id_.empty()) {
778 client_id_.resize(1);
781 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
782 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
783 bind_[2].buffer_length = client_id_length_;
784 bind_[2].length = &client_id_length_;
788 bind_[2].buffer_type = MYSQL_TYPE_NULL;
795 bind_[2].buffer = NULL;
796 bind_[2].is_null = &client_id_null_;
800 bind_[3].buffer_type = MYSQL_TYPE_LONG;
801 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
814 uint32_t valid_lft = lease_->valid_lft_;
815 if (valid_lft == Lease::INFINITY_LFT) {
818 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
820 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
821 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
822 bind_[4].buffer_length =
sizeof(expire_);
828 bind_[5].buffer_type = MYSQL_TYPE_LONG;
829 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
835 bind_[6].buffer_type = MYSQL_TYPE_TINY;
836 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
842 bind_[7].buffer_type = MYSQL_TYPE_TINY;
843 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
852 bind_[8].buffer_type = MYSQL_TYPE_STRING;
853 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
854 bind_[8].buffer_length = lease_->hostname_.length();
859 bind_[9].buffer_type = MYSQL_TYPE_LONG;
860 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
868 bind_[10].buffer_type = MYSQL_TYPE_STRING;
869 std::string ctx_txt = ctx->str();
871 bind_[10].buffer = user_context_;
872 bind_[10].buffer_length = ctx_txt.length();
876 bind_[10].buffer_type = MYSQL_TYPE_NULL;
880 relay_id_ = lease_->relay_id_;
881 if (!relay_id_.empty()) {
882 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
883 bind_[11].buffer =
reinterpret_cast<char*
>(&relay_id_[0]);
884 relay_id_length_ = relay_id_.size();
885 bind_[11].buffer_length = relay_id_length_;
886 bind_[11].length = &relay_id_length_;
888 bind_[11].buffer_type = MYSQL_TYPE_NULL;
890 bind_[11].buffer = NULL;
891 bind_[11].is_null = &relay_id_null_;
895 remote_id_ = lease_->remote_id_;
896 if (!remote_id_.empty()) {
897 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
898 bind_[12].buffer =
reinterpret_cast<char*
>(&remote_id_[0]);
899 remote_id_length_ = remote_id_.size();
900 bind_[12].buffer_length = remote_id_length_;
901 bind_[12].length = &remote_id_length_;
903 bind_[12].buffer_type = MYSQL_TYPE_NULL;
905 bind_[12].buffer = NULL;
906 bind_[12].is_null = &remote_id_null_;
911 bind_[13].buffer_type = MYSQL_TYPE_LONG;
912 bind_[13].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
918 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
921 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
923 }
catch (
const std::exception& ex) {
925 "Could not create bind array from Lease4: "
926 << lease_->addr_.toText() <<
", reason: " << ex.
what());
931 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
946 memset(bind_, 0,
sizeof(bind_));
949 bind_[0].buffer_type = MYSQL_TYPE_LONG;
950 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
957 hwaddr_length_ =
sizeof(hwaddr_buffer_);
958 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
959 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
960 bind_[1].buffer_length = hwaddr_length_;
961 bind_[1].length = &hwaddr_length_;
962 bind_[1].is_null = &hwaddr_null_;
965 client_id_length_ =
sizeof(client_id_buffer_);
966 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
967 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
968 bind_[2].buffer_length = client_id_length_;
969 bind_[2].length = &client_id_length_;
970 bind_[2].is_null = &client_id_null_;
975 bind_[3].buffer_type = MYSQL_TYPE_LONG;
976 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
982 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
983 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
984 bind_[4].buffer_length =
sizeof(expire_);
989 bind_[5].buffer_type = MYSQL_TYPE_LONG;
990 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
996 bind_[6].buffer_type = MYSQL_TYPE_TINY;
997 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1003 bind_[7].buffer_type = MYSQL_TYPE_TINY;
1004 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1013 hostname_length_ =
sizeof(hostname_buffer_);
1014 bind_[8].buffer_type = MYSQL_TYPE_STRING;
1015 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1016 bind_[8].buffer_length = hostname_length_;
1017 bind_[8].length = &hostname_length_;
1022 bind_[9].buffer_type = MYSQL_TYPE_LONG;
1023 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
1030 user_context_length_ =
sizeof(user_context_);
1031 bind_[10].buffer_type = MYSQL_TYPE_STRING;
1032 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
1033 bind_[10].buffer_length = user_context_length_;
1034 bind_[10].length = &user_context_length_;
1035 bind_[10].is_null = &user_context_null_;
1038 relay_id_length_ =
sizeof(relay_id_buffer_);
1039 bind_[11].buffer_type = MYSQL_TYPE_BLOB;
1040 bind_[11].buffer =
reinterpret_cast<char*
>(relay_id_buffer_);
1041 bind_[11].buffer_length = relay_id_length_;
1042 bind_[11].length = &relay_id_length_;
1043 bind_[11].is_null = &relay_id_null_;
1046 remote_id_length_ =
sizeof(remote_id_buffer_);
1047 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1048 bind_[12].buffer =
reinterpret_cast<char*
>(remote_id_buffer_);
1049 bind_[12].buffer_length = remote_id_length_;
1050 bind_[12].length = &remote_id_length_;
1051 bind_[12].is_null = &remote_id_null_;
1054 bind_[13].buffer_type = MYSQL_TYPE_LONG;
1055 bind_[13].buffer =
reinterpret_cast<char*
>(&pool_id_);
1061 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1064 BOOST_STATIC_ASSERT(13 < LEASE_COLUMNS);
1068 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1085 uint32_t valid_lft = valid_lifetime_;
1086 if (valid_lft == Lease::INFINITY_LFT) {
1089 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
1093 client_id_length_ = 0;
1098 std::string hostname(hostname_buffer_,
1099 hostname_buffer_ + hostname_length_);
1108 std::string user_context;
1110 user_context_[user_context_length_] =
'\0';
1111 user_context.assign(user_context_);
1116 if (!user_context.empty()) {
1117 ctx = Element::fromJSON(user_context);
1118 if (!ctx || (ctx->getType() != Element::map)) {
1120 <<
"' is not a JSON map");
1124 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
1127 valid_lifetime_, cltt,
1128 subnet_id_, fqdn_fwd_,
1129 fqdn_rev_, hostname));
1132 lease->state_ = state_;
1135 lease->setContext(ctx);
1140 lease->relay_id_.assign(relay_id_buffer_,
1141 relay_id_buffer_ + relay_id_length_);
1146 lease->remote_id_.assign(remote_id_buffer_,
1147 remote_id_buffer_ + remote_id_length_);
1151 lease->pool_id_ = pool_id_;
1167 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
1176 MYSQL_BIND bind_[LEASE_COLUMNS];
1177 std::string columns_[LEASE_COLUMNS];
1178 my_bool error_[LEASE_COLUMNS];
1180 std::vector<uint8_t> hwaddr_;
1181 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
1182 unsigned long hwaddr_length_;
1184 std::vector<uint8_t> client_id_;
1185 uint8_t client_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
1186 unsigned long client_id_length_;
1189 uint32_t subnet_id_;
1191 uint32_t valid_lifetime_;
1195 unsigned long hostname_length_;
1198 unsigned long user_context_length_;
1200 std::vector<uint8_t> relay_id_;
1201 uint8_t relay_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
1202 unsigned long relay_id_length_;
1204 std::vector<uint8_t> remote_id_;
1205 uint8_t remote_id_buffer_[ClientId::MAX_CLIENT_ID_LEN];
1206 unsigned long remote_id_length_;
1229 static const size_t ADDRESS_COL = 0;
1230 static const size_t DUID_COL = 1;
1231 static const size_t VALID_LIFETIME_COL = 2;
1232 static const size_t EXPIRE_COL = 3;
1233 static const size_t SUBNET_ID_COL = 4;
1234 static const size_t PREF_LIFETIME_COL = 5;
1235 static const size_t LEASE_TYPE_COL = 6;
1236 static const size_t IAID_COL = 7;
1237 static const size_t PREFIX_LEN_COL = 8;
1238 static const size_t FQDN_FWD_COL = 9;
1239 static const size_t FQDN_REV_COL = 10;
1240 static const size_t HOSTNAME_COL = 11;
1241 static const size_t HWADDR_COL = 12;
1242 static const size_t HWTYPE_COL = 13;
1243 static const size_t HWADDR_SOURCE_COL = 14;
1244 static const size_t STATE_COL = 15;
1245 static const size_t USER_CONTEXT_COL = 16;
1246 static const size_t POOL_ID_COL = 17;
1248 static const size_t LEASE_COLUMNS = 18;
1258 hwaddr_null_(
MLM_FALSE), duid_length_(0),
1259 iaid_(0), lease_type_(0), prefix_len_(0),
1260 pref_lifetime_(0), subnet_id_(0), pool_id_(0),
1261 valid_lifetime_(0), fqdn_fwd_(false), fqdn_rev_(false),
1262 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
1263 state_(0), user_context_length_(0),
1265 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
1266 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
1267 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
1268 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
1269 memset(user_context_, 0,
sizeof(user_context_));
1270 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
1273 columns_[ADDRESS_COL] =
"address";
1274 columns_[DUID_COL] =
"duid";
1275 columns_[VALID_LIFETIME_COL] =
"valid_lifetime";
1276 columns_[EXPIRE_COL] =
"expire";
1277 columns_[SUBNET_ID_COL] =
"subnet_id";
1278 columns_[PREF_LIFETIME_COL] =
"pref_lifetime";
1279 columns_[LEASE_TYPE_COL] =
"lease_type";
1280 columns_[IAID_COL] =
"iaid";
1281 columns_[PREFIX_LEN_COL] =
"prefix_len";
1282 columns_[FQDN_FWD_COL] =
"fqdn_fwd";
1283 columns_[FQDN_REV_COL] =
"fqdn_rev";
1284 columns_[HOSTNAME_COL] =
"hostname";
1285 columns_[HWADDR_COL] =
"hwaddr";
1286 columns_[HWTYPE_COL] =
"hwtype";
1287 columns_[HWADDR_SOURCE_COL] =
"hwaddr_source";
1288 columns_[STATE_COL] =
"state";
1289 columns_[USER_CONTEXT_COL] =
"user_context";
1290 columns_[POOL_ID_COL] =
"pool_id";
1291 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1312 memset(bind_, 0,
sizeof(bind_));
1316 addr6_ = lease->addr_.toBytes();
1317 if (addr6_.size() != 16) {
1322 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1323 bind_[0].buffer =
reinterpret_cast<char*
>(&addr6_[0]);
1324 bind_[0].buffer_length = 16;
1325 bind_[0].length = &addr6_length_;
1330 if (!lease_->duid_) {
1332 <<
" is missing mandatory client-id.");
1334 duid_ = lease_->duid_->getDuid();
1335 duid_length_ = duid_.size();
1337 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1338 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
1339 bind_[1].buffer_length = duid_length_;
1340 bind_[1].length = &duid_length_;
1345 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1346 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1359 uint32_t valid_lft = lease_->valid_lft_;
1360 if (valid_lft == Lease::INFINITY_LFT) {
1363 MySqlConnection::convertToDatabaseTime(lease_->cltt_, valid_lft,
1365 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1366 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1367 bind_[3].buffer_length =
sizeof(expire_);
1373 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1374 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1381 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1382 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1389 lease_type_ = lease_->type_;
1390 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1391 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1398 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1399 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1406 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1407 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1413 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1414 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1420 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1421 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1427 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1428 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1429 bind_[11].buffer_length = lease_->hostname_.length();
1436 hwaddr_ = hwaddr->hwaddr_;
1437 hwaddr_length_ = hwaddr->hwaddr_.size();
1444 if (hwaddr_.empty()) {
1448 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1449 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1450 bind_[12].buffer_length = hwaddr_length_;
1451 bind_[12].length = &hwaddr_length_;
1453 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1460 bind_[12].buffer = NULL;
1461 bind_[12].is_null = &hwaddr_null_;
1466 hwtype_ = lease->hwaddr_->htype_;
1467 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1468 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1472 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1479 bind_[13].buffer = NULL;
1480 bind_[13].is_null = &hwaddr_null_;
1485 hwaddr_source_ = lease->hwaddr_->source_;
1486 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1487 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1491 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1498 bind_[14].buffer = NULL;
1499 bind_[14].is_null = &hwaddr_null_;
1503 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1504 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1512 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1513 std::string ctx_txt = ctx->str();
1515 bind_[16].buffer = user_context_;
1516 bind_[16].buffer_length = ctx_txt.length();
1520 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1525 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1526 bind_[17].buffer =
reinterpret_cast<char*
>(&lease_->pool_id_);
1532 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1535 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1537 }
catch (
const std::exception& ex) {
1539 "Could not create bind array from Lease6: "
1540 << lease_->addr_.toText() <<
", reason: " << ex.
what());
1545 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1563 memset(bind_, 0,
sizeof(bind_));
1567 bind_[0].buffer_type = MYSQL_TYPE_BLOB;
1568 bind_[0].buffer =
reinterpret_cast<char*
>(addr6_buffer_);
1569 bind_[0].buffer_length = addr6_length_;
1570 bind_[0].length = &addr6_length_;
1575 duid_length_ =
sizeof(duid_buffer_);
1576 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1577 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1578 bind_[1].buffer_length = duid_length_;
1579 bind_[1].length = &duid_length_;
1584 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1585 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1591 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1592 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1593 bind_[3].buffer_length =
sizeof(expire_);
1598 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1599 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1605 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1606 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1612 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1613 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1619 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1620 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1626 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1627 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1633 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1634 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1640 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1641 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1647 hostname_length_ =
sizeof(hostname_buffer_);
1648 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1649 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1650 bind_[11].buffer_length = hostname_length_;
1651 bind_[11].length = &hostname_length_;
1657 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1658 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1659 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1660 bind_[12].buffer_length = hwaddr_length_;
1661 bind_[12].length = &hwaddr_length_;
1662 bind_[12].is_null = &hwaddr_null_;
1665 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1666 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1670 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1671 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1675 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1676 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1683 user_context_length_ =
sizeof(user_context_);
1684 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1685 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1686 bind_[16].buffer_length = user_context_length_;
1687 bind_[16].length = &user_context_length_;
1688 bind_[16].is_null = &user_context_null_;
1691 bind_[17].buffer_type = MYSQL_TYPE_LONG;
1692 bind_[17].buffer =
reinterpret_cast<char*
>(&pool_id_);
1698 setErrorIndicators(bind_, error_, LEASE_COLUMNS);
1701 BOOST_STATIC_ASSERT(17 < LEASE_COLUMNS);
1705 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1721 std::string address = addr.
toText();
1726 switch (lease_type_) {
1727 case Lease::TYPE_NA:
1728 type = Lease::TYPE_NA;
1731 case Lease::TYPE_TA:
1732 type = Lease::TYPE_TA;
1735 case Lease::TYPE_PD:
1736 type = Lease::TYPE_PD;
1741 static_cast<int>(lease_type_) <<
") for lease with "
1742 <<
"address " << address <<
". Only 0, 1, or 2 are "
1746 if (type != Lease::TYPE_PD) {
1751 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1755 std::string hostname(hostname_buffer_,
1756 hostname_buffer_ + hostname_length_);
1761 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1762 hwaddr->source_ = hwaddr_source_;
1766 std::string user_context;
1768 user_context_[user_context_length_] =
'\0';
1769 user_context.assign(user_context_);
1774 if (!user_context.empty()) {
1775 ctx = Element::fromJSON(user_context);
1776 if (!ctx || (ctx->getType() != Element::map)) {
1778 <<
"' is not a JSON map");
1784 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1786 valid_lifetime_, subnet_id_,
1787 fqdn_fwd_, fqdn_rev_,
1792 uint32_t valid_lft = valid_lifetime_;
1793 if (valid_lft == Lease::INFINITY_LFT) {
1796 MySqlConnection::convertFromDatabaseTime(expire_, valid_lft, cltt);
1798 result->cltt_ = cltt;
1799 result->current_cltt_ = cltt;
1802 result->state_ = state_;
1805 result->setContext(ctx);
1809 result->pool_id_ = pool_id_;
1825 return (getColumnsInError(error_, columns_, LEASE_COLUMNS));
1833 std::vector<uint8_t> addr6_;
1834 uint8_t addr6_buffer_[16];
1835 unsigned long addr6_length_;
1836 MYSQL_BIND bind_[LEASE_COLUMNS];
1837 std::string columns_[LEASE_COLUMNS];
1838 my_bool error_[LEASE_COLUMNS];
1840 std::vector<uint8_t> hwaddr_;
1841 uint8_t hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
1842 unsigned long hwaddr_length_;
1844 std::vector<uint8_t> duid_;
1845 uint8_t duid_buffer_[DUID::MAX_DUID_LEN];
1846 unsigned long duid_length_;
1849 uint8_t lease_type_;
1850 uint8_t prefix_len_;
1851 uint32_t pref_lifetime_;
1852 uint32_t subnet_id_;
1854 uint32_t valid_lifetime_;
1858 unsigned long hostname_length_;
1860 uint32_t hwaddr_source_;
1863 unsigned long user_context_length_;
1887 const bool fetch_type,
const bool fetch_pool =
false)
1888 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1889 fetch_type_(fetch_type), fetch_pool_(fetch_pool),
1892 bind_(fetch_type_ ? (fetch_pool_ ? 5 : 4) : (fetch_pool_ ? 4 : 3)),
1893 subnet_id_(0), pool_id_(0), lease_type_(
Lease::TYPE_NA),
1894 state_(
Lease::STATE_DEFAULT), state_count_(0) {
1895 validateStatement();
1908 const bool fetch_type,
const SubnetID& subnet_id)
1909 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1910 statement_(NULL), fetch_type_(fetch_type), fetch_pool_(false),
1913 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1914 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1916 validateStatement();
1932 const bool fetch_type,
const SubnetID& first_subnet_id,
1935 statement_index_(statement_index), statement_(NULL),
1936 fetch_type_(fetch_type), fetch_pool_(false),
1939 bind_(fetch_type_ ? 4 : 3), subnet_id_(0), pool_id_(0),
1940 lease_type_(
Lease::TYPE_NA), state_(
Lease::STATE_DEFAULT),
1942 validateStatement();
1947 (void) mysql_stmt_free_result(statement_);
1959 if (getSelectMode() != ALL_SUBNETS && getSelectMode() != ALL_SUBNET_POOLS) {
1960 MYSQL_BIND inbind[2];
1961 memset(inbind, 0,
sizeof(inbind));
1964 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1965 inbind[0].buffer =
reinterpret_cast<char*
>(&first_subnet_id_);
1969 if (getSelectMode() == SUBNET_RANGE) {
1970 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1971 inbind[1].buffer =
reinterpret_cast<char*
>(&last_subnet_id_);
1976 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1977 conn_.checkError(status, statement_index_,
"unable to bind parameters");
1982 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1983 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1990 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1991 bind_[col].buffer =
reinterpret_cast<char*
>(&pool_id_);
1999 bind_[col].buffer_type = MYSQL_TYPE_LONG;
2000 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
2004 fetch_type_ = Lease::TYPE_NA;
2008 bind_[col].buffer_type = MYSQL_TYPE_LONG;
2009 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
2014 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
2015 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
2020 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
2021 conn_.checkError(status, statement_index_,
"outbound binding failed");
2025 conn_.checkError(status, statement_index_,
"unable to execute");
2029 status = mysql_stmt_store_result(statement_);
2030 conn_.checkError(status, statement_index_,
"results storage failed");
2049 bool have_row =
false;
2050 int status = mysql_stmt_fetch(statement_);
2056 if (state_count_ >= 0) {
2060 if (!negative_count_) {
2061 negative_count_ =
true;
2066 }
else if (status != MYSQL_NO_DATA) {
2067 conn_.checkError(status, statement_index_,
"getNextRow failed");
2078 void validateStatement() {
2079 if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
2081 " - invalid statement index" << statement_index_);
2084 statement_ = conn_.getStatement(statement_index_);
2091 size_t statement_index_;
2094 MYSQL_STMT *statement_;
2103 std::vector<MYSQL_BIND> bind_;
2106 uint32_t subnet_id_;
2112 uint32_t lease_type_;
2118 int64_t state_count_;
2121 static bool negative_count_;
2125 bool MySqlLeaseStatsQuery::negative_count_ =
false;
2132 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
2137 MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
2140 if (MultiThreadingMgr::instance().getMode()) {
2144 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2145 if (!mgr_.pool_->pool_.empty()) {
2146 ctx_ = mgr_.pool_->pool_.back();
2147 mgr_.pool_->pool_.pop_back();
2151 ctx_ = mgr_.createContext();
2155 if (mgr_.pool_->pool_.empty()) {
2158 ctx_ = mgr_.pool_->pool_.back();
2162 MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
2163 if (MultiThreadingMgr::instance().getMode()) {
2165 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2166 mgr_.pool_->pool_.push_back(ctx_);
2173 MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::MySqlLeaseTrackingContextAlloc(
2176 if (MultiThreadingMgr::instance().getMode()) {
2180 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2181 if (mgr_.hasCallbacks() && !mgr_.tryLock(lease)) {
2184 if (!mgr_.pool_->pool_.empty()) {
2185 ctx_ = mgr_.pool_->pool_.back();
2186 mgr_.pool_->pool_.pop_back();
2190 ctx_ = mgr_.createContext();
2194 if (mgr_.pool_->pool_.empty()) {
2197 ctx_ = mgr_.pool_->pool_.back();
2201 MySqlLeaseMgr::MySqlLeaseTrackingContextAlloc::~MySqlLeaseTrackingContextAlloc() {
2202 if (MultiThreadingMgr::instance().getMode()) {
2204 lock_guard<mutex> lock(mgr_.pool_->mutex_);
2205 if (mgr_.hasCallbacks()) {
2206 mgr_.unlock(lease_);
2208 mgr_.pool_->pool_.push_back(ctx_);
2222 timer_name_ =
"MySqlLeaseMgr[";
2223 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
2224 timer_name_ +=
"]DbReconnectTimer";
2229 std::pair<uint32_t, uint32_t> db_version =
getVersion();
2230 if (code_version != db_version) {
2232 "MySQL schema version mismatch: need version: "
2233 << code_version.first <<
"." << code_version.second
2234 <<
" found version: " << db_version.first <<
"."
2235 << db_version.second);
2255 bool reopened =
false;
2257 const std::string timer_name = db_reconnect_ctl->timerName();
2264 }
catch (
const std::exception& ex) {
2280 if (!db_reconnect_ctl->checkRetries()) {
2283 .arg(db_reconnect_ctl->maxRetries());
2296 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
2297 .arg(db_reconnect_ctl->maxRetries())
2298 .arg(db_reconnect_ctl->retryInterval());
2304 db_reconnect_ctl->retryInterval(),
2322 ctx->conn_.openDatabase();
2325 if (ctx->conn_.getTls()) {
2326 std::string cipher = ctx->conn_.getTlsCipher();
2327 if (cipher.empty()) {
2337 ctx->conn_.prepareStatements(tagged_statements.begin(),
2338 tagged_statements.end());
2346 ctx->conn_.makeReconnectCtl(timer_name_);
2353 std::stringstream tmp;
2356 tmp <<
", library " << mysql_get_client_info();
2366 StatementIndex stindex,
2367 std::vector<MYSQL_BIND>& bind) {
2369 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), &bind[0]);
2370 checkError(ctx, status, stindex,
"unable to bind parameters");
2379 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
2382 checkError(ctx, status, stindex,
"unable to execute");
2392 .arg(lease->addr_.toText());
2395 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2399 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2406 lease->updateCurrentExpirationTime();
2419 .arg(lease->addr_.toText())
2425 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
2429 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2436 lease->updateCurrentExpirationTime();
2475 template <
typename Exchange,
typename LeaseCollection>
2478 StatementIndex stindex,
2481 LeaseCollection& result,
2482 bool single)
const {
2487 status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
2488 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2493 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2494 status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &outbind[0]);
2495 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2499 checkError(ctx, status, stindex,
"unable to execute");
2503 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
2504 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2511 while ((status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex))) == 0) {
2513 result.push_back(exchange->getLeaseData());
2518 ctx->conn_.text_statements_[stindex] <<
">");
2521 if (single && (++count > 1)) {
2523 "database where only one was expected for query "
2524 << ctx->conn_.text_statements_[stindex]);
2531 checkError(ctx, status, stindex,
"unable to fetch results");
2532 }
else if (status == MYSQL_DATA_TRUNCATED) {
2535 <<
" returned truncated data: columns affected are "
2536 << exchange->getErrorColumns());
2542 StatementIndex stindex, MYSQL_BIND* bind,
2550 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2553 if (collection.empty()) {
2556 result = *collection.begin();
2562 StatementIndex stindex, MYSQL_BIND* bind,
2570 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2573 if (collection.empty()) {
2576 result = *collection.begin();
2589 MYSQL_BIND inbind[1];
2590 memset(inbind, 0,
sizeof(inbind));
2593 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2594 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2601 MySqlLeaseContextAlloc get_context(*
this);
2615 MYSQL_BIND inbind[1];
2616 memset(inbind, 0,
sizeof(inbind));
2618 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2620 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2624 uint8_t single_byte_data = 0;
2631 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2632 : &single_byte_data;
2634 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2635 inbind[0].buffer_length = hwaddr_length;
2636 inbind[0].length = &hwaddr_length;
2642 MySqlLeaseContextAlloc get_context(*
this);
2657 MYSQL_BIND inbind[2];
2658 memset(inbind, 0,
sizeof(inbind));
2660 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2662 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2666 std::vector<uint8_t> single_byte_vec(1);
2673 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2674 : &single_byte_vec[0];
2676 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2677 inbind[0].buffer_length = hwaddr_length;
2678 inbind[0].length = &hwaddr_length;
2680 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2681 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2688 MySqlLeaseContextAlloc get_context(*
this);
2702 MYSQL_BIND inbind[1];
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;
2724 MySqlLeaseContextAlloc get_context(*
this);
2739 MYSQL_BIND inbind[2];
2740 memset(inbind, 0,
sizeof(inbind));
2742 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2744 std::vector<uint8_t> client_data = clientid.
getClientId();
2745 unsigned long client_data_length = client_data.size();
2749 if (client_data.empty()) {
2750 client_data.resize(1);
2753 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2754 inbind[0].buffer_length = client_data_length;
2755 inbind[0].length = &client_data_length;
2757 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2758 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2765 MySqlLeaseContextAlloc get_context(*
this);
2779 MYSQL_BIND inbind[1];
2780 memset(inbind, 0,
sizeof(inbind));
2783 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2784 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2791 MySqlLeaseContextAlloc get_context(*
this);
2805 MYSQL_BIND inbind[1];
2806 memset(inbind, 0,
sizeof(inbind));
2809 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2810 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2811 inbind[0].buffer_length = hostname.length();
2817 MySqlLeaseContextAlloc get_context(*
this);
2832 MySqlLeaseContextAlloc get_context(*
this);
2835 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2844 if (!lower_bound_address.
isV4()) {
2846 "retrieving leases from the lease database, got "
2847 << lower_bound_address);
2852 .arg(lower_bound_address.
toText());
2855 MYSQL_BIND inbind[2];
2856 memset(inbind, 0,
sizeof(inbind));
2859 uint32_t lb_address_data = lower_bound_address.
toUint32();
2860 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2861 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2865 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
2866 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2867 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
2874 MySqlLeaseContextAlloc get_context(*
this);
2890 MYSQL_BIND inbind[2];
2891 memset(inbind, 0,
sizeof(inbind));
2894 std::vector<uint8_t>addr6 = addr.
toBytes();
2895 if (addr6.size() != 16) {
2899 unsigned long addr6_length = 16;
2900 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2901 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
2902 inbind[0].buffer_length = 16;
2903 inbind[0].length = &addr6_length;
2906 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2907 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2913 MySqlLeaseContextAlloc get_context(*
this);
2923 uint32_t iaid)
const {
2930 MYSQL_BIND inbind[3];
2931 memset(inbind, 0,
sizeof(inbind));
2945 const vector<uint8_t>& duid_vector = duid.
getDuid();
2946 unsigned long duid_length = duid_vector.size();
2953 uint8_t single_byte_data = 0;
2954 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2955 : &single_byte_data;
2957 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2958 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2959 inbind[0].buffer_length = duid_length;
2960 inbind[0].length = &duid_length;
2963 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2964 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2968 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2969 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2976 MySqlLeaseContextAlloc get_context(*
this);
2986 uint32_t iaid,
SubnetID subnet_id)
const {
2994 MYSQL_BIND inbind[4];
2995 memset(inbind, 0,
sizeof(inbind));
2999 const vector<uint8_t>& duid_vector = duid.
getDuid();
3000 unsigned long duid_length = duid_vector.size();
3001 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3002 inbind[0].buffer =
reinterpret_cast<char*
>(
3003 const_cast<uint8_t*
>(&duid_vector[0]));
3004 inbind[0].buffer_length = duid_length;
3005 inbind[0].length = &duid_length;
3008 inbind[1].buffer_type = MYSQL_TYPE_LONG;
3009 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
3013 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3014 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
3018 inbind[3].buffer_type = MYSQL_TYPE_TINY;
3019 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
3026 MySqlLeaseContextAlloc get_context(*
this);
3040 MYSQL_BIND inbind[1];
3041 memset(inbind, 0,
sizeof(inbind));
3044 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3045 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
3052 MySqlLeaseContextAlloc get_context(*
this);
3067 MySqlLeaseContextAlloc get_context(*
this);
3070 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
3081 MYSQL_BIND inbind[1];
3082 memset(inbind, 0,
sizeof(inbind));
3084 const vector<uint8_t>& duid_vector = duid.
getDuid();
3085 unsigned long duid_length = duid_vector.size();
3087 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3088 inbind[0].buffer =
reinterpret_cast<char*
>(
3089 const_cast<uint8_t*
>(&duid_vector[0]));
3090 inbind[0].buffer_length = duid_length;
3091 inbind[0].length = &duid_length;
3096 MySqlLeaseContextAlloc get_context(*
this);
3110 MYSQL_BIND inbind[1];
3111 memset(inbind, 0,
sizeof(inbind));
3114 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3115 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
3116 inbind[0].buffer_length = hostname.length();
3122 MySqlLeaseContextAlloc get_context(*
this);
3134 if (!lower_bound_address.
isV6()) {
3136 "retrieving leases from the lease database, got "
3137 << lower_bound_address);
3142 .arg(lower_bound_address.
toText());
3145 MYSQL_BIND inbind[2];
3146 memset(inbind, 0,
sizeof(inbind));
3149 std::vector<uint8_t>lb_addr = lower_bound_address.
toBytes();
3150 if (lb_addr.size() != 16) {
3154 unsigned long lb_addr_length = 16;
3155 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3156 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_addr[0]);
3157 inbind[0].buffer_length = 16;
3158 inbind[0].length = &lb_addr_length;
3161 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
3162 inbind[1].buffer_type = MYSQL_TYPE_LONG;
3163 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
3170 MySqlLeaseContextAlloc get_context(*
this);
3180 const size_t max_leases)
const {
3188 const size_t max_leases)
const {
3194 template<
typename LeaseCollection>
3196 MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
3197 const size_t max_leases,
3198 StatementIndex statement_index)
const {
3200 MYSQL_BIND inbind[3];
3201 memset(inbind, 0,
sizeof(inbind));
3205 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3206 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3210 MYSQL_TIME expire_time;
3212 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3213 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3214 inbind[1].buffer_length =
sizeof(expire_time);
3218 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
3219 std::numeric_limits<uint32_t>::max();
3220 inbind[2].buffer_type = MYSQL_TYPE_LONG;
3221 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
3225 MySqlLeaseContextAlloc get_context(*
this);
3229 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
3236 template <
typename LeasePtr>
3239 StatementIndex stindex,
3244 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3245 checkError(ctx, status, stindex,
"unable to bind parameters");
3249 checkError(ctx, status, stindex,
"unable to execute");
3253 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex));
3256 if (affected_rows == 1) {
3261 if (affected_rows == 0) {
3263 lease->addr_.toText() <<
" as it does not exist");
3269 "that had the address " << lease->addr_.toText());
3277 .arg(lease->addr_.toText());
3280 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3284 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
3287 MYSQL_BIND inbind[2];
3288 memset(inbind, 0,
sizeof(inbind));
3290 uint32_t addr4 = lease->addr_.toUint32();
3291 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3292 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3295 bind.push_back(inbind[0]);
3300 uint32_t valid_lft = lease->current_valid_lft_;
3306 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3307 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3308 inbind[1].buffer_length =
sizeof(expire);
3310 bind.push_back(inbind[1]);
3313 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3316 lease->updateCurrentExpirationTime();
3329 .arg(lease->addr_.toText())
3337 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3341 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
3344 MYSQL_BIND inbind[2];
3345 memset(inbind, 0,
sizeof(inbind));
3348 std::vector<uint8_t>addr6 = lease->addr_.toBytes();
3349 if (addr6.size() != 16) {
3353 unsigned long addr6_length = 16;
3354 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3355 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3356 inbind[0].buffer_length = 16;
3357 inbind[0].length = &addr6_length;
3359 bind.push_back(inbind[0]);
3364 uint32_t valid_lft = lease->current_valid_lft_;
3370 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3371 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3372 inbind[1].buffer_length =
sizeof(expire);
3374 bind.push_back(inbind[1]);
3377 updateLeaseCommon(ctx, stindex, &bind[0], lease);
3380 lease->updateCurrentExpirationTime();
3384 switch (recorded_action) {
3412 StatementIndex stindex,
3415 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3416 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3420 checkError(ctx, status, stindex,
"unable to execute");
3424 return (
static_cast<uint64_t
>(mysql_stmt_affected_rows(ctx->conn_.getStatement(stindex))));
3434 MYSQL_BIND inbind[2];
3435 memset(inbind, 0,
sizeof(inbind));
3439 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3440 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
3446 uint32_t valid_lft = lease->current_valid_lft_;
3452 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3453 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3454 inbind[1].buffer_length =
sizeof(expire);
3457 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3460 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE4, inbind);
3463 if (affected_rows == 1) {
3471 if (affected_rows == 0) {
3478 "that had the address " << lease->addr_.toText());
3491 MYSQL_BIND inbind[2];
3492 memset(inbind, 0,
sizeof(inbind));
3495 std::vector<uint8_t>addr6 = addr.
toBytes();
3496 if (addr6.size() != 16) {
3500 unsigned long addr6_length = 16;
3501 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
3502 inbind[0].buffer =
reinterpret_cast<char*
>(&addr6[0]);
3503 inbind[0].buffer_length = 16;
3504 inbind[0].length = &addr6_length;
3509 uint32_t valid_lft = lease->current_valid_lft_;
3515 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3516 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3517 inbind[1].buffer_length =
sizeof(expire);
3520 MySqlLeaseTrackingContextAlloc get_context(*
this, lease);
3523 auto affected_rows = deleteLeaseCommon(ctx,
DELETE_LEASE6, inbind);
3526 if (affected_rows == 1) {
3538 if (affected_rows == 0) {
3545 "that had the address " << lease->addr_.toText());
3563 MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3564 StatementIndex statement_index) {
3566 MYSQL_BIND inbind[2];
3567 memset(inbind, 0,
sizeof(inbind));
3571 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3572 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3576 MYSQL_TIME expire_time;
3578 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3579 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3580 inbind[1].buffer_length =
sizeof(expire_time);
3583 MySqlLeaseContextAlloc get_context(*
this);
3587 uint64_t deleted_leases = deleteLeaseCommon(ctx, statement_index, inbind);
3589 .arg(deleted_leases);
3591 return (deleted_leases);
3595 MySqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
3597 if (!user_context) {
3602 MySqlLeaseContextAlloc get_context(*
this);
3614 std::string limit_text;
3615 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3617 limit_text = result[0]->getString();
3624 MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3629 MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3634 MySqlLeaseMgr::isJsonSupported()
const {
3636 MySqlLeaseContextAlloc get_context(*
this);
3646 bool json_supported(
false);
3649 json_supported = result[0]->getBool();
3652 return json_supported;
3656 MySqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
3659 MySqlLeaseContextAlloc get_context(*
this);
3667 in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(ltype));
3670 MySqlBinding::createInteger<int64_t>()
3677 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3679 count = result[0]->getInteger<int64_t>();
3686 MySqlLeaseMgr::recountClassLeases4() {
3691 MySqlLeaseMgr::recountClassLeases6() {
3696 MySqlLeaseMgr::clearClassLeaseCounts() {
3701 MySqlLeaseMgr::writeLeases4(
const std::string&) {
3706 MySqlLeaseMgr::writeLeases6(
const std::string&) {
3713 MySqlLeaseContextAlloc get_context(*
this);
3726 MySqlLeaseContextAlloc get_context(*
this);
3739 MySqlLeaseContextAlloc get_context(*
this);
3754 MySqlLeaseContextAlloc get_context(*
this);
3769 MySqlLeaseContextAlloc get_context(*
this);
3782 MySqlLeaseContextAlloc get_context(*
this);
3795 MySqlLeaseContextAlloc get_context(*
this);
3810 MySqlLeaseContextAlloc get_context(*
this);
3837 MySqlLeaseContextAlloc get_context(*
this);
3840 std::string name =
"";
3842 name = ctx->conn_.getParameter(
"name");
3851 return (std::string(
"MySQL Database"));
3854 std::pair<uint32_t, uint32_t>
3873 int status, StatementIndex index,
3874 const char* what)
const {
3875 ctx->conn_.checkError(status, index, what);
3880 deleteRelayId6(addr);
3881 deleteRemoteId6(addr);
3885 MySqlLeaseMgr::deleteRelayId6(
const IOAddress& addr) {
3887 MySqlLeaseContextAlloc get_context(*
this);
3892 memset(bind, 0,
sizeof(bind));
3894 std::vector<uint8_t> addr_data = addr.
toBytes();
3896 unsigned long addr_size = addr_data.size();
3897 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3898 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3899 bind[0].buffer_length = addr_size;
3900 bind[0].length = &addr_size;
3906 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3907 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3911 checkError(ctx, status, stindex,
"unable to execute");
3915 MySqlLeaseMgr::deleteRemoteId6(
const IOAddress& addr) {
3917 MySqlLeaseContextAlloc get_context(*
this);
3922 memset(bind, 0,
sizeof(bind));
3924 std::vector<uint8_t> addr_data = addr.
toBytes();
3926 unsigned long addr_size = addr_data.size();
3927 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3928 bind[0].buffer =
reinterpret_cast<char*
>(&addr_data[0]);
3929 bind[0].buffer_length = addr_size;
3930 bind[0].length = &addr_size;
3936 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3937 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3941 checkError(ctx, status, stindex,
"unable to execute");
3946 const vector<uint8_t>& relay_id) {
3948 MySqlLeaseContextAlloc get_context(*
this);
3953 memset(bind, 0,
sizeof(bind));
3955 unsigned long relay_id_size = relay_id.size();
3956 if (relay_id_size == 0) {
3959 std::vector<uint8_t> relay_id_data = relay_id;
3960 bind[0].buffer_type = MYSQL_TYPE_BLOB;
3961 bind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
3962 bind[0].buffer_length = relay_id_size;
3963 bind[0].length = &relay_id_size;
3966 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
3967 unsigned long lease_addr_length = lease_addr_data.size();
3968 if (lease_addr_length != 16) {
3971 bind[1].buffer_type = MYSQL_TYPE_BLOB;
3972 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
3973 bind[1].buffer_length = lease_addr_length;
3974 bind[1].length = &lease_addr_length;
3980 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
3981 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
3985 checkError(ctx, status, stindex,
"unable to execute");
3990 const vector<uint8_t>& remote_id) {
3992 MySqlLeaseContextAlloc get_context(*
this);
3997 memset(bind, 0,
sizeof(bind));
3999 unsigned long remote_id_size = remote_id.size();
4000 if (remote_id_size == 0) {
4003 std::vector<uint8_t> remote_id_data = remote_id;
4004 bind[0].buffer_type = MYSQL_TYPE_BLOB;
4005 bind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4006 bind[0].buffer_length = remote_id_size;
4007 bind[0].length = &remote_id_size;
4010 std::vector<uint8_t> lease_addr_data = lease_addr.
toBytes();
4011 unsigned long lease_addr_length = lease_addr_data.size();
4012 if (lease_addr_length != 16) {
4015 bind[1].buffer_type = MYSQL_TYPE_BLOB;
4016 bind[1].buffer =
reinterpret_cast<char*
>(&lease_addr_data[0]);
4017 bind[1].buffer_length = lease_addr_length;
4018 bind[1].length = &lease_addr_length;
4024 int status = mysql_stmt_bind_param(ctx->conn_.getStatement(stindex), bind);
4025 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
4029 checkError(ctx, status, stindex,
"unable to execute");
4036 std::stringstream tmp;
4039 for (std::vector<uint8_t>::const_iterator it =
id.begin();
4040 it !=
id.end(); ++it) {
4044 tmp << std::setw(2) << std::setfill(
'0')
4045 <<
static_cast<unsigned int>(*it);
4057 const time_t& qry_start_time ,
4058 const time_t& qry_end_time ) {
4062 .arg(lower_bound_address.
toText())
4063 .arg(idToText(relay_id))
4064 .arg(qry_start_time)
4068 if (!lower_bound_address.
isV4()) {
4070 "retrieving leases from the lease database, got "
4071 << lower_bound_address);
4075 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4079 bool have_qst = (qry_start_time > 0);
4080 bool have_qet = (qry_end_time > 0);
4083 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4088 size_t bindings = 3;
4095 MYSQL_BIND inbind[bindings];
4096 memset(inbind, 0,
sizeof(inbind));
4098 std::vector<uint8_t> relay_id_data = relay_id;
4099 unsigned long relay_id_length = relay_id.size();
4103 if (relay_id_data.empty()) {
4104 relay_id_data.resize(1);
4108 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4109 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4110 inbind[0].buffer_length = relay_id_length;
4111 inbind[0].length = &relay_id_length;
4114 uint32_t lb_address_data = lower_bound_address.
toUint32();
4115 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4116 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4121 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4123 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4124 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4125 inbind[index].is_unsigned =
MLM_TRUE;
4130 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4132 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4133 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4134 inbind[index].is_unsigned =
MLM_TRUE;
4139 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4140 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4141 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4142 inbind[index].is_unsigned =
MLM_TRUE;
4145 if (have_qst && !have_qet) {
4147 }
else if (have_qst && have_qet) {
4149 }
else if (!have_qst && have_qet) {
4157 MySqlLeaseContextAlloc get_context(*
this);
4160 getLeaseCollection(ctx, stindex, inbind, result);
4169 const time_t& qry_start_time ,
4170 const time_t& qry_end_time ) {
4174 .arg(lower_bound_address.
toText())
4175 .arg(idToText(remote_id))
4176 .arg(qry_start_time)
4180 if (!lower_bound_address.
isV4()) {
4182 "retrieving leases from the lease database, got "
4183 << lower_bound_address);
4187 if ((qry_start_time < 0) || (qry_end_time < 0)) {
4191 bool have_qst = (qry_start_time > 0);
4192 bool have_qet = (qry_end_time > 0);
4195 if (have_qst && have_qet && (qry_start_time > qry_end_time)) {
4200 size_t bindings = 3;
4207 MYSQL_BIND inbind[bindings];
4208 memset(inbind, 0,
sizeof(inbind));
4210 std::vector<uint8_t> remote_id_data = remote_id;
4211 unsigned long remote_id_length = remote_id.size();
4215 if (remote_id_data.empty()) {
4216 remote_id_data.resize(1);
4220 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4221 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4222 inbind[0].buffer_length = remote_id_length;
4223 inbind[0].length = &remote_id_length;
4226 uint32_t lb_address_data = lower_bound_address.
toUint32();
4227 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4228 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_address_data);
4233 uint32_t start_time =
static_cast<uint32_t
>(qry_start_time);
4235 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4236 inbind[index].buffer =
reinterpret_cast<char*
>(&start_time);
4237 inbind[index].is_unsigned =
MLM_TRUE;
4242 uint32_t end_time =
static_cast<uint32_t
>(qry_end_time);
4244 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4245 inbind[index].buffer =
reinterpret_cast<char*
>(&end_time);
4246 inbind[index].is_unsigned =
MLM_TRUE;
4251 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4252 inbind[index].buffer_type = MYSQL_TYPE_LONG;
4253 inbind[index].buffer =
reinterpret_cast<char*
>(&ps);
4254 inbind[index].is_unsigned =
MLM_TRUE;
4257 if (have_qst && !have_qet) {
4259 }
else if (have_qst && have_qet) {
4261 }
else if (!have_qst && have_qet) {
4269 MySqlLeaseContextAlloc get_context(*
this);
4272 getLeaseCollection(ctx, stindex, inbind, result);
4280 getConsistency()->getExtendedInfoSanityCheck();
4289 .arg(start_addr.
toText())
4293 MYSQL_BIND inbind[2];
4294 memset(inbind, 0,
sizeof(inbind));
4297 uint32_t start_addr_data = start_addr.
toUint32();
4298 inbind[0].buffer_type = MYSQL_TYPE_LONG;
4299 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_data);
4303 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4304 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4305 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4312 MySqlLeaseContextAlloc get_context(*
this);
4318 if (leases.empty()) {
4324 start_addr = leases.back()->addr_;
4325 for (
auto lease : leases) {
4327 vector<uint8_t> previous_relay_id = lease->relay_id_;
4328 vector<uint8_t> previous_remote_id = lease->remote_id_;
4329 if (!previous_user_context &&
4330 previous_relay_id.empty() &&
4331 previous_remote_id.empty()) {
4336 lease->relay_id_.clear();
4337 lease->remote_id_.clear();
4340 (previous_relay_id != lease->relay_id_) ||
4341 (previous_remote_id != lease->remote_id_)) {
4349 }
catch (
const std::exception& ex) {
4353 .arg(lease->addr_.toText())
4375 .arg(lower_bound_address.
toText())
4378 .arg(
static_cast<unsigned>(link_len));
4381 if (!link_addr.
isV6()) {
4383 "retrieving leases from the lease database, got "
4386 if (link_len > 128) {
4388 <<
static_cast<unsigned>(link_len));
4390 if (!lower_bound_address.
isV6()) {
4392 "retrieving leases from the lease database, got "
4393 << lower_bound_address);
4396 std::vector<uint8_t> relay_id_data = relay_id.
getDuid();
4397 unsigned long relay_id_size = relay_id_data.size();
4398 if (relay_id_size == 0) {
4406 MYSQL_BIND inbind[3];
4407 memset(inbind, 0,
sizeof(inbind));
4409 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4410 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4411 inbind[0].buffer_length = relay_id_size;
4412 inbind[0].length = &relay_id_size;
4415 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4416 unsigned long lb_addr_size = lb_addr_data.size();
4417 if (lb_addr_size != 16) {
4420 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4421 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4422 inbind[1].buffer_length = lb_addr_size;
4423 inbind[1].length = &lb_addr_size;
4426 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4427 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4428 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4432 MySqlLeaseContextAlloc get_context(*
this);
4439 IOAddress start_addr = lower_bound_address;
4440 if (lower_bound_address < first_addr) {
4441 start_addr = first_addr;
4442 }
else if (last_addr <= lower_bound_address) {
4451 MYSQL_BIND inbind[4];
4452 memset(inbind, 0,
sizeof(inbind));
4454 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4455 inbind[0].buffer =
reinterpret_cast<char*
>(&relay_id_data[0]);
4456 inbind[0].buffer_length = relay_id_size;
4457 inbind[0].length = &relay_id_size;
4460 std::vector<uint8_t> start_addr_data = start_addr.
toBytes();
4461 unsigned long start_addr_size = start_addr_data.size();
4462 if (start_addr_size != 16) {
4465 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4466 inbind[1].buffer =
reinterpret_cast<char*
>(&start_addr_data[0]);
4467 inbind[1].buffer_length = start_addr_size;
4468 inbind[1].length = &start_addr_size;
4471 std::vector<uint8_t> last_addr_data = last_addr.
toBytes();
4472 unsigned long last_addr_size = last_addr_data.size();
4473 if (last_addr_size != 16) {
4476 inbind[2].buffer_type = MYSQL_TYPE_BLOB;
4477 inbind[2].buffer =
reinterpret_cast<char*
>(&last_addr_data[0]);
4478 inbind[2].buffer_length = last_addr_size;
4479 inbind[2].length = &last_addr_size;
4482 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4483 inbind[3].buffer_type = MYSQL_TYPE_LONG;
4484 inbind[3].buffer =
reinterpret_cast<char*
>(&ps);
4488 MySqlLeaseContextAlloc get_context(*
this);
4506 .arg(lower_bound_address.
toText())
4507 .arg(idToText(remote_id))
4509 .arg(
static_cast<unsigned>(link_len));
4512 if (!link_addr.
isV6()) {
4514 "retrieving leases from the lease database, got "
4517 if (link_len > 128) {
4519 <<
static_cast<unsigned>(link_len));
4521 if (!lower_bound_address.
isV6()) {
4523 "retrieving leases from the lease database, got "
4524 << lower_bound_address);
4527 std::vector<uint8_t> remote_id_data = remote_id;
4528 unsigned long remote_id_size = remote_id_data.size();
4529 if (remote_id_size == 0) {
4537 MYSQL_BIND inbind[3];
4538 memset(inbind, 0,
sizeof(inbind));
4540 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4541 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4542 inbind[0].buffer_length = remote_id_size;
4543 inbind[0].length = &remote_id_size;
4546 std::vector<uint8_t> lb_addr_data = lower_bound_address.
toBytes();
4547 unsigned long lb_addr_size = lb_addr_data.size();
4548 if (lb_addr_size != 16) {
4551 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4552 inbind[1].buffer =
reinterpret_cast<char*
>(&lb_addr_data[0]);
4553 inbind[1].buffer_length = lb_addr_size;
4554 inbind[1].length = &lb_addr_size;
4557 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4558 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4559 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4563 MySqlLeaseContextAlloc get_context(*
this);
4570 IOAddress start_addr = lower_bound_address;
4571 if (lower_bound_address < first_addr) {
4572 start_addr = first_addr;
4573 }
else if (last_addr <= lower_bound_address) {
4582 MYSQL_BIND inbind[4];
4583 memset(inbind, 0,
sizeof(inbind));
4585 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4586 inbind[0].buffer =
reinterpret_cast<char*
>(&remote_id_data[0]);
4587 inbind[0].buffer_length = remote_id_size;
4588 inbind[0].length = &remote_id_size;
4591 std::vector<uint8_t> start_addr_data = start_addr.
toBytes();
4592 unsigned long start_addr_size = start_addr_data.size();
4593 if (start_addr_size != 16) {
4596 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4597 inbind[1].buffer =
reinterpret_cast<char*
>(&start_addr_data[0]);
4598 inbind[1].buffer_length = start_addr_size;
4599 inbind[1].length = &start_addr_size;
4602 std::vector<uint8_t> last_addr_data = last_addr.
toBytes();
4603 unsigned long last_addr_size = last_addr_data.size();
4604 if (last_addr_size != 16) {
4607 inbind[2].buffer_type = MYSQL_TYPE_BLOB;
4608 inbind[2].buffer =
reinterpret_cast<char*
>(&last_addr_data[0]);
4609 inbind[2].buffer_length = last_addr_size;
4610 inbind[2].length = &last_addr_size;
4613 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4614 inbind[3].buffer_type = MYSQL_TYPE_LONG;
4615 inbind[3].buffer =
reinterpret_cast<char*
>(&ps);
4619 MySqlLeaseContextAlloc get_context(*
this);
4636 .arg(lower_bound_address.
toText())
4638 .arg(
static_cast<unsigned>(link_len));
4641 if (!link_addr.
isV6()) {
4643 "retrieving leases from the lease database, got "
4646 if ((link_len == 0) || (link_len > 128)) {
4648 <<
static_cast<unsigned>(link_len));
4650 if (!lower_bound_address.
isV6()) {
4652 "retrieving leases from the lease database, got "
4653 << lower_bound_address);
4659 IOAddress start_addr = lower_bound_address;
4660 if (lower_bound_address < first_addr) {
4661 start_addr = first_addr;
4662 }
else if (last_addr <= lower_bound_address) {
4671 MYSQL_BIND inbind[3];
4672 memset(inbind, 0,
sizeof(inbind));
4675 std::vector<uint8_t> start_addr_data = start_addr.
toBytes();
4676 if (start_addr_data.size() != 16) {
4679 unsigned long start_addr_size = 16;
4680 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4681 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_data[0]);
4682 inbind[0].buffer_length = 16;
4683 inbind[0].length = &start_addr_size;
4686 std::vector<uint8_t> last_addr_data = last_addr.
toBytes();
4687 if (last_addr_data.size() != 16) {
4690 unsigned long last_addr_size = 16;
4691 inbind[1].buffer_type = MYSQL_TYPE_BLOB;
4692 inbind[1].buffer =
reinterpret_cast<char*
>(&last_addr_data[0]);
4693 inbind[1].buffer_length = 16;
4694 inbind[1].length = &last_addr_size;
4697 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4698 inbind[2].buffer_type = MYSQL_TYPE_LONG;
4699 inbind[2].buffer =
reinterpret_cast<char*
>(&ps);
4703 MySqlLeaseContextAlloc get_context(*
this);
4715 getConsistency()->getExtendedInfoSanityCheck();
4729 .arg(start_addr.
toText())
4733 MYSQL_BIND inbind[2];
4734 memset(inbind, 0,
sizeof(inbind));
4737 std::vector<uint8_t>start_addr_bytes = start_addr.
toBytes();
4738 if (start_addr_bytes.size() != 16) {
4742 unsigned long start_addr_size = 16;
4743 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
4744 inbind[0].buffer =
reinterpret_cast<char*
>(&start_addr_bytes[0]);
4745 inbind[0].buffer_length = 16;
4746 inbind[0].length = &start_addr_size;
4749 uint32_t ps =
static_cast<uint32_t
>(page_size.
page_size_);
4750 inbind[1].buffer_type = MYSQL_TYPE_LONG;
4751 inbind[1].buffer =
reinterpret_cast<char*
>(&ps);
4758 MySqlLeaseContextAlloc get_context(*
this);
4764 if (leases.empty()) {
4770 start_addr = leases.back()->addr_;
4771 for (
auto lease : leases) {
4779 if (modified || added) {
4786 }
catch (
const std::exception& ex) {
4790 .arg(lease->addr_.toText())
4806 MySqlLeaseContextAlloc get_context(*
this);
4812 checkError(ctx, status, stindex,
"unable to execute");
4818 checkError(ctx, status, stindex,
"unable to execute");
4825 MySqlLeaseContextAlloc get_context(*
this);
4832 memset(bind, 0,
sizeof(bind));
4835 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4836 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4838 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4839 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4844 checkError(ctx, status, stindex,
"unable to execute");
4847 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4848 checkError(ctx, status, stindex,
"unable to store result");
4853 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4855 checkError(ctx, status, stindex,
"unable to fetch results");
4857 return (
static_cast<size_t>(count));
4863 MySqlLeaseContextAlloc get_context(*
this);
4870 memset(bind, 0,
sizeof(bind));
4873 bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
4874 bind[0].buffer =
reinterpret_cast<char*
>(&count);
4876 int status = mysql_stmt_bind_result(ctx->conn_.getStatement(stindex), &bind[0]);
4877 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
4882 checkError(ctx, status, stindex,
"unable to execute");
4885 status = mysql_stmt_store_result(ctx->conn_.getStatement(stindex));
4886 checkError(ctx, status, stindex,
"unable to store result");
4891 status = mysql_stmt_fetch(ctx->conn_.getStatement(stindex));
4893 checkError(ctx, status, stindex,
"unable to fetch results");
4895 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 if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
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 IOAddress increase(const IOAddress &addr)
Returns an address increased by one.
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 const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
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.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database.
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)
Get the schema version.
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.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Holds DUID (DHCPv6 Unique Identifier)
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 isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
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.
Exchange MySQL and Lease4 Data.
MySqlLease4Exchange()
Constructor.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
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 > createBindForReceive()
Create BIND array to receive data.
std::string getErrorColumns()
Return columns in error.
Lease6Ptr getLeaseData()
Copy Received Data into Lease6 Object.
std::vector< MYSQL_BIND > createBindForSend(const Lease6Ptr &lease)
Create MYSQL_BIND objects for Lease6 Pointer.
MySqlLease6Exchange()
Constructor.
MySQL Lease Context Pool.
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 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 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 Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual std::pair< uint32_t, uint32_t > getVersion() const override
Returns backend version.
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.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress &link_addr, uint8_t link_len, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with on a given link.
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 trackUpdateLease(const LeasePtr &lease, bool mt_safe)
Invokes the callbacks when a lease is updated.
void trackAddLease(const LeasePtr &lease, bool mt_safe)
Invokes the callbacks when a new lease is added.
void trackDeleteLease(const LeasePtr &lease, bool mt_safe)
Invokes the callbacks when a lease is deleted.
bool hasCallbacks() const
Checks if any callbacks have been registered.
RAII class creating a critical section.
#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.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
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_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_GET_LINKADDR6
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
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.
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.