subnet.h 26 KB

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