Browse Source

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

Tomek Mrugalski 12 years ago
parent
commit
e4f44ed541
2 changed files with 24 additions and 11 deletions
  1. 0 9
      src/lib/dhcpsrv/subnet.cc
  2. 24 2
      src/lib/dhcpsrv/subnet.h

+ 0 - 9
src/lib/dhcpsrv/subnet.cc

@@ -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) {
 

+ 24 - 2
src/lib/dhcpsrv/subnet.h

@@ -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_;