 |
Kea
1.5.0
|
Go to the documentation of this file.
14 #include <boost/lexical_cast.hpp>
30 return (prefix < pool->getFirstAddress());
42 comparePoolFirstAddress(
const PoolPtr& pool1,
const PoolPtr& pool2) {
43 return (pool1->getFirstAddress() < pool2->getFirstAddress());
56 : id_(id == 0 ? generateNextID() : id), prefix_(prefix),
61 last_allocated_time_() {
62 if ((prefix.
isV6() && len > 128) ||
63 (prefix.
isV4() && len > 32)) {
65 "Invalid prefix length specified for subnet: " << len);
80 return ((first <= addr) && (addr <= last));
100 boost::posix_time::ptime
109 return (boost::posix_time::neg_infin);
140 std::stringstream tmp;
157 <<
static_cast<int>(type));
174 <<
static_cast<int>(type));
181 for (PoolCollection::const_iterator p = pools.begin(); p != pools.end(); ++p) {
182 uint64_t x = (*p)->getCapacity();
186 if (x > std::numeric_limits<uint64_t>::max() - sum) {
187 return (std::numeric_limits<uint64_t>::max());
200 for (PoolCollection::const_iterator p = pools.begin(); p != pools.end(); ++p) {
201 if (!(*p)->clientSupported(client_classes)) {
204 uint64_t x = (*p)->getCapacity();
208 if (x > std::numeric_limits<uint64_t>::max() - sum) {
209 return (std::numeric_limits<uint64_t>::max());
218 std::pair<IOAddress, uint8_t>
220 auto pos = prefix.find(
'/');
221 if ((pos == std::string::npos) ||
222 (pos == prefix.size() - 1) ||
228 IOAddress address(prefix.substr(0, pos));
229 int length = boost::lexical_cast<int>(prefix.substr(pos + 1));
230 return (std::make_pair(address,
static_cast<int>(length)));
251 if (!prefix.
isV4()) {
253 <<
" specified in subnet4");
267 return (network->getNextSubnet(first_subnet,
getID()));
287 subnet = network->getNextSubnet(first_subnet, subnet_id);
290 if (subnet && subnet->clientSupported(client_classes)) {
305 if (network && !network->clientSupported(client_classes)) {
313 if (!siaddr.
isV4()) {
332 filename_ = filename;
353 <<
static_cast<int>(type));
371 <<
static_cast<int>(type));
376 bool anypool )
const {
384 if (!pools.empty()) {
393 PoolCollection::const_iterator ub =
394 std::upper_bound(pools.begin(), pools.end(), hint,
395 prefixLessThanFirstAddress);
397 if (ub != pools.begin()) {
399 if ((*ub)->inRange(hint)) {
405 if (!candidate && anypool) {
406 candidate = *pools.begin();
424 if (!pools.empty()) {
425 PoolCollection::const_iterator ub =
426 std::upper_bound(pools.begin(), pools.end(), hint,
427 prefixLessThanFirstAddress);
429 if (ub != pools.begin()) {
431 if ((*ub)->inRange(hint) &&
432 (*ub)->clientSupported(client_classes)) {
452 if (!
inRange(pool->getFirstAddress()) || !
inRange(pool->getLastAddress())) {
455 <<
", with the following address range: "
456 << pool->getFirstAddress() <<
"-"
457 << pool->getLastAddress() <<
" does not match"
458 <<
" the prefix of a subnet: "
460 <<
" to which it is being added");
465 bool overlaps =
false;
479 <<
", with the following address range: "
480 << pool->getFirstAddress() <<
"-"
481 << pool->getLastAddress() <<
" overlaps with "
482 "an existing pool in the subnet: "
484 <<
" to which it is being added");
490 pools_writable.push_back(pool);
493 std::sort(pools_writable.begin(), pools_writable.end(),
494 comparePoolFirstAddress);
512 for (PoolCollection::const_iterator pool = pools.begin();
513 pool != pools.end(); ++pool) {
514 if ((*pool)->inRange(addr)) {
534 for (PoolCollection::const_iterator pool = pools.begin();
535 pool != pools.end(); ++pool) {
536 if (!(*pool)->clientSupported(client_classes)) {
539 if ((*pool)->inRange(addr)) {
570 PoolCollection::const_iterator pool3_it =
571 std::upper_bound(pools.begin(), pools.end(), pool->getFirstAddress(),
572 prefixLessThanFirstAddress);
580 if (pool3_it != pools.begin()) {
582 PoolPtr pool3 = *(pool3_it - 1);
583 if (pool3->getFirstAddress() == pool->getFirstAddress()) {
590 if (pool3_it != pools.end()) {
594 if (pool3->getFirstAddress() <= pool->getLastAddress()) {
601 if (pool3_it != pools.begin()) {
602 PoolPtr pool1 = *(pool3_it - 1);
604 if (pool->getFirstAddress() <= pool1->getLastAddress()) {
620 if (!prefix.
isV6()) {
622 <<
" specified in subnet6");
636 <<
"(" <<
static_cast<int>(type)
637 <<
"), must be TYPE_NA, TYPE_TA or TYPE_PD for Subnet6");
646 return (network->getNextSubnet(first_subnet,
getID()));
666 subnet = network->getNextSubnet(first_subnet, subnet_id);
669 if (subnet && subnet->clientSupported(client_classes)) {
683 if (network && !network->clientSupported(client_classes)) {
699 map->set(
"id", Element::create(
static_cast<long long>(
id)));
702 map->set(
"subnet", Element::create(
toText()));
713 merge(map, network_map);
723 map->set(
"server-hostname", Element::create(
getSname()));
726 map->set(
"boot-file-name",Element::create(
getFilename()));
731 for (PoolCollection::const_iterator pool = pools.cbegin();
732 pool != pools.cend(); ++pool) {
734 pool_list->add((*pool)->toElement());
736 map->set(
"pools", pool_list);
741 std::pair<IOAddress, uint8_t>
744 if (!parsed.first.isV4() || parsed.first.isV4Zero() ||
745 (parsed.second > 32) || (parsed.second == 0)) {
757 merge(map, network_map);
762 for (PoolCollection::const_iterator pool = pools.cbegin();
763 pool != pools.cend(); ++pool) {
765 pool_list->add((*pool)->toElement());
767 map->set(
"pools", pool_list);
771 ElementPtr pdpool_list = Element::createList();
772 for (PoolCollection::const_iterator pool = pdpools.cbegin();
773 pool != pdpools.cend(); ++pool) {
775 pdpool_list->add((*pool)->toElement());
777 map->set(
"pd-pools", pdpool_list);
782 std::pair<IOAddress, uint8_t>
785 if (!parsed.first.isV6() || parsed.first.isV6Zero() ||
786 (parsed.second > 128) || (parsed.second == 0)) {
void delPools(Lease::Type type)
Deletes all pools of specified type.
virtual void checkType(Lease::Type type) const =0
Checks if used pool type is valid.
Subnet6(const isc::asiolink::IOAddress &prefix, uint8_t length, const Triplet< uint32_t > &t1, const Triplet< uint32_t > &t2, const Triplet< uint32_t > &preferred_lifetime, const Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Constructor with all parameters.
virtual data::ElementPtr toElement() const
Unparses network object.
void setPreferred(const Triplet< uint32_t > &preferred)
Sets new preferred lifetime for a network.
std::map< Lease::Type, boost::posix_time::ptime > last_allocated_time_
Timestamp indicating when a lease of a specified type has been last allocated from this subnet.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
The IOAddress class represents an IP addresses (version agnostic)
void setValid(const Triplet< uint32_t > &valid)
Sets new valid lifetime for a network.
Type
Type of lease or pool.
void setSname(const std::string &sname)
Sets server hostname for the Subnet4.
bool isV6() const
Convenience function to check for an IPv6 address.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
virtual data::ElementPtr toElement() const
Unparses network object.
void setT2(const Triplet< uint32_t > &t2)
Sets new rebind timer for a network.
Subnet4(const isc::asiolink::IOAddress &prefix, uint8_t length, const Triplet< uint32_t > &t1, const Triplet< uint32_t > &t2, const Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Constructor with all parameters.
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
const PoolCollection & getPools(Lease::Type type) const
Returns all pools (const variant)
virtual data::ElementPtr toElement() const
Unparse a subnet object.
virtual std::string toText() const
Returns textual representation of the subnet (e.g.
const std::string & getSname() const
Returns server hostname for this subnet.
isc::asiolink::IOAddress last_allocated_ia_
last allocated address
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setSiaddr(const isc::asiolink::IOAddress &siaddr)
Sets siaddr for the Subnet4.
Specialization of the Network object for DHCPv6 case.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
uint8_t prefix_len_
a prefix length of the subnet
const PoolPtr getPool(Lease::Type type, const isc::asiolink::IOAddress &addr, bool anypool=true) const
Returns a pool that specified address belongs to.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
@ TYPE_TA
the lease contains temporary IPv6 address
static std::pair< asiolink::IOAddress, uint8_t > parsePrefixCommon(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
bool poolOverlaps(const Lease::Type &pool_type, const PoolPtr &pool) const
Checks if the specified pool overlaps with an existing pool.
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this network supports client that belongs to specified classes.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
virtual data::ElementPtr toElement() const
Unparse a subnet object.
uint64_t getPoolCapacity(Lease::Type type) const
Returns the number of possible leases for specified lease type.
void getSharedNetwork(SharedNetworkPtrType &shared_network) const
Retrieves pointer to a shared network associated with a subnet.
isc::asiolink::IOAddress last_allocated_ta_
last allocated temporary address
isc::asiolink::IOAddress prefix_
a prefix of the subnet
PoolCollection pools_
collection of IPv4 or non-temporary IPv6 pools in that subnet
std::string toText() const
Convert the address to a string.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
Subnet6Ptr getNextSubnet(const Subnet6Ptr &first_subnet) const
Returns next subnet within shared network.
void setT1(const Triplet< uint32_t > &t1)
Sets new renew timer for a network.
void setLastAllocated(Lease::Type type, const isc::asiolink::IOAddress &addr)
sets the last address that was tried from this subnet
PoolCollection & getPoolsWritable(Lease::Type type)
Returns all pools (non-const variant)
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this subnet and parent shared network supports the client that belongs to specified cl...
virtual data::ElementPtr toElement() const
Unparse a subnet object.
boost::posix_time::ptime getLastAllocatedTime(const Lease::Type &lease_type) const
Returns the timestamp when the setLastAllocated function was called.
const std::string & getFilename() const
Returns boot file name for this subnet.
PoolCollection pools_ta_
collection of IPv6 temporary address pools in that subnet
Cfg4o6 & get4o6()
Returns DHCP4o6 configuration parameters.
SubnetID getID() const
Returns unique ID for that subnet.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
bool inRange(const isc::asiolink::IOAddress &addr) const
checks if specified address is in range
bool inPool(Lease::Type type, const isc::asiolink::IOAddress &addr) const
checks if the specified address is in pools
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this subnet and parent shared network supports the client that belongs to specified cl...
isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
Subnet4Ptr getNextSubnet(const Subnet4Ptr &first_subnet) const
Returns next subnet within shared network.
boost::shared_ptr< Element > ElementPtr
static std::string typeToText(Type type)
returns text representation of a lease type
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
uint64_t sumPoolCapacity(const PoolCollection &pools) const
Returns a sum of possible leases in all pools.
Specialization of the Network object for DHCPv4 case.
isc::asiolink::IOAddress getSiaddr() const
Returns siaddr for this subnet.
bool isV4() const
Convenience function to check for an IPv4 address.
static std::pair< asiolink::IOAddress, uint8_t > parsePrefix(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
@ TYPE_NA
the lease contains non-temporary IPv6 address
void addPool(const PoolPtr &pool)
Adds a new pool for the subnet.
static std::pair< asiolink::IOAddress, uint8_t > parsePrefix(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
void setFilename(const std::string &filename)
Sets boot file name for the Subnet4.
Container for storing client class names.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
PoolCollection pools_pd_
collection of IPv6 prefix pools in that subnet
isc::asiolink::IOAddress last_allocated_pd_
last allocated IPv6 prefix
isc::asiolink::IOAddress getLastAllocated(Lease::Type type) const
returns the last address that was tried from this subnet
This structure contains information about DHCP4o6 (RFC7341)