21#include <boost/array.hpp>
22#include <boost/make_shared.hpp>
23#include <boost/static_assert.hpp>
24#include <mysqld_error.h>
101const size_t LIMITS_TEXT_MAX_LEN = 512;
103boost::array<TaggedStatement, MySqlLeaseMgr::NUM_STATEMENTS>
104tagged_statements = { {
105 {MySqlLeaseMgr::DELETE_LEASE4,
106 "DELETE FROM lease4 WHERE address = ? AND expire = ?"},
107 {MySqlLeaseMgr::DELETE_LEASE4_STATE_EXPIRED,
108 "DELETE FROM lease4 "
109 "WHERE state = ? AND expire < ?"},
110 {MySqlLeaseMgr::DELETE_LEASE6,
111 "DELETE FROM lease6 WHERE address = ? AND expire = ?"},
112 {MySqlLeaseMgr::DELETE_LEASE6_STATE_EXPIRED,
113 "DELETE FROM lease6 "
114 "WHERE state = ? AND expire < ?"},
115 {MySqlLeaseMgr::GET_LEASE4,
116 "SELECT address, hwaddr, client_id, "
117 "valid_lifetime, expire, subnet_id, "
118 "fqdn_fwd, fqdn_rev, hostname, "
119 "state, user_context "
121 {MySqlLeaseMgr::GET_LEASE4_ADDR,
122 "SELECT address, hwaddr, client_id, "
123 "valid_lifetime, expire, subnet_id, "
124 "fqdn_fwd, fqdn_rev, hostname, "
125 "state, user_context "
127 "WHERE address = ?"},
128 {MySqlLeaseMgr::GET_LEASE4_CLIENTID,
129 "SELECT address, hwaddr, client_id, "
130 "valid_lifetime, expire, subnet_id, "
131 "fqdn_fwd, fqdn_rev, hostname, "
132 "state, user_context "
134 "WHERE client_id = ?"},
135 {MySqlLeaseMgr::GET_LEASE4_CLIENTID_SUBID,
136 "SELECT address, hwaddr, client_id, "
137 "valid_lifetime, expire, subnet_id, "
138 "fqdn_fwd, fqdn_rev, hostname, "
139 "state, user_context "
141 "WHERE client_id = ? AND subnet_id = ?"},
142 {MySqlLeaseMgr::GET_LEASE4_HWADDR,
143 "SELECT address, hwaddr, client_id, "
144 "valid_lifetime, expire, subnet_id, "
145 "fqdn_fwd, fqdn_rev, hostname, "
146 "state, user_context "
149 {MySqlLeaseMgr::GET_LEASE4_HWADDR_SUBID,
150 "SELECT address, hwaddr, client_id, "
151 "valid_lifetime, expire, subnet_id, "
152 "fqdn_fwd, fqdn_rev, hostname, "
153 "state, user_context "
155 "WHERE hwaddr = ? AND subnet_id = ?"},
156 {MySqlLeaseMgr::GET_LEASE4_PAGE,
157 "SELECT address, hwaddr, client_id, "
158 "valid_lifetime, expire, subnet_id, "
159 "fqdn_fwd, fqdn_rev, hostname, "
160 "state, user_context "
165 {MySqlLeaseMgr::GET_LEASE4_SUBID,
166 "SELECT address, hwaddr, client_id, "
167 "valid_lifetime, expire, subnet_id, "
168 "fqdn_fwd, fqdn_rev, hostname, "
169 "state, user_context "
171 "WHERE subnet_id = ?"},
172 {MySqlLeaseMgr::GET_LEASE4_HOSTNAME,
173 "SELECT address, hwaddr, client_id, "
174 "valid_lifetime, expire, subnet_id, "
175 "fqdn_fwd, fqdn_rev, hostname, "
176 "state, user_context "
178 "WHERE hostname = ?"},
179 {MySqlLeaseMgr::GET_LEASE4_EXPIRE,
180 "SELECT address, hwaddr, client_id, "
181 "valid_lifetime, expire, subnet_id, "
182 "fqdn_fwd, fqdn_rev, hostname, "
183 "state, user_context "
186 "AND valid_lifetime != 4294967295 "
188 "ORDER BY expire ASC "
190 {MySqlLeaseMgr::GET_LEASE6,
191 "SELECT address, duid, valid_lifetime, "
192 "expire, subnet_id, pref_lifetime, "
193 "lease_type, iaid, prefix_len, "
194 "fqdn_fwd, fqdn_rev, hostname, "
195 "hwaddr, hwtype, hwaddr_source, "
196 "state, user_context "
198 {MySqlLeaseMgr::GET_LEASE6_ADDR,
199 "SELECT address, duid, valid_lifetime, "
200 "expire, subnet_id, pref_lifetime, "
201 "lease_type, iaid, prefix_len, "
202 "fqdn_fwd, fqdn_rev, hostname, "
203 "hwaddr, hwtype, hwaddr_source, "
204 "state, user_context "
206 "WHERE address = ? AND lease_type = ?"},
207 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
208 "SELECT address, duid, valid_lifetime, "
209 "expire, subnet_id, pref_lifetime, "
210 "lease_type, iaid, prefix_len, "
211 "fqdn_fwd, fqdn_rev, hostname, "
212 "hwaddr, hwtype, hwaddr_source, "
213 "state, user_context "
215 "WHERE duid = ? AND iaid = ? AND lease_type = ?"},
216 {MySqlLeaseMgr::GET_LEASE6_DUID_IAID_SUBID,
217 "SELECT address, duid, valid_lifetime, "
218 "expire, subnet_id, pref_lifetime, "
219 "lease_type, iaid, prefix_len, "
220 "fqdn_fwd, fqdn_rev, hostname, "
221 "hwaddr, hwtype, hwaddr_source, "
222 "state, user_context "
224 "WHERE duid = ? AND iaid = ? AND subnet_id = ? "
225 "AND lease_type = ?"},
226 {MySqlLeaseMgr::GET_LEASE6_PAGE,
227 "SELECT address, duid, valid_lifetime, "
228 "expire, subnet_id, pref_lifetime, "
229 "lease_type, iaid, prefix_len, "
230 "fqdn_fwd, fqdn_rev, hostname, "
231 "hwaddr, hwtype, hwaddr_source, "
232 "state, user_context "
237 {MySqlLeaseMgr::GET_LEASE6_SUBID,
238 "SELECT address, duid, valid_lifetime, "
239 "expire, subnet_id, pref_lifetime, "
240 "lease_type, iaid, prefix_len, "
241 "fqdn_fwd, fqdn_rev, hostname, "
242 "hwaddr, hwtype, hwaddr_source, "
243 "state, user_context "
245 "WHERE subnet_id = ?"},
246 {MySqlLeaseMgr::GET_LEASE6_DUID,
247 "SELECT address, duid, valid_lifetime, "
248 "expire, subnet_id, pref_lifetime, "
249 "lease_type, iaid, prefix_len, "
250 "fqdn_fwd, fqdn_rev, hostname, "
251 "hwaddr, hwtype, hwaddr_source, "
252 "state, user_context "
255 {MySqlLeaseMgr::GET_LEASE6_HOSTNAME,
256 "SELECT address, duid, valid_lifetime, "
257 "expire, subnet_id, pref_lifetime, "
258 "lease_type, iaid, prefix_len, "
259 "fqdn_fwd, fqdn_rev, hostname, "
260 "hwaddr, hwtype, hwaddr_source, "
261 "state, user_context "
263 "WHERE hostname = ?"},
264 {MySqlLeaseMgr::GET_LEASE6_EXPIRE,
265 "SELECT address, duid, valid_lifetime, "
266 "expire, subnet_id, pref_lifetime, "
267 "lease_type, iaid, prefix_len, "
268 "fqdn_fwd, fqdn_rev, hostname, "
269 "hwaddr, hwtype, hwaddr_source, "
270 "state, user_context "
273 "AND valid_lifetime != 4294967295 "
275 "ORDER BY expire ASC "
277 {MySqlLeaseMgr::INSERT_LEASE4,
278 "INSERT INTO lease4(address, hwaddr, client_id, "
279 "valid_lifetime, expire, subnet_id, "
280 "fqdn_fwd, fqdn_rev, hostname, "
281 "state, user_context) "
282 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
283 {MySqlLeaseMgr::INSERT_LEASE6,
284 "INSERT INTO lease6(address, duid, valid_lifetime, "
285 "expire, subnet_id, pref_lifetime, "
286 "lease_type, iaid, prefix_len, "
287 "fqdn_fwd, fqdn_rev, hostname, "
288 "hwaddr, hwtype, hwaddr_source, "
289 "state, user_context) "
290 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
291 {MySqlLeaseMgr::UPDATE_LEASE4,
292 "UPDATE lease4 SET address = ?, hwaddr = ?, "
293 "client_id = ?, valid_lifetime = ?, expire = ?, "
294 "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, "
296 "state = ?, user_context = ? "
297 "WHERE address = ? AND expire = ?"},
298 {MySqlLeaseMgr::UPDATE_LEASE6,
299 "UPDATE lease6 SET address = ?, duid = ?, "
300 "valid_lifetime = ?, expire = ?, subnet_id = ?, "
301 "pref_lifetime = ?, lease_type = ?, iaid = ?, "
302 "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, "
303 "hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
304 "state = ?, user_context = ? "
305 "WHERE address = ? AND expire = ?"},
306 {MySqlLeaseMgr::ALL_LEASE4_STATS,
307 "SELECT subnet_id, state, leases as state_count "
308 "FROM lease4_stat ORDER BY subnet_id, state"},
309 {MySqlLeaseMgr::SUBNET_LEASE4_STATS,
310 "SELECT subnet_id, state, leases as state_count "
312 "WHERE subnet_id = ? "
314 {MySqlLeaseMgr::SUBNET_RANGE_LEASE4_STATS,
315 "SELECT subnet_id, state, leases as state_count "
317 "WHERE subnet_id >= ? and subnet_id <= ? "
318 "ORDER BY subnet_id, state"},
319 {MySqlLeaseMgr::ALL_LEASE6_STATS,
320 "SELECT subnet_id, lease_type, state, leases as state_count "
321 "FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
322 {MySqlLeaseMgr::SUBNET_LEASE6_STATS,
323 "SELECT subnet_id, lease_type, state, leases as state_count "
325 "WHERE subnet_id = ? "
326 "ORDER BY lease_type, state"},
327 {MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
328 "SELECT subnet_id, lease_type, state, leases as state_count "
330 "WHERE subnet_id >= ? and subnet_id <= ? "
331 "ORDER BY subnet_id, lease_type, state"},
332 {MySqlLeaseMgr::CHECK_LEASE4_LIMITS,
"SELECT checkLease4Limits(?)"},
333 {MySqlLeaseMgr::CHECK_LEASE6_LIMITS,
"SELECT checkLease6Limits(?)"},
334 {MySqlLeaseMgr::IS_JSON_SUPPORTED,
"SELECT isJsonSupported()"},
335 {MySqlLeaseMgr::GET_LEASE4_COUNT_BY_CLASS,
337 "FROM lease4_stat_by_client_class "
338 "WHERE client_class = ?"},
339 {MySqlLeaseMgr::GET_LEASE6_COUNT_BY_CLASS,
341 "FROM lease6_stat_by_client_class "
342 "WHERE client_class = ? AND lease_type = ?"},
373 for (
size_t i = 0; i < count; ++i) {
394 std::string result =
"";
397 for (
size_t i = 0; i < count; ++i) {
399 if (!result.empty()) {
406 if (result.empty()) {
429 static const size_t LEASE_COLUMNS = 11;
438 client_id_length_(0), client_id_null_(
MLM_FALSE),
439 subnet_id_(0), valid_lifetime_(0),
440 fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0),
441 state_(0), user_context_length_(0),
443 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
444 memset(client_id_buffer_, 0,
sizeof(client_id_buffer_));
445 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
446 memset(user_context_, 0,
sizeof(user_context_));
447 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
450 columns_[0] =
"address";
451 columns_[1] =
"hwaddr";
452 columns_[2] =
"client_id";
453 columns_[3] =
"valid_lifetime";
454 columns_[4] =
"expire";
455 columns_[5] =
"subnet_id";
456 columns_[6] =
"fqdn_fwd";
457 columns_[7] =
"fqdn_rev";
458 columns_[8] =
"hostname";
459 columns_[9] =
"state";
460 columns_[10] =
"user_context";
461 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
483 memset(bind_, 0,
sizeof(bind_));
492 addr4_ = lease_->addr_.toUint32();
493 bind_[0].buffer_type = MYSQL_TYPE_LONG;
494 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
502 hwaddr_ = hwaddr->hwaddr_;
503 hwaddr_length_ = hwaddr->hwaddr_.size();
510 if (hwaddr_.empty()) {
514 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
515 bind_[1].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
516 bind_[1].buffer_length = hwaddr_length_;
517 bind_[1].length = &hwaddr_length_;
519 bind_[1].buffer_type = MYSQL_TYPE_NULL;
526 bind_[1].buffer = NULL;
527 bind_[1].is_null = &hwaddr_null_;
531 if (lease_->client_id_) {
532 client_id_ = lease_->client_id_->getClientId();
533 client_id_length_ = client_id_.size();
540 if (client_id_.empty()) {
541 client_id_.resize(1);
544 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
545 bind_[2].buffer =
reinterpret_cast<char*
>(&client_id_[0]);
546 bind_[2].buffer_length = client_id_length_;
547 bind_[2].length = &client_id_length_;
551 bind_[2].buffer_type = MYSQL_TYPE_NULL;
558 bind_[2].buffer = NULL;
559 bind_[2].is_null = &client_id_null_;
563 bind_[3].buffer_type = MYSQL_TYPE_LONG;
564 bind_[3].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
577 uint32_t valid_lft = lease_->valid_lft_;
583 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
584 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
585 bind_[4].buffer_length =
sizeof(expire_);
591 bind_[5].buffer_type = MYSQL_TYPE_LONG;
592 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
598 bind_[6].buffer_type = MYSQL_TYPE_TINY;
599 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
605 bind_[7].buffer_type = MYSQL_TYPE_TINY;
606 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
615 bind_[8].buffer_type = MYSQL_TYPE_STRING;
616 bind_[8].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
617 bind_[8].buffer_length = lease_->hostname_.length();
622 bind_[9].buffer_type = MYSQL_TYPE_LONG;
623 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->state_);
631 bind_[10].buffer_type = MYSQL_TYPE_STRING;
632 std::string ctx_txt = ctx->str();
634 bind_[10].buffer = user_context_;
635 bind_[10].buffer_length = ctx_txt.length();
639 bind_[10].buffer_type = MYSQL_TYPE_NULL;
646 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
648 }
catch (
const std::exception& ex) {
650 "Could not create bind array from Lease4: "
651 << lease_->addr_.toText() <<
", reason: " << ex.what());
656 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
671 memset(bind_, 0,
sizeof(bind_));
674 bind_[0].buffer_type = MYSQL_TYPE_LONG;
675 bind_[0].buffer =
reinterpret_cast<char*
>(&addr4_);
681 hwaddr_length_ =
sizeof(hwaddr_buffer_);
682 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
683 bind_[1].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
684 bind_[1].buffer_length = hwaddr_length_;
685 bind_[1].length = &hwaddr_length_;
690 client_id_length_ =
sizeof(client_id_buffer_);
691 bind_[2].buffer_type = MYSQL_TYPE_BLOB;
692 bind_[2].buffer =
reinterpret_cast<char*
>(client_id_buffer_);
693 bind_[2].buffer_length = client_id_length_;
694 bind_[2].length = &client_id_length_;
695 bind_[2].is_null = &client_id_null_;
700 bind_[3].buffer_type = MYSQL_TYPE_LONG;
701 bind_[3].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
707 bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
708 bind_[4].buffer =
reinterpret_cast<char*
>(&expire_);
709 bind_[4].buffer_length =
sizeof(expire_);
714 bind_[5].buffer_type = MYSQL_TYPE_LONG;
715 bind_[5].buffer =
reinterpret_cast<char*
>(&subnet_id_);
721 bind_[6].buffer_type = MYSQL_TYPE_TINY;
722 bind_[6].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
728 bind_[7].buffer_type = MYSQL_TYPE_TINY;
729 bind_[7].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
738 hostname_length_ =
sizeof(hostname_buffer_);
739 bind_[8].buffer_type = MYSQL_TYPE_STRING;
740 bind_[8].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
741 bind_[8].buffer_length = hostname_length_;
742 bind_[8].length = &hostname_length_;
747 bind_[9].buffer_type = MYSQL_TYPE_LONG;
748 bind_[9].buffer =
reinterpret_cast<char*
>(&state_);
755 user_context_length_ =
sizeof(user_context_);
756 bind_[10].buffer_type = MYSQL_TYPE_STRING;
757 bind_[10].buffer =
reinterpret_cast<char*
>(user_context_);
758 bind_[10].buffer_length = user_context_length_;
759 bind_[10].length = &user_context_length_;
760 bind_[10].is_null = &user_context_null_;
766 BOOST_STATIC_ASSERT(10 < LEASE_COLUMNS);
770 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
787 uint32_t valid_lft = valid_lifetime_;
795 client_id_length_ = 0;
800 std::string hostname(hostname_buffer_,
801 hostname_buffer_ + hostname_length_);
810 std::string user_context;
812 user_context_[user_context_length_] =
'\0';
813 user_context.assign(user_context_);
818 if (!user_context.empty()) {
822 <<
"' is not a JSON map");
826 Lease4Ptr lease(boost::make_shared<Lease4>(addr4_, hwaddr,
829 valid_lifetime_, cltt,
830 subnet_id_, fqdn_fwd_,
831 fqdn_rev_, hostname));
834 lease->state_ = state_;
837 lease->setContext(ctx);
863 MYSQL_BIND bind_[LEASE_COLUMNS];
864 std::string columns_[LEASE_COLUMNS];
867 std::vector<uint8_t> hwaddr_;
869 unsigned long hwaddr_length_;
871 std::vector<uint8_t> client_id_;
873 unsigned long client_id_length_;
877 uint32_t valid_lifetime_;
881 unsigned long hostname_length_;
884 unsigned long user_context_length_;
903 static const size_t LEASE_COLUMNS = 17;
912 hwaddr_null_(
MLM_FALSE), duid_length_(0),
913 iaid_(0), lease_type_(0), prefix_len_(0),
914 pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
915 fqdn_fwd_(false), fqdn_rev_(false),
916 hostname_length_(0), hwtype_(0), hwaddr_source_(0),
917 state_(0), user_context_length_(0),
919 memset(addr6_buffer_, 0,
sizeof(addr6_buffer_));
920 memset(duid_buffer_, 0,
sizeof(duid_buffer_));
921 memset(hostname_buffer_, 0,
sizeof(hostname_buffer_));
922 memset(hwaddr_buffer_, 0,
sizeof(hwaddr_buffer_));
923 memset(user_context_, 0,
sizeof(user_context_));
924 std::fill(&error_[0], &error_[LEASE_COLUMNS],
MLM_FALSE);
927 columns_[0] =
"address";
928 columns_[1] =
"duid";
929 columns_[2] =
"valid_lifetime";
930 columns_[3] =
"expire";
931 columns_[4] =
"subnet_id";
932 columns_[5] =
"pref_lifetime";
933 columns_[6] =
"lease_type";
934 columns_[7] =
"iaid";
935 columns_[8] =
"prefix_len";
936 columns_[9] =
"fqdn_fwd";
937 columns_[10] =
"fqdn_rev";
938 columns_[11] =
"hostname";
939 columns_[12] =
"hwaddr";
940 columns_[13] =
"hwtype";
941 columns_[14] =
"hwaddr_source";
942 columns_[15] =
"state";
943 columns_[16] =
"user_context";
944 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
965 memset(bind_, 0,
sizeof(bind_));
969 addr6_ = lease_->addr_.toText();
970 addr6_length_ = addr6_.size();
986 bind_[0].buffer_type = MYSQL_TYPE_STRING;
987 bind_[0].buffer =
const_cast<char*
>(addr6_.c_str());
988 bind_[0].buffer_length = addr6_length_;
989 bind_[0].length = &addr6_length_;
994 if (!lease_->duid_) {
996 <<
" is missing mandatory client-id.");
998 duid_ = lease_->duid_->getDuid();
999 duid_length_ = duid_.size();
1001 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1002 bind_[1].buffer =
reinterpret_cast<char*
>(&(duid_[0]));
1003 bind_[1].buffer_length = duid_length_;
1004 bind_[1].length = &duid_length_;
1009 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1010 bind_[2].buffer =
reinterpret_cast<char*
>(&lease_->valid_lft_);
1023 uint32_t valid_lft = lease_->valid_lft_;
1029 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1030 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1031 bind_[3].buffer_length =
sizeof(expire_);
1037 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1038 bind_[4].buffer =
reinterpret_cast<char*
>(&lease_->subnet_id_);
1045 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1046 bind_[5].buffer =
reinterpret_cast<char*
>(&lease_->preferred_lft_);
1053 lease_type_ = lease_->type_;
1054 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1055 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1062 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1063 bind_[7].buffer =
reinterpret_cast<char*
>(&lease_->iaid_);
1070 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1071 bind_[8].buffer =
reinterpret_cast<char*
>(&lease_->prefixlen_);
1077 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1078 bind_[9].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_fwd_);
1084 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1085 bind_[10].buffer =
reinterpret_cast<char*
>(&lease_->fqdn_rev_);
1091 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1092 bind_[11].buffer =
const_cast<char*
>(lease_->hostname_.c_str());
1093 bind_[11].buffer_length = lease_->hostname_.length();
1100 hwaddr_ = hwaddr->hwaddr_;
1101 hwaddr_length_ = hwaddr->hwaddr_.size();
1108 if (hwaddr_.empty()) {
1112 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1113 bind_[12].buffer =
reinterpret_cast<char*
>(&(hwaddr_[0]));
1114 bind_[12].buffer_length = hwaddr_length_;
1115 bind_[12].length = &hwaddr_length_;
1117 bind_[12].buffer_type = MYSQL_TYPE_NULL;
1124 bind_[12].buffer = NULL;
1125 bind_[12].is_null = &hwaddr_null_;
1130 hwtype_ = lease->hwaddr_->htype_;
1131 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1132 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1136 bind_[13].buffer_type = MYSQL_TYPE_NULL;
1143 bind_[13].buffer = NULL;
1144 bind_[13].is_null = &hwaddr_null_;
1149 hwaddr_source_ = lease->hwaddr_->source_;
1150 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1151 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1155 bind_[14].buffer_type = MYSQL_TYPE_NULL;
1162 bind_[14].buffer = NULL;
1163 bind_[14].is_null = &hwaddr_null_;
1167 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1168 bind_[15].buffer =
reinterpret_cast<char*
>(&lease_->state_);
1176 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1177 std::string ctx_txt = ctx->str();
1179 bind_[16].buffer = user_context_;
1180 bind_[16].buffer_length = ctx_txt.length();
1184 bind_[16].buffer_type = MYSQL_TYPE_NULL;
1191 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1193 }
catch (
const std::exception& ex) {
1195 "Could not create bind array from Lease6: "
1196 << lease_->addr_.toText() <<
", reason: " << ex.what());
1201 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1219 memset(bind_, 0,
sizeof(bind_));
1225 addr6_length_ =
sizeof(addr6_buffer_) - 1;
1226 bind_[0].buffer_type = MYSQL_TYPE_STRING;
1227 bind_[0].buffer = addr6_buffer_;
1228 bind_[0].buffer_length = addr6_length_;
1229 bind_[0].length = &addr6_length_;
1234 duid_length_ =
sizeof(duid_buffer_);
1235 bind_[1].buffer_type = MYSQL_TYPE_BLOB;
1236 bind_[1].buffer =
reinterpret_cast<char*
>(duid_buffer_);
1237 bind_[1].buffer_length = duid_length_;
1238 bind_[1].length = &duid_length_;
1243 bind_[2].buffer_type = MYSQL_TYPE_LONG;
1244 bind_[2].buffer =
reinterpret_cast<char*
>(&valid_lifetime_);
1250 bind_[3].buffer_type = MYSQL_TYPE_TIMESTAMP;
1251 bind_[3].buffer =
reinterpret_cast<char*
>(&expire_);
1252 bind_[3].buffer_length =
sizeof(expire_);
1257 bind_[4].buffer_type = MYSQL_TYPE_LONG;
1258 bind_[4].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1264 bind_[5].buffer_type = MYSQL_TYPE_LONG;
1265 bind_[5].buffer =
reinterpret_cast<char*
>(&pref_lifetime_);
1271 bind_[6].buffer_type = MYSQL_TYPE_TINY;
1272 bind_[6].buffer =
reinterpret_cast<char*
>(&lease_type_);
1278 bind_[7].buffer_type = MYSQL_TYPE_LONG;
1279 bind_[7].buffer =
reinterpret_cast<char*
>(&iaid_);
1285 bind_[8].buffer_type = MYSQL_TYPE_TINY;
1286 bind_[8].buffer =
reinterpret_cast<char*
>(&prefix_len_);
1292 bind_[9].buffer_type = MYSQL_TYPE_TINY;
1293 bind_[9].buffer =
reinterpret_cast<char*
>(&fqdn_fwd_);
1299 bind_[10].buffer_type = MYSQL_TYPE_TINY;
1300 bind_[10].buffer =
reinterpret_cast<char*
>(&fqdn_rev_);
1306 hostname_length_ =
sizeof(hostname_buffer_);
1307 bind_[11].buffer_type = MYSQL_TYPE_STRING;
1308 bind_[11].buffer =
reinterpret_cast<char*
>(hostname_buffer_);
1309 bind_[11].buffer_length = hostname_length_;
1310 bind_[11].length = &hostname_length_;
1316 hwaddr_length_ =
sizeof(hwaddr_buffer_);
1317 bind_[12].buffer_type = MYSQL_TYPE_BLOB;
1318 bind_[12].buffer =
reinterpret_cast<char*
>(hwaddr_buffer_);
1319 bind_[12].buffer_length = hwaddr_length_;
1320 bind_[12].length = &hwaddr_length_;
1321 bind_[12].is_null = &hwaddr_null_;
1324 bind_[13].buffer_type = MYSQL_TYPE_SHORT;
1325 bind_[13].buffer =
reinterpret_cast<char*
>(&hwtype_);
1329 bind_[14].buffer_type = MYSQL_TYPE_LONG;
1330 bind_[14].buffer =
reinterpret_cast<char*
>(&hwaddr_source_);
1334 bind_[15].buffer_type = MYSQL_TYPE_LONG;
1335 bind_[15].buffer =
reinterpret_cast<char*
>(&state_);
1342 user_context_length_ =
sizeof(user_context_);
1343 bind_[16].buffer_type = MYSQL_TYPE_STRING;
1344 bind_[16].buffer =
reinterpret_cast<char*
>(user_context_);
1345 bind_[16].buffer_length = user_context_length_;
1346 bind_[16].length = &user_context_length_;
1347 bind_[16].is_null = &user_context_null_;
1353 BOOST_STATIC_ASSERT(16 < LEASE_COLUMNS);
1357 return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[LEASE_COLUMNS]));
1374 addr6_buffer_[addr6_length_] =
'\0';
1375 std::string address = addr6_buffer_;
1381 switch (lease_type_) {
1396 static_cast<int>(lease_type_) <<
") for lease with "
1397 <<
"address " << address <<
". Only 0, 1, or 2 are "
1402 DuidPtr duid_ptr(
new DUID(duid_buffer_, duid_length_));
1406 std::string hostname(hostname_buffer_,
1407 hostname_buffer_ + hostname_length_);
1412 hwaddr.reset(
new HWAddr(hwaddr_buffer_, hwaddr_length_, hwtype_));
1413 hwaddr->source_ = hwaddr_source_;
1417 std::string user_context;
1419 user_context_[user_context_length_] =
'\0';
1420 user_context.assign(user_context_);
1425 if (!user_context.empty()) {
1429 <<
"' is not a JSON map");
1435 Lease6Ptr result(boost::make_shared<Lease6>(type, addr, duid_ptr, iaid_,
1437 valid_lifetime_, subnet_id_,
1438 fqdn_fwd_, fqdn_rev_,
1443 uint32_t valid_lft = valid_lifetime_;
1449 result->cltt_ = cltt;
1450 result->current_cltt_ = cltt;
1453 result->state_ = state_;
1456 result->setContext(ctx);
1483 unsigned long addr6_length_;
1484 MYSQL_BIND bind_[LEASE_COLUMNS];
1485 std::string columns_[LEASE_COLUMNS];
1486 my_bool error_[LEASE_COLUMNS];
1488 std::vector<uint8_t> hwaddr_;
1490 unsigned long hwaddr_length_;
1492 std::vector<uint8_t> duid_;
1494 unsigned long duid_length_;
1497 uint8_t lease_type_;
1498 uint8_t prefix_len_;
1499 uint32_t pref_lifetime_;
1500 uint32_t subnet_id_;
1501 uint32_t valid_lifetime_;
1505 unsigned long hostname_length_;
1507 uint32_t hwaddr_source_;
1510 unsigned long user_context_length_;
1533 const bool fetch_type)
1534 : conn_(conn), statement_index_(statement_index), statement_(NULL),
1535 fetch_type_(fetch_type),
1538 bind_(fetch_type_ ? 4 : 3),
1539 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1540 validateStatement();
1553 const bool fetch_type,
const SubnetID& subnet_id)
1554 :
LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
1555 statement_(NULL), fetch_type_(fetch_type),
1558 bind_(fetch_type_ ? 4 : 3),
1559 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1560 validateStatement();
1576 const bool fetch_type,
const SubnetID& first_subnet_id,
1579 statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
1582 bind_(fetch_type_ ? 4 : 3),
1583 subnet_id_(0), lease_type_(0), state_(0), state_count_(0) {
1584 validateStatement();
1589 (void) mysql_stmt_free_result(statement_);
1602 MYSQL_BIND inbind[2];
1603 memset(inbind, 0,
sizeof(inbind));
1606 inbind[0].buffer_type = MYSQL_TYPE_LONG;
1612 inbind[1].buffer_type = MYSQL_TYPE_LONG;
1618 int status = mysql_stmt_bind_param(statement_, &inbind[0]);
1619 conn_.
checkError(status, statement_index_,
"unable to bind parameters");
1624 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1625 bind_[col].buffer =
reinterpret_cast<char*
>(&subnet_id_);
1632 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1633 bind_[col].buffer =
reinterpret_cast<char*
>(&lease_type_);
1641 bind_[col].buffer_type = MYSQL_TYPE_LONG;
1642 bind_[col].buffer =
reinterpret_cast<char*
>(&state_);
1647 bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
1648 bind_[col].buffer =
reinterpret_cast<char*
>(&state_count_);
1653 int status = mysql_stmt_bind_result(statement_, &bind_[0]);
1654 conn_.
checkError(status, statement_index_,
"outbound binding failed");
1658 conn_.
checkError(status, statement_index_,
"unable to execute");
1662 status = mysql_stmt_store_result(statement_);
1663 conn_.
checkError(status, statement_index_,
"results storage failed");
1682 bool have_row =
false;
1683 int status = mysql_stmt_fetch(statement_);
1688 if (state_count_ >= 0) {
1692 if (!negative_count_) {
1693 negative_count_ =
true;
1698 }
else if (status != MYSQL_NO_DATA) {
1699 conn_.
checkError(status, statement_index_,
"getNextRow failed");
1710 void validateStatement() {
1713 " - invalid statement index" << statement_index_);
1723 size_t statement_index_;
1726 MYSQL_STMT *statement_;
1732 std::vector<MYSQL_BIND> bind_;
1735 uint32_t subnet_id_;
1738 uint32_t lease_type_;
1744 int64_t state_count_;
1747 static bool negative_count_;
1751bool MySqlLeaseStatsQuery::negative_count_ =
false;
1758 : conn_(parameters, io_service_accessor, db_reconnect_callback) {
1763MySqlLeaseMgr::MySqlLeaseContextAlloc::MySqlLeaseContextAlloc(
1766 if (MultiThreadingMgr::instance().getMode()) {
1770 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1771 if (!mgr_.pool_->pool_.empty()) {
1772 ctx_ = mgr_.pool_->pool_.back();
1773 mgr_.pool_->pool_.pop_back();
1777 ctx_ = mgr_.createContext();
1781 if (mgr_.pool_->pool_.empty()) {
1784 ctx_ = mgr_.pool_->pool_.back();
1788MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
1789 if (MultiThreadingMgr::instance().getMode()) {
1791 lock_guard<mutex> lock(mgr_.pool_->mutex_);
1792 mgr_.pool_->pool_.push_back(ctx_);
1800 : parameters_(parameters), timer_name_(
"") {
1803 timer_name_ =
"MySqlLeaseMgr[";
1804 timer_name_ += boost::lexical_cast<std::string>(
reinterpret_cast<uint64_t
>(
this));
1805 timer_name_ +=
"]DbReconnectTimer";
1810 std::pair<uint32_t, uint32_t> db_version =
getVersion();
1811 if (code_version != db_version) {
1813 "MySQL schema version mismatch: need version: "
1814 << code_version.first <<
"." << code_version.second
1815 <<
" found version: " << db_version.first <<
"."
1816 << db_version.second);
1836 bool reopened =
false;
1838 const std::string timer_name = db_reconnect_ctl->timerName();
1846 }
catch (
const std::exception& ex) {
1862 if (!db_reconnect_ctl->checkRetries()) {
1865 .arg(db_reconnect_ctl->maxRetries());
1878 .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
1879 .arg(db_reconnect_ctl->maxRetries())
1880 .arg(db_reconnect_ctl->retryInterval());
1886 db_reconnect_ctl->retryInterval(),
1904 ctx->conn_.openDatabase();
1907 if (ctx->conn_.getTls()) {
1908 std::string cipher = ctx->conn_.getTlsCipher();
1909 if (cipher.empty()) {
1919 ctx->conn_.prepareStatements(tagged_statements.begin(),
1920 tagged_statements.end());
1928 ctx->conn_.makeReconnectCtl(timer_name_);
1935 std::stringstream tmp;
1938 tmp <<
", library " << mysql_get_client_info();
1948 StatementIndex stindex,
1949 std::vector<MYSQL_BIND>& bind) {
1952 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], &bind[0]);
1953 checkError(ctx, status, stindex,
"unable to bind parameters");
1962 if (mysql_errno(ctx->conn_.mysql_) == ER_DUP_ENTRY) {
1965 checkError(ctx, status, stindex,
"unable to execute");
1975 .arg(lease->addr_.toText());
1978 MySqlLeaseContextAlloc get_context(*
this);
1982 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
1989 lease->updateCurrentExpirationTime();
1997 .arg(lease->addr_.toText())
2001 MySqlLeaseContextAlloc get_context(*
this);
2005 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2012 lease->updateCurrentExpirationTime();
2042template <
typename Exchange,
typename LeaseCollection>
2045 StatementIndex stindex,
2048 LeaseCollection& result,
2049 bool single)
const {
2054 status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2055 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2060 std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
2061 status = mysql_stmt_bind_result(ctx->conn_.statements_[stindex], &outbind[0]);
2062 checkError(ctx, status, stindex,
"unable to bind SELECT clause parameters");
2066 checkError(ctx, status, stindex,
"unable to execute");
2070 status = mysql_stmt_store_result(ctx->conn_.statements_[stindex]);
2071 checkError(ctx, status, stindex,
"unable to set up for storing all results");
2078 while ((status = mysql_stmt_fetch(ctx->conn_.statements_[stindex])) == 0) {
2080 result.push_back(exchange->getLeaseData());
2085 ctx->conn_.text_statements_[stindex] <<
">");
2088 if (single && (++count > 1)) {
2090 "database where only one was expected for query "
2091 << ctx->conn_.text_statements_[stindex]);
2098 checkError(ctx, status, stindex,
"unable to fetch results");
2099 }
else if (status == MYSQL_DATA_TRUNCATED) {
2102 <<
" returned truncated data: columns affected are "
2103 << exchange->getErrorColumns());
2109 StatementIndex stindex, MYSQL_BIND* bind,
2117 getLeaseCollection(ctx, stindex, bind, ctx->exchange4_, collection,
true);
2120 if (collection.empty()) {
2123 result = *collection.begin();
2129 StatementIndex stindex, MYSQL_BIND* bind,
2137 getLeaseCollection(ctx, stindex, bind, ctx->exchange6_, collection,
true);
2140 if (collection.empty()) {
2143 result = *collection.begin();
2156 MYSQL_BIND inbind[1];
2157 memset(inbind, 0,
sizeof(inbind));
2160 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2161 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2168 MySqlLeaseContextAlloc get_context(*
this);
2182 MYSQL_BIND inbind[1];
2183 memset(inbind, 0,
sizeof(inbind));
2185 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2187 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2191 uint8_t single_byte_data = 0;
2198 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2199 : &single_byte_data;
2201 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2202 inbind[0].buffer_length = hwaddr_length;
2203 inbind[0].length = &hwaddr_length;
2209 MySqlLeaseContextAlloc get_context(*
this);
2224 MYSQL_BIND inbind[2];
2225 memset(inbind, 0,
sizeof(inbind));
2227 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2229 unsigned long hwaddr_length = hwaddr.
hwaddr_.size();
2233 std::vector<uint8_t> single_byte_vec(1);
2240 uint8_t* data = !hwaddr.
hwaddr_.empty() ?
const_cast<uint8_t*
>(&hwaddr.
hwaddr_[0])
2241 : &single_byte_vec[0];
2243 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2244 inbind[0].buffer_length = hwaddr_length;
2245 inbind[0].length = &hwaddr_length;
2247 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2248 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2255 MySqlLeaseContextAlloc get_context(*
this);
2269 MYSQL_BIND inbind[1];
2270 memset(inbind, 0,
sizeof(inbind));
2272 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2274 std::vector<uint8_t> client_data = clientid.
getClientId();
2275 unsigned long client_data_length = client_data.size();
2279 if (client_data.empty()) {
2280 client_data.resize(1);
2283 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2284 inbind[0].buffer_length = client_data_length;
2285 inbind[0].length = &client_data_length;
2291 MySqlLeaseContextAlloc get_context(*
this);
2306 MYSQL_BIND inbind[2];
2307 memset(inbind, 0,
sizeof(inbind));
2309 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2311 std::vector<uint8_t> client_data = clientid.
getClientId();
2312 unsigned long client_data_length = client_data.size();
2316 if (client_data.empty()) {
2317 client_data.resize(1);
2320 inbind[0].buffer =
reinterpret_cast<char*
>(&client_data[0]);
2321 inbind[0].buffer_length = client_data_length;
2322 inbind[0].length = &client_data_length;
2324 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2325 inbind[1].buffer =
reinterpret_cast<char*
>(&subnet_id);
2332 MySqlLeaseContextAlloc get_context(*
this);
2346 MYSQL_BIND inbind[1];
2347 memset(inbind, 0,
sizeof(inbind));
2350 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2351 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2358 MySqlLeaseContextAlloc get_context(*
this);
2372 MYSQL_BIND inbind[1];
2373 memset(inbind, 0,
sizeof(inbind));
2376 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2377 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2378 inbind[0].buffer_length = hostname.length();
2384 MySqlLeaseContextAlloc get_context(*
this);
2399 MySqlLeaseContextAlloc get_context(*
this);
2402 getLeaseCollection(ctx,
GET_LEASE4, 0, result);
2411 if (!lower_bound_address.
isV4()) {
2413 "retrieving leases from the lease database, got "
2414 << lower_bound_address);
2419 .arg(lower_bound_address.
toText());
2422 MYSQL_BIND inbind[2];
2423 memset(inbind, 0,
sizeof(inbind));
2426 uint32_t lb_address_data = lower_bound_address.
toUint32();
2427 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2428 inbind[0].buffer =
reinterpret_cast<char*
>(&lb_address_data);
2432 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2433 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2434 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2441 MySqlLeaseContextAlloc get_context(*
this);
2457 MYSQL_BIND inbind[2];
2458 memset(inbind, 0,
sizeof(inbind));
2460 std::string addr6 = addr.
toText();
2461 unsigned long addr6_length = addr6.size();
2465 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2466 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2467 inbind[0].buffer_length = addr6_length;
2468 inbind[0].length = &addr6_length;
2471 inbind[1].buffer_type = MYSQL_TYPE_TINY;
2472 inbind[1].buffer =
reinterpret_cast<char*
>(&lease_type);
2478 MySqlLeaseContextAlloc get_context(*
this);
2488 uint32_t iaid)
const {
2495 MYSQL_BIND inbind[3];
2496 memset(inbind, 0,
sizeof(inbind));
2510 const vector<uint8_t>& duid_vector = duid.
getDuid();
2511 unsigned long duid_length = duid_vector.size();
2518 uint8_t single_byte_data = 0;
2519 uint8_t* data = !duid_vector.empty() ?
const_cast<uint8_t*
>(&duid_vector[0])
2520 : &single_byte_data;
2522 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2523 inbind[0].buffer =
reinterpret_cast<char*
>(data);
2524 inbind[0].buffer_length = duid_length;
2525 inbind[0].length = &duid_length;
2528 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2529 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2533 inbind[2].buffer_type = MYSQL_TYPE_TINY;
2534 inbind[2].buffer =
reinterpret_cast<char*
>(&lease_type);
2541 MySqlLeaseContextAlloc get_context(*
this);
2551 uint32_t iaid,
SubnetID subnet_id)
const {
2559 MYSQL_BIND inbind[4];
2560 memset(inbind, 0,
sizeof(inbind));
2564 const vector<uint8_t>& duid_vector = duid.
getDuid();
2565 unsigned long duid_length = duid_vector.size();
2566 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2567 inbind[0].buffer =
reinterpret_cast<char*
>(
2568 const_cast<uint8_t*
>(&duid_vector[0]));
2569 inbind[0].buffer_length = duid_length;
2570 inbind[0].length = &duid_length;
2573 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2574 inbind[1].buffer =
reinterpret_cast<char*
>(&iaid);
2578 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2579 inbind[2].buffer =
reinterpret_cast<char*
>(&subnet_id);
2583 inbind[3].buffer_type = MYSQL_TYPE_TINY;
2584 inbind[3].buffer =
reinterpret_cast<char*
>(&lease_type);
2591 MySqlLeaseContextAlloc get_context(*
this);
2605 MYSQL_BIND inbind[1];
2606 memset(inbind, 0,
sizeof(inbind));
2609 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2610 inbind[0].buffer =
reinterpret_cast<char*
>(&subnet_id);
2617 MySqlLeaseContextAlloc get_context(*
this);
2632 MySqlLeaseContextAlloc get_context(*
this);
2635 getLeaseCollection(ctx,
GET_LEASE6, 0, result);
2646 MYSQL_BIND inbind[1];
2647 memset(inbind, 0,
sizeof(inbind));
2649 const vector<uint8_t>& duid_vector = duid.
getDuid();
2650 unsigned long duid_length = duid_vector.size();
2652 inbind[0].buffer_type = MYSQL_TYPE_BLOB;
2653 inbind[0].buffer =
reinterpret_cast<char*
>(
2654 const_cast<uint8_t*
>(&duid_vector[0]));
2655 inbind[0].buffer_length = duid_length;
2656 inbind[0].length = &duid_length;
2661 MySqlLeaseContextAlloc get_context(*
this);
2675 MYSQL_BIND inbind[1];
2676 memset(inbind, 0,
sizeof(inbind));
2679 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2680 inbind[0].buffer =
const_cast<char*
>(hostname.c_str());
2681 inbind[0].buffer_length = hostname.length();
2687 MySqlLeaseContextAlloc get_context(*
this);
2699 if (!lower_bound_address.
isV6()) {
2701 "retrieving leases from the lease database, got "
2702 << lower_bound_address);
2707 .arg(lower_bound_address.
toText());
2710 MYSQL_BIND inbind[2];
2711 memset(inbind, 0,
sizeof(inbind));
2716 std::string lb_address_data =
"0";
2717 if (!lower_bound_address.
isV6Zero()) {
2718 lb_address_data = lower_bound_address.
toText();
2722 unsigned long lb_address_data_size = lb_address_data.size();
2723 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2724 inbind[0].buffer =
const_cast<char*
>(lb_address_data.c_str());
2725 inbind[0].buffer_length = lb_address_data_size;
2726 inbind[0].length = &lb_address_data_size;
2729 size_t* ps =
const_cast<size_t*
>(&page_size.
page_size_);
2730 inbind[1].buffer_type = MYSQL_TYPE_LONG;
2731 inbind[1].buffer =
reinterpret_cast<char*
>(ps);
2738 MySqlLeaseContextAlloc get_context(*
this);
2748 const size_t max_leases)
const {
2756 const size_t max_leases)
const {
2762template<
typename LeaseCollection>
2764MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
2765 const size_t max_leases,
2766 StatementIndex statement_index)
const {
2768 MYSQL_BIND inbind[3];
2769 memset(inbind, 0,
sizeof(inbind));
2773 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2774 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
2778 MYSQL_TIME expire_time;
2780 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2781 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
2782 inbind[1].buffer_length =
sizeof(expire_time);
2786 uint32_t limit = max_leases > 0 ?
static_cast<uint32_t
>(max_leases) :
2787 std::numeric_limits<uint32_t>::max();
2788 inbind[2].buffer_type = MYSQL_TYPE_LONG;
2789 inbind[2].buffer =
reinterpret_cast<char*
>(&limit);
2793 MySqlLeaseContextAlloc get_context(*
this);
2797 getLeaseCollection(ctx, statement_index, inbind, expired_leases);
2804template <
typename LeasePtr>
2807 StatementIndex stindex,
2812 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2813 checkError(ctx, status, stindex,
"unable to bind parameters");
2817 checkError(ctx, status, stindex,
"unable to execute");
2821 int affected_rows = mysql_stmt_affected_rows(ctx->conn_.statements_[stindex]);
2824 if (affected_rows == 1) {
2829 if (affected_rows == 0) {
2831 lease->addr_.toText() <<
" as it does not exist");
2837 "that had the address " << lease->addr_.toText());
2845 .arg(lease->addr_.toText());
2848 MySqlLeaseContextAlloc get_context(*
this);
2852 std::vector<MYSQL_BIND> bind = ctx->exchange4_->createBindForSend(lease);
2855 MYSQL_BIND inbind[2];
2856 memset(inbind, 0,
sizeof(inbind));
2858 uint32_t addr4 = lease->addr_.toUint32();
2859 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2860 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2863 bind.push_back(inbind[0]);
2868 uint32_t valid_lft = lease->current_valid_lft_;
2874 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2875 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2876 inbind[1].buffer_length =
sizeof(expire);
2878 bind.push_back(inbind[1]);
2881 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2884 lease->updateCurrentExpirationTime();
2892 .arg(lease->addr_.toText())
2896 MySqlLeaseContextAlloc get_context(*
this);
2900 std::vector<MYSQL_BIND> bind = ctx->exchange6_->createBindForSend(lease);
2903 MYSQL_BIND inbind[2];
2904 memset(inbind, 0,
sizeof(inbind));
2906 std::string addr6 = lease->addr_.toText();
2907 unsigned long addr6_length = addr6.size();
2911 inbind[0].buffer_type = MYSQL_TYPE_STRING;
2912 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
2913 inbind[0].buffer_length = addr6_length;
2914 inbind[0].length = &addr6_length;
2916 bind.push_back(inbind[0]);
2921 uint32_t valid_lft = lease->current_valid_lft_;
2927 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2928 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2929 inbind[1].buffer_length =
sizeof(expire);
2931 bind.push_back(inbind[1]);
2934 updateLeaseCommon(ctx, stindex, &bind[0], lease);
2937 lease->updateCurrentExpirationTime();
2946MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex,
2950 MySqlLeaseContextAlloc get_context(*
this);
2954 int status = mysql_stmt_bind_param(ctx->conn_.statements_[stindex], bind);
2955 checkError(ctx, status, stindex,
"unable to bind WHERE clause parameter");
2959 checkError(ctx, status, stindex,
"unable to execute");
2963 return (
static_cast<uint64_t
>(mysql_stmt_affected_rows(ctx->conn_.statements_[stindex])));
2973 MYSQL_BIND inbind[2];
2974 memset(inbind, 0,
sizeof(inbind));
2978 inbind[0].buffer_type = MYSQL_TYPE_LONG;
2979 inbind[0].buffer =
reinterpret_cast<char*
>(&addr4);
2985 uint32_t valid_lft = lease->current_valid_lft_;
2991 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
2992 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
2993 inbind[1].buffer_length =
sizeof(expire);
2995 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE4, inbind);
2998 if (affected_rows == 1) {
3003 if (affected_rows == 0) {
3010 "that had the address " << lease->addr_.toText());
3021 MYSQL_BIND inbind[2];
3022 memset(inbind, 0,
sizeof(inbind));
3024 std::string addr6 = addr.
toText();
3025 unsigned long addr6_length = addr6.size();
3029 inbind[0].buffer_type = MYSQL_TYPE_STRING;
3030 inbind[0].buffer =
const_cast<char*
>(addr6.c_str());
3031 inbind[0].buffer_length = addr6_length;
3032 inbind[0].length = &addr6_length;
3037 uint32_t valid_lft = lease->current_valid_lft_;
3043 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3044 inbind[1].buffer =
reinterpret_cast<char*
>(&expire);
3045 inbind[1].buffer_length =
sizeof(expire);
3047 auto affected_rows = deleteLeaseCommon(
DELETE_LEASE6, inbind);
3050 if (affected_rows == 1) {
3055 if (affected_rows == 0) {
3062 "that had the address " << lease->addr_.toText());
3080MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
3081 StatementIndex statement_index) {
3083 MYSQL_BIND inbind[2];
3084 memset(inbind, 0,
sizeof(inbind));
3088 inbind[0].buffer_type = MYSQL_TYPE_LONG;
3089 inbind[0].buffer =
reinterpret_cast<char*
>(&state);
3093 MYSQL_TIME expire_time;
3095 inbind[1].buffer_type = MYSQL_TYPE_TIMESTAMP;
3096 inbind[1].buffer =
reinterpret_cast<char*
>(&expire_time);
3097 inbind[1].buffer_length =
sizeof(expire_time);
3100 uint64_t deleted_leases = deleteLeaseCommon(statement_index, inbind);
3102 .arg(deleted_leases);
3104 return (deleted_leases);
3108MySqlLeaseMgr::checkLimits(
ConstElementPtr const& user_context, StatementIndex
const stindex)
const {
3110 if (!user_context) {
3115 MySqlLeaseContextAlloc get_context(*
this);
3127 std::string limit_text;
3128 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3130 limit_text = result[0]->getString();
3137MySqlLeaseMgr::checkLimits4(
ConstElementPtr const& user_context)
const {
3142MySqlLeaseMgr::checkLimits6(
ConstElementPtr const& user_context)
const {
3147MySqlLeaseMgr::isJsonSupported()
const {
3149 MySqlLeaseContextAlloc get_context(*
this);
3159 bool json_supported(
false);
3162 json_supported = result[0]->getBool();
3165 return json_supported;
3169MySqlLeaseMgr::getClassLeaseCount(
const ClientClass& client_class,
3172 MySqlLeaseContextAlloc get_context(*
this);
3180 in_bindings.push_back(MySqlBinding::createInteger<uint8_t>(ltype));
3183 MySqlBinding::createInteger<int64_t>()
3190 ctx->conn_.selectQuery(stindex, in_bindings, out_bindings,
3192 count = result[0]->getInteger<int64_t>();
3199MySqlLeaseMgr::recountClassLeases4() {
3204MySqlLeaseMgr::recountClassLeases6() {
3209MySqlLeaseMgr::clearClassLeaseCounts() {
3216 MySqlLeaseContextAlloc get_context(*
this);
3229 MySqlLeaseContextAlloc get_context(*
this);
3244 MySqlLeaseContextAlloc get_context(*
this);
3259 MySqlLeaseContextAlloc get_context(*
this);
3272 MySqlLeaseContextAlloc get_context(*
this);
3287 MySqlLeaseContextAlloc get_context(*
this);
3314 MySqlLeaseContextAlloc get_context(*
this);
3317 std::string name =
"";
3319 name = ctx->conn_.getParameter(
"name");
3328 return (std::string(
"MySQL Database"));
3331std::pair<uint32_t, uint32_t>
3350 int status, StatementIndex index,
3351 const char* what)
const {
3352 ctx->conn_.checkError(status, index, what);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
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.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
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.
std::vector< MYSQL_STMT * > statements_
Prepared statements.
static void convertToDatabaseTime(const time_t input_time, MYSQL_TIME &output_time)
Convert time_t value to database time.
static void convertFromDatabaseTime(const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
Convert Database Time to Lease Times.
static std::pair< uint32_t, uint32_t > getVersion(const ParameterMap ¶meters)
Get the schema version.
void checkError(const int status, const StatementIndex &index, const char *what)
Check Error and Throw Exception.
Fetch and Release MySQL Results.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds Client identifier or client IPv4 address.
static const size_t MAX_CLIENT_ID_LEN
Maximum size of a client ID.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
Holds DUID (DHCPv6 Unique Identifier)
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
static const size_t MAX_DUID_LEN
maximum duid size As defined in RFC 8415, section 11.1
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
static void destroy()
Destroy lease manager.
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
Base class for fulfilling a statistical lease data query.
SubnetID first_subnet_id_
First (or only) subnet_id in the selection criteria.
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
SubnetID last_subnet_id_
Last subnet_id in the selection criteria when a range is given.
Exchange MySQL and Lease4 Data.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
MySqlLease4Exchange()
Constructor.
std::vector< MYSQL_BIND > createBindForSend(const Lease4Ptr &lease)
Create MYSQL_BIND objects for Lease4 Pointer.
std::string getErrorColumns()
Return columns in error.
Lease4Ptr getLeaseData()
Copy Received Data into Lease4 Object.
Exchange MySQL and Lease6 Data.
std::vector< MYSQL_BIND > createBindForSend(const Lease6Ptr &lease)
Create MYSQL_BIND objects for Lease6 Pointer.
std::string getErrorColumns()
Return columns in error.
Lease6Ptr getLeaseData()
Copy Received Data into Lease6 Object.
std::vector< MYSQL_BIND > createBindForReceive()
Create BIND array to receive data.
MySqlLease6Exchange()
Constructor.
MySQL Lease Context Pool.
MySqlLeaseContext(const db::DatabaseConnection::ParameterMap ¶meters, db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback)
Constructor.
Common MySQL and Lease Data Methods.
static std::string getColumnsInError(my_bool *error, std::string *names, size_t count)
Return columns in error.
static void setErrorIndicators(MYSQL_BIND *bind, my_bool *error, size_t count)
Set error indicators.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual std::string getDescription() const override
Returns description of the backend.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
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 LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
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 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 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 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 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_LEASE6_COUNT_BY_CLASS
@ GET_LEASE4_HWADDR_SUBID
@ GET_LEASE4_COUNT_BY_CLASS
@ DELETE_LEASE4_STATE_EXPIRED
@ GET_LEASE4_CLIENTID_SUBID
@ DELETE_LEASE6_STATE_EXPIRED
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 LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual 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 wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
static bool dbReconnect(util::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
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)
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.
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.
boost::shared_ptr< const Element > ConstElementPtr
const my_bool MLM_FALSE
MySQL false value.
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
const uint32_t MYSQL_SCHEMA_VERSION_MINOR
const my_bool MLM_TRUE
MySQL true value.
bool my_bool
my_bool type in MySQL 8.x.
std::vector< MySqlBindingPtr > MySqlBindingCollection
Collection of bindings.
const int MLM_MYSQL_FETCH_SUCCESS
check for bool size
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
std::function< isc::asiolink::IOServicePtr()> IOServiceAccessor
Function which returns the IOService that can be used to recover the connection.
int MysqlExecuteStatement(MYSQL_STMT *stmt)
Execute a prepared statement.
const isc::log::MessageID DHCPSRV_MYSQL_GET_HOSTNAME4
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_MYSQL_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR4
std::string ClientClass
Defines a single class name.
const isc::log::MessageID DHCPSRV_MYSQL_COMMIT
const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MYSQL_NEGATIVE_LEASES_STAT
const isc::log::MessageID DHCPSRV_MYSQL_GET_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.
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_ADDR4
const isc::log::MessageID DHCPSRV_MYSQL_GET_IAID_SUBID_DUID
const isc::log::MessageID DHCPSRV_MYSQL_UPDATE_ADDR6
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_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
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_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
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_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.
static const size_t MAX_HWADDR_LEN
Maximum size of a hardware address.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
Contains a single row of lease statistical data.
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.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address