libdhcpsrv.dox 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Copyright (C) 2012, 2014 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. /**
  15. @page libdhcpsrv libdhcpsrv - Server DHCP library
  16. This library contains code useful for DHCPv4 and DHCPv6 server operations, like
  17. Lease Manager that stores leases information, configuration manager that stores
  18. configuration etc. The code here is server specific. For generic (useful in
  19. server, client, relay and other tools like perfdhcp) code, please see
  20. \ref libdhcp.
  21. This library contains several crucial elements of the DHCP server operation:
  22. - isc::dhcp::LeaseMgr - Lease Manager is a name for database backend that stores
  23. leases.
  24. - isc::dhcp::CfgMgr - Configuration Manager that holds DHCP specific
  25. configuration information (subnets, pools, options, timer values etc.) in
  26. easy to use format.
  27. - AllocEngine - allocation engine that handles new requestes and allocates new
  28. leases.
  29. @section leasemgr Lease Manager
  30. LeaseMgr provides a common, unified abstract API for all database backends. All
  31. backends are derived from the base class isc::dhcp::LeaseMgr. Currently the
  32. only available backend is MySQL (see \ref isc::dhcp::MySqlLeaseMgr).
  33. @section cfgmgr Configuration Manager
  34. Configuration Manager (\ref isc::dhcp::CfgMgr) is a singleton object which
  35. holds configuration information necessary for the operation of Kea daemons.
  36. A complete collection of information for the daemon is stored in the
  37. \ref isc::dhcp::SrvConfig object. Internally, the Configuration Manager
  38. holds a list of \ref isc::dhcp::SrvConfig objects, from which one
  39. is marked as "current configuration".
  40. When the server starts up or is being reconfigured a new
  41. \ref isc::dhcp::SrvConfig object, referred to as "staging configuration",
  42. is created. The staging configuration is held at the tip of the list of
  43. configurations. The object can be accessed by calling the
  44. \ref isc::dhcp::CfgMgr::getStagingCfg. This object can be accessed
  45. from different stages of the configuration parsing and modified as needed.
  46. Modifications of the staging configuration do not affect the current
  47. configuration. The staging configuration is unused until the
  48. \ref isc::dhcp::CfgMgr::commit function is called. This exception safe method
  49. marks the staging object as "current configuration". The const pointer to the
  50. current configuration can be accessed by calling a
  51. \ref isc::dhcp::CfgMgr::getCurrentCfg.
  52. The staging configuration can be discarded at any time before it is committed
  53. by calling the \ref isc::dhcp::CfgMgr::rollback. This removes the
  54. \ref isc::dhcp::SrvConfig object from the Configuration Manager. When
  55. the \ref isc::dhcp::CfgMgr::getStagingCfg is called again a fresh/default
  56. \ref isc::dhcp::SrvConfig object is returned.
  57. The Configuration Manager stores previous configurations, i.e. configurations
  58. which occurred prior to the most current configuration. This is currently
  59. unused (except for unit tests) by the deamons, but in the future this
  60. mechanism can be used to trigger a rollover of the server configuration
  61. to a last good configuration that the administrator prefers.
  62. The previous configurations are identified by the value which specifies a
  63. distance between the current configuration and the previous
  64. configuration. For example: the value of 1 identifies an immediate
  65. predecessor of the current configuration, the value of 2 identifies the
  66. one that occurred before it etc.
  67. @todo Currently, only a subset of configuration information is stored in
  68. the \ref isc::dhcp::SrvConfig object. Kea developers are actively working
  69. on migrating the other configuration parameters to it.
  70. @section hostmgr Host Manager
  71. Host Manager implemented by the \ref isc::dhcp::HostMgr is a singleton object
  72. which provides means to retrieve resources statically assigned to the DHCP
  73. clients, such as IP addresses, prefixes or hostnames. The statically assigned
  74. resources are called reservations (or host reservations) and they are
  75. represented in the code by the \ref isc::dhcp::Host class.
  76. The reservations can be specified in the configuration file or in some
  77. other storage (typically in a database). A dedicated object, called
  78. host data source, is needed to retrieve the host reservations from the
  79. database. This object must implement the \ref isc::dhcp::BaseHostDataSource
  80. interface and its implementation is specific to the type of storage
  81. holding the reservations. For example, the host data source managing
  82. host reservations in the MySQL database is required to establish
  83. connection to the MySQL databse and issue specific queries. Once
  84. implemented, the \ref isc::dhcp::HostMgr::create method must be updated
  85. to create an instance of this datasource. Note, that this instance is
  86. created as "alternate host data source" as opposed to the primary data
  87. source which returns host reservations specified in the configuration file.
  88. The primary data source is implemented internally in the
  89. \ref isc::dhcp::HostMgr and uses the configuration data structures held by
  90. the \ref isc::dhcp::CfgMgr to retrieve the reservations. In general, the
  91. \ref isc::dhcp::HostMgr first searches for the reservations using the
  92. primary data source and falls back to the use of alternate data source
  93. when nothing has been found. For those methods which are meant to return
  94. multiple reservations (e.g. find all reservations for the particular
  95. client), the \ref isc::dhcp::HostMgr will use both primary and alternate
  96. data source (if present) and concatenate results.
  97. For more information about the \ref isc::dhcp::HostMgr please refer to its
  98. documentation.
  99. @section optionsConfig Options Configuration Information
  100. The \ref isc::dhcp::CfgOption object holds a collection of options being
  101. sent to the client. Since each subnet comes with a distnict set of
  102. options, every \ref isc::dhcp::Subnet object holds its own copy of the
  103. \ref isc::dhcp::CfgOption object with specific options.
  104. The DHCP server also allows for configuration of "global" options
  105. which are shared by all subnets. The rule here is that if a particular
  106. option appears in the global options set and the subnet specific options
  107. set, the subnet specific option takes precedence. The global options
  108. configuration is held in the dedicated instance of the
  109. \ref isc::dhcp::CfgOption class. This instance is owned by the
  110. \ref isc::dhcp::SrvConfig class.
  111. When the new configuration is parsed, the global options are merged into
  112. the \ref isc::dhcp::CfgOption instances for all subnets. This is
  113. causing some overhead during the reconfiguration of the server but on
  114. the other hand it avoids the lookup of options in two places (among
  115. subnet specific options and global options) during each packet
  116. processing.
  117. One of the benefits of keeping a separate set of global options is
  118. that there may be cases when the server administrator doesn't specify
  119. any subnet configuration and only wants global options to be used.
  120. This is the case, when the DHCP server is used for stateless
  121. configuration, i.e. client's are not allocated an address or prefix,
  122. and only stateless configruation is handed out.
  123. @section allocengine Allocation Engine
  124. Allocation Engine (\ref isc::dhcp::AllocEngine) is what its name say - an engine
  125. that handles allocation of new leases. It takes parameters that the client
  126. provided (client-id, DUID, subnet, a hint if the user provided one, etc.) and
  127. then attempts to allocate a lease.
  128. There is no single best solution to the address assignment problem. Server
  129. is expected to pick an address from its available pools is currently not used.
  130. There are many possible algorithms that can do that, each with its own advantages
  131. and drawbacks. This allocation engine must provide robust operation is radically
  132. different scenarios, so there address selection problem was abstracted into
  133. separate module, called allocator. Its sole purpose is to pick an address from
  134. a pool. Allocation engine will then check if the picked address is free and if
  135. it is not, then will ask allocator to pick again.
  136. At least 3 allocators will be implemented:
  137. - Iterative - it iterates over all resources (addresses or prefixes) in
  138. available pools, one by one. The advantages of this approach are: speed
  139. (typically it only needs to increase address just one), the guarantee to cover
  140. all addresses and predictability. This allocator behaves reasonably good in
  141. case of nearing depletion. Even when pools are almost completely allocated, it
  142. still will be able to allocate outstanding leases efficiently. Predictability
  143. can also be considered a serious flaw in some environments, as prediction of the
  144. next address is trivial and can be leveraged by an attacker. Another drawback of
  145. this allocator is that it does not attempt to give the same address to returning
  146. clients (clients that released or expired their leases and are requesting a new
  147. lease will likely to get a different lease). This allocator is not suitable for
  148. temporary addresses, which must be randomized. This allocator is implemented
  149. in \ref isc::dhcp::AllocEngine::IterativeAllocator.
  150. - Hashed - ISC-DHCP uses hash of the client-id or DUID to determine, which
  151. address is tried first. If that address is not available, the result is hashed
  152. again. That procedure is repeated until available address is found or there
  153. are no more addresses left. The benefit of that approach is that it provides
  154. a relative lease stability, so returning old clients are likely to get the same
  155. address again. The drawbacks are increased computation cost, as each iteration
  156. requires use of a hashing function. That is especially difficult when the
  157. pools are almost depleted. It also may be difficult to guarantee that the
  158. repeated hashing will iterate over all available addresses in all pools. Flawed
  159. hash algorithm can go into cycles that iterate over only part of the addresses.
  160. It is difficult to detect such issues as only some initial seed (client-id
  161. or DUID) values may trigger short cycles. This allocator is currently not
  162. implemented. This will be the only allocator allowed for temporary addresses.
  163. - Random - Another possible approach to address selection is randomization. This
  164. allocator can pick an address randomly from the configured pool. The benefit
  165. of this approach is that it is easy to implement and makes attacks based on
  166. address prediction more difficult. The drawback of this approach is that
  167. returning clients are almost guaranteed to get a different address. Another
  168. drawback is that with almost depleted pools it is increasingly difficult to
  169. "guess" an address that is free. This allocator is currently not implemented.
  170. @subsection allocEngineTypes Different lease types support
  171. Allocation Engine has been extended to support different types of leases. Four
  172. types are supported: TYPE_V4 (IPv4 addresses), TYPE_NA (normal IPv6 addresses),
  173. TYPE_TA (temporary IPv6 addresses) and TYPE_PD (delegated prefixes). Support for
  174. TYPE_TA is partial. Some routines are able to handle it, while other are
  175. not. The major missing piece is the RandomAllocator, so there is no way to randomly
  176. generate an address. This defeats the purpose of using temporary addresses for now.
  177. @subsection allocEnginePD Prefix Delegation support in AllocEngine
  178. The Allocation Engine supports allocation of the IPv6 addresses and prefixes.
  179. For a prefix pool, the iterative allocator "walks over"
  180. every available pool. It is similar to how it iterates over address pool,
  181. but instead of increasing address by just one, it walks over the whole delegated
  182. prefix length in one step. This is implemented in
  183. isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(). Functionally the
  184. increaseAddress(addr) call is equivalent to increasePrefix(addr, 128)
  185. (increasing by a /128 prefix, i.e. a single address). However, both methods are
  186. kept, because increaseAddress() is faster and this is a routine that may be
  187. called many hundred thousands times per second.
  188. */