subnet.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. // Copyright (C) 2012-2015 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 SUBNET_H
  15. #define SUBNET_H
  16. #include <asiolink/io_address.h>
  17. #include <dhcp/option.h>
  18. #include <dhcp/classify.h>
  19. #include <dhcpsrv/cfg_option.h>
  20. #include <dhcpsrv/option_space_container.h>
  21. #include <dhcpsrv/pool.h>
  22. #include <dhcpsrv/triplet.h>
  23. #include <dhcpsrv/lease.h>
  24. #include <boost/shared_ptr.hpp>
  25. namespace isc {
  26. namespace dhcp {
  27. /// @brief a base class for Subnet4 and Subnet6
  28. ///
  29. /// This class presents a common base for IPv4 and IPv6 subnets.
  30. /// In a physical sense, a subnet defines a single network link with all devices
  31. /// attached to it. In most cases all devices attached to a single link can
  32. /// share the same parameters. Therefore Subnet holds several values that are
  33. /// typically shared by all hosts: renew timer (T1), rebind timer (T2) and
  34. /// leased addresses lifetime (valid-lifetime). It also holds the set
  35. /// of DHCP option instances configured for the subnet. These options are
  36. /// included in DHCP messages being sent to clients which are connected
  37. /// to the particular subnet.
  38. ///
  39. /// @todo: Implement support for options here
  40. /// @brief Unique identifier for a subnet (both v4 and v6)
  41. typedef uint32_t SubnetID;
  42. class Subnet {
  43. public:
  44. /// @brief Holds optional information about relay.
  45. ///
  46. /// In some cases it is beneficial to have additional information about
  47. /// a relay configured in the subnet. For now, the structure holds only
  48. /// IP address, but there may potentially be additional parameters added
  49. /// later, e.g. relay interface-id or relay-id.
  50. struct RelayInfo {
  51. /// @brief default and the only constructor
  52. ///
  53. /// @param addr an IP address of the relay (may be :: or 0.0.0.0)
  54. RelayInfo(const isc::asiolink::IOAddress& addr);
  55. /// @brief IP address of the relay
  56. isc::asiolink::IOAddress addr_;
  57. };
  58. /// @brief Specifies allowed host reservation mode.
  59. ///
  60. typedef enum {
  61. /// None - host reservation is disabled. No reservation types
  62. /// are allowed.
  63. HR_DISABLED,
  64. /// Only out-of-pool reservations is allowed. This mode
  65. /// allows AllocEngine to skip reservation checks when
  66. /// dealing with with addresses that are in pool.
  67. HR_OUT_OF_POOL,
  68. /// Both out-of-pool and in-pool reservations are allowed. This is the
  69. /// most flexible mode, where sysadmin have biggest liberty. However,
  70. /// there is a non-trivial performance penalty for it, as the
  71. /// AllocEngine code has to check whether there are reservations, even
  72. /// when dealing with reservations from within the dynamic pools.
  73. HR_ALL
  74. } HRMode;
  75. /// Pointer to the RelayInfo structure
  76. typedef boost::shared_ptr<Subnet::RelayInfo> RelayInfoPtr;
  77. /// @brief checks if specified address is in range
  78. bool inRange(const isc::asiolink::IOAddress& addr) const;
  79. /// @brief checks if the specified address is in pools
  80. ///
  81. /// Note the difference between inSubnet() and inPool(). For a given
  82. /// subnet (e.g. 2001::/64) there may be one or more pools defined
  83. /// that may or may not cover entire subnet, e.g. pool 2001::1-2001::10).
  84. /// inPool() returning true implies inSubnet(), but the reverse implication
  85. /// is not always true. For the given example, 2001::1234:abcd would return
  86. /// true for inSubnet(), but false for inPool() check.
  87. ///
  88. /// @param type type of pools to iterate over
  89. /// @param addr this address will be checked if it belongs to any pools in
  90. /// that subnet
  91. /// @return true if the address is in any of the pools
  92. bool inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const;
  93. /// @brief Return valid-lifetime for addresses in that prefix
  94. Triplet<uint32_t> getValid() const {
  95. return (valid_);
  96. }
  97. /// @brief Returns T1 (renew timer), expressed in seconds
  98. Triplet<uint32_t> getT1() const {
  99. return (t1_);
  100. }
  101. /// @brief Returns T2 (rebind timer), expressed in seconds
  102. Triplet<uint32_t> getT2() const {
  103. return (t2_);
  104. }
  105. /// @brief Returns pointer to the option data configuration for this subnet.
  106. CfgOptionPtr getCfgOption() {
  107. return (cfg_option_);
  108. }
  109. /// @brief Returns const pointer to the option data configuration for this
  110. /// subnet.
  111. ConstCfgOptionPtr getCfgOption() const {
  112. return (cfg_option_);
  113. }
  114. /// @brief returns the last address that was tried from this pool
  115. ///
  116. /// This method returns the last address that was attempted to be allocated
  117. /// from this subnet. This is used as helper information for the next
  118. /// iteration of the allocation algorithm.
  119. ///
  120. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  121. /// AllocEngine::IterativeAllocator and keep the data there
  122. ///
  123. /// @param type lease type to be returned
  124. /// @return address/prefix that was last tried from this pool
  125. isc::asiolink::IOAddress getLastAllocated(Lease::Type type) const;
  126. /// @brief sets the last address that was tried from this pool
  127. ///
  128. /// This method sets the last address that was attempted to be allocated
  129. /// from this subnet. This is used as helper information for the next
  130. /// iteration of the allocation algorithm.
  131. ///
  132. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  133. /// AllocEngine::IterativeAllocator and keep the data there
  134. /// @param addr address/prefix to that was tried last
  135. /// @param type lease type to be set
  136. void setLastAllocated(Lease::Type type,
  137. const isc::asiolink::IOAddress& addr);
  138. /// @brief Returns unique ID for that subnet
  139. /// @return unique ID for that subnet
  140. SubnetID getID() const { return (id_); }
  141. /// @brief Returns subnet parameters (prefix and prefix length)
  142. ///
  143. /// @return (prefix, prefix length) pair
  144. std::pair<isc::asiolink::IOAddress, uint8_t> get() const {
  145. return (std::make_pair(prefix_, prefix_len_));
  146. }
  147. /// @brief Adds a new pool for the subnet.
  148. ///
  149. /// This method checks that the address range represented by the pool
  150. /// matches the subnet prefix, if the pool type is different than
  151. /// IA_PD. The prefixes from the IA_PD pools don't need to match the
  152. /// prefix from the subnet from which they are handed out to the
  153. /// requesting router because the requesting router may use the
  154. /// delegated prefixes in different networks (using different subnets).
  155. ///
  156. /// @param pool pool to be added
  157. ///
  158. /// @throw isc::BadValue if the pool type is invalid or the pool
  159. /// is not an IA_PD pool and the address range of this pool does not
  160. /// match the subnet prefix.
  161. void addPool(const PoolPtr& pool);
  162. /// @brief Deletes all pools of specified type
  163. ///
  164. /// This method is used for testing purposes only
  165. /// @param type type of pools to be deleted
  166. void delPools(Lease::Type type);
  167. /// @brief Returns a pool that specified address belongs to
  168. ///
  169. /// If there is no pool that the address belongs to (hint is invalid), other
  170. /// pool of specified type will be returned.
  171. ///
  172. /// With anypool set to true, this is means give me a pool, preferably
  173. /// the one that addr belongs to. With anypool set to false, it means
  174. /// give me a pool that addr belongs to (or NULL if here is no such pool)
  175. ///
  176. /// @param type pool type that the pool is looked for
  177. /// @param addr address that the returned pool should cover (optional)
  178. /// @param anypool other pool may be returned as well, not only the one
  179. /// that addr belongs to
  180. /// @return found pool (or NULL)
  181. const PoolPtr getPool(Lease::Type type, const isc::asiolink::IOAddress& addr,
  182. bool anypool = true) const;
  183. /// @brief Returns a pool without any address specified
  184. ///
  185. /// @param type pool type that the pool is looked for
  186. /// @return returns one of the pools defined
  187. PoolPtr getAnyPool(Lease::Type type) {
  188. return (getPool(type, default_pool()));
  189. }
  190. /// @brief Returns the default address that will be used for pool selection
  191. ///
  192. /// It must be implemented in derived classes (should return :: for Subnet6
  193. /// and 0.0.0.0 for Subnet4)
  194. virtual isc::asiolink::IOAddress default_pool() const = 0;
  195. /// @brief Returns all pools (const variant)
  196. ///
  197. /// The reference is only valid as long as the object that returned it.
  198. ///
  199. /// @param type lease type to be set
  200. /// @return a collection of all pools
  201. const PoolCollection& getPools(Lease::Type type) const;
  202. /// @brief Sets name of the network interface for directly attached networks
  203. ///
  204. /// @param iface_name name of the interface
  205. void setIface(const std::string& iface_name);
  206. /// @brief Network interface name used to reach subnet (or "" for remote
  207. /// subnets)
  208. /// @return network interface name for directly attached subnets or ""
  209. std::string getIface() const;
  210. /// @brief Returns textual representation of the subnet (e.g.
  211. /// "2001:db8::/64")
  212. ///
  213. /// @return textual representation
  214. virtual std::string toText() const;
  215. /// @brief Resets subnet-id counter to its initial value (1)
  216. ///
  217. /// This should be called during reconfiguration, before any new
  218. /// subnet objects are created. It will ensure that the subnet_id will
  219. /// be consistent between reconfigures.
  220. static void resetSubnetID() {
  221. static_id_ = 1;
  222. }
  223. /// @brief Sets information about relay
  224. ///
  225. /// In some situations where there are shared subnets (i.e. two different
  226. /// subnets are available on the same physical link), there is only one
  227. /// relay that handles incoming requests from clients. In such a case,
  228. /// the usual subnet selection criteria based on relay belonging to the
  229. /// subnet being selected are no longer sufficient and we need to explicitly
  230. /// specify a relay. One notable example of such uncommon, but valid
  231. /// scenario is a cable network, where there is only one CMTS (one relay),
  232. /// but there are 2 distinct subnets behind it: one for cable modems
  233. /// and another one for CPEs and other user equipment behind modems.
  234. /// From manageability perspective, it is essential that modems get addresses
  235. /// from different subnet, so users won't tinker with their modems.
  236. ///
  237. /// Setting this parameter is not needed in most deployments.
  238. /// This structure holds IP address only for now, but it is expected to
  239. /// be extended in the future.
  240. ///
  241. /// @param relay structure that contains relay information
  242. void setRelayInfo(const isc::dhcp::Subnet::RelayInfo& relay);
  243. /// @brief Returns const reference to relay information
  244. ///
  245. /// @note The returned reference is only valid as long as the object
  246. /// returned it is valid.
  247. ///
  248. /// @return const reference to the relay information
  249. const isc::dhcp::Subnet::RelayInfo& getRelayInfo() {
  250. return (relay_);
  251. }
  252. /// @brief checks whether this subnet supports client that belongs to
  253. /// specified classes.
  254. ///
  255. /// This method checks whether a client that belongs to given classes can
  256. /// use this subnet. For example, if this class is reserved for client
  257. /// class "foo" and the client belongs to classes "foo", "bar" and "baz",
  258. /// it is supported. On the other hand, client belonging to classes
  259. /// "foobar" and "zyxxy" is not supported.
  260. ///
  261. /// @todo: Currently the logic is simple: client is supported if it belongs
  262. /// to any class mentioned in white_list_. We will eventually need a
  263. /// way to specify more fancy logic (e.g. to meet all classes, not just
  264. /// any)
  265. ///
  266. /// @param client_classes list of all classes the client belongs to
  267. /// @return true if client can be supported, false otherwise
  268. bool
  269. clientSupported(const isc::dhcp::ClientClasses& client_classes) const;
  270. /// @brief adds class class_name to the list of supported classes
  271. ///
  272. /// Also see explanation note in @ref white_list_.
  273. ///
  274. /// @param class_name client class to be supported by this subnet
  275. void
  276. allowClientClass(const isc::dhcp::ClientClass& class_name);
  277. /// @brief Specifies what type of Host Reservations are supported.
  278. ///
  279. /// Host reservations may be either in-pool (they reserve an address that
  280. /// is in the dynamic pool) or out-of-pool (they reserve an address that is
  281. /// not in the dynamic pool). HR may also be completely disabled for
  282. /// performance reasons.
  283. ///
  284. /// @return whether in-pool host reservations are allowed.
  285. HRMode
  286. getHostReservationMode() const {
  287. return (host_reservation_mode_);
  288. }
  289. /// @brief Sets host reservation mode.
  290. ///
  291. /// See @getHostReservationMode for details.
  292. ///
  293. /// @param mode mode to be set
  294. void setHostReservationMode(HRMode mode) {
  295. host_reservation_mode_ = mode;
  296. }
  297. protected:
  298. /// @brief Returns all pools (non-const variant)
  299. ///
  300. /// The reference is only valid as long as the object that returned it.
  301. ///
  302. /// @param type lease type to be set
  303. /// @return a collection of all pools
  304. PoolCollection& getPoolsWritable(Lease::Type type);
  305. /// @brief Protected constructor
  306. //
  307. /// By making the constructor protected, we make sure that no one will
  308. /// ever instantiate that class. Subnet4 and Subnet6 should be used instead.
  309. ///
  310. /// This constructor assigns a new subnet-id (see @ref generateNextID).
  311. /// This subnet-id has unique value that is strictly monotonously increasing
  312. /// for each subnet, until it is explicitly reset back to 1 during
  313. /// reconfiguration process.
  314. ///
  315. /// @param prefix subnet prefix
  316. /// @param len prefix length for the subnet
  317. /// @param t1 T1 (renewal-time) timer, expressed in seconds
  318. /// @param t2 T2 (rebind-time) timer, expressed in seconds
  319. /// @param valid_lifetime valid lifetime of leases in this subnet (in seconds)
  320. /// @param relay optional relay information (currently with address only)
  321. /// @param id arbitraty subnet id, value of 0 triggers autogeneration
  322. /// of subnet id
  323. Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len,
  324. const Triplet<uint32_t>& t1,
  325. const Triplet<uint32_t>& t2,
  326. const Triplet<uint32_t>& valid_lifetime,
  327. const isc::dhcp::Subnet::RelayInfo& relay,
  328. const SubnetID id);
  329. /// @brief virtual destructor
  330. ///
  331. /// A virtual destructor is needed because other classes
  332. /// derive from this class.
  333. virtual ~Subnet() { };
  334. /// @brief keeps the subnet-id value
  335. ///
  336. /// It is inreased every time a new Subnet object is created. It is reset
  337. /// (@ref resetSubnetID) every time reconfiguration
  338. /// occurs.
  339. ///
  340. /// Static value initialized in subnet.cc.
  341. static SubnetID static_id_;
  342. /// @brief returns the next unique Subnet-ID
  343. ///
  344. /// This method generates and returns the next unique subnet-id.
  345. /// It is a strictly monotonously increasing value (1,2,3,...) for
  346. /// each new Subnet object created. It can be explicitly reset
  347. /// back to 1 during reconfiguration (@ref resetSubnetID).
  348. ///
  349. /// @return the next unique Subnet-ID
  350. static SubnetID generateNextID() {
  351. return (static_id_++);
  352. }
  353. /// @brief Checks if used pool type is valid
  354. ///
  355. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  356. /// Allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  357. /// This method is implemented in derived classes.
  358. ///
  359. /// @param type type to be checked
  360. /// @throw BadValue if invalid value is used
  361. virtual void checkType(Lease::Type type) const = 0;
  362. /// @brief subnet-id
  363. ///
  364. /// Subnet-id is a unique value that can be used to find or identify
  365. /// a Subnet4 or Subnet6.
  366. SubnetID id_;
  367. /// @brief collection of IPv4 or non-temporary IPv6 pools in that subnet
  368. PoolCollection pools_;
  369. /// @brief collection of IPv6 temporary address pools in that subnet
  370. PoolCollection pools_ta_;
  371. /// @brief collection of IPv6 prefix pools in that subnet
  372. PoolCollection pools_pd_;
  373. /// @brief a prefix of the subnet
  374. isc::asiolink::IOAddress prefix_;
  375. /// @brief a prefix length of the subnet
  376. uint8_t prefix_len_;
  377. /// @brief a tripet (min/default/max) holding allowed renew timer values
  378. Triplet<uint32_t> t1_;
  379. /// @brief a tripet (min/default/max) holding allowed rebind timer values
  380. Triplet<uint32_t> t2_;
  381. /// @brief a tripet (min/default/max) holding allowed valid lifetime values
  382. Triplet<uint32_t> valid_;
  383. /// @brief last allocated address
  384. ///
  385. /// This is the last allocated address that was previously allocated from
  386. /// this particular subnet. Some allocation algorithms (e.g. iterative) use
  387. /// that value, others do not. It should be noted that although the value
  388. /// is usually correct, there are cases when it is invalid, e.g. after
  389. /// removing a pool, restarting or changing allocation algorithms. For
  390. /// that purpose it should be only considered a help that should not be
  391. /// fully trusted.
  392. isc::asiolink::IOAddress last_allocated_ia_;
  393. /// @brief last allocated temporary address
  394. ///
  395. /// See @ref last_allocated_ia_ for details.
  396. isc::asiolink::IOAddress last_allocated_ta_;
  397. /// @brief last allocated IPv6 prefix
  398. ///
  399. /// See @ref last_allocated_ia_ for details.
  400. isc::asiolink::IOAddress last_allocated_pd_;
  401. /// @brief Name of the network interface (if connected directly)
  402. std::string iface_;
  403. /// @brief Relay information
  404. ///
  405. /// See @ref RelayInfo for detailed description. This structure is public,
  406. /// so its fields are easily accessible. Making it protected would bring in
  407. /// the issue of returning references that may become stale after its parent
  408. /// subnet object disappears.
  409. RelayInfo relay_;
  410. /// @brief optional definition of a client class
  411. ///
  412. /// If defined, only clients belonging to that class will be allowed to use
  413. /// this particular subnet. The default value for this is an empty list,
  414. /// which means that any client is allowed, regardless of its class.
  415. ///
  416. /// @todo This is just a single list of allowed classes. We'll also need
  417. /// to add a black-list (only classes on the list are rejected, the rest
  418. /// are allowed). Implementing this will require more fancy parser logic,
  419. /// so it may be a while until we support this.
  420. ClientClasses white_list_;
  421. /// @brief Specifies host reservation mode
  422. ///
  423. /// See @ref HRMode type for details.
  424. HRMode host_reservation_mode_;
  425. private:
  426. /// @brief Pointer to the option data configuration for this subnet.
  427. CfgOptionPtr cfg_option_;
  428. };
  429. /// @brief A generic pointer to either Subnet4 or Subnet6 object
  430. typedef boost::shared_ptr<Subnet> SubnetPtr;
  431. /// @brief A configuration holder for IPv4 subnet.
  432. ///
  433. /// This class represents an IPv4 subnet.
  434. class Subnet4 : public Subnet {
  435. public:
  436. /// @brief Constructor with all parameters
  437. ///
  438. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  439. ///
  440. /// @param prefix Subnet4 prefix
  441. /// @param length prefix length
  442. /// @param t1 renewal timer (in seconds)
  443. /// @param t2 rebind timer (in seconds)
  444. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  445. /// @param id arbitraty subnet id, default value of 0 triggers
  446. /// autogeneration of subnet id
  447. Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
  448. const Triplet<uint32_t>& t1,
  449. const Triplet<uint32_t>& t2,
  450. const Triplet<uint32_t>& valid_lifetime,
  451. const SubnetID id = 0);
  452. /// @brief Sets siaddr for the Subnet4
  453. ///
  454. /// Will be used for siaddr field (the next server) that typically is used
  455. /// as TFTP server. If not specified, the default value of 0.0.0.0 is
  456. /// used.
  457. void setSiaddr(const isc::asiolink::IOAddress& siaddr);
  458. /// @brief Returns siaddr for this subnet
  459. ///
  460. /// @return siaddr value
  461. isc::asiolink::IOAddress getSiaddr() const;
  462. protected:
  463. /// @brief Returns default address for pool selection
  464. /// @return ANY IPv4 address
  465. virtual isc::asiolink::IOAddress default_pool() const {
  466. return (isc::asiolink::IOAddress("0.0.0.0"));
  467. }
  468. /// @brief Checks if used pool type is valid
  469. ///
  470. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  471. ///
  472. /// @param type type to be checked
  473. /// @throw BadValue if invalid value is used
  474. virtual void checkType(Lease::Type type) const;
  475. /// @brief siaddr value for this subnet
  476. isc::asiolink::IOAddress siaddr_;
  477. };
  478. /// @brief A pointer to a @c Subnet4 object
  479. typedef boost::shared_ptr<Subnet4> Subnet4Ptr;
  480. /// @brief A collection of @c Subnet4 objects
  481. ///
  482. /// That is a simple vector of pointers. It does not make much sense to
  483. /// optimize access time (e.g. using a map), because typical search
  484. /// pattern will use calling inRange() method on each subnet until
  485. /// a match is found.
  486. typedef std::vector<Subnet4Ptr> Subnet4Collection;
  487. /// @brief A configuration holder for IPv6 subnet.
  488. ///
  489. /// This class represents an IPv6 subnet.
  490. class Subnet6 : public Subnet {
  491. public:
  492. /// @brief Constructor with all parameters
  493. ///
  494. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  495. ///
  496. /// @param prefix Subnet6 prefix
  497. /// @param length prefix length
  498. /// @param t1 renewal timer (in seconds)
  499. /// @param t2 rebind timer (in seconds)
  500. /// @param preferred_lifetime preferred lifetime of leases (in seconds)
  501. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  502. /// @param id arbitraty subnet id, default value of 0 triggers
  503. /// autogeneration of subnet id
  504. Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
  505. const Triplet<uint32_t>& t1,
  506. const Triplet<uint32_t>& t2,
  507. const Triplet<uint32_t>& preferred_lifetime,
  508. const Triplet<uint32_t>& valid_lifetime,
  509. const SubnetID id = 0);
  510. /// @brief Returns preverred lifetime (in seconds)
  511. ///
  512. /// @return a triplet with preferred lifetime
  513. Triplet<uint32_t> getPreferred() const {
  514. return (preferred_);
  515. }
  516. /// @brief sets interface-id option (if defined)
  517. ///
  518. /// @param ifaceid pointer to interface-id option
  519. void setInterfaceId(const OptionPtr& ifaceid) {
  520. interface_id_ = ifaceid;
  521. }
  522. /// @brief returns interface-id value (if specified)
  523. /// @return interface-id option (if defined)
  524. OptionPtr getInterfaceId() const {
  525. return interface_id_;
  526. }
  527. protected:
  528. /// @brief Returns default address for pool selection
  529. /// @return ANY IPv6 address
  530. virtual isc::asiolink::IOAddress default_pool() const {
  531. return (isc::asiolink::IOAddress("::"));
  532. }
  533. /// @brief Checks if used pool type is valid
  534. ///
  535. /// allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  536. ///
  537. /// @param type type to be checked
  538. /// @throw BadValue if invalid value is used
  539. virtual void checkType(Lease::Type type) const;
  540. /// @brief specifies optional interface-id
  541. OptionPtr interface_id_;
  542. /// @brief a triplet with preferred lifetime (in seconds)
  543. Triplet<uint32_t> preferred_;
  544. };
  545. /// @brief A pointer to a Subnet6 object
  546. typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  547. /// @brief A collection of Subnet6 objects
  548. typedef std::vector<Subnet6Ptr> Subnet6Collection;
  549. } // end of isc::dhcp namespace
  550. } // end of isc namespace
  551. #endif // SUBNET_H