pool.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef POOL_H
  15. #define POOL_H
  16. #include <asiolink/io_address.h>
  17. #include <boost/shared_ptr.hpp>
  18. #include <vector>
  19. namespace isc {
  20. namespace dhcp {
  21. /// @brief base class for Pool4 and Pool6
  22. ///
  23. /// Stores information about pool of IPv4 or IPv6 addresses.
  24. /// That is a basic component of a configuration.
  25. class Pool {
  26. public:
  27. /// @brief returns Pool-id
  28. ///
  29. /// @return pool-id value
  30. /// Pool-id is an unique value that can be used to identify a pool.
  31. uint32_t getId() const {
  32. return (id_);
  33. }
  34. /// @brief Returns the first address in a pool.
  35. ///
  36. /// @return first address in a pool
  37. const isc::asiolink::IOAddress& getFirstAddress() const {
  38. return (first_);
  39. }
  40. /// @brief Returns the last address in a pool.
  41. /// @return last address in a pool
  42. const isc::asiolink::IOAddress& getLastAddress() const {
  43. return (last_);
  44. }
  45. /// @brief Checks if a given address is in the range.
  46. ///
  47. /// @return true, if the address is in pool
  48. bool inRange(const isc::asiolink::IOAddress& addr) const;
  49. protected:
  50. /// @brief protected constructor
  51. ///
  52. /// This constructor is protected to prevent anyone from instantiating
  53. /// Pool class directly. Instances of Pool4 and Pool6 should be created
  54. /// instead.
  55. Pool(const isc::asiolink::IOAddress& first,
  56. const isc::asiolink::IOAddress& last);
  57. /// @brief returns the next unique Pool-ID
  58. ///
  59. /// @return the next unique Pool-ID
  60. static uint32_t getNextID() {
  61. static uint32_t id = 0;
  62. return (id++);
  63. }
  64. /// @brief pool-id
  65. ///
  66. /// This ID is used to identify this specific pool.
  67. uint32_t id_;
  68. /// @brief The first address in a pool
  69. isc::asiolink::IOAddress first_;
  70. /// @brief The last address in a pool
  71. isc::asiolink::IOAddress last_;
  72. /// @brief Comments field
  73. ///
  74. /// @todo: This field is currently not used.
  75. std::string comments_;
  76. };
  77. /// @brief Pool information for IPv4 addresses
  78. ///
  79. /// It holds information about pool4, i.e. a range of IPv4 address space that
  80. /// is configured for DHCP allocation.
  81. class Pool4 : public Pool {
  82. public:
  83. /// @brief the constructor for Pool4 "min-max" style definition
  84. ///
  85. /// @param first the first address in a pool
  86. /// @param last the last address in a pool
  87. Pool4(const isc::asiolink::IOAddress& first,
  88. const isc::asiolink::IOAddress& last);
  89. /// @brief the constructor for Pool4 "prefix/len" style definition
  90. ///
  91. /// @param prefix specifies prefix of the pool
  92. /// @param prefix_len specifies length of the prefix of the pool
  93. Pool4(const isc::asiolink::IOAddress& prefix,
  94. uint8_t prefix_len);
  95. };
  96. /// @brief a pointer an IPv4 Pool
  97. typedef boost::shared_ptr<Pool4> Pool4Ptr;
  98. /// @brief a container for IPv4 Pools
  99. typedef std::vector<Pool4Ptr> Pool4Collection;
  100. /// @brief Pool information for IPv6 addresses and prefixes
  101. ///
  102. /// It holds information about pool6, i.e. a range of IPv6 address space that
  103. /// is configured for DHCP allocation.
  104. class Pool6 : public Pool {
  105. public:
  106. /// @brief specifies Pool type
  107. ///
  108. /// Currently there are 3 pool types defined in DHCPv6:
  109. /// - Non-temporary addresses (conveyed in IA_NA)
  110. /// - Temporary addresses (conveyed in IA_TA)
  111. /// - Delegated Prefixes (conveyed in IA_PD)
  112. /// There is a new one being worked on (IA_PA, see draft-ietf-dhc-host-gen-id), but
  113. /// support for it is not planned for now.
  114. typedef enum {
  115. TYPE_IA,
  116. TYPE_TA,
  117. TYPE_PD
  118. } Pool6Type;
  119. /// @brief the constructor for Pool6 "min-max" style definition
  120. ///
  121. /// @param type type of the pool (IA, TA or PD)
  122. /// @param first the first address in a pool
  123. /// @param last the last address in a pool
  124. Pool6(Pool6Type type, const isc::asiolink::IOAddress& first,
  125. const isc::asiolink::IOAddress& last);
  126. /// @brief the constructor for Pool6 "prefix/len" style definition
  127. ///
  128. /// @param type type of the pool (IA, TA or PD)
  129. /// @param prefix specifies prefix of the pool
  130. /// @param prefix_len specifies length of the prefix of the pool
  131. Pool6(Pool6Type type, const isc::asiolink::IOAddress& prefix,
  132. uint8_t prefix_len);
  133. /// @brief returns pool type
  134. ///
  135. /// @return pool type
  136. Pool6Type getType() const {
  137. return (type_);
  138. }
  139. private:
  140. /// @brief defines a pool type
  141. Pool6Type type_;
  142. /// @brief prefix length
  143. /// used by TYPE_PD only (zeroed for other types)
  144. uint8_t prefix_len_;
  145. };
  146. /// @brief a pointer an IPv6 Pool
  147. typedef boost::shared_ptr<Pool6> Pool6Ptr;
  148. /// @brief a container for IPv6 Pools
  149. typedef std::vector<Pool6Ptr> Pool6Collection;
  150. /// @brief a pointer to either IPv4 or IPv6 Pool
  151. typedef boost::shared_ptr<Pool> PoolPtr;
  152. /// @brief a container for either IPv4 or IPv6 Pools
  153. typedef std::vector<PoolPtr> PoolCollection;
  154. } // end of isc::dhcp namespace
  155. } // end of isc namespace
  156. #endif // POOL_H