libdhcpsrv.dox 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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::Configuration object. Internally, the Configuration Manager
  38. holds a list of \ref isc::dhcp::Configuration 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::Configuration 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::Configuration object from the Configuration Manager. When
  55. the \ref isc::dhcp::CfgMgr::getStagingCfg is called again a fresh/default
  56. \ref isc::dhcp::Configuration 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::Configuration object. Kea developers are actively working
  69. on migrating the other configuration parameters to it.
  70. @section allocengine Allocation Engine
  71. Allocation Engine (\ref isc::dhcp::AllocEngine) is what its name say - an engine
  72. that handles allocation of new leases. It takes parameters that the client
  73. provided (client-id, DUID, subnet, a hint if the user provided one, etc.) and
  74. then attempts to allocate a lease.
  75. There is no single best soluction to the address assignment problem. Server
  76. is expected to pick an address from its available pools is currently not used.
  77. There are many possible algorithms that can do that, each with its own advantages
  78. and drawbacks. This allocation engine must provide robust operation is radically
  79. different scenarios, so there address selection problem was abstracted into
  80. separate module, called allocator. Its sole purpose is to pick an address from
  81. a pool. Allocation engine will then check if the picked address is free and if
  82. it is not, then will ask allocator to pick again.
  83. At least 3 allocators will be implemented:
  84. - Iterative - it iterates over all resources (addresses or prefixes) in
  85. available pools, one by one. The advantages of this approach are: speed
  86. (typically it only needs to increase address just one), the guarantee to cover
  87. all addresses and predictability. This allocator behaves reasonably good in
  88. case of nearing depletion. Even when pools are almost completely allocated, it
  89. still will be able to allocate outstanding leases efficiently. Predictability
  90. can also be considered a serious flaw in some environments, as prediction of the
  91. next address is trivial and can be leveraged by an attacker. Another drawback of
  92. this allocator is that it does not attempt to give the same address to returning
  93. clients (clients that released or expired their leases and are requesting a new
  94. lease will likely to get a different lease). This allocator is not suitable for
  95. temporary addresses, which must be randomized. This allocator is implemented
  96. in \ref isc::dhcp::AllocEngine::IterativeAllocator.
  97. - Hashed - ISC-DHCP uses hash of the client-id or DUID to determine, which
  98. address is tried first. If that address is not available, the result is hashed
  99. again. That procedure is repeated until available address is found or there
  100. are no more addresses left. The benefit of that approach is that it provides
  101. a relative lease stability, so returning old clients are likely to get the same
  102. address again. The drawbacks are increased computation cost, as each iteration
  103. requires use of a hashing function. That is especially difficult when the
  104. pools are almost depleted. It also may be difficult to guarantee that the
  105. repeated hashing will iterate over all available addresses in all pools. Flawed
  106. hash algorithm can go into cycles that iterate over only part of the addresses.
  107. It is difficult to detect such issues as only some initial seed (client-id
  108. or DUID) values may trigger short cycles. This allocator is currently not
  109. implemented. This will be the only allocator allowed for temporary addresses.
  110. - Random - Another possible approach to address selection is randomization. This
  111. allocator can pick an address randomly from the configured pool. The benefit
  112. of this approach is that it is easy to implement and makes attacks based on
  113. address prediction more difficult. The drawback of this approach is that
  114. returning clients are almost guaranteed to get a different address. Another
  115. drawback is that with almost depleted pools it is increasingly difficult to
  116. "guess" an address that is free. This allocator is currently not implemented.
  117. @subsection allocEngineTypes Different lease types support
  118. Allocation Engine has been extended to support different types of leases. Four
  119. types are supported: TYPE_V4 (IPv4 addresses), TYPE_NA (normal IPv6 addresses),
  120. TYPE_TA (temporary IPv6 addresses) and TYPE_PD (delegated prefixes). Support for
  121. TYPE_TA is partial. Some routines are able to handle it, while other are
  122. not. The major missing piece is the RandomAllocator, so there is no way to randomly
  123. generate an address. This defeats the purpose of using temporary addresses for now.
  124. @subsection allocEnginePD Prefix Delegation support in AllocEngine
  125. The Allocation Engine supports allocation of the IPv6 addresses and prefixes.
  126. For a prefix pool, the iterative allocator "walks over"
  127. every available pool. It is similar to how it iterates over address pool,
  128. but instead of increasing address by just one, it walks over the whole delegated
  129. prefix length in one step. This is implemented in
  130. isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(). Functionally the
  131. increaseAddress(addr) call is equivalent to increasePrefix(addr, 128)
  132. (increasing by a /128 prefix, i.e. a single address). However, both methods are
  133. kept, because increaseAddress() is faster and this is a routine that may be
  134. called many hundred thousands times per second.
  135. */