subnet.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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 inRange() 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 inRange(), but the reverse implication
  85. /// is not always true. For the given example, 2001::1234:abcd would return
  86. /// true for inRange(), 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 Returns the number of possible leases for specified lease type
  203. ///
  204. /// @param type type of the lease
  205. uint64_t getPoolCapacity(Lease::Type type) const;
  206. /// @brief Sets name of the network interface for directly attached networks
  207. ///
  208. /// @param iface_name name of the interface
  209. void setIface(const std::string& iface_name);
  210. /// @brief Network interface name used to reach subnet (or "" for remote
  211. /// subnets)
  212. /// @return network interface name for directly attached subnets or ""
  213. std::string getIface() const;
  214. /// @brief Returns textual representation of the subnet (e.g.
  215. /// "2001:db8::/64")
  216. ///
  217. /// @return textual representation
  218. virtual std::string toText() const;
  219. /// @brief Resets subnet-id counter to its initial value (1)
  220. ///
  221. /// This should be called during reconfiguration, before any new
  222. /// subnet objects are created. It will ensure that the subnet_id will
  223. /// be consistent between reconfigures.
  224. static void resetSubnetID() {
  225. static_id_ = 1;
  226. }
  227. /// @brief Sets information about relay
  228. ///
  229. /// In some situations where there are shared subnets (i.e. two different
  230. /// subnets are available on the same physical link), there is only one
  231. /// relay that handles incoming requests from clients. In such a case,
  232. /// the usual subnet selection criteria based on relay belonging to the
  233. /// subnet being selected are no longer sufficient and we need to explicitly
  234. /// specify a relay. One notable example of such uncommon, but valid
  235. /// scenario is a cable network, where there is only one CMTS (one relay),
  236. /// but there are 2 distinct subnets behind it: one for cable modems
  237. /// and another one for CPEs and other user equipment behind modems.
  238. /// From manageability perspective, it is essential that modems get addresses
  239. /// from different subnet, so users won't tinker with their modems.
  240. ///
  241. /// Setting this parameter is not needed in most deployments.
  242. /// This structure holds IP address only for now, but it is expected to
  243. /// be extended in the future.
  244. ///
  245. /// @param relay structure that contains relay information
  246. void setRelayInfo(const isc::dhcp::Subnet::RelayInfo& relay);
  247. /// @brief Returns const reference to relay information
  248. ///
  249. /// @note The returned reference is only valid as long as the object
  250. /// returned it is valid.
  251. ///
  252. /// @return const reference to the relay information
  253. const isc::dhcp::Subnet::RelayInfo& getRelayInfo() {
  254. return (relay_);
  255. }
  256. /// @brief checks whether this subnet supports client that belongs to
  257. /// specified classes.
  258. ///
  259. /// This method checks whether a client that belongs to given classes can
  260. /// use this subnet. For example, if this class is reserved for client
  261. /// class "foo" and the client belongs to classes "foo", "bar" and "baz",
  262. /// it is supported. On the other hand, client belonging to classes
  263. /// "foobar" and "zyxxy" is not supported.
  264. ///
  265. /// @todo: Currently the logic is simple: client is supported if it belongs
  266. /// to any class mentioned in white_list_. We will eventually need a
  267. /// way to specify more fancy logic (e.g. to meet all classes, not just
  268. /// any)
  269. ///
  270. /// @param client_classes list of all classes the client belongs to
  271. /// @return true if client can be supported, false otherwise
  272. bool
  273. clientSupported(const isc::dhcp::ClientClasses& client_classes) const;
  274. /// @brief adds class class_name to the list of supported classes
  275. ///
  276. /// Also see explanation note in @ref white_list_.
  277. ///
  278. /// @param class_name client class to be supported by this subnet
  279. void
  280. allowClientClass(const isc::dhcp::ClientClass& class_name);
  281. /// @brief Specifies what type of Host Reservations are supported.
  282. ///
  283. /// Host reservations may be either in-pool (they reserve an address that
  284. /// is in the dynamic pool) or out-of-pool (they reserve an address that is
  285. /// not in the dynamic pool). HR may also be completely disabled for
  286. /// performance reasons.
  287. ///
  288. /// @return whether in-pool host reservations are allowed.
  289. HRMode
  290. getHostReservationMode() const {
  291. return (host_reservation_mode_);
  292. }
  293. /// @brief Sets host reservation mode.
  294. ///
  295. /// See @ref getHostReservationMode for details.
  296. ///
  297. /// @param mode mode to be set
  298. void setHostReservationMode(HRMode mode) {
  299. host_reservation_mode_ = mode;
  300. }
  301. protected:
  302. /// @brief Returns all pools (non-const variant)
  303. ///
  304. /// The reference is only valid as long as the object that returned it.
  305. ///
  306. /// @param type lease type to be set
  307. /// @return a collection of all pools
  308. PoolCollection& getPoolsWritable(Lease::Type type);
  309. /// @brief Protected constructor
  310. //
  311. /// By making the constructor protected, we make sure that no one will
  312. /// ever instantiate that class. Subnet4 and Subnet6 should be used instead.
  313. ///
  314. /// This constructor assigns a new subnet-id (see @ref generateNextID).
  315. /// This subnet-id has unique value that is strictly monotonously increasing
  316. /// for each subnet, until it is explicitly reset back to 1 during
  317. /// reconfiguration process.
  318. ///
  319. /// @param prefix subnet prefix
  320. /// @param len prefix length for the subnet
  321. /// @param t1 T1 (renewal-time) timer, expressed in seconds
  322. /// @param t2 T2 (rebind-time) timer, expressed in seconds
  323. /// @param valid_lifetime valid lifetime of leases in this subnet (in seconds)
  324. /// @param relay optional relay information (currently with address only)
  325. /// @param id arbitraty subnet id, value of 0 triggers autogeneration
  326. /// of subnet id
  327. Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len,
  328. const Triplet<uint32_t>& t1,
  329. const Triplet<uint32_t>& t2,
  330. const Triplet<uint32_t>& valid_lifetime,
  331. const isc::dhcp::Subnet::RelayInfo& relay,
  332. const SubnetID id);
  333. /// @brief virtual destructor
  334. ///
  335. /// A virtual destructor is needed because other classes
  336. /// derive from this class.
  337. virtual ~Subnet() { };
  338. /// @brief keeps the subnet-id value
  339. ///
  340. /// It is inreased every time a new Subnet object is created. It is reset
  341. /// (@ref resetSubnetID) every time reconfiguration
  342. /// occurs.
  343. ///
  344. /// Static value initialized in subnet.cc.
  345. static SubnetID static_id_;
  346. /// @brief returns the next unique Subnet-ID
  347. ///
  348. /// This method generates and returns the next unique subnet-id.
  349. /// It is a strictly monotonously increasing value (1,2,3,...) for
  350. /// each new Subnet object created. It can be explicitly reset
  351. /// back to 1 during reconfiguration (@ref resetSubnetID).
  352. ///
  353. /// @return the next unique Subnet-ID
  354. static SubnetID generateNextID() {
  355. return (static_id_++);
  356. }
  357. /// @brief Checks if used pool type is valid
  358. ///
  359. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  360. /// Allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  361. /// This method is implemented in derived classes.
  362. ///
  363. /// @param type type to be checked
  364. /// @throw BadValue if invalid value is used
  365. virtual void checkType(Lease::Type type) const = 0;
  366. /// @brief returns a sum of possible leases in all pools
  367. /// @param pools list of pools
  368. /// @return sum of possible leases
  369. uint64_t sumPoolCapacity(const PoolCollection& pools) const;
  370. /// @brief subnet-id
  371. ///
  372. /// Subnet-id is a unique value that can be used to find or identify
  373. /// a Subnet4 or Subnet6.
  374. SubnetID id_;
  375. /// @brief collection of IPv4 or non-temporary IPv6 pools in that subnet
  376. PoolCollection pools_;
  377. /// @brief collection of IPv6 temporary address pools in that subnet
  378. PoolCollection pools_ta_;
  379. /// @brief collection of IPv6 prefix pools in that subnet
  380. PoolCollection pools_pd_;
  381. /// @brief a prefix of the subnet
  382. isc::asiolink::IOAddress prefix_;
  383. /// @brief a prefix length of the subnet
  384. uint8_t prefix_len_;
  385. /// @brief a tripet (min/default/max) holding allowed renew timer values
  386. Triplet<uint32_t> t1_;
  387. /// @brief a tripet (min/default/max) holding allowed rebind timer values
  388. Triplet<uint32_t> t2_;
  389. /// @brief a tripet (min/default/max) holding allowed valid lifetime values
  390. Triplet<uint32_t> valid_;
  391. /// @brief last allocated address
  392. ///
  393. /// This is the last allocated address that was previously allocated from
  394. /// this particular subnet. Some allocation algorithms (e.g. iterative) use
  395. /// that value, others do not. It should be noted that although the value
  396. /// is usually correct, there are cases when it is invalid, e.g. after
  397. /// removing a pool, restarting or changing allocation algorithms. For
  398. /// that purpose it should be only considered a help that should not be
  399. /// fully trusted.
  400. isc::asiolink::IOAddress last_allocated_ia_;
  401. /// @brief last allocated temporary address
  402. ///
  403. /// See @ref last_allocated_ia_ for details.
  404. isc::asiolink::IOAddress last_allocated_ta_;
  405. /// @brief last allocated IPv6 prefix
  406. ///
  407. /// See @ref last_allocated_ia_ for details.
  408. isc::asiolink::IOAddress last_allocated_pd_;
  409. /// @brief Name of the network interface (if connected directly)
  410. std::string iface_;
  411. /// @brief Relay information
  412. ///
  413. /// See @ref RelayInfo for detailed description. This structure is public,
  414. /// so its fields are easily accessible. Making it protected would bring in
  415. /// the issue of returning references that may become stale after its parent
  416. /// subnet object disappears.
  417. RelayInfo relay_;
  418. /// @brief optional definition of a client class
  419. ///
  420. /// If defined, only clients belonging to that class will be allowed to use
  421. /// this particular subnet. The default value for this is an empty list,
  422. /// which means that any client is allowed, regardless of its class.
  423. ///
  424. /// @todo This is just a single list of allowed classes. We'll also need
  425. /// to add a black-list (only classes on the list are rejected, the rest
  426. /// are allowed). Implementing this will require more fancy parser logic,
  427. /// so it may be a while until we support this.
  428. ClientClasses white_list_;
  429. /// @brief Specifies host reservation mode
  430. ///
  431. /// See @ref HRMode type for details.
  432. HRMode host_reservation_mode_;
  433. private:
  434. /// @brief Pointer to the option data configuration for this subnet.
  435. CfgOptionPtr cfg_option_;
  436. };
  437. /// @brief A generic pointer to either Subnet4 or Subnet6 object
  438. typedef boost::shared_ptr<Subnet> SubnetPtr;
  439. /// @brief A configuration holder for IPv4 subnet.
  440. ///
  441. /// This class represents an IPv4 subnet.
  442. class Subnet4 : public Subnet {
  443. public:
  444. /// @brief Constructor with all parameters
  445. ///
  446. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  447. ///
  448. /// @param prefix Subnet4 prefix
  449. /// @param length prefix length
  450. /// @param t1 renewal timer (in seconds)
  451. /// @param t2 rebind timer (in seconds)
  452. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  453. /// @param id arbitraty subnet id, default value of 0 triggers
  454. /// autogeneration of subnet id
  455. Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
  456. const Triplet<uint32_t>& t1,
  457. const Triplet<uint32_t>& t2,
  458. const Triplet<uint32_t>& valid_lifetime,
  459. const SubnetID id = 0);
  460. /// @brief Sets siaddr for the Subnet4
  461. ///
  462. /// Will be used for siaddr field (the next server) that typically is used
  463. /// as TFTP server. If not specified, the default value of 0.0.0.0 is
  464. /// used.
  465. void setSiaddr(const isc::asiolink::IOAddress& siaddr);
  466. /// @brief Returns siaddr for this subnet
  467. ///
  468. /// @return siaddr value
  469. isc::asiolink::IOAddress getSiaddr() const;
  470. /// @brief Sets the flag indicating if the client identifier should be
  471. /// used to identify the client's lease.
  472. ///
  473. /// @param match If this value is true, the client identifiers are not
  474. /// used for lease lookup.
  475. void setMatchClientId(const bool match) {
  476. match_client_id_ = match;
  477. }
  478. /// @brief Returns the flag indicating if the client identifiers should
  479. /// be used to identify the client's lease.
  480. ///
  481. /// @return true if client identifiers should be used, false otherwise.
  482. bool getMatchClientId() const {
  483. return (match_client_id_);
  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. };
  504. /// @brief A pointer to a @c Subnet4 object
  505. typedef boost::shared_ptr<Subnet4> Subnet4Ptr;
  506. /// @brief A collection of @c Subnet4 objects
  507. ///
  508. /// That is a simple vector of pointers. It does not make much sense to
  509. /// optimize access time (e.g. using a map), because typical search
  510. /// pattern will use calling inRange() method on each subnet until
  511. /// a match is found.
  512. typedef std::vector<Subnet4Ptr> Subnet4Collection;
  513. /// @brief A configuration holder for IPv6 subnet.
  514. ///
  515. /// This class represents an IPv6 subnet.
  516. class Subnet6 : public Subnet {
  517. public:
  518. /// @brief Constructor with all parameters
  519. ///
  520. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  521. ///
  522. /// @param prefix Subnet6 prefix
  523. /// @param length prefix length
  524. /// @param t1 renewal timer (in seconds)
  525. /// @param t2 rebind timer (in seconds)
  526. /// @param preferred_lifetime preferred lifetime of leases (in seconds)
  527. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  528. /// @param id arbitraty subnet id, default value of 0 triggers
  529. /// autogeneration of subnet id
  530. Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
  531. const Triplet<uint32_t>& t1,
  532. const Triplet<uint32_t>& t2,
  533. const Triplet<uint32_t>& preferred_lifetime,
  534. const Triplet<uint32_t>& valid_lifetime,
  535. const SubnetID id = 0);
  536. /// @brief Returns preverred lifetime (in seconds)
  537. ///
  538. /// @return a triplet with preferred lifetime
  539. Triplet<uint32_t> getPreferred() const {
  540. return (preferred_);
  541. }
  542. /// @brief sets interface-id option (if defined)
  543. ///
  544. /// @param ifaceid pointer to interface-id option
  545. void setInterfaceId(const OptionPtr& ifaceid) {
  546. interface_id_ = ifaceid;
  547. }
  548. /// @brief returns interface-id value (if specified)
  549. /// @return interface-id option (if defined)
  550. OptionPtr getInterfaceId() const {
  551. return interface_id_;
  552. }
  553. protected:
  554. /// @brief Returns default address for pool selection
  555. /// @return ANY IPv6 address
  556. virtual isc::asiolink::IOAddress default_pool() const {
  557. return (isc::asiolink::IOAddress("::"));
  558. }
  559. /// @brief Checks if used pool type is valid
  560. ///
  561. /// allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  562. ///
  563. /// @param type type to be checked
  564. /// @throw BadValue if invalid value is used
  565. virtual void checkType(Lease::Type type) const;
  566. /// @brief specifies optional interface-id
  567. OptionPtr interface_id_;
  568. /// @brief a triplet with preferred lifetime (in seconds)
  569. Triplet<uint32_t> preferred_;
  570. };
  571. /// @brief A pointer to a Subnet6 object
  572. typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  573. /// @brief A collection of Subnet6 objects
  574. typedef std::vector<Subnet6Ptr> Subnet6Collection;
  575. } // end of isc::dhcp namespace
  576. } // end of isc namespace
  577. #endif // SUBNET_H