libdhcpsrv.dox 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright (C) 2012 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) stores configuration information
  35. necessary for DHCPv4 and DHCPv6 server operation. In particular, it stores
  36. subnets (\ref isc::dhcp::Subnet4 and \ref isc::dhcp::Subnet6) together with
  37. their pools (\ref isc::dhcp::Pool4 and \ref isc::dhcp::Pool6), options and
  38. other information specified by the used in BIND10 configuration.
  39. @section allocengine Allocation Engine
  40. Allocation Engine (\ref isc::dhcp::AllocEngine) is what its name say - an engine
  41. that handles allocation of new leases. It takes parameters that the client
  42. provided (client-id, DUID, subnet, a hint if the user provided one, etc.) and
  43. then attempts to allocate a lease.
  44. There is no single best soluction to the address assignment problem. Server
  45. is expected to pick an address from its available pools is currently not used.
  46. There are many possible algorithms that can do that, each with its own advantages
  47. and drawbacks. This allocation engine must provide robust operation is radically
  48. different scenarios, so there address selection problem was abstracted into
  49. separate module, called allocator. Its sole purpose is to pick an address from
  50. a pool. Allocation engine will then check if the picked address is free and if
  51. it is not, then will ask allocator to pick again.
  52. At least 3 allocators will be implemented:
  53. - Iterative - it iterates over all resources (addresses or prefixes) in
  54. available pools, one by one. The advantages of this approach are: speed
  55. (typically it only needs to increase address just one), the guarantee to cover
  56. all addresses and predictability. This allocator behaves reasonably good in
  57. case of nearing depletion. Even when pools are almost completely allocated, it
  58. still will be able to allocate outstanding leases efficiently. Predictability
  59. can also be considered a serious flaw in some environments, as prediction of the
  60. next address is trivial and can be leveraged by an attacker. Another drawback of
  61. this allocator is that it does not attempt to give the same address to returning
  62. clients (clients that released or expired their leases and are requesting a new
  63. lease will likely to get a different lease). This allocator is not suitable for
  64. temporary addresses, which must be randomized. This allocator is implemented
  65. in \ref isc::dhcp::AllocEngine::IterativeAllocator.
  66. - Hashed - ISC-DHCP uses hash of the client-id or DUID to determine, which
  67. address is tried first. If that address is not available, the result is hashed
  68. again. That procedure is repeated until available address is found or there
  69. are no more addresses left. The benefit of that approach is that it provides
  70. a relative lease stability, so returning old clients are likely to get the same
  71. address again. The drawbacks are increased computation cost, as each iteration
  72. requires use of a hashing function. That is especially difficult when the
  73. pools are almost depleted. It also may be difficult to guarantee that the
  74. repeated hashing will iterate over all available addresses in all pools. Flawed
  75. hash algorithm can go into cycles that iterate over only part of the addresses.
  76. It is difficult to detect such issues as only some initial seed (client-id
  77. or DUID) values may trigger short cycles. This allocator is currently not
  78. implemented. This will be the only allocator allowed for temporary addresses.
  79. - Random - Another possible approach to address selection is randomization. This
  80. allocator can pick an address randomly from the configured pool. The benefit
  81. of this approach is that it is easy to implement and makes attacks based on
  82. address prediction more difficult. The drawback of this approach is that
  83. returning clients are almost guaranteed to get a different address. Another
  84. drawback is that with almost depleted pools it is increasingly difficult to
  85. "guess" an address that is free. This allocator is currently not implemented.
  86. @subsection allocEngineTypes Different lease types support
  87. Allocation Engine has been extended to support different types of leases. Four
  88. types are supported: TYPE_V4 (IPv4 addresses), TYPE_NA (normal IPv6 addresses),
  89. TYPE_TA (temporary IPv6 addresses) and TYPE_PD (delegated prefixes). Support for
  90. TYPE_TA is partial. Some routines are able to handle it, while other are
  91. not. The major missing piece is the RandomAllocator, so there is no way to randomly
  92. generate an address. This defeats the purpose of using temporary addresses for now.
  93. @subsection allocEnginePD Prefix Delegation support in AllocEngine
  94. The Allocation Engine supports allocation of the IPv6 addresses and prefixes.
  95. For a prefix pool, the iterative allocator "walks over"
  96. every available pool. It is similar to how it iterates over address pool,
  97. but instead of increasing address by just one, it walks over the whole delegated
  98. prefix length in one step. This is implemented in
  99. isc::dhcp::AllocEngine::IterativeAllocator::increasePrefix(). Functionally the
  100. increaseAddress(addr) call is equivalent to increasePrefix(addr, 128)
  101. (increasing by a /128 prefix, i.e. a single address). However, both methods are
  102. kept, because increaseAddress() is faster and this is a routine that may be
  103. called many hundred thousands times per second.
  104. */