/// @brief Default destructor implementation.
virtual ~BaseHostDataSource() { }
+ /// @brief Adds a new host to the collection.
+ ///
+ /// The implementations of this method should guard against duplicate
+ /// reservations for the same host, where possible. For example, when the
+ /// reservation for the same HW address and subnet id is added twice, the
+ /// implementation should throw an exception. Note, that usually it is
+ /// impossible to guard against adding duplicated host, where one instance
+ /// is identified by HW address, another one by DUID.
+ ///
+ /// @param host Pointer to the new @c Host object being added.
+ virtual void add(const HostPtr& host) = 0;
+
+ /// @brief Attempts to delete a host by (subnet-id, address)
+ ///
+ /// This method supports both v4 and v6.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param addr specified address.
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) = 0;
+
+ /// @brief Attempts to delete a host by (subnet-id4, identifier, identifier-type)
+ ///
+ /// This method supports both v4 hosts only.
+ ///
+ /// @param subnet_id IPv4 Subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del4(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len) = 0;
+
+ /// @brief Attempts to delete a host by (subnet-id6, identifier, identifier-type)
+ ///
+ /// This method supports both v6 hosts only.
+ ///
+ /// @param subnet_id IPv6 Subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del6(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len) = 0;
+
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This method returns all @c Host objects which represent reservations
virtual ConstHostPtr
get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const = 0;
- /// @brief Adds a new host to the collection.
- ///
- /// The implementations of this method should guard against duplicate
- /// reservations for the same host, where possible. For example, when the
- /// reservation for the same HW address and subnet id is added twice, the
- /// implementation should throw an exception. Note, that usually it is
- /// impossible to guard against adding duplicated host, where one instance
- /// is identified by HW address, another one by DUID.
- ///
- /// @param host Pointer to the new @c Host object being added.
- virtual void add(const HostPtr& host) = 0;
-
- /// @brief Attempts to delete a host by (subnet-id, address)
- ///
- /// This method supports both v4 and v6.
- ///
- /// @param subnet_id subnet identifier.
- /// @param addr specified address.
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) = 0;
-
- /// @brief Attempts to delete a host by (subnet-id4, identifier, identifier-type)
- ///
- /// This method supports both v4 hosts only.
- ///
- /// @param subnet_id IPv4 Subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del4(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len) = 0;
-
- /// @brief Attempts to delete a host by (subnet-id6, identifier, identifier-type)
- ///
- /// This method supports both v6 hosts only.
- ///
- /// @param subnet_id IPv6 Subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del6(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len) = 0;
-
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
where_values.add(&host_ipv4_subnet_id);
where_values.add(&host_ipv4_address);
-
// Run statement.
ConstHostPtr result = getHost(CqlHostExchange::GET_HOST_BY_IPV4_SUBNET_ID_AND_ADDRESS,
where_values);
host, subnet_id, reservation, option_space, option_descriptor,
CqlHostExchange::INSERT_HOST, assigned_values);
-
host_exchange->executeMutation(dbconn_, assigned_values,
CqlHostExchange::INSERT_HOST);
} catch (const StatementNotApplied& exception) {
impl_->add(host);
}
+bool
+CqlHostDataSource::del(const SubnetID& /*subnet_id*/, const asiolink::IOAddress& /*addr*/) {
+ isc_throw(NotImplemented, "CqlHostDataSource::del NotImplemented");
+}
+
+bool
+CqlHostDataSource::del4(const SubnetID& /*subnet_id*/, const Host::IdentifierType& /*type*/,
+ const uint8_t* /*identifier_begin*/, const size_t /*identifier_len*/) {
+ isc_throw(NotImplemented, "CqlHostDataSource::del4 NotImplemented");
+}
+
+bool
+CqlHostDataSource::del6(const SubnetID& /*subnet_id*/, const Host::IdentifierType& /*type*/,
+ const uint8_t* /*identifier_begin*/, const size_t /*identifier_len*/) {
+ isc_throw(NotImplemented, "CqlHostDataSource::del6 NotImplemented");
+}
+
ConstHostCollection
CqlHostDataSource::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_HOST_GET_ALL);
return (impl_->get6(subnet_id, address));
}
-bool
-CqlHostDataSource::del(const SubnetID& /*subnet_id*/, const asiolink::IOAddress& /*addr*/) {
- isc_throw(NotImplemented, "CqlHostDataSource::del NotImplemented");
-}
-
-bool
-CqlHostDataSource::del4(const SubnetID& /*subnet_id*/, const Host::IdentifierType& /*type*/,
- const uint8_t* /*identifier_begin*/, const size_t /*identifier_len*/) {
- isc_throw(NotImplemented, "CqlHostDataSource::del4 NotImplemented");
-}
-
-bool
-CqlHostDataSource::del6(const SubnetID& /*subnet_id*/, const Host::IdentifierType& /*type*/,
- const uint8_t* /*identifier_begin*/, const size_t /*identifier_len*/) {
- isc_throw(NotImplemented, "CqlHostDataSource::del6 NotImplemented");
-}
-
std::string
CqlHostDataSource::getType() const {
return std::string("cql");
/// @param host pointer to the new @ref Host being added.
virtual void add(const HostPtr& host) override;
+ /// @brief Attempts to delete a host by (subnet-id, address)
+ ///
+ /// This method supports both v4 and v6.
+ ///
+ /// @param subnet_id subnet identfier.
+ /// @param addr specified address.
+ /// @return true if deletion was successful, false if the host was not
+ /// there.
+ /// @throw various exceptions in case of errors
+ virtual bool del(const SubnetID& subnet_id,
+ const asiolink::IOAddress& addr);
+
+ /// @brief Attempts to delete a host by (subnet-id4, identifier-type,
+ /// identifier).
+ ///
+ /// This method supports v4 hosts only.
+ ///
+ /// @param subnet_id IPv4 Subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ /// @return true if deletion was successful, false if the host was not
+ /// there.
+ /// @throw various exceptions in case of errors
+ virtual bool del4(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin,
+ const size_t identifier_len);
+
+ /// @brief Attempts to delete a host by (subnet-id6, identifier-type,
+ /// identifier).
+ ///
+ /// This method supports v6 hosts only.
+ ///
+ /// @param subnet_id IPv6 Subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ /// @return true if deletion was successful, false if the host was not
+ /// there.
+ /// @throw various exceptions in case of errors
+ virtual bool del6(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin,
+ const size_t identifier_len);
+
+ /// @brief Return all @ref Host objects for the specified @ref HWAddr or
+ /// @ref DUID.
+ ///
+ /// Returns all @ref Host objects which represent reservations
+ /// for the specified HW address or DUID. Note, that this method may
+ /// return multiple reservations because a particular client may have
+ /// reservations in multiple subnets and the same client may be identified
+ /// by HW address or DUID. The server is unable to verify that the specific
+ /// DUID and HW address belong to the same client, until the client sends
+ /// a DHCP message.
+ ///
+ /// Specifying both @ref HWAddr and @ref DUID is allowed for this method
+ /// and results in returning all objects that are associated with hardware
+ /// address OR duid. For example: if one @ref Host is associated with the
+ /// specified @ref HWAddr and another @ref Host is associated with the
+ /// specified @ref DUID, two hosts will be returned.
+ ///
+ /// @param hwaddr HW address of the client or NULL if no HW address
+ /// available.
+ /// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
+ ///
+ /// @return collection of const @ref Host objects.
+ virtual ConstHostCollection
+ getAll(const HWAddrPtr& hwaddr,
+ const DuidPtr& duid = DuidPtr()) const override;
+
+ /// @brief Return all hosts connected to any subnet for which reservations
+ /// have been made using a specified identifier.
+ ///
+ /// This method returns all @ref Host objects which represent reservations
+ /// for a specified identifier. This method may return multiple hosts
+ /// because a particular client may have reservations in multiple subnets.
+ ///
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ ///
+ /// @return Collection of const @ref Host objects.
+ virtual ConstHostCollection
+ getAll(const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin,
+ const size_t identifier_len) const override;
+
+ /// @brief Returns a collection of hosts using the specified IPv4 address.
+ ///
+ /// This method may return multiple @ref Host objects if they are connected
+ /// to different subnets.
+ ///
+ /// @param address IPv4 address for which the @ref Host object is searched.
+ ///
+ /// @return Collection of const @ref Host objects.
+ virtual ConstHostCollection
+ getAll4(const asiolink::IOAddress& address) const override;
+
/// @brief Retrieves a single @ref Host connected to an IPv4 subnet.
///
/// Implementations of this method should guard against the case when
get6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const override;
- /// @brief Return all @ref Host objects for the specified @ref HWAddr or
- /// @ref DUID.
- ///
- /// Returns all @ref Host objects which represent reservations
- /// for the specified HW address or DUID. Note, that this method may
- /// return multiple reservations because a particular client may have
- /// reservations in multiple subnets and the same client may be identified
- /// by HW address or DUID. The server is unable to verify that the specific
- /// DUID and HW address belong to the same client, until the client sends
- /// a DHCP message.
- ///
- /// Specifying both @ref HWAddr and @ref DUID is allowed for this method
- /// and results in returning all objects that are associated with hardware
- /// address OR duid. For example: if one @ref Host is associated with the
- /// specified @ref HWAddr and another @ref Host is associated with the
- /// specified @ref DUID, two hosts will be returned.
- ///
- /// @param hwaddr HW address of the client or NULL if no HW address
- /// available.
- /// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
- ///
- /// @return collection of const @ref Host objects.
- virtual ConstHostCollection
- getAll(const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const override;
-
- /// @brief Return all hosts connected to any subnet for which reservations
- /// have been made using a specified identifier.
- ///
- /// This method returns all @ref Host objects which represent reservations
- /// for a specified identifier. This method may return multiple hosts
- /// because a particular client may have reservations in multiple subnets.
- ///
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- ///
- /// @return Collection of const @ref Host objects.
- virtual ConstHostCollection
- getAll(const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin,
- const size_t identifier_len) const override;
-
- /// @brief Returns a collection of hosts using the specified IPv4 address.
- ///
- /// This method may return multiple @ref Host objects if they are connected
- /// to different subnets.
- ///
- /// @param address IPv4 address for which the @ref Host object is searched.
- ///
- /// @return Collection of const @ref Host objects.
- virtual ConstHostCollection
- getAll4(const asiolink::IOAddress& address) const override;
-
- /// @brief Attempts to delete a host by (subnet-id, address)
- ///
- /// This method supports both v4 and v6.
- ///
- /// @param subnet_id subnet identfier.
- /// @param addr specified address.
- /// @return true if deletion was successful, false if the host was not
- /// there.
- /// @throw various exceptions in case of errors
- virtual bool del(const SubnetID& subnet_id,
- const asiolink::IOAddress& addr);
-
- /// @brief Attempts to delete a host by (subnet-id4, identifier-type,
- /// identifier).
- ///
- /// This method supports v4 hosts only.
- ///
- /// @param subnet_id IPv4 Subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- /// @return true if deletion was successful, false if the host was not
- /// there.
- /// @throw various exceptions in case of errors
- virtual bool del4(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin,
- const size_t identifier_len);
-
- /// @brief Attempts to delete a host by (subnet-id6, identifier-type,
- /// identifier).
- ///
- /// This method supports v6 hosts only.
- ///
- /// @param subnet_id IPv6 Subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- /// @return true if deletion was successful, false if the host was not
- /// there.
- /// @throw various exceptions in case of errors
- virtual bool del6(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin,
- const size_t identifier_len);
-
/// @brief Returns textual description of the backend.
///
/// @return Description of the backend.
const DUID& duid,
uint32_t iaid,
SubnetID subnet_id) const override;
- /// @brief Returns a collection of expired DHCPv6 leases.
+
+ /// @brief Returns a collection of expired DHCPv4 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases6(Lease6Collection& expired_leases,
+ virtual void getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const override;
- /// @brief Returns a collection of expired DHCPv4 leases.
+ /// @brief Returns a collection of expired DHCPv6 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases4(Lease4Collection& expired_leases,
+ virtual void getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const override;
-
/// @}
/// @brief Updates IPv4 lease.
Lease6Ptr getLease6(Lease::Type type, const DUID& duid,
uint32_t iaid, SubnetID subnet_id) const;
- /// @brief Returns a collection of expired DHCPv6 leases.
+ /// @brief Returns a collection of expired DHCPv4 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases6(Lease6Collection& expired_leases,
+ virtual void getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const = 0;
-
- /// @brief Returns a collection of expired DHCPv4 leases.
+ /// @brief Returns a collection of expired DHCPv6 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases4(Lease4Collection& expired_leases,
+ virtual void getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const = 0;
/// @brief Updates IPv4 lease.
}
void
-Memfile_LeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
+Memfile_LeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_EXPIRED6)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_EXPIRED4)
.arg(max_leases);
// Obtain the index which segragates leases by state and time.
- const Lease6StorageExpirationIndex& index = storage6_.get<ExpirationIndexTag>();
+ const Lease4StorageExpirationIndex& index = storage4_.get<ExpirationIndexTag>();
// Retrieve leases which are not reclaimed and which haven't expired. The
// 'less-than' operator will be used for both components of the index. So,
// for the 'state' 'false' is less than 'true'. Also the leases with
// expiration time lower than current time will be returned.
- Lease6StorageExpirationIndex::const_iterator ub =
+ Lease4StorageExpirationIndex::const_iterator ub =
index.upper_bound(boost::make_tuple(false, time(NULL)));
// Copy only the number of leases indicated by the max_leases parameter.
- for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
+ for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
(lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
max_leases));
++lease) {
- expired_leases.push_back(Lease6Ptr(new Lease6(**lease)));
+ expired_leases.push_back(Lease4Ptr(new Lease4(**lease)));
}
}
void
-Memfile_LeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
+Memfile_LeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_EXPIRED4)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_EXPIRED6)
.arg(max_leases);
// Obtain the index which segragates leases by state and time.
- const Lease4StorageExpirationIndex& index = storage4_.get<ExpirationIndexTag>();
+ const Lease6StorageExpirationIndex& index = storage6_.get<ExpirationIndexTag>();
// Retrieve leases which are not reclaimed and which haven't expired. The
// 'less-than' operator will be used for both components of the index. So,
// for the 'state' 'false' is less than 'true'. Also the leases with
// expiration time lower than current time will be returned.
- Lease4StorageExpirationIndex::const_iterator ub =
+ Lease6StorageExpirationIndex::const_iterator ub =
index.upper_bound(boost::make_tuple(false, time(NULL)));
// Copy only the number of leases indicated by the max_leases parameter.
- for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
+ for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
(lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
max_leases));
++lease) {
- expired_leases.push_back(Lease4Ptr(new Lease4(**lease)));
+ expired_leases.push_back(Lease6Ptr(new Lease6(**lease)));
}
}
uint32_t iaid,
SubnetID subnet_id) const;
- /// @brief Returns a collection of expired DHCPv6 leases.
+ /// @brief Returns a collection of expired DHCPv4 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases6(Lease6Collection& expired_leases,
+ virtual void getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const;
-
- /// @brief Returns a collection of expired DHCPv4 leases.
+ /// @brief Returns a collection of expired DHCPv6 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases4(Lease4Collection& expired_leases,
+ virtual void getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const;
/// @brief Updates IPv4 lease.
my_bool dhcp4_boot_file_name_null_;
//@}
-
};
/// @brief Extends base exchange class with ability to retrieve DHCP options
/// @brief Reservation id for last processed row.
uint32_t most_recent_reservation_id_;
-
};
/// @brief This class is used for storing IPv6 reservations in a MySQL database.
bool is_readonly_;
};
-
/// @brief Array of tagged statements.
typedef boost::array<TaggedStatement, MySqlHostDataSourceImpl::NUM_STATEMENTS>
TaggedStatementArray;
}
}
-
MySqlHostDataSource::
MySqlHostDataSource(const MySqlConnection::ParameterMap& parameters)
: impl_(new MySqlHostDataSourceImpl(parameters)) {
inbind[0].length = &addr6_length;
inbind[0].buffer_length = addr6_length;
-
uint8_t tmp = prefix_len;
inbind[1].buffer_type = MYSQL_TYPE_TINY;
inbind[1].buffer = reinterpret_cast<char*>(&tmp);
inbind[1].is_unsigned = MLM_TRUE;
-
ConstHostCollection collection;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_PREFIX,
inbind, impl_->host_ipv6_exchange_,
return (result);
}
-
// Miscellaneous database methods.
std::string MySqlHostDataSource::getName() const {
impl_->conn_.commit();
}
-
void
MySqlHostDataSource::rollback() {
// If operating in read-only mode, throw exception.
impl_->conn_.rollback();
}
-
}; // end of isc::dhcp namespace
}; // end of isc namespace
/// Releases prepared MySQL statements used by the backend.
virtual ~MySqlHostDataSource();
+ /// @brief Adds a new host to the collection.
+ ///
+ /// The implementations of this method should guard against duplicate
+ /// reservations for the same host, where possible. For example, when the
+ /// reservation for the same HW address and subnet id is added twice, the
+ /// addHost method should throw an DuplicateEntry exception. Note, that
+ /// usually it is impossible to guard against adding duplicated host, where
+ /// one instance is identified by HW address, another one by DUID.
+ ///
+ /// @param host Pointer to the new @c Host object being added.
+ virtual void add(const HostPtr& host);
+
+ /// @brief Attempts to delete a host by (subnet-id, address)
+ ///
+ /// This method supports both v4 and v6.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param addr specified address.
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
+
+ /// @brief Attempts to delete a host by (subnet4-id, identifier type, identifier)
+ ///
+ /// This method supports v4 hosts only.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ ///
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del4(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len);
+
+ /// @brief Attempts to delete a host by (subnet6-id, identifier type, identifier)
+ ///
+ /// This method supports v6 hosts only.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ ///
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del6(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len);
+
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This method returns all @c Host objects which represent reservations
virtual ConstHostPtr
get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @brief Adds a new host to the collection.
- ///
- /// The implementations of this method should guard against duplicate
- /// reservations for the same host, where possible. For example, when the
- /// reservation for the same HW address and subnet id is added twice, the
- /// addHost method should throw an DuplicateEntry exception. Note, that
- /// usually it is impossible to guard against adding duplicated host, where
- /// one instance is identified by HW address, another one by DUID.
- ///
- /// @param host Pointer to the new @c Host object being added.
- virtual void add(const HostPtr& host);
-
- /// @brief Attempts to delete a host by (subnet-id, address)
- ///
- /// This method supports both v4 and v6.
- ///
- /// @param subnet_id subnet identifier.
- /// @param addr specified address.
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
-
- /// @brief Attempts to delete a host by (subnet4-id, identifier type, identifier)
- ///
- /// This method supports v4 hosts only.
- ///
- /// @param subnet_id subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- ///
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del4(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len);
-
- /// @brief Attempts to delete a host by (subnet6-id, identifier type, identifier)
- ///
- /// This method supports v6 hosts only.
- ///
- /// @param subnet_id subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- ///
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del6(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len);
-
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
}
#endif // MYSQL_HOST_DATA_SOURCE_H
-
}
void
-MySqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
+MySqlLeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_EXPIRED6)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_EXPIRED4)
.arg(max_leases);
- getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE6_EXPIRE);
+ getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE4_EXPIRE);
}
void
-MySqlLeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
+MySqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_EXPIRED4)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_EXPIRED6)
.arg(max_leases);
- getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE4_EXPIRE);
+ getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE6_EXPIRE);
}
template<typename LeaseCollection>
return (deleted_leases);
}
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startLeaseStatsQuery4() {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ RECOUNT_LEASE4_STATS,
+ false));
+ query->start();
+ return(query);
+}
+
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startLeaseStatsQuery6() {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ RECOUNT_LEASE6_STATS,
+ true));
+ query->start();
+ return(query);
+}
+
size_t
MySqlLeaseMgr::wipeLeases4(const SubnetID& /*subnet_id*/) {
isc_throw(NotImplemented, "wipeLeases4 is not implemented for MySQL backend");
return (std::make_pair(major, minor));
}
-LeaseStatsQueryPtr
-MySqlLeaseMgr::startLeaseStatsQuery4() {
- LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
- RECOUNT_LEASE4_STATS,
- false));
- query->start();
- return(query);
-}
-
-LeaseStatsQueryPtr
-MySqlLeaseMgr::startLeaseStatsQuery6() {
- LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
- RECOUNT_LEASE6_STATS,
- true));
- query->start();
- return(query);
-}
-
void
MySqlLeaseMgr::commit() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_COMMIT);
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
uint32_t iaid, SubnetID subnet_id) const;
- /// @brief Returns a collection of expired DHCPv6 leases.
+ /// @brief Returns a collection of expired DHCPv4 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases6(Lease6Collection& expired_leases,
+ virtual void getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const;
-
- /// @brief Returns a collection of expired DHCPv4 leases.
+ /// @brief Returns a collection of expired DHCPv6 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases4(Lease4Collection& expired_leases,
+ virtual void getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const;
/// @brief Updates IPv4 lease.
/// @return Number of leases deleted.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs);
+ /// @brief Deletes all expired-reclaimed DHCPv6 leases.
+ ///
+ /// @param secs Number of seconds since expiration of leases before
+ /// they can be removed. Leases which have expired later than this
+ /// time will not be deleted.
+ ///
+ /// @return Number of leases deleted.
+ virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
+
+ /// @brief Creates and runs the IPv4 lease stats query
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery4 and then
+ /// invokes its start method, which fetches its statistical data
+ /// result set by executing the RECOUNT_LEASE_STATS4 query.
+ /// The query object is then returned.
+ ///
+ /// @return The populated query as a pointer to an LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
+
+ /// @brief Creates and runs the IPv6 lease stats query
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery6 and then
+ /// invokes its start method, which fetches its statistical data
+ /// result set by executing the RECOUNT_LEASE_STATS6 query.
+ /// The query object is then returned.
+ ///
+ /// @return The populated query as a pointer to an LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
+
/// @brief Removes specified IPv4 leases.
///
/// This rather dangerous method is able to remove all leases from specified
/// @return number of leases removed.
virtual size_t wipeLeases6(const SubnetID& subnet_id);
- /// @brief Deletes all expired-reclaimed DHCPv6 leases.
- ///
- /// @param secs Number of seconds since expiration of leases before
- /// they can be removed. Leases which have expired later than this
- /// time will not be deleted.
- ///
- /// @return Number of leases deleted.
- virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
-
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
uint64_t deleteExpiredReclaimedLeasesCommon(const uint32_t secs,
StatementIndex statement_index);
- /// @brief Creates and runs the IPv4 lease stats query
- ///
- /// It creates an instance of a MySqlLeaseStatsQuery4 and then
- /// invokes its start method, which fetches its statistical data
- /// result set by executing the RECOUNT_LEASE_STATS4 query.
- /// The query object is then returned.
- ///
- /// @return The populated query as a pointer to an LeaseStatsQuery
- virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
-
- /// @brief Creates and runs the IPv6 lease stats query
- ///
- /// It creates an instance of a MySqlLeaseStatsQuery6 and then
- /// invokes its start method, which fetches its statistical data
- /// result set by executing the RECOUNT_LEASE_STATS6 query.
- /// The query object is then returned.
- ///
- /// @return The populated query as a pointer to an LeaseStatsQuery
- virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
-
/// @brief Check Error and Throw Exception
///
/// This method invokes @ref MySqlConnection::checkError.
HostPtr host_;
};
-
/// @brief Extends base exchange class with ability to retrieve DHCP options
/// from the 'dhcp4_options' and 'dhcp6_options' tables.
///
/// @brief Reservation id for last processed row.
uint64_t most_recent_reservation_id_;
-
};
/// @brief This class is used for storing IPv6 reservations in a PgSQL database.
} // end of anonymous namespace
-
namespace isc {
namespace dhcp {
}
return (last_id);
-
}
bool
}
}
-
/*********** PgSqlHostDataSource *********************/
-
PgSqlHostDataSource::
PgSqlHostDataSource(const PgSqlConnection::ParameterMap& parameters)
: impl_(new PgSqlHostDataSourceImpl(parameters)) {
return (impl_->delStatement(PgSqlHostDataSourceImpl::DEL_HOST_SUBID4_ID,
bind_array));
-
}
bool
return (impl_->delStatement(PgSqlHostDataSourceImpl::DEL_HOST_SUBID6_ID,
bind_array));
-
}
ConstHostCollection
impl_->conn_.commit();
}
-
void
PgSqlHostDataSource::rollback() {
// If operating in read-only mode, throw exception.
/// the destruction of member impl_.
virtual ~PgSqlHostDataSource();
+ /// @brief Adds a new host to the collection.
+ ///
+ /// The method will insert the given host and all of its children (v4
+ /// options, v6 options, and v6 reservations) into the database. It
+ /// relies on constraints defined as part of the PostgreSQL schema to
+ /// defend against duplicate entries and to ensure referential
+ /// integrity.
+ ///
+ /// Violation of any of these constraints for a host will result in a
+ /// DuplicateEntry exception:
+ ///
+ /// -# IPV4_ADDRESS and DHCP4_SUBNET_ID combination must be unique
+ /// -# IPV6 ADDRESS and PREFIX_LEN combination must be unique
+ /// -# DHCP ID, DHCP ID TYPE, and DHCP4_SUBNET_ID combination must be unique
+ /// -# DHCP ID, DHCP ID TYPE, and DHCP6_SUBNET_ID combination must be unique
+ ///
+ /// In addition, violating the following referential constraints will
+ /// a DbOperationError exception:
+ ///
+ /// -# DHCP ID TYPE must be defined in the HOST_IDENTIFIER_TYPE table
+ /// -# For DHCP4 Options:
+ /// -# HOST_ID must exist with HOSTS
+ /// -# SCOPE_ID must be defined in DHCP_OPTION_SCOPE
+ /// -# For DHCP6 Options:
+ /// -# HOST_ID must exist with HOSTS
+ /// -# SCOPE_ID must be defined in DHCP_OPTION_SCOPE
+ /// -# For IPV6 Reservations:
+ /// -# HOST_ID must exist with HOSTS
+ /// -# Address and Prefix Length must be unique (DuplicateEntry)
+ ///
+ /// @param host Pointer to the new @c Host object being added.
+ /// @throw DuplicateEntry or DbOperationError dependent on the constraint
+ /// violation
+ virtual void add(const HostPtr& host);
+
+ /// @brief Attempts to delete a host by (subnet-id, address)
+ ///
+ /// This method supports both v4 and v6.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param addr specified address.
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
+
+ /// @brief Attempts to delete a host by (subnet4-id, identifier type, identifier)
+ ///
+ /// This method supports v4 hosts only.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ ///
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del4(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len);
+
+ /// @brief Attempts to delete a host by (subnet6-id, identifier type, identifier)
+ ///
+ /// This method supports v6 hosts only.
+ ///
+ /// @param subnet_id subnet identifier.
+ /// @param identifier_type Identifier type.
+ /// @param identifier_begin Pointer to a beginning of a buffer containing
+ /// an identifier.
+ /// @param identifier_len Identifier length.
+ ///
+ /// @return true if deletion was successful, false if the host was not there.
+ /// @throw various exceptions in case of errors
+ virtual bool del6(const SubnetID& subnet_id,
+ const Host::IdentifierType& identifier_type,
+ const uint8_t* identifier_begin, const size_t identifier_len);
+
/// @brief Return all hosts for the specified HW address or DUID.
///
/// This method returns all @c Host objects which represent reservations
virtual ConstHostPtr
get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
- /// @brief Adds a new host to the collection.
- ///
- /// The method will insert the given host and all of its children (v4
- /// options, v6 options, and v6 reservations) into the database. It
- /// relies on constraints defined as part of the PostgreSQL schema to
- /// defend against duplicate entries and to ensure referential
- /// integrity.
- ///
- /// Violation of any of these constraints for a host will result in a
- /// DuplicateEntry exception:
- ///
- /// -# IPV4_ADDRESS and DHCP4_SUBNET_ID combination must be unique
- /// -# IPV6 ADDRESS and PREFIX_LEN combination must be unique
- /// -# DHCP ID, DHCP ID TYPE, and DHCP4_SUBNET_ID combination must be unique
- /// -# DHCP ID, DHCP ID TYPE, and DHCP6_SUBNET_ID combination must be unique
- ///
- /// In addition, violating the following referential constraints will
- /// a DbOperationError exception:
- ///
- /// -# DHCP ID TYPE must be defined in the HOST_IDENTIFIER_TYPE table
- /// -# For DHCP4 Options:
- /// -# HOST_ID must exist with HOSTS
- /// -# SCOPE_ID must be defined in DHCP_OPTION_SCOPE
- /// -# For DHCP6 Options:
- /// -# HOST_ID must exist with HOSTS
- /// -# SCOPE_ID must be defined in DHCP_OPTION_SCOPE
- /// -# For IPV6 Reservations:
- /// -# HOST_ID must exist with HOSTS
- /// -# Address and Prefix Length must be unique (DuplicateEntry)
- ///
- /// @param host Pointer to the new @c Host object being added.
- /// @throw DuplicateEntry or DbOperationError dependent on the constraint
- /// violation
- virtual void add(const HostPtr& host);
-
- /// @brief Attempts to delete a host by (subnet-id, address)
- ///
- /// This method supports both v4 and v6.
- ///
- /// @param subnet_id subnet identifier.
- /// @param addr specified address.
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
-
- /// @brief Attempts to delete a host by (subnet4-id, identifier type, identifier)
- ///
- /// This method supports v4 hosts only.
- ///
- /// @param subnet_id subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- ///
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del4(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len);
-
- /// @brief Attempts to delete a host by (subnet6-id, identifier type, identifier)
- ///
- /// This method supports v6 hosts only.
- ///
- /// @param subnet_id subnet identifier.
- /// @param identifier_type Identifier type.
- /// @param identifier_begin Pointer to a beginning of a buffer containing
- /// an identifier.
- /// @param identifier_len Identifier length.
- ///
- /// @return true if deletion was successful, false if the host was not there.
- /// @throw various exceptions in case of errors
- virtual bool del6(const SubnetID& subnet_id,
- const Host::IdentifierType& identifier_type,
- const uint8_t* identifier_begin, const size_t identifier_len);
-
/// @brief Return backend type
///
/// Returns the type of database as the string "postgresql". This is
virtual void rollback();
private:
-
/// @brief Pointer to the implementation of the @ref PgSqlHostDataSource.
PgSqlHostDataSourceImpl* impl_;
};
namespace {
-/// @todo TKM lease6 needs to accommodate hwaddr,hwtype, and hwaddr source
+/// @todo TKM lease6 needs to accommodate hwaddr, hwtype, and hwaddr source
/// columns. This is covered by tickets #3557, #4530, and PR#9.
/// @brief Catalog of all the SQL statements currently supported. Note
return (result);
}
+Lease4Ptr
+PgSqlLeaseMgr::getLease4(const ClientId&, const HWAddr&, SubnetID) const {
+ /// This function is currently not implemented because allocation engine
+ /// searches for the lease using HW address or client identifier.
+ /// It never uses both parameters in the same time. We need to
+ /// consider if this function is needed at all.
+ isc_throw(NotImplemented, "The PgSqlLeaseMgr::getLease4 function was"
+ " called, but it is not implemented");
+}
+
Lease4Ptr
PgSqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
return (result);
}
-Lease4Ptr
-PgSqlLeaseMgr::getLease4(const ClientId&, const HWAddr&, SubnetID) const {
- /// This function is currently not implemented because allocation engine
- /// searches for the lease using HW address or client identifier.
- /// It never uses both parameters in the same time. We need to
- /// consider if this function is needed at all.
- isc_throw(NotImplemented, "The PgSqlLeaseMgr::getLease4 function was"
- " called, but it is not implemented");
-}
-
Lease4Collection
PgSqlLeaseMgr::getLeases4(SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_SUBID4)
}
void
-PgSqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
+PgSqlLeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_EXPIRED6)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_EXPIRED4)
.arg(max_leases);
- getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE6_EXPIRE);
+ getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE4_EXPIRE);
}
void
-PgSqlLeaseMgr::getExpiredLeases4(Lease4Collection& expired_leases,
+PgSqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_EXPIRED4)
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_EXPIRED6)
.arg(max_leases);
- getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE4_EXPIRE);
+ getExpiredLeasesCommon(expired_leases, max_leases, GET_LEASE6_EXPIRE);
}
template<typename LeaseCollection>
virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
SubnetID subnet_id) const;
- /// @brief Returns all IPv4 leases for the particular subnet identifier.
- ///
- /// @param subnet_id subnet identifier.
- ///
- /// @return Lease collection (may be empty if no IPv4 lease found).
- virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
-
- /// @brief Returns all IPv4 leases.
- ///
- /// @return Lease collection (may be empty if no IPv4 lease found).
- virtual Lease4Collection getLeases4() const;
-
/// @brief Returns existing IPv4 lease for specified client-id
///
/// There can be at most one lease for a given HW address in a single
virtual Lease4Ptr getLease4(const ClientId& clientid,
SubnetID subnet_id) const;
+ /// @brief Returns all IPv4 leases for the particular subnet identifier.
+ ///
+ /// @param subnet_id subnet identifier.
+ ///
+ /// @return Lease collection (may be empty if no IPv4 lease found).
+ virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
+
+ /// @brief Returns all IPv4 leases.
+ ///
+ /// @return Lease collection (may be empty if no IPv4 lease found).
+ virtual Lease4Collection getLeases4() const;
+
/// @brief Returns existing IPv6 lease for a given IPv6 address.
///
/// For a given address, we assume that there will be only one lease.
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
uint32_t iaid, SubnetID subnet_id) const;
- /// @brief Returns a collection of expired DHCPv6 leases.
+ /// @brief Returns a collection of expired DHCPv4 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases6(Lease6Collection& expired_leases,
+ virtual void getExpiredLeases4(Lease4Collection& expired_leases,
const size_t max_leases) const;
-
- /// @brief Returns a collection of expired DHCPv4 leases.
+ /// @brief Returns a collection of expired DHCPv6 leases.
///
/// This method returns at most @c max_leases expired leases. The leases
/// returned haven't been reclaimed, i.e. the database query must exclude
/// by the database backend are added.
/// @param max_leases A maximum number of leases to be returned. If this
/// value is set to 0, all expired (but not reclaimed) leases are returned.
- virtual void getExpiredLeases4(Lease4Collection& expired_leases,
+ virtual void getExpiredLeases6(Lease6Collection& expired_leases,
const size_t max_leases) const;
/// @brief Updates IPv4 lease.
PRIMARY KEY ((hwaddr_source))
);
+INSERT INTO lease_hwaddr_source (hwaddr_source, name) VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
+
-- Hardware address obtained from raw sockets
INSERT INTO lease_hwaddr_source (hwaddr_source, name) VALUES (1, 'HWADDR_SOURCE_RAW');
-- Table `host_reservations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS host_reservations (
+ id bigint,
host_identifier blob,
host_identifier_type int,
host_ipv4_subnet_id int,
host_ipv6_subnet_id int,
host_ipv4_address int,
+ host_ipv4_next_server int,
+ host_ipv4_server_hostname text,
+ host_ipv4_boot_file_name text,
hostname text,
+ user_context text,
host_ipv4_client_classes text,
host_ipv6_client_classes text,
-- reservation
option_is_persistent boolean,
option_client_class text,
option_subnet_id int,
- id bigint,
+ option_user_context text,
+ option_scope_id int,
PRIMARY KEY ((id))
);
CREATE INDEX IF NOT EXISTS host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
CREATE INDEX IF NOT EXISTS host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
-TRUNCATE SCHEMA_VERSION;
+--
+-- Table structure for table host_identifier_type.
+--
+
+CREATE TABLE IF NOT EXISTS host_identifier_type (
+ type int,
+ name varchar,
+ PRIMARY KEY ((type))
+);
+
+-- Insert currently defined type names.
+INSERT INTO host_identifier_type (type, name) VALUES (0, 'hw-address');
+INSERT INTO host_identifier_type (type, name) VALUES (1, 'duid');
+INSERT INTO host_identifier_type (type, name) VALUES (2, 'circuit-id');
+INSERT INTO host_identifier_type (type, name) VALUES (3, 'client-id');
+INSERT INTO host_identifier_type (type, name) VALUES (4, 'flex-id');
+
+--
+-- Table structure for table dhcp_option_scope.
+--
+
+CREATE TABLE IF NOT EXISTS dhcp_option_scope (
+ scope_id int,
+ scope_name varchar,
+ PRIMARY KEY ((scope_name))
+);
+
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (0, 'global');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (1, 'subnet');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (2, 'client-class');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (3, 'host');
+
+DELETE FROM schema_version WHERE version=1;
INSERT INTO schema_version (version, minor) VALUES(2, 0);
-- This line concludes database upgrade to version 2.0
-
-- -----------------------------------------------------
-- Table \`host_reservations\`
-- -----------------------------------------------------
-CREATE TABLE host_reservations (
+CREATE TABLE IF NOT EXISTS host_reservations (
id bigint,
host_identifier blob,
host_identifier_type int,
host_ipv4_subnet_id int,
host_ipv6_subnet_id int,
host_ipv4_address int,
+ host_ipv4_next_server int,
+ host_ipv4_server_hostname text,
+ host_ipv4_boot_file_name text,
hostname text,
+ user_context text,
host_ipv4_client_classes text,
host_ipv6_client_classes text,
+ -- reservation
reserved_ipv6_prefix_address text,
reserved_ipv6_prefix_length int,
reserved_ipv6_prefix_address_type int,
iaid int,
+ -- option
option_universe int,
option_code int,
option_value blob,
option_is_persistent boolean,
option_client_class text,
option_subnet_id int,
- PRIMARY KEY (id)
+ option_user_context text,
+ option_scope_id int,
+ PRIMARY KEY ((id))
);
+
CREATE INDEX IF NOT EXISTS host_reservationsindex1 ON host_reservations (host_identifier);
CREATE INDEX IF NOT EXISTS host_reservationsindex2 ON host_reservations (host_identifier_type);
CREATE INDEX IF NOT EXISTS host_reservationsindex3 ON host_reservations (host_ipv4_subnet_id);
CREATE INDEX IF NOT EXISTS host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
CREATE INDEX IF NOT EXISTS host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
+--
+-- Table structure for table host_identifier_type.
+--
+
+CREATE TABLE IF NOT EXISTS host_identifier_type (
+ type int,
+ name varchar,
+ PRIMARY KEY ((type))
+);
+
+-- Insert currently defined type names.
+INSERT INTO host_identifier_type (type, name) VALUES (0, 'hw-address');
+INSERT INTO host_identifier_type (type, name) VALUES (1, 'duid');
+INSERT INTO host_identifier_type (type, name) VALUES (2, 'circuit-id');
+INSERT INTO host_identifier_type (type, name) VALUES (3, 'client-id');
+INSERT INTO host_identifier_type (type, name) VALUES (4, 'flex-id');
+
+--
+-- Table structure for table dhcp_option_scope.
+--
+
+CREATE TABLE IF NOT EXISTS dhcp_option_scope (
+ scope_id int,
+ scope_name varchar,
+ PRIMARY KEY ((scope_name))
+);
+
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (0, 'global');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (1, 'subnet');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (2, 'client-class');
+INSERT INTO dhcp_option_scope (scope_id, scope_name) VALUES (3, 'host');
+
DELETE FROM schema_version WHERE version=1;
INSERT INTO schema_version (version, minor) VALUES(2, 0);
name VARCHAR(40) DEFAULT NULL
);
+-- In the event hardware address cannot be determined, we need to satisfy
+-- foreign key constraint between lease6 and lease_hardware_source.
+INSERT INTO lease_hwaddr_source VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
+
-- Hardware address obtained from raw sockets.
INSERT INTO lease_hwaddr_source VALUES (1, 'HWADDR_SOURCE_RAW');
INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM');
--- In the event hardware address cannot be determined, we need to satisfy
--- foreign key constraint between lease6 and lease_hardware_source.
-INSERT INTO lease_hwaddr_source VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
-
-- Adding ORDER BY clause to sort by lease address.
--
-- FUNCTION that returns a result set containing the data for lease4 dumps.
name VARCHAR(40) DEFAULT NULL
);
+-- In the event hardware address cannot be determined, we need to satisfy
+-- foreign key constraint between lease6 and lease_hardware_source
+INSERT INTO lease_hwaddr_source VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
+
-- Hardware address obtained from raw sockets
INSERT INTO lease_hwaddr_source VALUES (1, 'HWADDR_SOURCE_RAW');
INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM');
--- In the event hardware address cannot be determined, we need to satisfy
--- foreign key constraint between lease6 and lease_hardware_source
-INSERT INTO lease_hwaddr_source VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
-
-- Adding ORDER BY clause to sort by lease address
--
-- FUNCTION that returns a result set containing the data for lease4 dumps