Commit e4f44ed5 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[2320] dynamic_cast in Subnet::getPool() removed

parent 2bbe63db
......@@ -88,15 +88,6 @@ void Subnet::addPool(const PoolPtr& pool) {
PoolPtr Subnet::getPool(isc::asiolink::IOAddress hint) {
// This is an ugly workaround for having the ability to have default value
// for both protocol families. The alternative to this would be to define
// getPool() as pure virtual and have Subnet4 and Subnet6 provide their
// own methods. Those two implementation would only differ by a default
// value, so it would just include duplicate code.
if (dynamic_cast<Subnet4*>(this) && hint.toText() == "::") {
hint = IOAddress("0.0.0.0");
}
PoolPtr candidate;
for (PoolCollection::iterator pool = pools_.begin(); pool != pools_.end(); ++pool) {
......
......@@ -306,8 +306,19 @@ public:
///
/// @param addr address that the returned pool should cover (optional)
/// @return Pointer to found Pool4 or Pool6 (or NULL)
PoolPtr getPool(isc::asiolink::IOAddress addr =
isc::asiolink::IOAddress("::"));
PoolPtr getPool(isc::asiolink::IOAddress addr);
/// @brief Returns a pool without any address specified
/// @return returns one of the pools defined
PoolPtr getPool() {
return (getPool(default_pool()));
}
/// @brief Returns the default address that will be used for pool selection
///
/// It must be implemented in derived classes (should return :: for Subnet6
/// and 0.0.0.0 for Subnet4)
virtual isc::asiolink::IOAddress default_pool() const = 0;
/// @brief returns all pools
///
......@@ -421,6 +432,11 @@ protected:
/// @throw isc::BadValue if provided option is invalid.
virtual void validateOption(const OptionPtr& option) const;
/// @brief Returns default address for pool selection
/// @return ANY IPv4 address
virtual isc::asiolink::IOAddress default_pool() const {
return (isc::asiolink::IOAddress("0.0.0.0"));
}
};
/// @brief A pointer to a Subnet4 object
......@@ -466,6 +482,12 @@ protected:
/// @throw isc::BadValue if provided option is invalid.
virtual void validateOption(const OptionPtr& option) const;
/// @brief Returns default address for pool selection
/// @return ANY IPv6 address
virtual isc::asiolink::IOAddress default_pool() const {
return (isc::asiolink::IOAddress("::"));
}
/// @brief collection of pools in that list
Pool6Collection pools_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment