alloc_engine.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 ALLOC_ENGINE_H
  15. #define ALLOC_ENGINE_H
  16. #include <asiolink/io_address.h>
  17. #include <dhcp/duid.h>
  18. #include <dhcp/hwaddr.h>
  19. #include <dhcp/pkt4.h>
  20. #include <dhcp/pkt6.h>
  21. #include <dhcp/option6_ia.h>
  22. #include <dhcpsrv/host.h>
  23. #include <dhcpsrv/subnet.h>
  24. #include <dhcpsrv/lease_mgr.h>
  25. #include <hooks/callout_handle.h>
  26. #include <boost/shared_ptr.hpp>
  27. #include <boost/noncopyable.hpp>
  28. #include <map>
  29. namespace isc {
  30. namespace dhcp {
  31. /// An exception that is thrown when allocation module fails (e.g. due to
  32. /// lack of available addresses)
  33. class AllocFailed : public isc::Exception {
  34. public:
  35. /// @brief constructor
  36. ///
  37. /// @param file name of the file, where exception occurred
  38. /// @param line line of the file, where exception occurred
  39. /// @param what text description of the issue that caused exception
  40. AllocFailed(const char* file, size_t line, const char* what)
  41. : isc::Exception(file, line, what) {}
  42. };
  43. /// @brief DHCPv4 and DHCPv6 allocation engine
  44. ///
  45. /// This class represents a DHCP allocation engine. It is responsible
  46. /// for picking subnets, choosing and allocating a lease, extending,
  47. /// renewing, releasing and possibly expiring leases.
  48. ///
  49. /// @todo: Does not handle out of leases well
  50. /// @todo: Does not handle out of allocation attempts well
  51. class AllocEngine : public boost::noncopyable {
  52. protected:
  53. /// @brief base class for all address/prefix allocation algorithms
  54. ///
  55. /// This is an abstract class that should not be used directly, but rather
  56. /// specialized implementations should be used instead.
  57. class Allocator {
  58. public:
  59. /// @brief picks one address out of available pools in a given subnet
  60. ///
  61. /// This method returns one address from the available pools in the
  62. /// specified subnet. It should not check if the address is used or
  63. /// reserved - AllocEngine will check that and will call pickAddress
  64. /// again if necessary. The number of times this method is called will
  65. /// increase as the number of available leases will decrease.
  66. ///
  67. /// This method can also be used to pick a prefix. We should not rename
  68. /// it to pickLease(), because at this early stage there is no concept
  69. /// of a lease yet. Here it is a matter of selecting one address or
  70. /// prefix from the defined pool, without going into details who it is
  71. /// for or who uses it. I thought that pickAddress() is less confusing
  72. /// than pickResource(), because nobody would immediately know what the
  73. /// resource means in this context.
  74. ///
  75. /// @param subnet next address will be returned from pool of that subnet
  76. /// @param duid Client's DUID
  77. /// @param hint client's hint
  78. ///
  79. /// @return the next address
  80. virtual isc::asiolink::IOAddress
  81. pickAddress(const SubnetPtr& subnet, const DuidPtr& duid,
  82. const isc::asiolink::IOAddress& hint) = 0;
  83. /// @brief Default constructor.
  84. ///
  85. /// Specifies which type of leases this allocator will assign
  86. /// @param pool_type specifies pool type (addresses, temp. addr or prefixes)
  87. Allocator(Lease::Type pool_type)
  88. :pool_type_(pool_type) {
  89. }
  90. /// @brief virtual destructor
  91. virtual ~Allocator() {
  92. }
  93. protected:
  94. /// @brief defines pool type allocation
  95. Lease::Type pool_type_;
  96. };
  97. /// defines a pointer to allocator
  98. typedef boost::shared_ptr<Allocator> AllocatorPtr;
  99. /// @brief Address/prefix allocator that iterates over all addresses
  100. ///
  101. /// This class implements an iterative algorithm that returns all addresses in
  102. /// a pool iteratively, one after another. Once the last address is reached,
  103. /// it starts allocating from the beginning of the first pool (i.e. it loops
  104. /// over).
  105. class IterativeAllocator : public Allocator {
  106. public:
  107. /// @brief default constructor
  108. ///
  109. /// Does not do anything
  110. /// @param type - specifies allocation type
  111. IterativeAllocator(Lease::Type type);
  112. /// @brief returns the next address from pools in a subnet
  113. ///
  114. /// @param subnet next address will be returned from pool of that subnet
  115. /// @param duid Client's DUID (ignored)
  116. /// @param hint client's hint (ignored)
  117. /// @return the next address
  118. virtual isc::asiolink::IOAddress
  119. pickAddress(const SubnetPtr& subnet,
  120. const DuidPtr& duid,
  121. const isc::asiolink::IOAddress& hint);
  122. protected:
  123. /// @brief Returns the next prefix
  124. ///
  125. /// This method works for IPv6 addresses only. It increases the
  126. /// specified prefix by a given prefix_len. For example, 2001:db8::
  127. /// increased by prefix length /32 will become 2001:db9::. This method
  128. /// is used to iterate over IPv6 prefix pools
  129. ///
  130. /// @param prefix prefix to be increased
  131. /// @param prefix_len length of the prefix to be increased
  132. /// @return result prefix
  133. static isc::asiolink::IOAddress
  134. increasePrefix(const isc::asiolink::IOAddress& prefix,
  135. const uint8_t prefix_len);
  136. };
  137. /// @brief Address/prefix allocator that gets an address based on a hash
  138. ///
  139. /// @todo: This is a skeleton class for now and is missing an implementation.
  140. class HashedAllocator : public Allocator {
  141. public:
  142. /// @brief default constructor (does nothing)
  143. /// @param type - specifies allocation type
  144. HashedAllocator(Lease::Type type);
  145. /// @brief returns an address based on hash calculated from client's DUID.
  146. ///
  147. /// @todo: Implement this method
  148. ///
  149. /// @param subnet an address will be picked from pool of that subnet
  150. /// @param duid Client's DUID
  151. /// @param hint a hint (last address that was picked)
  152. /// @return selected address
  153. virtual isc::asiolink::IOAddress pickAddress(const SubnetPtr& subnet,
  154. const DuidPtr& duid,
  155. const isc::asiolink::IOAddress& hint);
  156. };
  157. /// @brief Random allocator that picks address randomly
  158. ///
  159. /// @todo: This is a skeleton class for now and is missing an implementation.
  160. class RandomAllocator : public Allocator {
  161. public:
  162. /// @brief default constructor (does nothing)
  163. /// @param type - specifies allocation type
  164. RandomAllocator(Lease::Type type);
  165. /// @brief returns a random address from pool of specified subnet
  166. ///
  167. /// @todo: Implement this method
  168. ///
  169. /// @param subnet an address will be picked from pool of that subnet
  170. /// @param duid Client's DUID (ignored)
  171. /// @param hint the last address that was picked (ignored)
  172. /// @return a random address from the pool
  173. virtual isc::asiolink::IOAddress
  174. pickAddress(const SubnetPtr& subnet, const DuidPtr& duid,
  175. const isc::asiolink::IOAddress& hint);
  176. };
  177. public:
  178. /// @brief specifies allocation type
  179. typedef enum {
  180. ALLOC_ITERATIVE, // iterative - one address after another
  181. ALLOC_HASHED, // hashed - client's DUID/client-id is hashed
  182. ALLOC_RANDOM // random - an address is randomly selected
  183. } AllocType;
  184. /// @brief Constructor.
  185. ///
  186. /// Instantiates necessary services, required to run DHCP server.
  187. /// In particular, creates IfaceMgr that will be responsible for
  188. /// network interaction. Will instantiate lease manager, and load
  189. /// old or create new DUID.
  190. ///
  191. /// @param engine_type selects allocation algorithm
  192. /// @param attempts number of attempts for each lease allocation before
  193. /// we give up (0 means unlimited)
  194. /// @param ipv6 specifies if the engine should work for IPv4 or IPv6
  195. AllocEngine(AllocType engine_type, unsigned int attempts, bool ipv6 = true);
  196. /// @brief Destructor.
  197. virtual ~AllocEngine() { }
  198. /// @brief Returns allocator for a given pool type
  199. ///
  200. /// @param type type of pool (V4, IA, TA or PD)
  201. /// @throw BadValue if allocator for a given type is missing
  202. /// @return pointer to allocator handling a given resource types
  203. AllocatorPtr getAllocator(Lease::Type type);
  204. private:
  205. /// @brief a pointer to currently used allocator
  206. ///
  207. /// For IPv4, there will be only one allocator: TYPE_V4
  208. /// For IPv6, there will be 3 allocators: TYPE_NA, TYPE_TA, TYPE_PD
  209. std::map<Lease::Type, AllocatorPtr> allocators_;
  210. /// @brief number of attempts before we give up lease allocation (0=unlimited)
  211. unsigned int attempts_;
  212. // hook name indexes (used in hooks callouts)
  213. int hook_index_lease4_select_; ///< index for lease4_select hook
  214. int hook_index_lease6_select_; ///< index for lease6_select hook
  215. public:
  216. /// @brief Defines a single hint (an address + prefix-length).
  217. ///
  218. /// This is an entry that represents what the client had requested,
  219. /// either an address or a prefix. Prefix length is 128 for regular
  220. /// addresses.
  221. typedef std::pair<isc::asiolink::IOAddress, uint8_t> HintType;
  222. /// @brief Container for client's hints.
  223. typedef std::vector<HintType> HintContainer;
  224. /// @brief Context information for the DHCPv6 leases allocation.
  225. ///
  226. /// This structure holds a set of information provided by the DHCPv6
  227. /// server to the allocation engine. In particular, it holds the
  228. /// client identifying information, such as HW address or client
  229. /// identifier. It also holds the information about the subnet that
  230. /// the client is connected to.
  231. ///
  232. /// This structure is also used to pass some information from
  233. /// the allocation engine back to the server, i.e. the old leases
  234. /// which the client had before the allocation.
  235. ///
  236. /// This structure is expected to be common for a single client, even
  237. /// if multiple IAs are used. Some of the fields will need to be
  238. /// updated for every call (there's a separate call to the allocation
  239. /// engine for each IA option).
  240. ///
  241. /// This structure is meant to be extended in the future, if more
  242. /// information should be passed to the allocation engine. Note
  243. /// that the big advantage of using the context structure to pass
  244. /// information to the allocation engine methods is that adding
  245. /// new information doesn't modify the API of the allocation engine.
  246. struct ClientContext6 {
  247. /// @brief Subnet selected for the client by the server.
  248. Subnet6Ptr subnet_;
  249. /// @brief Client identifier
  250. DuidPtr duid_;
  251. /// @brief iaid IAID field from IA_NA or IA_PD that is being processed
  252. uint32_t iaid_;
  253. /// @brief Lease type (IA or PD)
  254. Lease::Type type_;
  255. /// @brief Hardware/MAC address (if available, may be NULL)
  256. HWAddrPtr hwaddr_;
  257. /// @brief client's hints
  258. ///
  259. /// There will typically be just one address, but the protocol allows
  260. /// more than one address or prefix for each IA container.
  261. HintContainer hints_;
  262. /// @brief A boolean value which indicates that server takes
  263. /// responsibility for the forward DNS Update for this lease
  264. /// (if true).
  265. bool fwd_dns_update_;
  266. /// @brief A boolean value which indicates that server takes
  267. /// responsibility for the reverse DNS Update for this lease
  268. /// (if true).
  269. bool rev_dns_update_;
  270. /// @brief Hostname.
  271. ///
  272. /// The server retrieves the hostname from the Client FQDN option,
  273. /// Hostname option or the host reservation record for the client.
  274. std::string hostname_;
  275. /// @brief Callout handle associated with the client's message.
  276. hooks::CalloutHandlePtr callout_handle_;
  277. /// @brief Indicates if this is a real or fake allocation.
  278. ///
  279. /// The real allocation is when the allocation engine is supposed
  280. /// to make an update in a lease database: create new lease, or
  281. /// update existing lease.
  282. bool fake_allocation_;
  283. /// @brief A pointer to any old leases that the client had before update
  284. /// but are no longer valid after the update/allocation.
  285. ///
  286. /// This collection is typically empty, except cases when we are doing
  287. /// address reassignment, e.g. because there is a host reservation that
  288. /// gives this address to someone else, so we had to return the address,
  289. /// and give a new one to this client.
  290. Lease6Collection old_leases_;
  291. /// @brief A pointer to any leases that have changed FQDN information.
  292. ///
  293. /// This list may contain old versions of the leases that are still
  294. /// valid. In particular, it will contain a lease if the client's
  295. /// FQDN has changed.
  296. Lease6Collection changed_leases_;
  297. /// @brief A pointer to the object identifying host reservations.
  298. ///
  299. /// May be NULL if there are no reservations.
  300. ConstHostPtr host_;
  301. /// @brief A pointer to the client's message
  302. ///
  303. /// This is used exclusively for hook purposes.
  304. Pkt6Ptr query_;
  305. /// @brief A pointer to the IA_NA/IA_PD option to be sent in response
  306. Option6IAPtr ia_rsp_;
  307. /// @brief Specifies whether new leases in Renew/Rebind are allowed
  308. ///
  309. /// This field controls what to do when renewing or rebinding client
  310. /// does not have any leases. RFC3315 and the stateful-issues draft do
  311. /// not specify it and it is left up to the server configuration policy.
  312. /// False (the default) means that the client will not get any new
  313. /// unreserved leases if his existing leases are no longer suitable.
  314. /// True means that the allocation engine will do its best to assign
  315. /// something.
  316. bool allow_new_leases_in_renewals_;
  317. /// @brief Default constructor.
  318. ClientContext6();
  319. /// @brief Constructor with parameters.
  320. ///
  321. /// Note that several less frequently used parameters (callout_handle,
  322. /// old_leases, host) fields are not set. They should be set explicitly,
  323. /// if needed.
  324. ///
  325. /// @param subnet subnet the allocation should come from
  326. /// @param duid Client's DUID
  327. /// @param iaid iaid field from the IA_NA container that client sent
  328. /// @param hint a hint that the client provided
  329. /// @param type lease type (IA, TA or PD)
  330. /// @param fwd_dns A boolean value which indicates that server takes
  331. /// responsibility for the forward DNS Update for this lease
  332. /// (if true).
  333. /// @param rev_dns A boolean value which indicates that server takes
  334. /// responsibility for the reverse DNS Update for this lease
  335. /// (if true).
  336. /// @param hostname A fully qualified domain-name of the client.
  337. /// @param fake_allocation is this real i.e. REQUEST (false) or just picking
  338. /// an address for SOLICIT that is not really allocated (true)
  339. ClientContext6(const Subnet6Ptr& subnet, const DuidPtr& duid,
  340. const uint32_t iaid, const isc::asiolink::IOAddress& hint,
  341. const Lease::Type type, const bool fwd_dns, const bool
  342. rev_dns, const std::string& hostname, const bool
  343. fake_allocation);
  344. };
  345. /// @brief Allocates IPv6 leases for a given IA container
  346. ///
  347. /// This method uses the currently selected allocator to pick allocatable
  348. /// resources (i.e. addresses or prefixes) from specified subnet, creates
  349. /// a lease (one or more, if needed) for that resources and then inserts
  350. /// it into LeaseMgr (if this allocation is not fake, i.e. this is not a
  351. /// response to SOLICIT).
  352. ///
  353. /// This method uses host reservation if ctx.host_ is set. The easy way to
  354. /// set it is to call @ref AllocEngine::findReservation(ctx). The host reservation
  355. /// is convenient, but incurs performance penalty, so it can be tweaked on
  356. /// a per subnet basis. There are three possible modes:
  357. /// 1. disabled (no host reservation at all). This is the most performant one
  358. /// as the code can skip all checks;
  359. /// 2. out-of-pool (only reservations that are outside
  360. /// of the dynamic pools are allowed. This is a compromise - it requires
  361. /// a sysadmin to be more careful with the reservations, but the code
  362. /// can skip reservation checks while managing in-pool addresses);
  363. /// 3. in-pool (which also allow out-of-pool; this is the most flexible
  364. /// mode, but it means that the allocation engine has to do reservation
  365. /// checks on every lease, even those dynamically assigned, which degrades
  366. /// performance).
  367. ///
  368. /// The logic in this method is as follows:
  369. /// -# Case 1. if there are no leases, and there are reservations...
  370. /// Are the reserved addresses/prefixes used by someone else?
  371. /// -# yes: we have a problem. We can't assign the reserved address yet,
  372. /// because it is used by someone else. We can't immediately release
  373. /// the lease as there is some other client that is currently using it.
  374. /// We will temporarily assign a different, unreserved lease for this
  375. /// client. In the mean time, the other client will hopefully get back
  376. /// to us, so we could revoke his lease.
  377. /// -# no: assign them => done
  378. /// -# Case 2. if there are leases and there are no reservations...
  379. /// Are the leases reserved for someone else?
  380. /// -# yes: release them, assign something else
  381. /// -# no: renew them => done
  382. /// -# Case 3. if there are leases and there are reservations...
  383. /// Are the leases matching reservations?
  384. /// -# yes: renew them => done
  385. /// -# no: release existing leases, assign new ones based on reservations
  386. /// -# Case 4. if there are no leases and no reservations...
  387. /// assign new leases (this is the "normal" case when the reservations
  388. /// are disabled).
  389. ///
  390. /// @param ctx client context that passes all necessary information. See
  391. /// @ref ClientContext6 for details.
  392. ///
  393. /// The following fields of ClientContext6 are used:
  394. ///
  395. /// @ref ClientContext6::subnet_ subnet the allocation should come from<br/>
  396. /// @ref ClientContext6::duid_ Client's DUID<br/>
  397. /// @ref ClientContext6::iaid_ iaid field from the IA_NA container
  398. /// that client sent<br/>
  399. /// @ref ClientContext6::hints_ a hint that the client provided<br/>
  400. /// @ref ClientContext6::type_ lease type (IA, TA or PD)<br/>
  401. /// @ref ClientContext6::fwd_dns_update_ A boolean value which indicates
  402. /// that server takes responsibility for the forward DNS Update
  403. /// for this lease (if true).<br/>
  404. /// @ref ClientContext6::rev_dns_update_ A boolean value which indicates
  405. /// that server takes responsibility for the reverse DNS Update for
  406. /// this lease (if true).<br/>
  407. /// @ref ClientContext6::hostname_ A fully qualified domain-name of the client.<br/>
  408. /// @ref ClientContext6::fake_allocation_ is this real i.e. REQUEST (false)
  409. /// or just picking an address for SOLICIT that is not really
  410. /// allocated (true)<br/>
  411. /// @ref ClientContext6::callout_handle_ a callout handle (used in hooks). A
  412. /// lease callouts will be executed if this parameter is passed.<br/>
  413. /// @ref ClientContext6::old_leases_ [out] Collection to which this function
  414. /// will append old leases. Leases are stored in the same order as in
  415. /// the collection of new leases, being returned. For newly allocated
  416. /// leases (not renewed) the NULL pointers are stored in this
  417. /// collection as old leases.<br/>
  418. /// @ref ClientContext6::hwaddr_ Hardware address (optional, may be null if
  419. /// not available)<br/>
  420. /// @ref ClientContext6::host_ Host reservation. allocateLeases6 will set
  421. /// this field, if appropriate reservation is found.
  422. ///
  423. /// @return Allocated IPv6 leases (may be empty if allocation failed)
  424. Lease6Collection
  425. allocateLeases6(ClientContext6& ctx);
  426. /// @brief Renews existing DHCPv6 leases for a given IA.
  427. ///
  428. /// This method updates the leases associated with a specified IA container.
  429. /// It will extend the leases under normal circumstances, but sometimes
  430. /// there may be reasons why not to do so. Such a reasons may be:
  431. /// - client attempts to renew an address that is not valid
  432. /// - client attempts to renew an address that is now reserved for someone
  433. /// else (see host reservation)
  434. /// - client's leases does not match his reservations
  435. ///
  436. /// This method will call the lease6_renew callout.
  437. ///
  438. /// @param ctx Message processing context. It holds various information
  439. /// extracted from the client's message and required to allocate a lease.
  440. /// In particular, @ref ClientContext6::hints_ provides list of addresses or
  441. /// prefixes the client had sent. @ref ClientContext6::old_leases_ will
  442. /// contain removed leases in this case.
  443. ///
  444. /// @return Returns renewed lease.
  445. Lease6Collection renewLeases6(ClientContext6& ctx);
  446. /// @brief Attempts to find appropriate host reservation.
  447. ///
  448. /// Attempts to find appropriate host reservation in HostMgr. If found, it
  449. /// will be set in ctx.host_.
  450. /// @param ctx Client context that contains all necessary information.
  451. void findReservation(ClientContext6& ctx) const;
  452. private:
  453. /// @brief creates a lease and inserts it in LeaseMgr if necessary
  454. ///
  455. /// Creates a lease based on specified parameters and tries to insert it
  456. /// into the database. That may fail in some cases, i.e. when there is another
  457. /// allocation process and we lost a race to a specific lease.
  458. ///
  459. /// @param ctx client context that passes all necessary information. See
  460. /// @ref ClientContext6 for details.
  461. /// @param addr an address that was selected and is confirmed to be
  462. /// available
  463. /// @param prefix_len length of the prefix (for PD only)
  464. /// should be 128 for other lease types
  465. ///
  466. /// The following fields of the ctx structure are used:
  467. /// @ref ClientContext6::subnet_ subnet the lease is allocated from
  468. /// @ref ClientContext6::duid_ client's DUID
  469. /// @ref ClientContext6::iaid_ IAID from the IA_NA container the client sent to us
  470. /// @ref ClientContext6::type_ lease type (IA, TA or PD)
  471. /// @ref ClientContext6::fwd_dns_update_ A boolean value which indicates that server takes
  472. /// responsibility for the forward DNS Update for this lease
  473. /// (if true).
  474. /// @ref ClientContext6::rev_dns_update_ A boolean value which indicates that server takes
  475. /// responsibility for the reverse DNS Update for this lease
  476. /// (if true).
  477. /// @ref ClientContext6::hostname_ A fully qualified domain-name of the client.
  478. /// @ref ClientContext6::hwaddr_ Hardware address (optional, may be null for Lease6)
  479. /// @ref ClientContext6::callout_handle_ a callout handle (used in hooks). A lease callouts
  480. /// will be executed if this parameter is passed (and there are callouts
  481. /// registered)
  482. /// @ref ClientContext6::fake_allocation_ is this real i.e. REQUEST (false) or just picking
  483. /// an address for SOLICIT that is not really allocated (true)
  484. /// @return allocated lease (or NULL in the unlikely case of the lease just
  485. /// became unavailable)
  486. Lease6Ptr createLease6(ClientContext6& ctx,
  487. const isc::asiolink::IOAddress& addr,
  488. const uint8_t prefix_len);
  489. /// @brief Allocates a normal, in-pool, unreserved lease from the pool.
  490. ///
  491. /// It attempts to pick a hint first, then uses allocator iteratively until
  492. /// an available (not used, not reserved) lease is found. In principle, it
  493. /// may return more than one lease, but we currently handle only one.
  494. /// This may change in the future.
  495. ///
  496. /// @param ctx client context that contains all details (subnet, client-id, etc.)
  497. /// @return collection of newly allocated leases
  498. Lease6Collection allocateUnreservedLeases6(ClientContext6& ctx);
  499. /// @brief Creates new leases based on reservations.
  500. ///
  501. /// This method allocates new leases, based on host reservation. Existing
  502. /// leases are specified in existing_leases parameter. A new lease is not created,
  503. /// if there is a lease for specified address on existing_leases list or there is
  504. /// a lease used by someone else.
  505. ///
  506. /// @param ctx client context that contains all details (subnet, client-id, etc.)
  507. /// @param existing_leases leases that are already associated with the client
  508. void
  509. allocateReservedLeases6(ClientContext6& ctx, Lease6Collection& existing_leases);
  510. /// @brief Removes leases that are reserved for someone else.
  511. ///
  512. /// Goes through the list specified in existing_leases and removes those that
  513. /// are reserved by someone else. The removed leases are added to the
  514. /// ctx.removed_leases_ collection.
  515. ///
  516. /// @param ctx client context that contains all details (subnet, client-id, etc.)
  517. /// @param existing_leases [in/out] leases that should be checked
  518. void
  519. removeNonmatchingReservedLeases6(ClientContext6& ctx,
  520. Lease6Collection& existing_leases);
  521. /// @brief Removed leases that are not reserved for this client
  522. ///
  523. /// This method iterates over existing_leases and will remove leases that are
  524. /// not reserved for this client. It will leave at least one lease on the list,
  525. /// if possible. The reason to run this method is that if there is a reservation
  526. /// for address A for client X and client X already has a lease for a
  527. /// different address B, we should assign A and release B. However,
  528. /// if for some reason we can't assign A, keeping B would be better than
  529. /// not having a lease at all. Hence we may keep B if that's the only lease
  530. /// left.
  531. ///
  532. /// @param ctx client context that contains all details (subnet, client-id, etc.)
  533. /// @param existing_leases [in/out] leases that should be checked
  534. void
  535. removeNonreservedLeases6(ClientContext6& ctx,
  536. Lease6Collection& existing_leases);
  537. /// @brief Reuses expired IPv6 lease
  538. ///
  539. /// Updates existing expired lease with new information. Lease database
  540. /// is updated if this is real (i.e. REQUEST, fake_allocation = false), not
  541. /// dummy allocation request (i.e. SOLICIT, fake_allocation = true).
  542. ///
  543. /// @param expired old, expired lease
  544. /// @param ctx client context that contains all details.
  545. /// @param prefix_len prefix length (for PD leases)
  546. /// Should be 128 for other lease types
  547. ///
  548. /// The following parameters are used from the ctx structure:
  549. /// @ref ClientContext6::subnet_ subnet the lease is allocated from
  550. /// @ref ClientContext6::duid_ client's DUID
  551. /// @ref ClientContext6::iaid_ IAID from the IA_NA container the client sent to us
  552. /// @ref ClientContext6::fwd_dns_update_ A boolean value which indicates that server takes
  553. /// responsibility for the forward DNS Update for this lease
  554. /// (if true).
  555. /// @ref ClientContext6::rev_dns_update_ A boolean value which indicates that server takes
  556. /// responsibility for the reverse DNS Update for this lease
  557. /// (if true).
  558. /// @ref ClientContext6::hostname_ A fully qualified domain-name of the client.
  559. /// @ref ClientContext6::callout_handle_ a callout handle (used in hooks). A
  560. /// lease callouts will be executed if this parameter is passed.
  561. /// @ref ClientContext6::fake_allocation_ is this real i.e. REQUEST (false)
  562. /// or just picking an address for SOLICIT that is not really
  563. /// allocated (true)
  564. ///
  565. /// @return refreshed lease
  566. /// @throw BadValue if trying to recycle lease that is still valid
  567. Lease6Ptr reuseExpiredLease(Lease6Ptr& expired,
  568. ClientContext6& ctx,
  569. uint8_t prefix_len);
  570. /// @brief Updates FQDN data for a collection of leases.
  571. ///
  572. /// @param ctx IPv6 client context (old versions of the leases that had
  573. /// FQDN data changed will be stored in ctx.changed_leases_,
  574. /// ctx.fwd_dns_update, ctx.rev_dns_update, ctx.hostname_
  575. /// and ctx.fake_allocation_ will be used.
  576. /// @param leases Collection of leases for which FQDN data should be
  577. /// updated.
  578. ///
  579. /// @return Collection of leases with updated FQDN data. Note that returned
  580. /// collection holds updated FQDN data even for fake allocation.
  581. Lease6Collection updateFqdnData(ClientContext6& ctx,
  582. const Lease6Collection& leases);
  583. /// @brief Utility function that removes all leases with a specified address
  584. /// @param container A collection of Lease6 pointers
  585. /// @param addr address to be removed
  586. /// @return true if removed (false otherwise)
  587. static bool
  588. removeLeases(Lease6Collection& container,
  589. const asiolink::IOAddress& addr);
  590. /// @brief Extends specified IPv6 lease
  591. ///
  592. /// This method attempts to extend the lease. It will call the lease6_renew
  593. /// or lease6_rebind hooks (depending on the client's message specified in
  594. /// ctx.query). The lease will be extended in LeaseMgr, unless the hooks
  595. /// library will set the skip flag.
  596. ///
  597. /// @param ctx client context that passes all necessary information. See
  598. /// @ref ClientContext6 for details.
  599. /// @param lease IPv6 lease to be extended.
  600. void extendLease6(ClientContext6& ctx, Lease6Ptr lease);
  601. public:
  602. /// @brief Context information for the DHCPv4 lease allocation.
  603. ///
  604. /// This structure holds a set of information provided by the DHCPv4
  605. /// server to the allocation engine. In particular, it holds the
  606. /// client identifying information, such as HW address or client
  607. /// identifier. It also holds the information about the subnet that
  608. /// the client is connected to.
  609. ///
  610. /// This structure is also used to pass some information from
  611. /// the allocation engine back to the server, i.e. the old lease
  612. /// which the client had before the allocation.
  613. ///
  614. /// This structure is meant to be extended in the future, if more
  615. /// information should be passed to the allocation engine. Note
  616. /// that the big advantage of using the context structure to pass
  617. /// information to the allocation engine methods is that adding
  618. /// new information doesn't modify the API of the allocation engine.
  619. struct ClientContext4 {
  620. /// @brief Subnet selected for the client by the server.
  621. Subnet4Ptr subnet_;
  622. /// @brief Client identifier from the DHCP message.
  623. ClientIdPtr clientid_;
  624. /// @brief HW address from the DHCP message.
  625. HWAddrPtr hwaddr_;
  626. /// @brief An address that the client desires.
  627. ///
  628. /// If this address is set to 0 it indicates that this address
  629. /// is unspecified.
  630. asiolink::IOAddress requested_address_;
  631. /// @brief Perform forward DNS update.
  632. bool fwd_dns_update_;
  633. /// @brief Perform reverse DNS update.
  634. bool rev_dns_update_;
  635. /// @brief Hostname.
  636. ///
  637. /// The server retrieves the hostname from the Client FQDN option,
  638. /// Hostname option or the host reservation record for the client.
  639. std::string hostname_;
  640. /// @brief Callout handle associated with the client's message.
  641. hooks::CalloutHandlePtr callout_handle_;
  642. /// @brief Indicates if this is a real or fake allocation.
  643. ///
  644. /// The real allocation is when the allocation engine is supposed
  645. /// to make an update in a lease database: create new lease, or
  646. /// update existing lease.
  647. bool fake_allocation_;
  648. /// @brief A pointer to an old lease that the client had before update.
  649. Lease4Ptr old_lease_;
  650. /// @brief A pointer to the object identifying host reservations.
  651. ConstHostPtr host_;
  652. /// @brief A pointer to the object representing a lease in conflict.
  653. ///
  654. /// This pointer is set by some of the allocation methods when
  655. /// the lease can't be allocated because there is another lease
  656. /// which is in conflict with this allocation.
  657. Lease4Ptr conflicting_lease_;
  658. /// @brief A pointer to the client's message.
  659. ///
  660. /// This is used in logging to retrieve the client's and the
  661. /// transaction identification information.
  662. Pkt4Ptr query_;
  663. /// @brief Default constructor.
  664. ClientContext4();
  665. /// @brief Constructor with parameters
  666. ///
  667. /// @param subnet subnet the allocation should come from (mandatory)
  668. /// @param clientid Client identifier (optional)
  669. /// @param hwaddr Client's hardware address info (mandatory)
  670. /// @param requested_addr A hint that the client provided (may be 0.0.0.0)
  671. /// @param fwd_dns_update Indicates whether forward DNS
  672. /// update will be performed for the client (true) or not (false).
  673. /// @param rev_dns_update Indicates whether reverse DNS
  674. /// update will be performed for the client (true) or not (false).
  675. /// @param hostname A string carrying hostname to be used for DNS updates.
  676. /// @param fake_allocation Is this real i.e. REQUEST (false)
  677. /// or just picking an address for DISCOVER that is not really
  678. /// allocated (true)
  679. ClientContext4(const Subnet4Ptr& subnet, const ClientIdPtr& clientid,
  680. const HWAddrPtr& hwaddr,
  681. const asiolink::IOAddress& requested_addr,
  682. const bool fwd_dns_update, const bool rev_dns_update,
  683. const std::string& hostname, const bool fake_allocation);
  684. };
  685. /// @brief Pointer to the @c ClientContext4.
  686. typedef boost::shared_ptr<ClientContext4> ClientContext4Ptr;
  687. /// @brief Returns IPv4 lease.
  688. ///
  689. /// This method finds a lease for a client using the following algorithm:
  690. /// - If a lease exists for the combination of the HW address or client id
  691. /// and a subnet, try to use this lease for the client. If the client
  692. /// has a reservation for an address for which the lease was created or
  693. /// the client desires to renew the lease for this address (ciaddr or
  694. /// requested IP address option), the server renews the lease for the
  695. /// client. If the client desires a different address or the server has
  696. /// a (potentially new) reservation for a different address for this
  697. /// client, the existing lease is replaced with a new lease.
  698. /// - If the client has no lease in the lease database the server will try
  699. /// to allocate a new lease. If the client has a reservation for the
  700. /// particular address or if it has specified a desired address the
  701. /// server will check if the particular address is not allocated to
  702. /// another client. If the address is available, the server will allocate
  703. /// this address for the client.
  704. /// - If the desired address is unavailable the server checks if the
  705. /// lease for this address has expired. If the lease is expired, the
  706. /// server will allocate this lease to the client. The relevant
  707. /// information will be updated, e.g. new client HW address, host name
  708. /// etc.
  709. /// - If the desired address is in use by another client, the server will
  710. /// try to allocate a different address. The server picks addresses from
  711. /// a dynamic pool and checks if the address is available and that
  712. /// it is not reserved for another client. If it is in use by another
  713. /// client or if it is reserved for another client, the address is not
  714. /// allocated. The server picks the next address and repeats this check.
  715. /// Note that the server ceases allocation after the configured number
  716. /// of unsuccessful attempts.
  717. ///
  718. /// The lease allocation process is slightly different for the
  719. /// DHCPDISCOVER and DHCPREQUEST messages. In the former case, the client
  720. /// may specify the requested IP address option with a desired address and
  721. /// the server treats this address as a hint. This means that the server may
  722. /// allocate a different address at its discretion and send it to the
  723. /// client in the DHCPOFFER. If the client accepts this offer it specifies
  724. /// this address in the requested IP address option in the DHCPREQUEST.
  725. /// At this point, the allocation engine will use the requested IP address
  726. /// as a hard requirement and if this address can't be allocated for
  727. /// any reason, the allocation engine returns NULL lease. As a result,
  728. /// the DHCP server sends a DHCPNAK to the client and the client
  729. /// falls back to the DHCP server discovery.
  730. ///
  731. /// The only exception from this rule is when the client doesn't specify
  732. /// a requested IP address option (invalid behavior) in which case the
  733. /// allocation engine will try to allocate any address.
  734. ///
  735. /// If there is an address reservation specified for the particular client
  736. /// the reserved address always takes precedence over addresses from the
  737. /// dynamic pool or even an address currently allocated for this client.
  738. ///
  739. /// It is possible that the address reserved for the particular client
  740. /// is in use by another client, e.g. as a result of pools reconfiguration.
  741. /// In this case, when the client requests allocation of the reserved
  742. /// address and the server determines that it is leased to someone else,
  743. /// the allocation engine allocates a different address for this client.
  744. ///
  745. /// When the client having a lease returns to renew, the allocation engine
  746. /// doesn't extend the lease for it and returns a NULL pointer. The client
  747. /// falls back to the 4-way exchange and a different lease is allocated.
  748. /// At this point, the reserved address is freed and can be allocated to
  749. /// the client which holds this reservation. However, this client has a
  750. /// lease for a different address at this time. When the client renews its
  751. /// lease it receives the DHCPNAK and falls back to the DHCP server
  752. /// discovery and obtains the lease for the reserved address.
  753. ///
  754. /// When a server should do DNS updates, it is required that allocation
  755. /// returns the information about how the lease was obtained by the allocation
  756. /// engine. In particular, the DHCP server should be able to check whether
  757. /// an existing lease was returned, or a new lease was allocated. When an
  758. /// existing lease was returned, the server should check whether the FQDN has
  759. /// changed between the allocation of the old and new lease. If so, the server
  760. /// should perform the appropriate DNS update. If not, the server may choose
  761. /// to not perform the update. The information about the old lease is returned via
  762. /// @c old_lease parameter. If NULL value is returned, it is an indication
  763. /// that a new lease was allocated for the client. If non-NULL value is
  764. /// returned, it is an indication that allocation engine reused/renewed an
  765. /// existing lease.
  766. ///
  767. /// @param ctx client context that passes all necessary information. See
  768. /// @ref ClientContext4 for details.
  769. ///
  770. /// The following fields of @ref ClientContext4 are used:
  771. ///
  772. /// - @ref ClientContext4::subnet_ subnet the allocation should come from
  773. /// - @ref ClientContext4::clientid_ Client identifier
  774. /// - @ref ClientContext4::hwaddr_ Client's hardware address info
  775. /// - @ref ClientContext4::requested_address_ A hint that the client provided
  776. /// - @ref ClientContext4::fwd_dns_update_ Indicates whether forward DNS
  777. /// update will be performed for the client (true) or not (false).
  778. /// - @ref ClientContext4::rev_dns_update_ Indicates whether reverse DNS
  779. /// update will be performed for the client (true) or not (false).
  780. /// - @ref ClientContext4::hostname_ A string carrying hostname to be used for
  781. /// DNS updates.
  782. /// - @ref ClientContext4::fake_allocation_ Is this real i.e. REQUEST (false)
  783. /// or just picking an address for DISCOVER that is not really
  784. /// allocated (true)
  785. /// - @ref ClientContext4::host_ Pointer to the object representing the
  786. // static reservations (host reservations) for the client.
  787. /// - @ref ClientContext4::callout_handle_ A callout handle (used in hooks).
  788. /// A lease callouts will be executed if this parameter is passed.
  789. /// - @ref ClientContext4::old_lease_ [out] Holds the pointer to a previous
  790. /// instance of a lease. The NULL pointer indicates that lease didn't
  791. /// exist prior to calling this function (e.g. new lease has been allocated).
  792. ///
  793. /// @return Allocated IPv4 lease (or NULL if allocation failed).
  794. Lease4Ptr allocateLease4(ClientContext4& ctx);
  795. /// @brief Attempts to find the host reservation for the client.
  796. ///
  797. /// This method attempts to find the host reservation for the client. If
  798. /// found, it is set in the @c ctx.host_. If the host reservations are
  799. /// disabled for the particular subnet or the reservation is not found
  800. /// for the client, the @c ctx.host_ is set to NULL.
  801. ///
  802. /// @param ctx Client context holding various information about the client.
  803. static void findReservation(ClientContext4& ctx);
  804. private:
  805. /// @brief Offers the lease.
  806. ///
  807. /// This method is called by the @c AllocEngine::allocateLease4 when
  808. /// the server is processing a DHCPDISCOVER message, i.e. the fake
  809. /// allocation case.
  810. ///
  811. /// This method doesn't modify leases in the lease database. It finds
  812. /// the most suitable lease for the client and returns it to the caller.
  813. /// The server uses this lease when it sends the DHCPOFFER to the
  814. /// client from which it has received a DHCPDISCOVER message.
  815. ///
  816. /// The lease is found using the following algorithm:
  817. /// -# If there is a reservation for the client, try to use the reserved
  818. /// address. This may fail if the particular address is in use by
  819. /// another client. In such case:
  820. /// -# If the client has a lease, try to offer this lease. This may fail
  821. /// if it turns out that this address is reserved for another client
  822. /// or the address doesn't belong to the address pool. In such case:
  823. /// -# Try to allocate the address provided by the client as a hint.
  824. /// This may fail if the address is in use or is reserved by some
  825. /// other client. In such case:
  826. /// -# Try to offer an address from the dynamic pool.
  827. ///
  828. /// @throw various exceptions if the allocation goes wrong.
  829. ///
  830. /// @param ctx Client context holding the data extracted from the
  831. /// client's message.
  832. ///
  833. /// @return A pointer to the offered lease, or NULL if no suitable lease
  834. /// has been found.
  835. Lease4Ptr discoverLease4(ClientContext4& ctx);
  836. /// @brief Allocates the lease.
  837. ///
  838. /// This method is called by the @c AllocEngine::allocateLease4 when
  839. /// the server is processing a DHCPREQUEST message, i.e. the real
  840. /// allocation case.
  841. ///
  842. /// This method modifies the lease information in the lease database.
  843. /// It adds new leases, modifies existing leases or deletes them.
  844. ///
  845. /// The method returns NULL to indicate that the lease allocation
  846. /// has failed when any of the following occur:
  847. /// -# The requested address is specified but is reserved for another
  848. /// client.
  849. /// -# The requested address is in use by another client.
  850. /// -# There is a reservation for the particular client, the
  851. /// reserved address is not in use by another client and the
  852. /// requested address is different than the reserved address.
  853. /// -# There is no reservation for the client and the requested address
  854. /// is not in the dynamic pool.
  855. ///
  856. /// If none of the above occurs, the method will try to allocate the
  857. /// lease for the client using the following algorithm:
  858. /// -# If the client has a lease and the client is requesting the
  859. /// address for which it has a lease, renew its lease.
  860. /// -# If the client is requesting a different address than that for
  861. /// which it has a lease, try to allocate the requested address.
  862. /// This may fail if the address is in use by another client.
  863. /// -# If the client is not requesting any specific address, allocate
  864. /// the address from the dynamic pool.
  865. ///
  866. /// @throws various exceptions if the allocation goes wrong.
  867. ///
  868. /// @param ctx Client context holding the data extracted from the
  869. /// client's message.
  870. ///
  871. /// @return A pointer to the allocated lease, or NULL if no suitable
  872. /// lease could be allocated.
  873. Lease4Ptr requestLease4(ClientContext4& ctx);
  874. /// @brief Creates a lease and inserts it in LeaseMgr if necessary
  875. ///
  876. /// Creates a lease based on specified parameters and tries to insert it
  877. /// into the database. That may fail in some cases, e.g. when there is another
  878. /// allocation process and we lost a race to a specific lease.
  879. ///
  880. /// @param ctx client context that contains additional parameters.
  881. /// @param addr An address that was selected and is confirmed to be available
  882. ///
  883. /// In particular, the following fields from Client context are used:
  884. /// - @ref ClientContext4::subnet_ Subnet the lease is allocated from
  885. /// - @ref ClientContext4::clientid_ Client identifier
  886. /// - @ref ClientContext4::hwaddr_ Client's hardware address
  887. /// - @ref ClientContext4::fwd_dns_update_ Indicates whether forward DNS update
  888. /// will be performed for the client (true) or not (false).
  889. /// - @ref ClientContext4::rev_dns_update_ Indicates whether reverse DNS update
  890. /// will be performed for the client (true) or not (false).
  891. /// - @ref ClientContext4::hostname_ A string carrying hostname to be used for
  892. /// DNS updates.
  893. /// - @ref ClientContext4::callout_handle_ a callout handle (used in hooks).
  894. /// A lease callouts will be executed if this parameter is passed
  895. /// (and there are callouts registered)
  896. /// - @ref ClientContext4::fake_allocation_ Is this real i.e. REQUEST (false)
  897. /// or just picking an address for DISCOVER that is not really
  898. /// allocated (true)
  899. /// @return allocated lease (or NULL in the unlikely case of the lease just
  900. /// becomed unavailable)
  901. Lease4Ptr createLease4(const ClientContext4& ctx,
  902. const isc::asiolink::IOAddress& addr);
  903. /// @brief Renews a DHCPv4 lease.
  904. ///
  905. /// This method updates the lease with the information from the provided
  906. /// context and invokes the lease4_renew callout.
  907. ///
  908. /// The address of the lease being renewed is NOT updated.
  909. ///
  910. /// @param lease A lease to be renewed.
  911. /// @param ctx Message processing context. It holds various information
  912. /// extracted from the client's message and required to allocate a lease.
  913. ///
  914. /// @return Returns renewed lease. Note that the lease is only updated when
  915. /// it is an actual allocation (not processing a DHCPDISCOVER message).
  916. Lease4Ptr renewLease4(const Lease4Ptr& lease, ClientContext4& ctx);
  917. /// @brief Reuses expired DHCPv4 lease.
  918. ///
  919. /// Makes a new allocation using an expired lease. The lease is updated with
  920. /// the information from the provided context. Typically, an expired lease
  921. /// which belonged to one client may be assigned to another client
  922. /// which asked for the specific address.
  923. ///
  924. /// @param expired An old, expired lease.
  925. /// @param ctx Message processing context. It holds various information
  926. /// extracted from the client's message and required to allocate a lease.
  927. ///
  928. /// @return Updated lease instance.
  929. /// @throw BadValue if trying to reuse a lease which is still valid or
  930. /// when the provided parameters are invalid.
  931. Lease4Ptr reuseExpiredLease4(Lease4Ptr& expired, ClientContext4& ctx);
  932. /// @brief Allocates the lease by replacing an existing lease.
  933. ///
  934. /// This method checks if the lease database contains the lease for
  935. /// the specified address. If the lease exists and has expired, it
  936. /// reuses the expired lease. If the lease doesn't exist, it creates
  937. /// the new lease.
  938. ///
  939. /// @param address Requested address for which the lease should be
  940. /// allocted.
  941. /// @param ctx Client context holding the data extracted from the
  942. /// client's message.
  943. ///
  944. /// @return A pointer to the allocated lease or NULL if the allocation
  945. /// was not successful.
  946. Lease4Ptr allocateOrReuseLease4(const asiolink::IOAddress& address,
  947. ClientContext4& ctx);
  948. /// @brief Allocates the lease from the dynamic pool.
  949. ///
  950. /// This method allocates the lease from the dynamic pool. It uses
  951. /// one of the allocators to pick addresses from the pool and if the
  952. /// address appears to be available, it allocates the new lease
  953. /// using this address. The number of attempts depends on the size
  954. /// of the dynamic pool. If all of the addresses in the pool have
  955. /// been tried and all of them appeared to be in use, the allocation
  956. /// fails. This is the case when the pool is exhausted.
  957. ///
  958. /// The time required to find a suitable lease depends on the current
  959. /// pool utilization.
  960. ///
  961. /// @param ctx Client context holding the data extracted from the
  962. /// client's message.
  963. ///
  964. /// @return A pointer to the allocated lease or NULL if the allocation
  965. /// was not successful.
  966. Lease4Ptr allocateUnreservedLease4(ClientContext4& ctx);
  967. /// @brief Updates the specified lease with the information from a context.
  968. ///
  969. /// The context, specified as an argument to this method, holds various
  970. /// information gathered from the client's message and passed to the
  971. /// allocation engine. The allocation engine uses this information to make
  972. /// lease allocation decisions. Some public methods of the allocation engine
  973. /// requires updating the lease information with the data gathered from the
  974. /// context, e.g. @c AllocEngine::reuseExpiredLease requires updating the
  975. /// expired lease with fresh information from the context to create a
  976. /// lease to be held for the client.
  977. ///
  978. /// Note that this doesn't update the lease address.
  979. ///
  980. /// @warning This method doesn't check if the pointer to the lease is
  981. /// valid nor if the subnet to the pointer in the @c ctx is valid.
  982. /// The caller is responsible for making sure that they are valid.
  983. ///
  984. /// @param [out] lease A pointer to the lease to be updated.
  985. /// @param ctx A context containing information from the server about the
  986. /// client and its message.
  987. void updateLease4Information(const Lease4Ptr& lease,
  988. ClientContext4& ctx) const;
  989. };
  990. /// @brief A pointer to the @c AllocEngine object.
  991. typedef boost::shared_ptr<AllocEngine> AllocEnginePtr;
  992. }; // namespace isc::dhcp
  993. }; // namespace isc
  994. #endif // ALLOC_ENGINE_H