|
@@ -1117,6 +1117,29 @@ public:
|
|
|
boost::shared_ptr<MySqlHostExchange> exchange,
|
|
|
ConstHostCollection& result, bool single) const;
|
|
|
|
|
|
+ /// @brief Retrieves a host by subnet and client's unique identifier.
|
|
|
+ ///
|
|
|
+ /// This method is used by both MySqlHostDataSource::get4 and
|
|
|
+ /// MySqlHOstDataSource::get6 methods.
|
|
|
+ ///
|
|
|
+ /// @param subnet_id Subnet identifier.
|
|
|
+ /// @param identifier_type Identifier type.
|
|
|
+ /// @param identifier_begin Pointer to a begining of a buffer containing
|
|
|
+ /// an identifier.
|
|
|
+ /// @param identifier_len Identifier length.
|
|
|
+ /// @param stindex Statement index.
|
|
|
+ /// @param exchange Pointer to the exchange object used for the
|
|
|
+ /// particular query.
|
|
|
+ ///
|
|
|
+ /// @return Pointer to const instance of Host or null pointer if
|
|
|
+ /// no host found.
|
|
|
+ ConstHostPtr getHost(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin,
|
|
|
+ const size_t identifier_len,
|
|
|
+ MySqlHostDataSource::StatementIndex stindex,
|
|
|
+ boost::shared_ptr<MySqlHostExchange> exchange) const;
|
|
|
+
|
|
|
/// @brief Pointer to the object representing an exchange which
|
|
|
/// can be used to retrieve DHCPv4 reservation.
|
|
|
boost::shared_ptr<MySqlHostExchange> host_exchange_;
|
|
@@ -1276,6 +1299,50 @@ getHostCollection(MySqlHostDataSource::StatementIndex stindex,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ConstHostPtr
|
|
|
+MySqlHostDataSourceImpl::
|
|
|
+getHost(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin,
|
|
|
+ const size_t identifier_len,
|
|
|
+ MySqlHostDataSource::StatementIndex stindex,
|
|
|
+ boost::shared_ptr<MySqlHostExchange> exchange) const {
|
|
|
+
|
|
|
+ // Set up the WHERE clause value
|
|
|
+ MYSQL_BIND inbind[3];
|
|
|
+ memset(inbind, 0, sizeof(inbind));
|
|
|
+
|
|
|
+ uint32_t subnet_buffer = static_cast<uint32_t>(subnet_id);
|
|
|
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
|
|
|
+ inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
|
|
|
+ inbind[0].is_unsigned = MLM_TRUE;
|
|
|
+
|
|
|
+ // Identifier value.
|
|
|
+ std::vector<char> identifier_vec(identifier_begin,
|
|
|
+ identifier_begin + identifier_len);
|
|
|
+ unsigned long length = identifier_vec.size();
|
|
|
+ inbind[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
+ inbind[2].buffer = &identifier_vec[0];
|
|
|
+ inbind[2].buffer_length = length;
|
|
|
+ inbind[2].length = &length;
|
|
|
+
|
|
|
+ // Identifier type.
|
|
|
+ char identifier_type_copy = static_cast<char>(identifier_type);
|
|
|
+ inbind[1].buffer_type = MYSQL_TYPE_TINY;
|
|
|
+ inbind[1].buffer = reinterpret_cast<char*>(&identifier_type_copy);
|
|
|
+ inbind[1].is_unsigned = MLM_TRUE;
|
|
|
+
|
|
|
+ ConstHostCollection collection;
|
|
|
+ getHostCollection(stindex, inbind, exchange, collection, true);
|
|
|
+
|
|
|
+ // Return single record if present, else clear the host.
|
|
|
+ ConstHostPtr result;
|
|
|
+ if (!collection.empty())
|
|
|
+ result = *collection.begin();
|
|
|
+
|
|
|
+ return (result);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
MySqlHostDataSource::
|
|
|
MySqlHostDataSource(const MySqlConnection::ParameterMap& parameters)
|
|
@@ -1314,58 +1381,57 @@ MySqlHostDataSource::add(const HostPtr& host) {
|
|
|
|
|
|
// Gets the last inserted hosts id
|
|
|
uint64_t host_id = mysql_insert_id(impl_->conn_.mysql_);
|
|
|
- for (IPv6ResrvIterator resv = v6resv.first; resv != v6resv.second; ++resv) {
|
|
|
+ for (IPv6ResrvIterator resv = v6resv.first; resv != v6resv.second;
|
|
|
+ ++resv) {
|
|
|
impl_->addResv(resv->second, host_id);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ConstHostCollection
|
|
|
-MySqlHostDataSource::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
|
|
|
-
|
|
|
- // Set up the WHERE clause value
|
|
|
- MYSQL_BIND inbind[2];
|
|
|
- memset(inbind, 0, sizeof(inbind));
|
|
|
+MySqlHostDataSource::getAll(const HWAddrPtr& hwaddr,
|
|
|
+ const DuidPtr& duid) const {
|
|
|
|
|
|
- uint8_t dhcp_identifier_type = 0;
|
|
|
- long unsigned int length = 0;
|
|
|
if (duid){
|
|
|
- // DUID
|
|
|
- // set proper dhcp_identifier_type
|
|
|
- dhcp_identifier_type = BaseHostDataSource::ID_DUID; // 1
|
|
|
- inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type);
|
|
|
-
|
|
|
- const vector<uint8_t>& duid_vector = duid->getDuid();
|
|
|
- length = duid_vector.size();
|
|
|
- inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[0].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&duid_vector[0]));
|
|
|
- inbind[0].buffer_length = length;
|
|
|
- inbind[0].length = &length;
|
|
|
+ return (getAll(Host::IDENT_DUID, &duid->getDuid()[0],
|
|
|
+ duid->getDuid().size()));
|
|
|
+
|
|
|
} else if (hwaddr) {
|
|
|
- // HW Address
|
|
|
- dhcp_identifier_type = BaseHostDataSource::ID_HWADDR; // 0
|
|
|
- inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type);
|
|
|
-
|
|
|
- const vector<uint8_t>& hwaddr_vector = hwaddr->hwaddr_;
|
|
|
- length = hwaddr_vector.size();
|
|
|
- inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[0].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&hwaddr_vector[0]));
|
|
|
- inbind[0].buffer_length = length;
|
|
|
- inbind[0].length = &length;
|
|
|
+ return (getAll(Host::IDENT_HWADDR,
|
|
|
+ &hwaddr->hwaddr_[0],
|
|
|
+ hwaddr->hwaddr_.size()));
|
|
|
}
|
|
|
|
|
|
- // dhcp identifier type
|
|
|
+ return (ConstHostCollection());
|
|
|
+}
|
|
|
+
|
|
|
+ConstHostCollection
|
|
|
+MySqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin,
|
|
|
+ const size_t identifier_len) const {
|
|
|
+ // Set up the WHERE clause value
|
|
|
+ MYSQL_BIND inbind[2];
|
|
|
+ memset(inbind, 0, sizeof(inbind));
|
|
|
+
|
|
|
+ // Identifier type.
|
|
|
+ char identifier_type_copy = static_cast<char>(identifier_type);
|
|
|
+ inbind[1].buffer = &identifier_type_copy;
|
|
|
inbind[1].buffer_type = MYSQL_TYPE_TINY;
|
|
|
- inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type);
|
|
|
inbind[1].is_unsigned = MLM_TRUE;
|
|
|
|
|
|
+ // Identifier value.
|
|
|
+ std::vector<char> identifier_vec(identifier_begin,
|
|
|
+ identifier_begin + identifier_len);
|
|
|
+ unsigned long int length = identifier_vec.size();
|
|
|
+ inbind[0].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
+ inbind[0].buffer = &identifier_vec[0];
|
|
|
+ inbind[0].buffer_length = length;
|
|
|
+ inbind[0].length = &length;
|
|
|
+
|
|
|
ConstHostCollection result;
|
|
|
impl_->getHostCollection(GET_HOST_HWADDR_DUID, inbind,
|
|
|
impl_->host_ipv6_exchange_,
|
|
|
result, false);
|
|
|
-
|
|
|
return (result);
|
|
|
}
|
|
|
|
|
@@ -1392,15 +1458,6 @@ ConstHostPtr
|
|
|
MySqlHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
|
|
|
const DuidPtr& duid) const {
|
|
|
|
|
|
- // Set up the WHERE clause value
|
|
|
- MYSQL_BIND inbind[3];
|
|
|
- memset(inbind, 0, sizeof(inbind));
|
|
|
-
|
|
|
- uint32_t subnet_buffer = static_cast<uint32_t>(subnet_id);
|
|
|
- inbind[0].buffer_type = MYSQL_TYPE_LONG;
|
|
|
- inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
|
|
|
- inbind[0].is_unsigned = MLM_TRUE;
|
|
|
-
|
|
|
/// @todo: Rethink the logic in BaseHostDataSource::get4(subnet, hwaddr, duid)
|
|
|
if (hwaddr && duid) {
|
|
|
isc_throw(BadValue, "MySQL host data source get4() called with both"
|
|
@@ -1411,53 +1468,28 @@ MySqlHostDataSource::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
|
|
|
"neither hwaddr or duid specified, one of them is required");
|
|
|
}
|
|
|
|
|
|
- unsigned long length = 0;
|
|
|
- uint8_t dhcp_identifier_type_ = 0;
|
|
|
-
|
|
|
// Choosing one of the identifiers
|
|
|
if (hwaddr) {
|
|
|
- // set identifier type
|
|
|
- dhcp_identifier_type_ = BaseHostDataSource::ID_HWADDR; // 0
|
|
|
-
|
|
|
- // set identifier value
|
|
|
- const vector<uint8_t>& hwaddr_vector = hwaddr->hwaddr_;
|
|
|
- length = hwaddr_vector.size();
|
|
|
- inbind[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[2].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&hwaddr_vector[0]));
|
|
|
- inbind[2].buffer_length = length;
|
|
|
- inbind[2].length = &length;
|
|
|
+ return (get4(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
|
|
|
+ hwaddr->hwaddr_.size()));
|
|
|
|
|
|
} else if (duid) {
|
|
|
- // set identifier type
|
|
|
- dhcp_identifier_type_ = BaseHostDataSource::ID_DUID; // 1
|
|
|
-
|
|
|
- // set identifier value
|
|
|
- const vector<uint8_t>& duid_vector = duid->getDuid();
|
|
|
- length = duid_vector.size();
|
|
|
- inbind[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[2].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&duid_vector[0]));
|
|
|
- inbind[2].buffer_length = length;
|
|
|
- inbind[2].length = &length;
|
|
|
+ return (get4(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
|
|
|
+ duid->getDuid().size()));
|
|
|
}
|
|
|
|
|
|
- // dhcp identifier type
|
|
|
- inbind[1].buffer_type = MYSQL_TYPE_TINY;
|
|
|
- inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type_);
|
|
|
- inbind[1].is_unsigned = MLM_TRUE;
|
|
|
-
|
|
|
- ConstHostCollection collection;
|
|
|
- impl_->getHostCollection(GET_HOST_SUBID4_DHCPID, inbind,
|
|
|
- impl_->host_exchange_, collection,
|
|
|
- true);
|
|
|
+ return (ConstHostPtr());
|
|
|
+}
|
|
|
|
|
|
- // Return single record if present, else clear the host.
|
|
|
- ConstHostPtr result;
|
|
|
- if (!collection.empty())
|
|
|
- result = *collection.begin();
|
|
|
+ConstHostPtr
|
|
|
+MySqlHostDataSource::get4(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin,
|
|
|
+ const size_t identifier_len) const {
|
|
|
|
|
|
- return (result);
|
|
|
+ return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
|
|
|
+ identifier_len, GET_HOST_SUBID4_DHCPID,
|
|
|
+ impl_->host_exchange_));
|
|
|
}
|
|
|
|
|
|
ConstHostPtr
|
|
@@ -1493,15 +1525,6 @@ ConstHostPtr
|
|
|
MySqlHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
|
|
|
const HWAddrPtr& hwaddr) const {
|
|
|
|
|
|
- // Set up the WHERE clause value
|
|
|
- MYSQL_BIND inbind[3];
|
|
|
- memset(inbind, 0, sizeof(inbind));
|
|
|
-
|
|
|
- uint32_t subnet_buffer = static_cast<uint32_t>(subnet_id);
|
|
|
- inbind[0].buffer_type = MYSQL_TYPE_LONG;
|
|
|
- inbind[0].buffer = reinterpret_cast<char*>(&subnet_buffer);
|
|
|
- inbind[0].is_unsigned = MLM_TRUE;
|
|
|
-
|
|
|
/// @todo: Rethink the logic in BaseHostDataSource::get6(subnet, hwaddr, duid)
|
|
|
if (hwaddr && duid) {
|
|
|
isc_throw(BadValue, "MySQL host data source get6() called with both"
|
|
@@ -1512,53 +1535,27 @@ MySqlHostDataSource::get6(const SubnetID& subnet_id, const DuidPtr& duid,
|
|
|
"neither hwaddr or duid specified, one of them is required");
|
|
|
}
|
|
|
|
|
|
- unsigned long length = 0;
|
|
|
- uint8_t dhcp_identifier_type_ = 0;
|
|
|
-
|
|
|
// Choosing one of the identifiers
|
|
|
if (hwaddr) {
|
|
|
- // set identifier type
|
|
|
- dhcp_identifier_type_ = BaseHostDataSource::ID_HWADDR; // 0
|
|
|
-
|
|
|
- // set identifier value
|
|
|
- const vector<uint8_t>& hwaddr_vector = hwaddr->hwaddr_;
|
|
|
- length = hwaddr_vector.size();
|
|
|
- inbind[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[2].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&hwaddr_vector[0]));
|
|
|
- inbind[2].buffer_length = length;
|
|
|
- inbind[2].length = &length;
|
|
|
+ return (get6(subnet_id, Host::IDENT_HWADDR, &hwaddr->hwaddr_[0],
|
|
|
+ hwaddr->hwaddr_.size()));
|
|
|
} else if (duid) {
|
|
|
- // set identifier type
|
|
|
- dhcp_identifier_type_ = BaseHostDataSource::ID_DUID; // 1
|
|
|
-
|
|
|
- // set identifier value
|
|
|
- const vector<uint8_t>& duid_vector = duid->getDuid();
|
|
|
- length = duid_vector.size();
|
|
|
- inbind[2].buffer_type = MYSQL_TYPE_BLOB;
|
|
|
- inbind[2].buffer = reinterpret_cast<char*>
|
|
|
- (const_cast<uint8_t*>(&duid_vector[0]));
|
|
|
- inbind[2].buffer_length = length;
|
|
|
- inbind[2].length = &length;
|
|
|
+ return (get6(subnet_id, Host::IDENT_DUID, &duid->getDuid()[0],
|
|
|
+ duid->getDuid().size()));
|
|
|
}
|
|
|
|
|
|
- // dhcp identifier type
|
|
|
- inbind[1].buffer_type = MYSQL_TYPE_TINY;
|
|
|
- inbind[1].buffer = reinterpret_cast<char*>(&dhcp_identifier_type_);
|
|
|
- inbind[1].is_unsigned = MLM_TRUE;
|
|
|
-
|
|
|
- ConstHostCollection collection;
|
|
|
- impl_->getHostCollection(GET_HOST_SUBID6_DHCPID, inbind,
|
|
|
- impl_->host_ipv6_exchange_,
|
|
|
- collection, true);
|
|
|
-
|
|
|
- // Return single record if present, else clear the host.
|
|
|
- ConstHostPtr result;
|
|
|
- if (!collection.empty()) {
|
|
|
- result = *collection.begin();
|
|
|
- }
|
|
|
+ return (ConstHostPtr());
|
|
|
+}
|
|
|
|
|
|
- return (result);
|
|
|
+ConstHostPtr
|
|
|
+MySqlHostDataSource::get6(const SubnetID& subnet_id,
|
|
|
+ const Host::IdentifierType& identifier_type,
|
|
|
+ const uint8_t* identifier_begin,
|
|
|
+ const size_t identifier_len) const {
|
|
|
+
|
|
|
+ return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
|
|
|
+ identifier_len, GET_HOST_SUBID6_DHCPID,
|
|
|
+ impl_->host_ipv6_exchange_));
|
|
|
}
|
|
|
|
|
|
ConstHostPtr
|