config-backend.dox 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Copyright (C) 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 configBackend Kea Configuration Backends
  16. @section configBackendIntro Introduction
  17. Kea is a flexible DHCP protocol engine. It offers a selection of lease database
  18. backends, extensibility via the hooks API and the definition of custom options.
  19. Depending on the environment, one lease database backend may be better than
  20. other. Similarly, because the best way of configuring the server can depend on
  21. the environment, Kea provides different ways of obtaining configuration
  22. information, through the Configuration Backend. Since the means by which
  23. configuration information is received cannot be part of the configuration itself, it
  24. has to be chosen at the compilation time (when configuring the sources).
  25. This page explains the background to the Configuration Backend and how
  26. it is implemented. It is aimed at people who want to develop and
  27. maintain their own backends.
  28. @section configBackendMotivation Motivation for Different Backends
  29. BIND10 (the project under which the first stages of Kea were developed)
  30. used to maintain an extensive framework that was responsible for the
  31. configuration of components. After BIND10 was cancelled, two projects
  32. were created: <a href="http://kea.isc.org">Kea</a> (focused on DHCP)
  33. and <a href="http://www.bundy-dns.de">Bundy</a> (aimed at DNS). The
  34. Kea team decided to remove the BIND10 framework, while the Bundy team
  35. decided to keep it. However, even though the Kea team is focused on a
  36. backend that reads a JSON configuration file from disk, it decided to
  37. make it easy for others to use different backends.
  38. While ISC currently (May 2014) plans to maintain only one configuration backend
  39. (a JSON file read from disk), there may be other organizations (e.g.
  40. the Bundy project community) that will maintain other backends. It is quite
  41. possible that additional backends (e.g. using LDAP or XML) will be
  42. developed and maintained by other organizations.
  43. @section configBackendAdding How to Add a New Configuration Backend
  44. The configuration backend concept was designed to make external (i.e. not
  45. maintained by ISC) configurations backends easy to maintain. In particular,
  46. the set of patches vs. separate files required strongly favors separate
  47. files. This is important if an external organization wants to develop its
  48. own configuration backend and then needs to apply it every ISC release
  49. of Kea.
  50. The following steps are needed to add new configuration backend (it is assumed
  51. that the modified component is DHCPv4. Similar approach applies to other
  52. components: DHCPv6 or D2):
  53. -# Modify AC_ARG_WITH(kea-config,...) macro in configure.ac
  54. -# Add your own AM_CONDITIONAL(CONFIG_BACKEND_FOO, ...) macro in configure.ac
  55. -# Add your own conditional AC_DEFINE(CONFIG_BACKEND_FOO, ...) invocation
  56. in configure.ac
  57. -# Modify the sanity check in configure.ac to allow your configuration backend name.
  58. -# Modify src/bin/dhcp4/Makefile.am to include your own backend
  59. implementation (e.g. foo_controller.cc).
  60. -# Write your own implementation of isc::dhcp::ControlledDhcpv4Srv::init(),
  61. isc::dhcp::ControlledDhcpv4Srv::init() and isc::dhcp::ControlledDhcpv4Srv::cleanup()
  62. and put it in foo_controller.cc
  63. Optionally you can also:
  64. -# Modify src/bin/dhcp4/tests/Makefile.am to include foo_controller_unittest.cc if
  65. selected backend is foo.
  66. -# Implement unit-tests for your backend in foo_controller_unittest.cc file.
  67. @section configBackendJSONDesign The JSON Configuration Backend
  68. The following are some considerations that shaped the design of the configuration
  69. backend framework.
  70. -# A new parameter called --with-kea-config was implemented in the
  71. configure script. It allows the selection at compilation time of how the
  72. servers will be configured. Currently (June 2014),
  73. there are two values: JSON (the default, read configuration from a JSON file)
  74. and BUNDY (use the BUNDY/BIND10 framework). The Bundy/BIND10 framework was removed
  75. from the Kea repository. Other projects
  76. (e.g. Bundy) who want to maintain Bundy framework, are advised to maintain
  77. the framework in their repositories, import Kea modules and compile them
  78. with Bundy backend.
  79. This switchable backend concept is quite simple. There are just different
  80. implementations of ControlledXSrv class, each backend keeping its code
  81. in a separate file. It is a matter of compiling/linking
  82. one file or another. Hence it is easy to remove the old backend (and for
  83. external projects, like Bundy, to keep it if they desire so). It is also easy
  84. for other organizations to add and maintain their own backends (e.g. LDAP).
  85. -# Each backend must use the common code for configuration and command
  86. processing callbacks. They all assume that JSON formatted parameters are sent
  87. and they are expected to return well formatted JSON responses. The exact
  88. format of configuration and commands is module specific.
  89. -# After Kea 0.9 is released, a form of secure socket will be implemented
  90. through which commands can be sent. Whatever the design, it will allow the
  91. sending of configurations and commands in JSON format and the receiving of
  92. responses. Once that is done, Kea will have the same capability the BIND10
  93. framework to send additional parameters. One obvious use case will be to send
  94. a new configuration file name as the parameter for "reload".
  95. -# A command handler needs to be added for reading the configuration from a
  96. file. Its main responsibility is to load the configuration and process
  97. it. The JSON backend must call that handler when starting up the server.
  98. This is implemented in configure() function in kea_controller.cc files
  99. in src/bin/dhcp4 and src/bin/dhcp6 directories.
  100. -# Extend the existing JSON parser. The current JSON parser in @ref
  101. isc::data::Element::fromJSON() needs to be extended to allow optional
  102. preprocessing. For now that capability simply removes whole-line
  103. comments staring with the hash character, but it is expected to grow over
  104. time (in-line comments and file inclusions are the obvious envisaged
  105. additions). This is implemented in @ref isc::data::Element::fromJSONFile.
  106. -# Implement a common base class for the Kea4, Kea6, and D2 servers. Some
  107. operations will be common for all three components: logger initialization,
  108. handling and, at some future point, control socket. This calls for a small
  109. base class that @ref isc::dhcp::Dhcpv4Srv "Dhcpv4Srv", @ref
  110. isc::dhcp::Dhcpv6Srv "Dhcpv6Srv" and the @ref isc::d2::D2Controller
  111. "D2Controller" classes can use. It is expected that the base class (@ref
  112. isc::dhcp::Daemon) will be a small one but will grow over time as the code is
  113. unified. This has been implemented in @ref isc::dhcp::Daemon.
  114. -# A way is needed to initialize stand-alone logging (i.e. each
  115. Kea component will initialize it on its own).
  116. -# The current format of the BIND10 configuration file (BIND 10 stored its
  117. configuration in (installation directory)/var/bind10/b10-config.db) will be
  118. retained as the configuration file format. Its actual naming is now arbitrary
  119. and left up to the user (it is passed as a parameter to the -c command line
  120. option). From the implementation perspective, this is slight change
  121. from the BIND10 days, as back then a subset of the configuration was received by
  122. the daemon processes. Nowadays the whole configuration is pased. To take a
  123. specific example, the following is how b10-config.db looks today:
  124. @code
  125. {
  126. "Init": { ... }
  127. "Dhcp4": {
  128. "subnet4" { subnet definitions here },
  129. "option-data" { option data here },
  130. "interfaces": [ "eth0" ],
  131. ...
  132. },
  133. "Dhcp6": {
  134. "subnet6" { subnet definitions here },
  135. "option-data" { option data here },
  136. "interfaces": [ "eth0" ],
  137. ...
  138. },
  139. "Logging": {
  140. "Loggers": [{"name": *, "severity": "DEBUG" }]
  141. }
  142. }
  143. @endcode
  144. <br/>
  145. The Kea components used to receive only relevant parts of it (e.g. Kea4
  146. received config that contained content of the Dhcp4 element). Now they
  147. will receive all of it. The modification in the code to handle this
  148. is really minor: just iterate over the top level elements and pick the appropriate
  149. tree (or get the element by name). Also, that approach makes the logging
  150. initialization code very easy to share among Kea4, Kea6 and D2.
  151. -# The .spec files used in BIND 10 by the control program to validate commands
  152. will be retained. They will be kept and maintained even though no use of
  153. them is planned. At some future time syntax validation may be implemented,
  154. although it is out of scope for Kea 0.9 (and probably
  155. for 1.0 as it is pretty big task).
  156. -# Addition of a shell script to start/stop Kea4,Kea6 and D2. There will be a script that will
  157. start, stop and reconfigure the daemons. Its only
  158. job will be to pass the configuration file to each daemon and remember its PID file, so
  159. that sending signals will be be possible (for configuration reload or shutdown). Optionally,
  160. it could also print out a status based on PID, but that may be tricky to
  161. implement in a portable way. The minimum set of commands will be:
  162. -# Start the processes
  163. - eventually based on configuration, initially start them all
  164. - it could launch a nanny script which restarts them on a crash (past 0.9)
  165. -# Prompt the processes to reload configuration
  166. - for now it will be a matter of sending singal to the right process
  167. - this could also decide if D2 should still be running or not, and react accordingly (post 0.9)
  168. -# Stop the processes in an orderly fashion
  169. -# Perhaps return status of each process
  170. This script has been implemented in src/bin/keactl/keactl.
  171. */