subnet.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 <dhcp/option_space_container.h>
  20. #include <dhcpsrv/cfg_option.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 This structure contains information about DHCP4o6 (RFC7341)
  440. ///
  441. /// DHCP4o6 is completely optional. If it is not enabled, this structure
  442. /// does not contain any information.
  443. struct Cfg4o6 {
  444. /// the default constructor.
  445. ///
  446. /// Initializes fields to their default value.
  447. Cfg4o6()
  448. :enabled_(false), subnet4o6_(std::make_pair(asiolink::IOAddress("::"), 128u)) {
  449. }
  450. /// @brief Returns whether the DHCP4o6 is enabled or not.
  451. /// @return true if enabled
  452. bool enabled() const {
  453. return (enabled_);
  454. }
  455. /// @brief Sets the DHCP4o6 enabled status.
  456. /// @param enabled specifies if the DHCP4o6 should be enabled or not
  457. void enabled(bool enabled) {
  458. enabled_ = enabled;
  459. }
  460. /// @brief Returns the DHCP4o6 interface.
  461. /// @return value of the 4o6-interface parameter.
  462. std::string getIface4o6() const {
  463. return (iface4o6_);
  464. }
  465. /// @brief Sets the 4o6-interface.
  466. /// @param iface name of the network interface the 4o6 traffic is received on
  467. void setIface4o6(const std::string& iface) {
  468. iface4o6_ = iface;
  469. }
  470. /// @brief Returns prefix/len for the IPv6 subnet.
  471. /// @return prefix/length pair
  472. std::pair<asiolink::IOAddress, uint8_t> getSubnet4o6() const {
  473. return (subnet4o6_);
  474. }
  475. /// @brief Sets the prefix/length information (content of the 4o6-subnet).
  476. /// @param subnet IOAddress that represents a prefix
  477. /// @param prefix specifies prefix length
  478. void setSubnet4o6(const asiolink::IOAddress& subnet, uint8_t prefix) {
  479. subnet4o6_ = std::make_pair(subnet, prefix);
  480. }
  481. /// @brief Returns the interface-id.
  482. /// @return the option representing interface-id (or NULL)
  483. OptionPtr getInterfaceId() const {
  484. return (interface_id_);
  485. }
  486. /// @brief Sets the interface-id
  487. /// @param opt option to be used as interface-id match
  488. void setInterfaceId(const OptionPtr& opt) {
  489. interface_id_ = opt;
  490. }
  491. private:
  492. /// Specifies if 4o6 is enabled on this subnet.
  493. bool enabled_;
  494. /// Specifies the network interface used as v4 subnet selector.
  495. std::string iface4o6_;
  496. /// Specifies the IPv6 subnet used for v4 subnet selection.
  497. std::pair<asiolink::IOAddress, uint8_t> subnet4o6_;
  498. /// Specifies the v6 interface-id used for v4 subnet selection.
  499. OptionPtr interface_id_;
  500. };
  501. /// @brief A configuration holder for IPv4 subnet.
  502. ///
  503. /// This class represents an IPv4 subnet.
  504. class Subnet4 : public Subnet {
  505. public:
  506. /// @brief Constructor with all parameters
  507. ///
  508. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  509. ///
  510. /// @param prefix Subnet4 prefix
  511. /// @param length prefix length
  512. /// @param t1 renewal timer (in seconds)
  513. /// @param t2 rebind timer (in seconds)
  514. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  515. /// @param id arbitraty subnet id, default value of 0 triggers
  516. /// autogeneration of subnet id
  517. Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
  518. const Triplet<uint32_t>& t1,
  519. const Triplet<uint32_t>& t2,
  520. const Triplet<uint32_t>& valid_lifetime,
  521. const SubnetID id = 0);
  522. /// @brief Sets siaddr for the Subnet4
  523. ///
  524. /// Will be used for siaddr field (the next server) that typically is used
  525. /// as TFTP server. If not specified, the default value of 0.0.0.0 is
  526. /// used.
  527. void setSiaddr(const isc::asiolink::IOAddress& siaddr);
  528. /// @brief Returns siaddr for this subnet
  529. ///
  530. /// @return siaddr value
  531. isc::asiolink::IOAddress getSiaddr() const;
  532. /// @brief Sets the flag indicating if the client identifier should be
  533. /// used to identify the client's lease.
  534. ///
  535. /// @param match If this value is true, the client identifiers are not
  536. /// used for lease lookup.
  537. void setMatchClientId(const bool match) {
  538. match_client_id_ = match;
  539. }
  540. /// @brief Returns the flag indicating if the client identifiers should
  541. /// be used to identify the client's lease.
  542. ///
  543. /// @return true if client identifiers should be used, false otherwise.
  544. bool getMatchClientId() const {
  545. return (match_client_id_);
  546. }
  547. /// @brief Returns DHCP4o6 configuration parameters.
  548. ///
  549. /// This structure is always available. If the 4o6 is not enabled, its
  550. /// enabled_ field will be set to false.
  551. Cfg4o6& get4o6() {
  552. return (dhcp4o6_);
  553. }
  554. private:
  555. /// @brief Returns default address for pool selection
  556. /// @return ANY IPv4 address
  557. virtual isc::asiolink::IOAddress default_pool() const {
  558. return (isc::asiolink::IOAddress("0.0.0.0"));
  559. }
  560. /// @brief Checks if used pool type is valid
  561. ///
  562. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  563. ///
  564. /// @param type type to be checked
  565. /// @throw BadValue if invalid value is used
  566. virtual void checkType(Lease::Type type) const;
  567. /// @brief siaddr value for this subnet
  568. isc::asiolink::IOAddress siaddr_;
  569. /// @brief Should server use client identifiers for client lease
  570. /// lookup.
  571. bool match_client_id_;
  572. /// @brief All the information related to DHCP4o6
  573. Cfg4o6 dhcp4o6_;
  574. };
  575. /// @brief A pointer to a @c Subnet4 object
  576. typedef boost::shared_ptr<Subnet4> Subnet4Ptr;
  577. /// @brief A collection of @c Subnet4 objects
  578. ///
  579. /// That is a simple vector of pointers. It does not make much sense to
  580. /// optimize access time (e.g. using a map), because typical search
  581. /// pattern will use calling inRange() method on each subnet until
  582. /// a match is found.
  583. typedef std::vector<Subnet4Ptr> Subnet4Collection;
  584. /// @brief A configuration holder for IPv6 subnet.
  585. ///
  586. /// This class represents an IPv6 subnet.
  587. class Subnet6 : public Subnet {
  588. public:
  589. /// @brief Constructor with all parameters
  590. ///
  591. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  592. ///
  593. /// @param prefix Subnet6 prefix
  594. /// @param length prefix length
  595. /// @param t1 renewal timer (in seconds)
  596. /// @param t2 rebind timer (in seconds)
  597. /// @param preferred_lifetime preferred lifetime of leases (in seconds)
  598. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  599. /// @param id arbitraty subnet id, default value of 0 triggers
  600. /// autogeneration of subnet id
  601. Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
  602. const Triplet<uint32_t>& t1,
  603. const Triplet<uint32_t>& t2,
  604. const Triplet<uint32_t>& preferred_lifetime,
  605. const Triplet<uint32_t>& valid_lifetime,
  606. const SubnetID id = 0);
  607. /// @brief Returns preverred lifetime (in seconds)
  608. ///
  609. /// @return a triplet with preferred lifetime
  610. Triplet<uint32_t> getPreferred() const {
  611. return (preferred_);
  612. }
  613. /// @brief sets interface-id option (if defined)
  614. ///
  615. /// @param ifaceid pointer to interface-id option
  616. void setInterfaceId(const OptionPtr& ifaceid) {
  617. interface_id_ = ifaceid;
  618. }
  619. /// @brief returns interface-id value (if specified)
  620. /// @return interface-id option (if defined)
  621. OptionPtr getInterfaceId() const {
  622. return interface_id_;
  623. }
  624. /// @brief Enables or disables Rapid Commit option support for the subnet.
  625. ///
  626. /// @param rapid_commit A boolean value indicating that the Rapid Commit
  627. /// option support is enabled (if true), or disabled (if false).
  628. void setRapidCommit(const bool rapid_commit) {
  629. rapid_commit_ = rapid_commit;
  630. };
  631. /// @brief Returns boolean value indicating that the Rapid Commit option
  632. /// is supported or unsupported for the subnet.
  633. ///
  634. /// @return true if the Rapid Commit option is supported, false otherwise.
  635. bool getRapidCommit() const {
  636. return (rapid_commit_);
  637. }
  638. private:
  639. /// @brief Returns default address for pool selection
  640. /// @return ANY IPv6 address
  641. virtual isc::asiolink::IOAddress default_pool() const {
  642. return (isc::asiolink::IOAddress("::"));
  643. }
  644. /// @brief Checks if used pool type is valid
  645. ///
  646. /// allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  647. ///
  648. /// @param type type to be checked
  649. /// @throw BadValue if invalid value is used
  650. virtual void checkType(Lease::Type type) const;
  651. /// @brief specifies optional interface-id
  652. OptionPtr interface_id_;
  653. /// @brief a triplet with preferred lifetime (in seconds)
  654. Triplet<uint32_t> preferred_;
  655. /// @brief A flag indicating if Rapid Commit option is supported
  656. /// for this subnet.
  657. ///
  658. /// It's default value is false, which indicates that the Rapid
  659. /// Commit is disabled for the subnet.
  660. bool rapid_commit_;
  661. };
  662. /// @brief A pointer to a Subnet6 object
  663. typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  664. /// @brief A collection of Subnet6 objects
  665. typedef std::vector<Subnet6Ptr> Subnet6Collection;
  666. } // end of isc::dhcp namespace
  667. } // end of isc namespace
  668. #endif // SUBNET_H