subnet.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. // Copyright (C) 2012-2013 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 <boost/shared_ptr.hpp>
  17. #include <boost/multi_index_container.hpp>
  18. #include <boost/multi_index/hashed_index.hpp>
  19. #include <boost/multi_index/sequenced_index.hpp>
  20. #include <boost/multi_index/mem_fun.hpp>
  21. #include <boost/multi_index/member.hpp>
  22. #include <asiolink/io_address.h>
  23. #include <dhcp/option.h>
  24. #include <dhcp/classify.h>
  25. #include <dhcpsrv/key_from_key.h>
  26. #include <dhcpsrv/option_space_container.h>
  27. #include <dhcpsrv/pool.h>
  28. #include <dhcpsrv/triplet.h>
  29. #include <dhcpsrv/lease.h>
  30. namespace isc {
  31. namespace dhcp {
  32. /// @brief a base class for Subnet4 and Subnet6
  33. ///
  34. /// This class presents a common base for IPv4 and IPv6 subnets.
  35. /// In a physical sense, a subnet defines a single network link with all devices
  36. /// attached to it. In most cases all devices attached to a single link can
  37. /// share the same parameters. Therefore Subnet holds several values that are
  38. /// typically shared by all hosts: renew timer (T1), rebind timer (T2) and
  39. /// leased addresses lifetime (valid-lifetime). It also holds the set
  40. /// of DHCP option instances configured for the subnet. These options are
  41. /// included in DHCP messages being sent to clients which are connected
  42. /// to the particular subnet.
  43. ///
  44. /// @todo: Implement support for options here
  45. /// @brief Unique identifier for a subnet (both v4 and v6)
  46. typedef uint32_t SubnetID;
  47. class Subnet {
  48. public:
  49. /// @brief Option descriptor.
  50. ///
  51. /// Option descriptor holds information about option configured for
  52. /// a particular subnet. This information comprises the actual option
  53. /// instance and information whether this option is sent to DHCP client
  54. /// only on request (persistent = false) or always (persistent = true).
  55. struct OptionDescriptor {
  56. /// Option instance.
  57. OptionPtr option;
  58. /// Persistent flag, if true option is always sent to the client,
  59. /// if false option is sent to the client on request.
  60. bool persistent;
  61. /// @brief Constructor.
  62. ///
  63. /// @param opt option
  64. /// @param persist if true option is always sent.
  65. OptionDescriptor(const OptionPtr& opt, bool persist)
  66. : option(opt), persistent(persist) {};
  67. /// @brief Constructor
  68. ///
  69. /// @param persist if true option is always sent.
  70. OptionDescriptor(bool persist)
  71. : option(OptionPtr()), persistent(persist) {};
  72. };
  73. /// A pointer to option descriptor.
  74. typedef boost::shared_ptr<OptionDescriptor> OptionDescriptorPtr;
  75. /// @brief Multi index container for DHCP option descriptors.
  76. ///
  77. /// This container comprises three indexes to access option
  78. /// descriptors:
  79. /// - sequenced index: used to access elements in the order they
  80. /// have been added to the container,
  81. /// - option type index: used to search option descriptors containing
  82. /// options with specific option code (aka option type).
  83. /// - persistency flag index: used to search option descriptors with
  84. /// 'persistent' flag set to true.
  85. ///
  86. /// This container is the equivalent of three separate STL containers:
  87. /// - std::list of all options,
  88. /// - std::multimap of options with option code used as a multimap key,
  89. /// - std::multimap of option descriptors with option persistency flag
  90. /// used as a multimap key.
  91. /// The major advantage of this container over 3 separate STL containers
  92. /// is automatic synchronization of all indexes when elements are added,
  93. /// removed or modified in the container. With separate containers,
  94. /// the synchronization would have to be guaranteed by the Subnet class
  95. /// code. This would increase code complexity and presumably it would
  96. /// be much harder to add new search criteria (indexes).
  97. ///
  98. /// @todo we may want to search for options using option spaces when
  99. /// they are implemented.
  100. ///
  101. /// @see http://www.boost.org/doc/libs/1_51_0/libs/multi_index/doc/index.html
  102. typedef boost::multi_index_container<
  103. // Container comprises elements of OptionDescriptor type.
  104. OptionDescriptor,
  105. // Here we start enumerating various indexes.
  106. boost::multi_index::indexed_by<
  107. // Sequenced index allows accessing elements in the same way
  108. // as elements in std::list.
  109. // Sequenced is an index #0.
  110. boost::multi_index::sequenced<>,
  111. // Start definition of index #1.
  112. boost::multi_index::hashed_non_unique<
  113. // KeyFromKeyExtractor is the index key extractor that allows
  114. // accessing option type being held by the OptionPtr through
  115. // OptionDescriptor structure.
  116. KeyFromKeyExtractor<
  117. // Use option type as the index key. The type is held
  118. // in OptionPtr object so we have to call Option::getType
  119. // to retrieve this key for each element.
  120. boost::multi_index::const_mem_fun<
  121. Option,
  122. uint16_t,
  123. &Option::getType
  124. >,
  125. // Indicate that OptionPtr is a member of
  126. // OptionDescriptor structure.
  127. boost::multi_index::member<
  128. OptionDescriptor,
  129. OptionPtr,
  130. &OptionDescriptor::option
  131. >
  132. >
  133. >,
  134. // Start definition of index #2.
  135. // Use 'persistent' struct member as a key.
  136. boost::multi_index::hashed_non_unique<
  137. boost::multi_index::member<
  138. OptionDescriptor,
  139. bool,
  140. &OptionDescriptor::persistent
  141. >
  142. >
  143. >
  144. > OptionContainer;
  145. /// Pointer to the OptionContainer object.
  146. typedef boost::shared_ptr<OptionContainer> OptionContainerPtr;
  147. /// Type of the index #1 - option type.
  148. typedef OptionContainer::nth_index<1>::type OptionContainerTypeIndex;
  149. /// Pair of iterators to represent the range of options having the
  150. /// same option type value. The first element in this pair represents
  151. /// the beginning of the range, the second element represents the end.
  152. typedef std::pair<OptionContainerTypeIndex::const_iterator,
  153. OptionContainerTypeIndex::const_iterator> OptionContainerTypeRange;
  154. /// Type of the index #2 - option persistency flag.
  155. typedef OptionContainer::nth_index<2>::type OptionContainerPersistIndex;
  156. /// @brief Holds optional information about relay.
  157. ///
  158. /// In some cases it is beneficial to have additional information about
  159. /// a relay configured in the subnet. For now, the structure holds only
  160. /// IP address, but there may potentially be additional parameters added
  161. /// later, e.g. relay interface-id or relay-id.
  162. struct RelayInfo {
  163. /// @brief default and the only constructor
  164. ///
  165. /// @param addr an IP address of the relay (may be :: or 0.0.0.0)
  166. RelayInfo(const isc::asiolink::IOAddress& addr);
  167. /// @brief IP address of the relay
  168. isc::asiolink::IOAddress addr_;
  169. };
  170. /// Pointer to the RelayInfo structure
  171. typedef boost::shared_ptr<Subnet::RelayInfo> RelayInfoPtr;
  172. /// @brief checks if specified address is in range
  173. bool inRange(const isc::asiolink::IOAddress& addr) const;
  174. /// @brief Add new option instance to the collection.
  175. ///
  176. /// @param option option instance.
  177. /// @param persistent if true, send an option regardless if client
  178. /// requested it or not.
  179. /// @param option_space name of the option space to add an option to.
  180. ///
  181. /// @throw isc::BadValue if invalid option provided.
  182. void addOption(const OptionPtr& option, bool persistent,
  183. const std::string& option_space);
  184. /// @brief Adds new vendor option instance to the collection.
  185. ///
  186. /// @param option option instance.
  187. /// @param persistent if true, send an option regardless if client
  188. /// requested it or not.
  189. /// @param vendor_id enterprise id of the vendor space to add an option to.
  190. void addVendorOption(const OptionPtr& option, bool persistent,
  191. uint32_t vendor_id);
  192. /// @brief Delete all options configured for the subnet.
  193. void delOptions();
  194. /// @brief Deletes all vendor options configured for the subnet.
  195. void delVendorOptions();
  196. /// @brief checks if the specified address is in pools
  197. ///
  198. /// Note the difference between inSubnet() and inPool(). For a given
  199. /// subnet (e.g. 2001::/64) there may be one or more pools defined
  200. /// that may or may not cover entire subnet, e.g. pool 2001::1-2001::10).
  201. /// inPool() returning true implies inSubnet(), but the reverse implication
  202. /// is not always true. For the given example, 2001::1234:abcd would return
  203. /// true for inSubnet(), but false for inPool() check.
  204. ///
  205. /// @param type type of pools to iterate over
  206. /// @param addr this address will be checked if it belongs to any pools in
  207. /// that subnet
  208. /// @return true if the address is in any of the pools
  209. bool inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const;
  210. /// @brief Return valid-lifetime for addresses in that prefix
  211. Triplet<uint32_t> getValid() const {
  212. return (valid_);
  213. }
  214. /// @brief Returns T1 (renew timer), expressed in seconds
  215. Triplet<uint32_t> getT1() const {
  216. return (t1_);
  217. }
  218. /// @brief Returns T2 (rebind timer), expressed in seconds
  219. Triplet<uint32_t> getT2() const {
  220. return (t2_);
  221. }
  222. /// @brief Return a collection of option descriptors.
  223. ///
  224. /// @param option_space name of the option space.
  225. ///
  226. /// @return pointer to collection of options configured for a subnet.
  227. OptionContainerPtr
  228. getOptionDescriptors(const std::string& option_space) const;
  229. /// @brief Return a collection of vendor option descriptors.
  230. ///
  231. /// @param vendor_id enterprise id of the option space.
  232. ///
  233. /// @return pointer to collection of options configured for a subnet.
  234. OptionContainerPtr
  235. getVendorOptionDescriptors(uint32_t vendor_id) const;
  236. /// @brief Return single option descriptor.
  237. ///
  238. /// @param option_space name of the option space.
  239. /// @param option_code code of the option to be returned.
  240. ///
  241. /// @return option descriptor found for the specified option space
  242. /// and option code.
  243. OptionDescriptor
  244. getOptionDescriptor(const std::string& option_space,
  245. const uint16_t option_code);
  246. /// @brief Return single vendor option descriptor.
  247. ///
  248. /// @param vendor_id enterprise id of the option space.
  249. /// @param option_code code of the option to be returned.
  250. ///
  251. /// @return option descriptor found for the specified option space
  252. /// and option code.
  253. OptionDescriptor
  254. getVendorOptionDescriptor(uint32_t vendor_id, uint16_t option_code);
  255. /// @brief returns the last address that was tried from this pool
  256. ///
  257. /// This method returns the last address that was attempted to be allocated
  258. /// from this subnet. This is used as helper information for the next
  259. /// iteration of the allocation algorithm.
  260. ///
  261. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  262. /// AllocEngine::IterativeAllocator and keep the data there
  263. ///
  264. /// @param type lease type to be returned
  265. /// @return address/prefix that was last tried from this pool
  266. isc::asiolink::IOAddress getLastAllocated(Lease::Type type) const;
  267. /// @brief sets the last address that was tried from this pool
  268. ///
  269. /// This method sets the last address that was attempted to be allocated
  270. /// from this subnet. This is used as helper information for the next
  271. /// iteration of the allocation algorithm.
  272. ///
  273. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  274. /// AllocEngine::IterativeAllocator and keep the data there
  275. /// @param addr address/prefix to that was tried last
  276. /// @param type lease type to be set
  277. void setLastAllocated(Lease::Type type,
  278. const isc::asiolink::IOAddress& addr);
  279. /// @brief Returns unique ID for that subnet
  280. /// @return unique ID for that subnet
  281. SubnetID getID() const { return (id_); }
  282. /// @brief Returns subnet parameters (prefix and prefix length)
  283. ///
  284. /// @return (prefix, prefix length) pair
  285. std::pair<isc::asiolink::IOAddress, uint8_t> get() const {
  286. return (std::make_pair(prefix_, prefix_len_));
  287. }
  288. /// @brief Adds a new pool.
  289. /// @param pool pool to be added
  290. void addPool(const PoolPtr& pool);
  291. /// @brief Deletes all pools of specified type
  292. ///
  293. /// This method is used for testing purposes only
  294. /// @param type type of pools to be deleted
  295. void delPools(Lease::Type type);
  296. /// @brief Returns a pool that specified address belongs to
  297. ///
  298. /// If there is no pool that the address belongs to (hint is invalid), other
  299. /// pool of specified type will be returned.
  300. ///
  301. /// With anypool set to true, this is means give me a pool, preferably
  302. /// the one that addr belongs to. With anypool set to false, it means
  303. /// give me a pool that addr belongs to (or NULL if here is no such pool)
  304. ///
  305. /// @param type pool type that the pool is looked for
  306. /// @param addr address that the returned pool should cover (optional)
  307. /// @param anypool other pool may be returned as well, not only the one
  308. /// that addr belongs to
  309. /// @return found pool (or NULL)
  310. const PoolPtr getPool(Lease::Type type, const isc::asiolink::IOAddress& addr,
  311. bool anypool = true) const;
  312. /// @brief Returns a pool without any address specified
  313. ///
  314. /// @param type pool type that the pool is looked for
  315. /// @return returns one of the pools defined
  316. PoolPtr getAnyPool(Lease::Type type) {
  317. return (getPool(type, default_pool()));
  318. }
  319. /// @brief Returns the default address that will be used for pool selection
  320. ///
  321. /// It must be implemented in derived classes (should return :: for Subnet6
  322. /// and 0.0.0.0 for Subnet4)
  323. virtual isc::asiolink::IOAddress default_pool() const = 0;
  324. /// @brief Returns all pools (const variant)
  325. ///
  326. /// The reference is only valid as long as the object that returned it.
  327. ///
  328. /// @param type lease type to be set
  329. /// @return a collection of all pools
  330. const PoolCollection& getPools(Lease::Type type) const;
  331. /// @brief Sets name of the network interface for directly attached networks
  332. ///
  333. /// @param iface_name name of the interface
  334. void setIface(const std::string& iface_name);
  335. /// @brief Network interface name used to reach subnet (or "" for remote
  336. /// subnets)
  337. /// @return network interface name for directly attached subnets or ""
  338. std::string getIface() const;
  339. /// @brief Returns textual representation of the subnet (e.g.
  340. /// "2001:db8::/64")
  341. ///
  342. /// @return textual representation
  343. virtual std::string toText() const;
  344. /// @brief Resets subnet-id counter to its initial value (1)
  345. ///
  346. /// This should be called during reconfiguration, before any new
  347. /// subnet objects are created. It will ensure that the subnet_id will
  348. /// be consistent between reconfigures.
  349. static void resetSubnetID() {
  350. static_id_ = 1;
  351. }
  352. /// @brief Sets address of the relay
  353. ///
  354. /// In some situations where there are shared subnets (i.e. two different
  355. /// subnets are available on the same physical link), there is only one
  356. /// relay that handles incoming requests from clients. In such a case,
  357. /// the usual subnet selection criteria based on relay belonging to the
  358. /// subnet being selected are no longer sufficient and we need to explicitly
  359. /// specify a relay. One notable example of such uncommon, but valid
  360. /// scenario is a cable network, where there is only one CMTS (one relay),
  361. /// but there are 2 distinct subnets behind it: one for cable modems
  362. /// and another one for CPEs and other user equipment behind modems.
  363. /// From manageability perspective, it is essential that modems get addresses
  364. /// from different subnet, so users won't tinker with their modems.
  365. ///
  366. /// Setting this parameter is not needed in most deployments.
  367. ///
  368. /// @params relay IP address of the relay
  369. void setRelay(const isc::dhcp::Subnet::RelayInfo& relay);
  370. /// @brief Relay information
  371. ///
  372. /// See @ref RelayInfo for detailed description. This structure is public,
  373. /// so its fields are easily accessible. Making it protected would bring in
  374. /// the issue of returning references that may become stale after its parent
  375. /// subnet object disappears.
  376. RelayInfo relay_;
  377. /// @brief checks whether this subnet supports client that belongs to
  378. /// specified classes.
  379. ///
  380. /// This method checks whether a client that belongs to given classes can
  381. /// use this subnet. For example, if this class is reserved for client
  382. /// class "foo" and the client belongs to classes "foo", "bar" and "baz",
  383. /// it is supported. On the other hand, client belonging to classes
  384. /// "foobar" and "zyxxy" is not supported.
  385. ///
  386. /// @param client_classes list of all classes the client belongs to
  387. /// @return true if client can be supported, false otherwise
  388. bool
  389. clientSupported(const isc::dhcp::ClientClasses& client_classes) const;
  390. /// @brief adds class class_name to the list of supported classes
  391. ///
  392. /// @param class_name client class to be supported by this subnet
  393. void
  394. allowClientClass(const isc::dhcp::ClientClass& class_name);
  395. protected:
  396. /// @brief Returns all pools (non-const variant)
  397. ///
  398. /// The reference is only valid as long as the object that returned it.
  399. ///
  400. /// @param type lease type to be set
  401. /// @return a collection of all pools
  402. PoolCollection& getPoolsWritable(Lease::Type type);
  403. /// @brief Protected constructor
  404. //
  405. /// By making the constructor protected, we make sure that noone will
  406. /// ever instantiate that class. Subnet4 and Subnet6 should be used instead.
  407. ///
  408. /// This constructor assigns a new subnet-id (see @ref generateNextID).
  409. /// This subnet-id has unique value that is strictly monotonously increasing
  410. /// for each subnet, until it is explicitly reset back to 1 during
  411. /// reconfiguration process.
  412. ///
  413. /// @param prefix subnet prefix
  414. /// @param len prefix length for the subnet
  415. /// @param t1 T1 (renewal-time) timer, expressed in seconds
  416. /// @param t2 T2 (rebind-time) timer, expressed in seconds
  417. /// @param valid_lifetime valid lifetime of leases in this subnet (in seconds)
  418. /// @param relay optional relay information (currently with address only)
  419. Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len,
  420. const Triplet<uint32_t>& t1,
  421. const Triplet<uint32_t>& t2,
  422. const Triplet<uint32_t>& valid_lifetime,
  423. const isc::dhcp::Subnet::RelayInfo& relay);
  424. /// @brief virtual destructor
  425. ///
  426. /// A virtual destructor is needed because other classes
  427. /// derive from this class.
  428. virtual ~Subnet() { };
  429. /// @brief keeps the subnet-id value
  430. ///
  431. /// It is inreased every time a new Subnet object is created.
  432. /// It is reset (@ref resetSubnetId) every time reconfiguration occurs.
  433. ///
  434. /// Static value initialized in subnet.cc.
  435. static SubnetID static_id_;
  436. /// @brief returns the next unique Subnet-ID
  437. ///
  438. /// This method generates and returns the next unique subnet-id.
  439. /// It is a strictly monotonously increasing value (1,2,3,...) for
  440. /// each new Subnet object created. It can be explicitly reset
  441. /// back to 1 during reconfiguration (@ref resetSubnetID).
  442. ///
  443. /// @return the next unique Subnet-ID
  444. static SubnetID generateNextID() {
  445. return (static_id_++);
  446. }
  447. /// @brief Checks if used pool type is valid
  448. ///
  449. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  450. /// Allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  451. /// This method is implemented in derived classes.
  452. ///
  453. /// @param type type to be checked
  454. /// @throw BadValue if invalid value is used
  455. virtual void checkType(Lease::Type type) const = 0;
  456. /// @brief Check if option is valid and can be added to a subnet.
  457. ///
  458. /// @param option option to be validated.
  459. virtual void validateOption(const OptionPtr& option) const = 0;
  460. /// @brief subnet-id
  461. ///
  462. /// Subnet-id is a unique value that can be used to find or identify
  463. /// a Subnet4 or Subnet6.
  464. SubnetID id_;
  465. /// @brief collection of IPv4 or non-temporary IPv6 pools in that subnet
  466. PoolCollection pools_;
  467. /// @brief collection of IPv6 temporary address pools in that subnet
  468. PoolCollection pools_ta_;
  469. /// @brief collection of IPv6 prefix pools in that subnet
  470. PoolCollection pools_pd_;
  471. /// @brief a prefix of the subnet
  472. isc::asiolink::IOAddress prefix_;
  473. /// @brief a prefix length of the subnet
  474. uint8_t prefix_len_;
  475. /// @brief a tripet (min/default/max) holding allowed renew timer values
  476. Triplet<uint32_t> t1_;
  477. /// @brief a tripet (min/default/max) holding allowed rebind timer values
  478. Triplet<uint32_t> t2_;
  479. /// @brief a tripet (min/default/max) holding allowed valid lifetime values
  480. Triplet<uint32_t> valid_;
  481. /// @brief last allocated address
  482. ///
  483. /// This is the last allocated address that was previously allocated from
  484. /// this particular subnet. Some allocation algorithms (e.g. iterative) use
  485. /// that value, others do not. It should be noted that although the value
  486. /// is usually correct, there are cases when it is invalid, e.g. after
  487. /// removing a pool, restarting or changing allocation algorithms. For
  488. /// that purpose it should be only considered a help that should not be
  489. /// fully trusted.
  490. isc::asiolink::IOAddress last_allocated_ia_;
  491. /// @brief last allocated temporary address
  492. ///
  493. /// See @ref last_allocated_ia_ for details.
  494. isc::asiolink::IOAddress last_allocated_ta_;
  495. /// @brief last allocated IPv6 prefix
  496. ///
  497. /// See @ref last_allocated_ia_ for details.
  498. isc::asiolink::IOAddress last_allocated_pd_;
  499. /// @brief Name of the network interface (if connected directly)
  500. std::string iface_;
  501. /// @brief optional definition of a client class
  502. ///
  503. /// If defined, only clients belonging to that class will be allowed to use
  504. /// this particular subnet. The default value for this is "", which means
  505. /// that any client is allowed, regardless of its class.
  506. ClientClass white_list_;
  507. private:
  508. /// A collection of option spaces grouping option descriptors.
  509. typedef OptionSpaceContainer<OptionContainer,
  510. OptionDescriptor, std::string> OptionSpaceCollection;
  511. /// A collection of vendor space option descriptors.
  512. typedef OptionSpaceContainer<OptionContainer,
  513. OptionDescriptor, uint32_t> VendorOptionSpaceCollection;
  514. /// Regular options are kept here
  515. OptionSpaceCollection option_spaces_;
  516. /// Vendor options are kept here
  517. VendorOptionSpaceCollection vendor_option_spaces_;
  518. };
  519. /// @brief A generic pointer to either Subnet4 or Subnet6 object
  520. typedef boost::shared_ptr<Subnet> SubnetPtr;
  521. /// @brief A configuration holder for IPv4 subnet.
  522. ///
  523. /// This class represents an IPv4 subnet.
  524. class Subnet4 : public Subnet {
  525. public:
  526. /// @brief Constructor with all parameters
  527. ///
  528. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  529. ///
  530. /// @param prefix Subnet4 prefix
  531. /// @param length prefix length
  532. /// @param t1 renewal timer (in seconds)
  533. /// @param t2 rebind timer (in seconds)
  534. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  535. Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
  536. const Triplet<uint32_t>& t1,
  537. const Triplet<uint32_t>& t2,
  538. const Triplet<uint32_t>& valid_lifetime);
  539. /// @brief Sets siaddr for the Subnet4
  540. ///
  541. /// Will be used for siaddr field (the next server) that typically is used
  542. /// as TFTP server. If not specified, the default value of 0.0.0.0 is
  543. /// used.
  544. void setSiaddr(const isc::asiolink::IOAddress& siaddr);
  545. /// @brief Returns siaddr for this subnet
  546. ///
  547. /// @return siaddr value
  548. isc::asiolink::IOAddress getSiaddr() const;
  549. protected:
  550. /// @brief Check if option is valid and can be added to a subnet.
  551. ///
  552. /// @param option option to be validated.
  553. ///
  554. /// @throw isc::BadValue if provided option is invalid.
  555. virtual void validateOption(const OptionPtr& option) const;
  556. /// @brief Returns default address for pool selection
  557. /// @return ANY IPv4 address
  558. virtual isc::asiolink::IOAddress default_pool() const {
  559. return (isc::asiolink::IOAddress("0.0.0.0"));
  560. }
  561. /// @brief Checks if used pool type is valid
  562. ///
  563. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  564. ///
  565. /// @param type type to be checked
  566. /// @throw BadValue if invalid value is used
  567. virtual void checkType(Lease::Type type) const;
  568. /// @brief siaddr value for this subnet
  569. isc::asiolink::IOAddress siaddr_;
  570. };
  571. /// @brief A pointer to a Subnet4 object
  572. typedef boost::shared_ptr<Subnet4> Subnet4Ptr;
  573. /// @brief A collection of Subnet6 objects
  574. typedef std::vector<Subnet4Ptr> Subnet4Collection;
  575. /// @brief A configuration holder for IPv6 subnet.
  576. ///
  577. /// This class represents an IPv6 subnet.
  578. class Subnet6 : public Subnet {
  579. public:
  580. /// @brief Constructor with all parameters
  581. ///
  582. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  583. ///
  584. /// @param prefix Subnet6 prefix
  585. /// @param length prefix length
  586. /// @param t1 renewal timer (in seconds)
  587. /// @param t2 rebind timer (in seconds)
  588. /// @param preferred_lifetime preferred lifetime of leases (in seconds)
  589. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  590. Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
  591. const Triplet<uint32_t>& t1,
  592. const Triplet<uint32_t>& t2,
  593. const Triplet<uint32_t>& preferred_lifetime,
  594. const Triplet<uint32_t>& valid_lifetime);
  595. /// @brief Returns preverred lifetime (in seconds)
  596. ///
  597. /// @return a triplet with preferred lifetime
  598. Triplet<uint32_t> getPreferred() const {
  599. return (preferred_);
  600. }
  601. /// @brief sets interface-id option (if defined)
  602. ///
  603. /// @param ifaceid pointer to interface-id option
  604. void setInterfaceId(const OptionPtr& ifaceid) {
  605. interface_id_ = ifaceid;
  606. }
  607. /// @brief returns interface-id value (if specified)
  608. /// @return interface-id option (if defined)
  609. OptionPtr getInterfaceId() const {
  610. return interface_id_;
  611. }
  612. protected:
  613. /// @brief Check if option is valid and can be added to a subnet.
  614. ///
  615. /// @param option option to be validated.
  616. ///
  617. /// @throw isc::BadValue if provided option is invalid.
  618. virtual void validateOption(const OptionPtr& option) const;
  619. /// @brief Returns default address for pool selection
  620. /// @return ANY IPv6 address
  621. virtual isc::asiolink::IOAddress default_pool() const {
  622. return (isc::asiolink::IOAddress("::"));
  623. }
  624. /// @brief Checks if used pool type is valid
  625. ///
  626. /// allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  627. ///
  628. /// @param type type to be checked
  629. /// @throw BadValue if invalid value is used
  630. virtual void checkType(Lease::Type type) const;
  631. /// @brief specifies optional interface-id
  632. OptionPtr interface_id_;
  633. /// @brief a triplet with preferred lifetime (in seconds)
  634. Triplet<uint32_t> preferred_;
  635. };
  636. /// @brief A pointer to a Subnet6 object
  637. typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  638. /// @brief A collection of Subnet6 objects
  639. typedef std::vector<Subnet6Ptr> Subnet6Collection;
  640. } // end of isc::dhcp namespace
  641. } // end of isc namespace
  642. #endif // SUBNET_T