dhcp4.dox 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 dhcp4 DHCPv4 Server Component
  16. BIND10 offers DHCPv4 server implementation. It is implemented as
  17. b10-dhcp4 component. Its primary code is located in
  18. isc::dhcp::Dhcpv4Srv class. It uses \ref libdhcp extensively,
  19. especially isc::dhcp::Pkt4, isc::dhcp::Option and
  20. isc::dhcp::IfaceMgr classes. Currently this code offers skeleton
  21. functionality, i.e. it is able to receive and process incoming
  22. requests and trasmit responses. However, it does not have database
  23. management, so it returns only one, hardcoded lease to whoever asks
  24. for it.
  25. DHCPv4 server component does not support direct traffic (relayed
  26. only), as support for transmission to hosts without IPv4 address
  27. assigned is not implemented in IfaceMgr yet.
  28. @section dhcpv4Session BIND10 message queue integration
  29. DHCPv4 server component is now integrated with BIND10 message queue.
  30. The integration is performed by establishSession() and disconnectSession()
  31. functions in isc::dhcp::ControlledDhcpv4Srv class. main() method defined
  32. in the src/bin/dhcp4/main.cc file instantiates isc::dhcp::ControlledDhcpv4Srv
  33. class that establishes connection with msgq and install necessary handlers
  34. for receiving commands and configuration updates. It is derived from
  35. a base isc::dhcp::Dhcpv4Srv class that implements DHCPv4 server functionality,
  36. without any controlling mechanisms.
  37. ControlledDhcpv4Srv instantiates several components to make management
  38. session possible. In particular, isc::cc::Session cc_session
  39. object uses ASIO for establishing connection. It registers its socket
  40. in isc::asiolink::IOService io_service object. Typically, other components
  41. (e.g. auth or resolver) that use ASIO for their communication, register their
  42. other sockets in the
  43. same io_service and then just call io_service.run() method that does
  44. not return, until one of the callback decides that it is time to shut down
  45. the whole component cal calls io_service.stop(). DHCPv4 works in a
  46. different way. It does receive messages using select()
  47. (see isc::dhcp::IfaceMgr::receive4()), which is incompatible with ASIO.
  48. To solve this problem, socket descriptor is extracted from cc_session
  49. object and is passed to IfaceMgr by using isc::dhcp::IfaceMgr::set_session_socket().
  50. IfaceMgr then uses this socket in its select() call. If there is some
  51. data to be read, it calls registered callback that is supposed to
  52. read and process incoming data.
  53. This somewhat complicated approach is needed for a simple reason. In
  54. embedded deployments there will be no message queue. Not referring directly
  55. to anything related to message queue in isc::dhcp::Dhcpv4Srv and
  56. isc::dhcp::IfaceMgr classes brings in two benefits. First, the can
  57. be used with and without message queue. Second benefit is related to the
  58. first one: \ref libdhcp is supposed to be simple and robust and not require
  59. many dependencies. One notable example of a use case that benefits from
  60. this approach is a perfdhcp tool. Finally, the idea is that it should be
  61. possible to instantiate Dhcpv4Srv object directly, thus getting a server
  62. that does not support msgq. That is useful for embedded environments.
  63. It may also be useful in validation.
  64. @section dhcpv4ConfigParser Configuration Parser in DHCPv4
  65. This parser follows exactly the same logic as its DHCPv6 counterpart.
  66. See \ref dhcpv6ConfigParser.
  67. @section dhcpv4ConfigInherit DHCPv4 configuration inheritance
  68. Configuration inheritance in DHCPv4 follows exactly the same logic as its DHCPv6
  69. counterpart. See \ref dhcpv6ConfigInherit.
  70. @section dhcpv4OptionsParse Custom functions to parse message options
  71. The DHCPv4 server uses the same logic to supply custom callback function to
  72. parse message option as DHCPv6 server implementation. See \ref dhcpv6OptionsParse.
  73. @section dhcpv4DDNSIntegration DHCPv4 Server Support for the Dynamic DNS Updates
  74. T
  75. he DHCPv4 server supports processing of the DHCPv4 Client FQDN option (RFC4702)
  76. and the DHCPv4 Host Name option (RFC2132). Client may send one of these options
  77. to convey its fully qualified or partial name to the server. The server may use
  78. this name to perform DNS updates for the client. If server receives both options
  79. in the same message, the DHCPv4 Client FQDN %Option is processed and the Host
  80. Name option is ignored. If only Host Name Option is present in the client's
  81. message, it is used to update DNS.
  82. Server may be configured to use a different name to perform DNS update for the
  83. client. In this case the server will return one of the DHCPv4 Client FQDN or
  84. Host Name %Option in its response with the name which was selected for the
  85. client to indicate that this name will be used to perform DNS update.
  86. The b10-dhcp-ddns process is responsible for the actual communication with the
  87. DNS, i.e. to send DNS update messages. The b10-dhcp4 module is responsible for
  88. generating @ref isc::dhcp_ddns::NameChangeRequest and sending it to
  89. the b10-dhcp-ddns module. The @ref isc::dhcp_ddns::NameChangeRequest object
  90. represents changes to the DNS bindings, related to acquisition, renewal or
  91. release of the DHCP lease. The b10-dhcp4 module implements the simple FIFO queue
  92. of the NameChangeRequest objects. The module logic, which processes the incoming
  93. DHCPv4 Client FQDN and Host Name Options puts these requests into the FIFO queue.
  94. @todo Currently the FIFO queue is not processed after the NameChangeRequests are
  95. generated and added to it. In the future implementation steps it is planned to
  96. create a code which will check if there are any outstanding requests in the queue
  97. and send them to the b10-dhcp-ddns module when server is idle waiting for DHCP
  98. messages.
  99. When client gets an address from the server, a DHCPv4 server may generate 0, 1
  100. or 2 NameChangeRequests during single message processing. Server generates no
  101. NameChangeRequests if it is not configured to update DNS or it rejects the DNS
  102. update for any other reason.
  103. Server may generate 1 NameChangeRequest in a case when client acquired a new
  104. lease or it releases an existing lease. In the former case, the NameChangeRequest
  105. type is CHG_ADD, which indicates that the b10-dhcp-ddns module should add a new
  106. DNS binding for the client, and it is assumed that there is no DNS binding for
  107. this client already. In the latter case, the NameChangeRequest type is CHG_REMOVE
  108. to indicate to the b10-dhcp-ddns module that an existing DNS binding should be
  109. removed from the DNS. The binding consists of the forward and reverse mapping.
  110. The server may only remove the mapping which it had added. Therefore, the lease
  111. database holds the information which updates (no update, reverse only update,
  112. forward only update or both reverse and forward update) have been performed when
  113. the lease was acquired or renewed. Server checks this information to make a
  114. decision which mapping it is supposed to remove when lease is released.
  115. Server may generate 2 NameChangeRequests in case a client is renewing a lease and
  116. it already has a DNS binding for that lease. The DHCPv4 server will check if
  117. there is an existing lease for the client which has sent a message and if DNS
  118. Updates had been performed for this lease. If the notion of client's FQDN changes,
  119. comparing to the information stored in the lease database, the DHCPv4 has to
  120. remove an existing binding from the DNS and then add a new binding according to
  121. the new FQDN information received from the client. If the client's FQDN
  122. information (including the client's name and type of update performed) doesn't
  123. change comparing to the NameChangeRequest is not generated.
  124. The DHCPv4 Client FQDN %Option comprises flags which communicate to the server
  125. what updates (if any) client expects the server to perform. Server may be
  126. configured to obey client's preference or to do FQDN processing in a different way.
  127. If the server overrides client's preference it will communicate it by sending
  128. the DHCPv4 Client FQDN %Option in its responses to a client, with the appropriate
  129. flags set.
  130. @todo Note, that current implementation doesn't allow configuration of the
  131. server's behaviour with respect to DNS Updates. This is planned for the future.
  132. The default behaviour is constituted by the set of constants defined in the
  133. (upper part of) dhcp4_srv.cc file. Once the configuration is implemented,
  134. these constants will be removed.
  135. @section dhcpv4Classifier DHCPv4 Client Classification
  136. Kea DHCPv4 server currently supports simplified client classification. It is called
  137. "simplified", because the incoming packets are classified based on the content
  138. of the vendor class (60) option. More flexible classification is planned, but there
  139. are no specific development dates agreed.
  140. For each incoming packet, @ref isc::dhcp::Dhcpv4Srv::classifyPacket() method is called.
  141. It attempts to extract content of the vendor class option and interpret as a name
  142. of the class. For now, the code has been tested with two classes used in cable modem
  143. networks: eRouter1.0 and docsis3.0, but any other content of the vendor class option will
  144. be interpreted as a class name.
  145. In principle any given packet can belong to zero or more classes. As the current
  146. classifier is very modest, there's only one way to assign a class (based on vendor class
  147. option), the ability to assign more than one class to a packet is not yet exercised.
  148. Neverthless, there is such a possibility and it will be used in a near future. To
  149. check whether a packet belongs to given class, isc::dhcp::Pkt4::inClass method should
  150. be used.
  151. Currently there is a short code section that alternates packet processing depending on
  152. which class it belongs to. It is planned to move that capability to an external hook
  153. library. See ticket #3275. The class specific behavior is:
  154. - docsis3.0 packets have siaddr (next server) field set
  155. - docsis3.0 packets have file field set to the content of the boot-file-name option
  156. - eRouter1.0 packets have siaddr (next server) field cleared
  157. Aforementioned modifications are conducted in @ref isc::dhcp::Dhcpv4Srv::classSpecificProcessing.
  158. It is possible to define class restrictions in subnet, so a given subnet is only
  159. accessible to clients that belong to a given class. That is implemented as isc::dhcp::Pkt4::classes_
  160. being passed in isc::dhcp::Dhcpv4Srv::selectSubnet() to isc::dhcp::CfgMgr::getSubnet4().
  161. Currently this capability is usable, but the number of scenarios it supports is
  162. limited.
  163. @section dhcpv4ConfigBackend Configuration backend for DHCPv4
  164. There are many theoretical ways in which server configuration can be stored. Kea 0.8 and
  165. earlier versions used BIND10 framework and its internal storage for DHCPv6 server configuration.
  166. The legacy ISC-DHCP implementation uses flat files. Configuration stored in JSON files is
  167. becoming more and more popular among various projects. There are unofficial patches for
  168. ISC-DHCP that keep parts of the configuration in LDAP. It was also suggested that in some
  169. cases it would be convenient to keep configuration in XML files.
  170. Kea 0.9 introduces configuration backends that are switchable during compilation phase.
  171. There is a new parameter for configure script: --with-kea-config. It currently supports
  172. two values: BUNDY and JSON.
  173. BUNDY (which is the default value as of May 2014) means that Kea4 is linked with the
  174. Bundy (former BIND10) configuration backend that connects to the BIND10 framework and in general works
  175. exactly the same as Kea 0.8 and earlier versions. The benefits of that backend are uniform
  176. integration with Bundy/BIND10 framework, easy on-line reconfiguration using bindctl, available
  177. RESTful API. On the other hand, it requires the whole heavy Bundy framework that requires
  178. Python3 to be present. That framework is going away with the release of Kea 0.9.
  179. JSON is a new configuration backend that causes Kea to read JSON configuration file from
  180. disk. It does not require any framework and thus is considered more lightweight. It will
  181. allow dynamic on-line reconfiguration, but will lack remote capabilities (i.e. no RESTful
  182. API). This configuration backend is expected to be the default for upcoming Kea 0.9. It
  183. requires <tt> -c config-file </tt> command-line option.
  184. Internally, configuration backends are implemented as different implementations of the
  185. isc::dhcp::ControlledDhcpv4Srv class, stored in {kea,bundy}_controller.cc files. Depending on
  186. the choice made by ./configure script, only one of those files is compiled and linked.
  187. There are backend specific tests in src/bin/dhcp4/tests/{kea,bundy}_controller_unittest.cc.
  188. Only tests specific to selected backend are linked and executed during make distcheck.
  189. While it is unlikely that ISC will support more than one backend at any given time, there
  190. are several aspects that make that approach appealing in the long term. First, having
  191. two backends is essential during transition time, where both old and new backend is used.
  192. Second, there are external organizations that develop and presumably maintain LDAP backend
  193. for ISC-DHCP. Is at least possible that similar will happen for Kea. Finally, if we ever
  194. extend the isc::dhcp::CfgMgr with configuration export, this approach could be used as
  195. a migration tool.
  196. @section dhcpv4Other Other DHCPv4 topics
  197. For hooks API support in DHCPv4, see @ref dhcpv4Hooks.
  198. */