lease-expiration.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="lease-expiration">
  7. <title>Lease Expiration in DHCPv4 and DHCPv6</title>
  8. <para>The primary role of the DHCP server is to assign addresses and/or
  9. delegate prefixes to DHCP clients. These addresses and prefixes are
  10. often referred to as "leases". Leases are typically assigned to clients
  11. for a finite amount of time, known as the "valid lifetime". DHCP clients who
  12. wish to continue using their assigned leases, will periodically renew them
  13. by sending the appropriate message to the DHCP server. The DHCP server records
  14. the time when these leases are renewed and calculates new expiration times
  15. for them.
  16. </para>
  17. <para>If the client does not renew a lease before its valid lifetime
  18. elapses, the lease is considered expired. There are many situations
  19. when the client may cease lease renewals. A common scenario is when
  20. the machine running the client shuts down for an extended period of
  21. time.</para>
  22. <para> The process through which the DHCP server makes expired leases
  23. available for reassignment is referred to as "lease reclamation" and expired
  24. leases returned to availability through this process are referred to as
  25. "reclaimed".
  26. The DHCP server attempts to reclaim an expired lease as soon as it detects
  27. that it has expired. One way in which the server detects expiration occurs
  28. when it is trying to allocate a lease to a client and finds this
  29. lease already present in the database but expired. Another way
  30. is by periodically querying the lease
  31. database for them. Regardless of how an expired lease is detected, before
  32. it may assigned to a client, it must be reclaimed.
  33. </para>
  34. <para>
  35. This chapter explains how to configure the server to periodically query
  36. for the expired leases and how to minimize the impact of the periodic lease
  37. reclamation process on the server's responsiveness. Finally, it explains
  38. "lease affinity", which provides the means to assign the same lease to a
  39. returning client after its lease has expired.
  40. </para>
  41. <para>Although, all configuration examples in this section are provided
  42. for the DHCPv4 server, the same parameters may be used for the
  43. DHCPv6 server configuration.
  44. </para>
  45. <section id="lease-reclamation">
  46. <title>Lease Reclamation</title>
  47. <para>Lease reclamation is the process through which an expired lease
  48. becomes available for assignment to the same or different client.
  49. This process involves the following steps for each reclaimed lease:
  50. </para>
  51. <itemizedlist>
  52. <listitem>
  53. <simpara>Invoke callouts for the <command>lease4_expire</command> or
  54. <command>lease6_expire</command> hook points if hook libraries
  55. supporting those callouts are currently loaded.</simpara>
  56. </listitem>
  57. <listitem>
  58. <simpara>Update DNS, i.e. remove any DNS entries associated with
  59. the expired lease.</simpara>
  60. </listitem>
  61. <listitem>
  62. <simpara>Update lease information in the lease database to
  63. indicate that the lease is now available for re-assignment.</simpara>
  64. </listitem>
  65. <listitem>
  66. <simpara>Update counters on the server, which includes
  67. increasing the number of reclaimed leases and decreasing the
  68. number of assigned addresses or delegated prefixes.</simpara>
  69. </listitem>
  70. </itemizedlist>
  71. <para>Please refer to <xref linkend="dhcp-ddns-server"/> to see
  72. how to configure DNS updates in Kea, and to
  73. <xref linkend="hooks-libraries"/> for information about using
  74. hooks libraries.</para>
  75. </section>
  76. <section id="lease-reclaim-config">
  77. <title>Configuring Lease Reclamation</title>
  78. <para>Kea can be configured to periodically detect and reclaim expired
  79. leases. During this process the lease entries in the database are
  80. modified or removed. While this is happening the server will not process incoming DHCP
  81. messages to avoid issues with concurrent access to database information.
  82. As a result, the server will be unresponsive while lease reclamation
  83. is performed and DHCP queries will accumulate; responses will be
  84. sent once the leases reclamation cycle is complete.</para>
  85. <para>In deployments where response time is critical, administrators may
  86. wish to minimize the interruptions in service caused by lease reclamation.
  87. Toward this end, Kea provides configuration parameters to control: the
  88. frequency of lease reclamation cycles, the maximum number of leases
  89. processed in a single reclamation cycle, and the maximum amount of time a
  90. single reclamation cycle is allowed to run before being interrupted. The
  91. following examples demonstrate how these parameters can be used:
  92. <screen>
  93. "Dhcp4": {
  94. ...
  95. "expired-leases-processing": {
  96. "reclaim-timer-wait-time": 5,
  97. "max-reclaim-leases": 0,
  98. "max-reclaim-time": 0,
  99. "flush-reclaimed-timer-wait-time": 0,
  100. },
  101. ...
  102. }
  103. </screen>
  104. </para>
  105. <para>The first parameter is expressed in seconds and specifies an
  106. interval between the two consecutive lease reclamation cycles. This
  107. is explained by the following diagram.
  108. <screen>
  109. | c1 | | c2 | |c3| | c4 |
  110. |&#x3c;----&#x3e;|&#x3c;----------&#x3e;|&#x3c;--&#x3e;|&#x3c;----------&#x3e;|&#x3c;&#x3e;|&#x3c;----------&#x3e;|&#x3c;--&#x3e;|
  111. ---------------------------------------------------------------->
  112. | | 5s | | 5s | | 5s | | time
  113. </screen>
  114. </para>
  115. <para>This diagram shows four lease reclamation cycles (c1 through c4) of variable duration.
  116. Note that the duration of the reclamation cycle depends on the number
  117. of expired leases detected and processed in the particular cycle. This
  118. duration is also usually significantly shorter than the interval between
  119. the cycles.
  120. </para>
  121. <para>According to the <command>reclaim-timer-wait-time</command> the
  122. server keeps fixed intervals of five seconds between the end of one cycle
  123. and the start of the next cycle. This guarantees the presence of
  124. 5s long periods during which the server remains responsive to DHCP
  125. queries and does not perform lease reclamation. The
  126. <command>max-reclaim-leases</command> and
  127. <command>max-reclaim-time</command> are set to 0, which sets
  128. no restriction on the maximum number of leases reclaimed
  129. in the particular cycle, or on the maximum duration of each cycle.
  130. </para>
  131. <para>In deployments with high lease pool utilization, relatively
  132. short valid lifetimes, and frequently disconnecting clients which
  133. allow leases to expire, the number of expired leases requiring reclamation
  134. at any given time may rise significantly. In this case it is often
  135. desirable to apply restrictions on the maximum duration of a reclamation
  136. cycle or the maximum number of leases reclaimed in a cycle. The following
  137. configuration demonstrates how this can be done:
  138. <screen>
  139. "Dhcp4": {
  140. ...
  141. "expired-leases-processing": {
  142. "reclaim-timer-wait-time": 3,
  143. "max-reclaim-leases": 100,
  144. "max-reclaim-time": 50,
  145. "unwarned-reclaim-cycles": 10,
  146. },
  147. ...
  148. }
  149. </screen>
  150. </para>
  151. <para>The <command>max-reclaim-leases</command> parameter limits the number
  152. of leases reclaimed in a single cycle to 100. The
  153. <command>max-reclaim-time</command> limits the maximum duration of each
  154. cycle to 50ms. The lease reclamation cycle will be interrupted if either
  155. of these limitations is reached. The reclamation of all unreclaimed
  156. leases will be attempted in subsequent cycles.</para>
  157. <para>The following diagram illustrates the behavior of the system in the
  158. presence of many expired leases, when the limits are applied for the
  159. reclamation cycles.
  160. <screen>
  161. | c1 | | c2 | | c3 | | c4 |
  162. |&#x3c;--&#x3e;|&#x3c;--------------&#x3e;|&#x3c;--&#x3e;|&#x3c;--------------&#x3e;|&#x3c;--&#x3e;|&#x3c;--------------&#x3e;|&#x3c;--&#x3e;|&#x3c;--
  163. ------------------------------------------------------------------------------>
  164. |50ms| 3s |50ms| 3s |50ms| 3s |50ms| time
  165. </screen>
  166. </para>
  167. <para>The diagram demonstrates the case when each reclamation cycle would take
  168. more than 50ms, and thus is interrupted according to the value of the
  169. <command>max-reclaim-time</command>. This results in equal durations of
  170. all reclamation cycles over time. Note that in this example the limitation
  171. of maximum 100 leases is not reached. This may be the case when database
  172. transactions are slow or callouts in the hook libraries attached to
  173. the server are slow. Regardless, the choosing values for either the
  174. maximum number of leases or a maximum cycle time strongly depends on the
  175. particular deployment, lease database backend being used, and any hooks
  176. libraries etc. Administrators may need to experiment to tune the system
  177. to suit the dynamics of their deployment.</para>
  178. <para>It is important to realize that with the use of these limits, there
  179. is a risk that expired leases will accumulate faster than the server can
  180. reclaim them. This should not be the problem if the server is dealing
  181. with a temporary burst of expirations, because it should be able to
  182. eventually deal with them over time. However, if leases expire at a high
  183. rate for a longer period of time, the unreclaimed leases will pile up in
  184. the database. In order to notify the administrator that the current
  185. configuration does not satisfy the needs for reclamation of expired
  186. leases, the server issues a warning message in the log if it was unable
  187. to reclaim all leases within the last couple of reclamation cycles. The
  188. number of cycles after which such warning is issued is specified with the
  189. <command>unwarned-reclaim-cycles</command> configuration parameter.
  190. </para>
  191. <para>Setting the <command>reclaim-timer-wait-time</command> to 0 disables
  192. periodic reclamation of the expired leases.</para>
  193. </section>
  194. <section id="lease-affinity">
  195. <title>Configuring Lease Affinity</title>
  196. <para>Suppose that a laptop goes to a sleep mode after a period of user
  197. inactivity. While the laptop is in sleep mode, its DHCP client will not
  198. renew leases obtained from the server and these leases will eventually
  199. expire. When the laptop wakes up, it is often desirable for it to continue
  200. using its previous assigned IP addresses. In order to facilitate this,
  201. the server needs to correlate returning clients with their expired leases
  202. When the client returns, the server will first check for those leases and
  203. re-assign them if they have not been assigned to another client. The ability
  204. of the server to re-assign the same lease to a returning client is
  205. referred to as "lease affinity".
  206. </para>
  207. <para>When lease affinity is enabled, the server will still
  208. reclaim leases according to the parameters described in
  209. <xref linkend="lease-reclaim-config"/>, but the reclaimed leases
  210. will be held in the database (rather than removed) for the specified
  211. amount of time. When the client returns, the server will first check
  212. if there are any reclaimed leases associated with this client and
  213. re-assign them if possible. However, it is important to note that
  214. any reclaimed lease may be assigned to another client if that client
  215. specifically asks for it. Therefore, the lease affinity does not
  216. guarantee that the reclaimed lease will be available for the client
  217. who used it before; it merely increases the chances for the client to
  218. be assigned the same lease. If the lease pool is small (this mostly applies
  219. to DHCPv4 for which address space is small), there is an increased
  220. likelihood that the expired lease will be assigned to another client.
  221. </para>
  222. <para>Consider the following configuration:
  223. <screen>
  224. "Dhcp4": {
  225. ...
  226. "expired-leases-processing": {
  227. "reclaim-timer-wait-time": 3,
  228. "hold-reclaimed-time": 1800,
  229. "flush-reclaimed-timer-wait-time": 5
  230. },
  231. ...
  232. }
  233. </screen>
  234. </para>
  235. <para>The <command>hold-reclaim-time</command> specifies how many seconds
  236. after an expiration a reclaimed lease should be held in the database
  237. for re-assignment to the same client. In the example given above,
  238. reclaimed leases will be held for 30 minutes (1800s) after their
  239. expiration. During this time, the server will likely be able to
  240. re-assign the same lease to the returning client, unless another client
  241. requests this lease and the server assigns it.</para>
  242. <para>The server must periodically remove reclaimed leases for which the
  243. time indicated by <command>hold-reclaim-time</command> has elapsed. The
  244. <command>flush-reclaimed-timer-wait-time</command> controls how
  245. often the server removes such leases. In the example provided
  246. above, the server will initiate removal of such leases 5 seconds after
  247. the previous removal attempt was completed. Setting this value to 0
  248. disables lease affinity, in which case leases will be removed from the
  249. lease database when they are reclaimed. If lease affinity is enabled, it
  250. is recommended that <command>hold-reclaim-time</command> be set to a value significantly
  251. higher than the <command>reclaim-timer-wait-time</command>, as timely
  252. removal of expired-reclaimed leases is less critical while the removal
  253. process may impact server responsiveness.</para>
  254. </section>
  255. <section id="lease-reclamation-defaults">
  256. <title>Default Configuration Values for Leases Reclamation</title>
  257. <para>The following list presents all configuration parameters
  258. pertaining to processing expired leases with their default values:</para>
  259. <itemizedlist>
  260. <listitem>
  261. <simpara><command>reclaim-timer-wait-time</command> = 10 [seconds]</simpara>
  262. </listitem>
  263. <listitem>
  264. <simpara><command>flush-reclaimed-timer-wait-time</command> = 25 [seconds]</simpara>
  265. </listitem>
  266. <listitem>
  267. <simpara><command>hold-reclaimed-time</command> = 3600 [seconds]</simpara>
  268. </listitem>
  269. <listitem>
  270. <simpara><command>max-reclaim-leases</command> = 100 </simpara>
  271. </listitem>
  272. <listitem>
  273. <simpara><command>max-reclaim-time</command> = 250 [milliseconds]</simpara>
  274. </listitem>
  275. <listitem>
  276. <simpara><command>unwarned-reclaim-cycles</command> = 5</simpara>
  277. </listitem>
  278. </itemizedlist>
  279. <para>The default value for any parameter is used when this parameter not
  280. explicitly specified in the configuration. Also, the
  281. <command>expired-leases-processing</command> map may be omitted entirely
  282. in the configuration, in which case the default values are used for all
  283. parameters listed above.</para>
  284. </section>
  285. <section id="leases-reclamation-using-command">
  286. <title>Reclaiming Expired Leases with Command</title>
  287. <para>The <emphasis>leases-reclaim</emphasis> command can be used to trigger
  288. leases reclamation at any time. Please consult the
  289. <xref linkend="command-leases-reclaim"/> for the details about using this
  290. command.</para>
  291. </section>
  292. </chapter>