From: Tomek Mrugalski Date: Wed, 17 Oct 2012 16:05:25 +0000 (+0200) Subject: [2324] Subnet now stores last allocated address. X-Git-Tag: trac2487_base~21^2~9^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4f9ae7bf9569106d47a0ff227552eb6a956aa4e;p=thirdparty%2Fkea.git [2324] Subnet now stores last allocated address. --- diff --git a/src/lib/dhcp/subnet.cc b/src/lib/dhcp/subnet.cc index d0c4cb35fe..737207caac 100644 --- a/src/lib/dhcp/subnet.cc +++ b/src/lib/dhcp/subnet.cc @@ -27,7 +27,8 @@ Subnet::Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len, const Triplet& t2, const Triplet& valid_lifetime) :id_(getNextID()), prefix_(prefix), prefix_len_(len), t1_(t1), - t2_(t2), valid_(valid_lifetime) { + t2_(t2), valid_(valid_lifetime), + last_allocated_(lastAddrInPrefix(prefix, len)) { if ( (prefix.getFamily() == AF_INET6 && len > 128) || (prefix.getFamily() == AF_INET && len > 32) ) { isc_throw(BadValue, "Invalid prefix length specified for subnet: " << len); diff --git a/src/lib/dhcp/subnet.h b/src/lib/dhcp/subnet.h index 7e4e0b7f07..86b9007079 100644 --- a/src/lib/dhcp/subnet.h +++ b/src/lib/dhcp/subnet.h @@ -33,6 +33,11 @@ namespace dhcp { /// leased addresses lifetime (valid-lifetime). /// /// @todo: Implement support for options here + + +/// @brief Unique indentifier for a subnet (both v4 and v6) +typedef uint32_t SubnetID; + class Subnet { public: /// @brief checks if specified address is in range @@ -53,6 +58,16 @@ public: return (t2_); } + isc::asiolink::IOAddress getLastAllocated() { + return (last_allocated_); + } + + void setLastAllocated(const isc::asiolink::IOAddress& addr) { + last_allocated_ = addr; + } + + SubnetID getID() { return id_; } + protected: /// @brief protected constructor // @@ -66,8 +81,8 @@ protected: /// @brief returns the next unique Subnet-ID /// /// @return the next unique Subnet-ID - static uint32_t getNextID() { - static uint32_t id = 0; + static SubnetID getNextID() { + static SubnetID id = 0; return (id++); } @@ -75,7 +90,7 @@ protected: /// /// Subnet-id is a unique value that can be used to find or identify /// a Subnet4 or Subnet6. - uint32_t id_; + SubnetID id_; /// @brief a prefix of the subnet isc::asiolink::IOAddress prefix_; @@ -91,6 +106,17 @@ protected: /// @brief a tripet (min/default/max) holding allowed valid lifetime values Triplet valid_; + + /// @brief last allocated address + /// + /// This is the last allocated address that was previously allocated from + /// this particular subnet. Some allocation algorithms (e.g. iterative) use + /// that value, others do not. It should be noted that although the value + /// is usually correct, there are cases when it is invalid, e.g. after + /// removing a pool, restarting or changing allocation algorithms. For + /// that purpose it should be only considered a help that should not be + /// fully trusted. + isc::asiolink::IOAddress last_allocated_; }; /// @brief A configuration holder for IPv4 subnet. @@ -124,8 +150,7 @@ public: /// @brief returns all pools /// - /// The reference is only valid as long as the object that - /// returned it. + /// The reference is only valid as long as the object that returned it. /// /// @return a collection of all pools const Pool4Collection& getPools() const {