lease-expiration.xml 15 KB

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